-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature param for custom ad notification dark mode background color.
- Loading branch information
Showing
8 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/views/brave_ads/color_util.h" | ||
|
||
#include "base/strings/string_number_conversions.h" | ||
#include "base/strings/string_piece.h" | ||
|
||
namespace brave_ads { | ||
|
||
bool RgbStringToSkColor(base::StringPiece rgb, SkColor* color) { | ||
DCHECK(color); | ||
|
||
// Expect three RGB color components with length == 2, e.g. 42fe4c. | ||
constexpr size_t kColorComponentsCount = 3; | ||
constexpr size_t kColorComponentLen = 2; | ||
|
||
if (rgb.size() != kColorComponentsCount * kColorComponentLen) { | ||
return false; | ||
} | ||
|
||
uint32_t components[kColorComponentsCount]; | ||
for (size_t i = 0; i < kColorComponentsCount; ++i) { | ||
const size_t beg = kColorComponentLen * i; | ||
uint32_t component = 0; | ||
if (!base::HexStringToUInt(rgb.substr(beg, kColorComponentLen), | ||
&component)) { | ||
return false; | ||
} | ||
components[i] = component; | ||
} | ||
|
||
*color = SkColorSetRGB(components[0], components[1], components[2]); | ||
return true; | ||
} | ||
|
||
} // namespace brave_ads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_VIEWS_BRAVE_ADS_COLOR_UTIL_H_ | ||
#define BRAVE_BROWSER_UI_VIEWS_BRAVE_ADS_COLOR_UTIL_H_ | ||
|
||
#include "base/strings/string_piece_forward.h" | ||
#include "third_party/skia/include/core/SkColor.h" | ||
|
||
namespace brave_ads { | ||
|
||
bool RgbStringToSkColor(base::StringPiece rgb, SkColor* color); | ||
|
||
} // namespace brave_ads | ||
|
||
#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_ADS_COLOR_UTIL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/browser/ui/views/brave_ads/color_util.h" | ||
#include "base/strings/string_piece.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "third_party/skia/include/core/SkColor.h" | ||
|
||
// npm run test -- brave_unit_tests --filter=ColorUtilTest.* | ||
|
||
TEST(ColorUtilTest, CheckRgbStringToSkColor) { | ||
SkColor color; | ||
EXPECT_TRUE(brave_ads::RgbStringToSkColor("42fe4c", &color)); | ||
EXPECT_EQ(SkColorSetRGB(0x42, 0xfe, 0x4c), color); | ||
|
||
EXPECT_FALSE(brave_ads::RgbStringToSkColor("", &color)); | ||
EXPECT_FALSE(brave_ads::RgbStringToSkColor("42fe4", &color)); | ||
EXPECT_FALSE(brave_ads::RgbStringToSkColor("h2fe4c", &color)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters