Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated colors that used in theme_properties to color provider pipeline (uplift to 1.41.x) #13865

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/themes/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ source_set("themes") {
"//brave/components/sidebar/buildflags",
"//brave/components/speedreader:buildflags",
"//chrome/browser:theme_properties",
"//chrome/browser/ui/color:mixers",
"//skia:skia",
"//ui/gfx:color_utils",
"//ui/native_theme:native_theme",
Expand Down
23 changes: 23 additions & 0 deletions browser/themes/brave_private_window_theme_supplier.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2022 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/themes/brave_private_window_theme_supplier.h"

#include "brave/browser/ui/color/brave_color_mixer.h"
#include "ui/color/color_provider_manager.h"

BravePrivateWindowThemeSupplier::BravePrivateWindowThemeSupplier(
bool private_window)
: CustomThemeSupplier(ThemeType::kAutogenerated),
for_private_window_(private_window) {}

BravePrivateWindowThemeSupplier::~BravePrivateWindowThemeSupplier() = default;

void BravePrivateWindowThemeSupplier::AddColorMixers(
ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) const {
for_private_window_ ? AddBravePrivateThemeColorMixer(provider, key)
: AddBraveTorThemeColorMixer(provider, key);
}
31 changes: 31 additions & 0 deletions browser/themes/brave_private_window_theme_supplier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright (c) 2022 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_THEMES_BRAVE_PRIVATE_WINDOW_THEME_SUPPLIER_H_
#define BRAVE_BROWSER_THEMES_BRAVE_PRIVATE_WINDOW_THEME_SUPPLIER_H_

#include "chrome/browser/themes/custom_theme_supplier.h"

// A theme supplier for private (or tor) window.
class BravePrivateWindowThemeSupplier : public CustomThemeSupplier {
public:
explicit BravePrivateWindowThemeSupplier(bool private_window);

BravePrivateWindowThemeSupplier(const BravePrivateWindowThemeSupplier&) =
delete;
BravePrivateWindowThemeSupplier& operator=(
const BravePrivateWindowThemeSupplier&) = delete;

protected:
~BravePrivateWindowThemeSupplier() override;

void AddColorMixers(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) const override;

// false if this is for tor window.
bool for_private_window_ = true;
};

#endif // BRAVE_BROWSER_THEMES_BRAVE_PRIVATE_WINDOW_THEME_SUPPLIER_H_
6 changes: 1 addition & 5 deletions browser/themes/brave_theme_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/browser/themes/brave_theme_helper_utils.h"
#include "brave/browser/themes/theme_properties.h"
#include "brave/browser/ui/color/color_palette.h"
#include "brave/components/brave_vpn/buildflags/buildflags.h"
#include "brave/components/sidebar/buildflags/buildflags.h"
#include "build/build_config.h"
Expand All @@ -23,11 +24,6 @@

namespace {

// TODO(simonhong): Get colors from brave's palette.
// Omnibox text colors
const SkColor kDarkOmniboxText = SkColorSetRGB(0xff, 0xff, 0xff);
const SkColor kLightOmniboxText = SkColorSetRGB(0x42, 0x42, 0x42);

#if BUILDFLAG(IS_LINUX)
bool IsUsingSystemTheme(const CustomThemeSupplier* theme_supplier) {
return theme_supplier &&
Expand Down
17 changes: 17 additions & 0 deletions browser/themes/brave_theme_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/browser/themes/brave_theme_helper_utils.h"
#include "brave/browser/themes/theme_properties.h"
#include "brave/browser/ui/color/color_palette.h"
#include "brave/components/constants/pref_names.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -20,6 +21,7 @@
#include "content/public/test/browser_test.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
#include "ui/color/color_provider.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h"

Expand Down Expand Up @@ -188,6 +190,21 @@ IN_PROC_BROWSER_TEST_F(BraveThemeServiceTest, OmniboxColorTest) {
tp->GetColor(ThemeProperties::COLOR_OMNIBOX_RESULTS_BG));
}

// Check some colors from color provider pipeline.
IN_PROC_BROWSER_TEST_F(BraveThemeServiceTest, ColorProviderTest) {
auto* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
auto* cp = browser_view->GetColorProvider();
SkColor frame_active_color = cp->GetColor(ui::kColorFrameActive);
EXPECT_TRUE(frame_active_color == kLightFrame ||
frame_active_color == kDarkFrame);

auto* private_browser = CreateIncognitoBrowser();
browser_view = BrowserView::GetBrowserViewForBrowser(private_browser);
cp = browser_view->GetColorProvider();
frame_active_color = cp->GetColor(ui::kColorFrameActive);
EXPECT_EQ(kPrivateFrame, frame_active_color);
}

// Some tests are failing for Windows x86 CI,
// See https://github.com/brave/brave-browser/issues/22767
#if BUILDFLAG(IS_WIN) && defined(ARCH_CPU_X86)
Expand Down
5 changes: 5 additions & 0 deletions browser/themes/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ brave_browser_themes_deps = []
if (!is_android) {
brave_browser_themes_sources += [
"//brave/browser/themes/brave_dark_mode_utils.cc",
"//brave/browser/themes/brave_private_window_theme_supplier.cc",
"//brave/browser/themes/brave_private_window_theme_supplier.h",
"//brave/browser/themes/brave_theme_helper.cc",
"//brave/browser/themes/brave_theme_helper.h",
"//brave/browser/themes/brave_theme_helper_utils.cc",
Expand All @@ -31,9 +33,12 @@ if (!is_android) {
"//brave/components/brave_vpn/buildflags",
"//brave/components/constants",
"//brave/components/sidebar/buildflags",
"//chrome/browser/ui",
"//chrome/browser/ui/color:color_headers",
"//chrome/common",
"//components/pref_registry",
"//components/prefs",
"//ui/color",
"//ui/gfx",
"//ui/native_theme",
]
Expand Down
22 changes: 5 additions & 17 deletions browser/themes/theme_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
#include "brave/browser/themes/theme_properties.h"

#include "base/notreached.h"
#include "brave/browser/ui/color/color_palette.h"
#include "chrome/browser/themes/theme_properties.h"
#include "ui/gfx/color_palette.h"

namespace {

const SkColor kLightToolbar = SkColorSetRGB(0xf3, 0xf3, 0xf3);
const SkColor kLightFrame = SkColorSetRGB(0xd5, 0xd9, 0xdc);
const SkColor kLightToolbarIcon = SkColorSetRGB(0x42, 0x42, 0x42);

absl::optional<SkColor> MaybeGetDefaultColorForBraveLightUi(int id) {
switch (id) {
// Applies when the window is active, tabs and also tab bar everywhere
Expand All @@ -27,7 +24,7 @@ absl::optional<SkColor> MaybeGetDefaultColorForBraveLightUi(int id) {
// except active tab
case ThemeProperties::COLOR_FRAME_INACTIVE:
case ThemeProperties::COLOR_TAB_BACKGROUND_INACTIVE_FRAME_INACTIVE:
return color_utils::HSLShift(kLightFrame, { -1, -1, 0.6 });
return color_utils::HSLShift(kLightFrame, {-1, -1, 0.6});
// Active tab and also the URL toolbar
// Parts of this color show up as you hover over innactive tabs too
case ThemeProperties::COLOR_TOOLBAR:
Expand Down Expand Up @@ -131,10 +128,6 @@ absl::optional<SkColor> MaybeGetDefaultColorForBraveLightUi(int id) {
}
}

const SkColor kDarkToolbar = SkColorSetRGB(0x30, 0x34, 0x43);
const SkColor kDarkFrame = SkColorSetRGB(0x0C, 0x0C, 0x17);
const SkColor kDarkToolbarIcon = SkColorSetRGB(0xed, 0xed, 0xed);

absl::optional<SkColor> MaybeGetDefaultColorForBraveDarkUi(int id) {
switch (id) {
// Applies when the window is active, tabs and also tab bar everywhere
Expand All @@ -146,7 +139,7 @@ absl::optional<SkColor> MaybeGetDefaultColorForBraveDarkUi(int id) {
// except active tab
case ThemeProperties::COLOR_FRAME_INACTIVE:
case ThemeProperties::COLOR_TAB_BACKGROUND_INACTIVE_FRAME_INACTIVE:
return color_utils::HSLShift(kDarkFrame, { -1, -1, 0.6 });
return color_utils::HSLShift(kDarkFrame, {-1, -1, 0.6});
// Active tab and also the URL toolbar
// Parts of this color show up as you hover over innactive tabs too
case ThemeProperties::COLOR_TOOLBAR:
Expand Down Expand Up @@ -253,9 +246,6 @@ absl::optional<SkColor> MaybeGetDefaultColorForBraveDarkUi(int id) {
}
}

const SkColor kPrivateFrame = SkColorSetRGB(0x19, 0x16, 0x2F);
const SkColor kPrivateToolbar = SkColorSetRGB(0x32, 0x25, 0x60);

absl::optional<SkColor> MaybeGetDefaultColorForPrivateUi(int id) {
switch (id) {
// Applies when the window is active, tabs and also tab bar everywhere
Expand All @@ -267,7 +257,7 @@ absl::optional<SkColor> MaybeGetDefaultColorForPrivateUi(int id) {
// except active tab
case ThemeProperties::COLOR_FRAME_INACTIVE:
case ThemeProperties::COLOR_TAB_BACKGROUND_INACTIVE_FRAME_INACTIVE:
return color_utils::HSLShift(kPrivateFrame, { -1, -1, 0.55 });
return color_utils::HSLShift(kPrivateFrame, {-1, -1, 0.55});
// Active tab and also the URL toolbar
// Parts of this color show up as you hover over innactive tabs too
case ThemeProperties::COLOR_TOOLBAR:
Expand All @@ -293,8 +283,6 @@ absl::optional<SkColor> MaybeGetDefaultColorForPrivateUi(int id) {
}
}

const SkColor kPrivateTorFrame = SkColorSetRGB(0x19, 0x0E, 0x2A);
const SkColor kPrivateTorToolbar = SkColorSetRGB(0x49, 0x2D, 0x58);
absl::optional<SkColor> MaybeGetDefaultColorForPrivateTorUi(int id) {
switch (id) {
// Applies when the window is active, tabs and also tab bar everywhere
Expand All @@ -306,7 +294,7 @@ absl::optional<SkColor> MaybeGetDefaultColorForPrivateTorUi(int id) {
// except active tab
case ThemeProperties::COLOR_FRAME_INACTIVE:
case ThemeProperties::COLOR_TAB_BACKGROUND_INACTIVE_FRAME_INACTIVE:
return color_utils::HSLShift(kPrivateTorFrame, { -1, -1, 0.55 });
return color_utils::HSLShift(kPrivateTorFrame, {-1, -1, 0.55});
// Active tab and also the URL toolbar
// Parts of this color show up as you hover over innactive tabs too
case ThemeProperties::COLOR_TOOLBAR:
Expand Down
9 changes: 2 additions & 7 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ source_set("ui") {
"views/crash_report_permission_ask_dialog_view.h",
"views/download/brave_download_item_view.cc",
"views/download/brave_download_item_view.h",
"views/frame/brave_browser_frame.cc",
"views/frame/brave_browser_frame.h",
"views/frame/brave_browser_view.cc",
"views/frame/brave_browser_view.h",
"views/frame/brave_opaque_browser_frame_view.cc",
Expand Down Expand Up @@ -247,13 +249,6 @@ source_set("ui") {
]
}

if (is_win || is_mac) {
sources += [
"views/frame/brave_browser_frame.cc",
"views/frame/brave_browser_frame.h",
]
}

if (is_linux) {
sources += [
"views/brave_views_delegate_linux.cc",
Expand Down
137 changes: 137 additions & 0 deletions browser/ui/color/brave_color_mixer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* Copyright (c) 2022 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/color/brave_color_mixer.h"

#include "brave/browser/ui/color/color_palette.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_recipe.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"

void AddBraveLightThemeColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) {
ui::ColorMixer& mixer = provider->AddMixer();

mixer[kColorDownloadShelfButtonText] = {gfx::kBraveGrey800};

mixer[ui::kColorFrameActive] = {kLightFrame};
mixer[kColorTabBackgroundInactiveFrameActive] = {ui::kColorFrameActive};
mixer[kColorNewTabButtonBackgroundFrameActive] = {ui::kColorFrameActive};
mixer[kColorToolbarContentAreaSeparator] = {ui::kColorFrameActive};

mixer[ui::kColorFrameInactive] = {
color_utils::HSLShift(kLightFrame, {-1, -1, 0.6})};
mixer[kColorTabBackgroundInactiveFrameInactive] = {ui::kColorFrameInactive};
mixer[kColorNewTabButtonBackgroundFrameInactive] = {ui::kColorFrameInactive};

mixer[kColorToolbar] = {kLightToolbar};
mixer[kColorToolbarTopSeparatorFrameActive] = {kColorToolbar};
mixer[kColorToolbarTopSeparatorFrameInactive] = {kColorToolbar};
mixer[kColorTabBackgroundActiveFrameActive] = {kColorToolbar};
mixer[kColorTabBackgroundActiveFrameInactive] = {kColorToolbar};

mixer[kColorTabForegroundActiveFrameActive] = {kLightToolbarIcon};
mixer[kColorTabForegroundInactiveFrameActive] = {
kColorTabForegroundActiveFrameActive};
mixer[kColorBookmarkBarForeground] = {kColorTabForegroundActiveFrameActive};
mixer[kColorToolbarButtonIcon] = {kColorTabForegroundActiveFrameActive};

mixer[kColorToolbarButtonIconInactive] = {
color_utils::AlphaBlend(kLightToolbarIcon, kLightToolbar, 0.3f)};
}

void AddBraveDarkThemeColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) {
ui::ColorMixer& mixer = provider->AddMixer();

mixer[kColorDownloadShelfButtonText] = {SK_ColorWHITE};

mixer[ui::kColorFrameActive] = {kDarkFrame};
mixer[kColorTabBackgroundInactiveFrameActive] = {ui::kColorFrameActive};
mixer[kColorNewTabButtonBackgroundFrameActive] = {ui::kColorFrameActive};

mixer[ui::kColorFrameInactive] = {
color_utils::HSLShift(kDarkFrame, {-1, -1, 0.6})};
mixer[kColorTabBackgroundInactiveFrameInactive] = {ui::kColorFrameInactive};
mixer[kColorNewTabButtonBackgroundFrameInactive] = {ui::kColorFrameInactive};

mixer[kColorToolbar] = {kDarkToolbar};
mixer[kColorToolbarTopSeparatorFrameActive] = {kColorToolbar};
mixer[kColorToolbarTopSeparatorFrameInactive] = {kColorToolbar};
mixer[kColorToolbarContentAreaSeparator] = {kColorToolbar};
mixer[kColorTabStrokeFrameActive] = {kColorToolbar};
mixer[kColorTabStrokeFrameInactive] = {kColorToolbar};
mixer[kColorTabBackgroundActiveFrameActive] = {kColorToolbar};
mixer[kColorTabBackgroundActiveFrameInactive] = {kColorToolbar};

mixer[kColorTabForegroundActiveFrameActive] = {
SkColorSetRGB(0xF3, 0xF3, 0xF3)};
mixer[kColorBookmarkBarForeground] = {kColorTabForegroundActiveFrameActive};
mixer[kColorTabForegroundInactiveFrameActive] = {
kColorTabForegroundActiveFrameActive};
mixer[kColorToolbarButtonIcon] = {kDarkToolbarIcon};

mixer[kColorToolbarButtonIconInactive] = {
color_utils::AlphaBlend(kDarkToolbarIcon, kDarkToolbar, 0.3f)};
}

void AddBravePrivateThemeColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) {
AddBraveDarkThemeColorMixer(provider, key);

ui::ColorMixer& mixer = provider->AddMixer();

mixer[ui::kColorFrameActive] = {kPrivateFrame};
mixer[kColorTabBackgroundInactiveFrameActive] = {ui::kColorFrameActive};
mixer[kColorNewTabButtonBackgroundFrameActive] = {ui::kColorFrameActive};

mixer[ui::kColorFrameInactive] = {
color_utils::HSLShift(kPrivateFrame, {-1, -1, 0.55})};
mixer[kColorTabBackgroundInactiveFrameInactive] = {ui::kColorFrameInactive};
mixer[kColorNewTabButtonBackgroundFrameInactive] = {ui::kColorFrameInactive};

mixer[kColorToolbar] = {kPrivateToolbar};
mixer[kColorToolbarContentAreaSeparator] = {kColorToolbar};
mixer[kColorTabBackgroundActiveFrameActive] = {kColorToolbar};
mixer[kColorTabBackgroundActiveFrameInactive] = {kColorToolbar};

mixer[kColorTabForegroundActiveFrameActive] = {
SkColorSetRGB(0xF3, 0xF3, 0xF3)};

mixer[kColorBookmarkBarForeground] = {SkColorSetRGB(0xFF, 0xFF, 0xFF)};
mixer[kColorTabForegroundInactiveFrameActive] = {
SkColorSetRGB(0xFF, 0xFF, 0xFF)};

mixer[kColorToolbarButtonIcon] = {kDarkToolbarIcon};
mixer[kColorToolbarButtonIconInactive] = {
color_utils::AlphaBlend(kDarkToolbarIcon, kPrivateToolbar, 0.3f)};
}

void AddBraveTorThemeColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) {
AddBravePrivateThemeColorMixer(provider, key);

ui::ColorMixer& mixer = provider->AddMixer();

mixer[ui::kColorFrameActive] = {kPrivateTorFrame};
mixer[kColorTabBackgroundInactiveFrameActive] = {ui::kColorFrameActive};
mixer[kColorNewTabButtonBackgroundFrameActive] = {ui::kColorFrameActive};

mixer[ui::kColorFrameInactive] = {
color_utils::HSLShift(kPrivateTorFrame, {-1, -1, 0.55})};
mixer[kColorTabBackgroundInactiveFrameInactive] = {ui::kColorFrameInactive};
mixer[kColorNewTabButtonBackgroundFrameInactive] = {ui::kColorFrameInactive};

mixer[kColorToolbar] = {kPrivateTorToolbar};
mixer[kColorToolbarContentAreaSeparator] = {kColorToolbar};
mixer[kColorTabBackgroundActiveFrameActive] = {kColorToolbar};
mixer[kColorTabBackgroundActiveFrameInactive] = {kColorToolbar};

mixer[kColorToolbarButtonIconInactive] = {
color_utils::AlphaBlend(kDarkToolbarIcon, kPrivateTorToolbar, 0.3f)};
}
Loading