-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #351 from brave/brave_theme
Brave theme
- Loading branch information
Showing
18 changed files
with
275 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
source_set("themes") { | ||
sources = [ | ||
"brave_theme_service.cc", | ||
"brave_theme_service.h", | ||
"brave_theme_service_win.cc", | ||
"brave_theme_service_win.h", | ||
"theme_properties.cc", | ||
"theme_properties.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//brave/common", | ||
"//chrome/common", | ||
"//components/prefs", | ||
"//components/pref_registry", | ||
"//components/version_info", | ||
"//skia", | ||
] | ||
} |
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,51 @@ | ||
/* 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_theme_service.h" | ||
|
||
#include "brave/browser/themes/theme_properties.h" | ||
#include "brave/common/pref_names.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/themes/theme_service_factory.h" | ||
#include "components/pref_registry/pref_registry_syncable.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
// static | ||
void BraveThemeService::RegisterProfilePrefs( | ||
user_prefs::PrefRegistrySyncable* registry) { | ||
registry->RegisterIntegerPref(kBraveThemeType, BRAVE_THEME_TYPE_DEFAULT); | ||
} | ||
|
||
// static | ||
BraveThemeService::BraveThemeType BraveThemeService::GetBraveThemeType(Profile* profile) { | ||
return static_cast<BraveThemeService::BraveThemeType>( | ||
profile->GetPrefs()->GetInteger(kBraveThemeType)); | ||
} | ||
|
||
BraveThemeService::BraveThemeService() {} | ||
|
||
BraveThemeService::~BraveThemeService() {} | ||
|
||
void BraveThemeService::Init(Profile* profile) { | ||
brave_theme_type_pref_.Init( | ||
kBraveThemeType, | ||
profile->GetPrefs(), | ||
base::Bind(&BraveThemeService::OnPreferenceChanged, | ||
base::Unretained(this))); | ||
ThemeService::Init(profile); | ||
} | ||
|
||
SkColor BraveThemeService::GetDefaultColor(int id, bool incognito) const { | ||
const base::Optional<SkColor> braveColor = | ||
MaybeGetDefaultColorForBraveUi(id, incognito, profile()); | ||
if (braveColor) | ||
return braveColor.value(); | ||
|
||
return ThemeService::GetDefaultColor(id, incognito); | ||
} | ||
|
||
void BraveThemeService::OnPreferenceChanged(const std::string& pref_name) { | ||
DCHECK(pref_name == kBraveThemeType); | ||
NotifyThemeChanged(); | ||
} |
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,44 @@ | ||
/* 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_THEME_SERVICE_H_ | ||
#define BRAVE_BROWSER_THEMES_BRAVE_THEME_SERVICE_H_ | ||
|
||
#include "chrome/browser/themes/theme_service.h" | ||
#include "components/prefs/pref_member.h" | ||
|
||
namespace user_prefs { | ||
class PrefRegistrySyncable; | ||
} | ||
|
||
class BraveThemeService : public ThemeService { | ||
public: | ||
enum BraveThemeType { | ||
BRAVE_THEME_TYPE_DEFAULT, // Choose theme by channel | ||
BRAVE_THEME_TYPE_DARK, // Use dark theme regardless of channel | ||
BRAVE_THEME_TYPE_LIGHT, // Use light theme regardless of channel | ||
}; | ||
|
||
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | ||
static BraveThemeType GetBraveThemeType(Profile* profile); | ||
|
||
BraveThemeService(); | ||
~BraveThemeService() override; | ||
|
||
// ThemeService overrides: | ||
void Init(Profile* profile) override; | ||
|
||
protected: | ||
// ThemeService overrides: | ||
SkColor GetDefaultColor(int id, bool incognito) const override; | ||
|
||
private: | ||
void OnPreferenceChanged(const std::string& pref_name); | ||
|
||
IntegerPrefMember brave_theme_type_pref_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BraveThemeService); | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_THEMES_BRAVE_THEME_SERVICE_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,46 @@ | ||
/* 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_theme_service.h" | ||
#include "brave/common/pref_names.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/themes/theme_properties.h" | ||
#include "chrome/browser/themes/theme_service.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
using BraveThemeServiceTest = InProcessBrowserTest; | ||
using BTS = BraveThemeService; | ||
|
||
namespace { | ||
void SetBraveThemeType(Profile* profile, BTS::BraveThemeType type) { | ||
profile->GetPrefs()->SetInteger(kBraveThemeType, type); | ||
} | ||
} // namespace | ||
|
||
IN_PROC_BROWSER_TEST_F(BraveThemeServiceTest, BraveThemeChangeTest) { | ||
Profile* profile = browser()->profile(); | ||
#if defined(OFFICIAL_BUILD) | ||
const SkColor light_frame_color = SkColorSetRGB(0xD8, 0xDE, 0xE1); | ||
#endif | ||
const SkColor dark_frame_color = SkColorSetRGB(0x58, 0x5B, 0x5E); | ||
|
||
// Check default type is set initially. | ||
EXPECT_EQ(BTS::BRAVE_THEME_TYPE_DEFAULT, BTS::GetBraveThemeType(profile)); | ||
|
||
const ui::ThemeProvider& tp = ThemeService::GetThemeProviderForProfile(profile); | ||
SetBraveThemeType(browser()->profile(), BTS::BRAVE_THEME_TYPE_LIGHT); | ||
EXPECT_EQ(BTS::BRAVE_THEME_TYPE_LIGHT, BTS::GetBraveThemeType(profile)); | ||
#if defined(OFFICIAL_BUILD) | ||
EXPECT_EQ(light_frame_color, tp.GetColor(ThemeProperties::COLOR_FRAME)); | ||
#else | ||
// Non-official build always uses dark theme. | ||
EXPECT_EQ(dark_frame_color, tp.GetColor(ThemeProperties::COLOR_FRAME)); | ||
#endif | ||
|
||
SetBraveThemeType(browser()->profile(), BTS::BRAVE_THEME_TYPE_DARK); | ||
EXPECT_EQ(BTS::BRAVE_THEME_TYPE_DARK, BTS::GetBraveThemeType(profile)); | ||
EXPECT_EQ(dark_frame_color, tp.GetColor(ThemeProperties::COLOR_FRAME)); | ||
} |
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,16 @@ | ||
/* 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_theme_service_win.h" | ||
|
||
#include "chrome/browser/themes/theme_properties.h" | ||
|
||
SkColor BraveThemeServiceWin::GetDefaultColor(int id, bool incognito) const { | ||
// Prevent dcheck in chrome/browser/themes/theme_properties.cc(384) | ||
// It assumes this id handled in theme service. | ||
if (DwmColorsAllowed() && id == ThemeProperties::COLOR_ACCENT_BORDER) | ||
return dwm_accent_border_color_; | ||
// Skip ThemeServiceWin::GetDefaultColor() to prevent using dwm frame color. | ||
return BraveThemeService::GetDefaultColor(id, incognito); | ||
} |
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,22 @@ | ||
/* 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_THEME_SERVICE_WIN_H_ | ||
#define BRAVE_BROWSER_THEMES_BRAVE_THEME_SERVICE_WIN_H_ | ||
|
||
#include "chrome/browser/themes/theme_service_win.h" | ||
|
||
class BraveThemeServiceWin : public ThemeServiceWin { | ||
public: | ||
BraveThemeServiceWin() = default; | ||
~BraveThemeServiceWin() override = default; | ||
|
||
private: | ||
// ThemeServiceWin overrides: | ||
SkColor GetDefaultColor(int id, bool incognito) const override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BraveThemeServiceWin); | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_THEMES_BRAVE_THEME_SERVICE_WIN_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
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 was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
chromium_src/chrome/browser/themes/theme_service_aurax11.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,10 @@ | ||
/* 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_theme_service.h" | ||
|
||
#undef ThemeService | ||
#define ThemeService BraveThemeService | ||
#include "../../../../../chrome/browser/themes/theme_service_aurax11.h" | ||
#undef ThemeService |
18 changes: 18 additions & 0 deletions
18
chromium_src/chrome/browser/themes/theme_service_factory.cc
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 @@ | ||
/* 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 "build/build_config.h" | ||
#include "chrome/browser/themes/theme_service.h" | ||
|
||
#if defined(OS_WIN) | ||
#include "brave/browser/themes/brave_theme_service_win.h" | ||
#undef ThemeServiceWin | ||
#define ThemeServiceWin BraveThemeServiceWin | ||
#elif !defined(USE_X11) | ||
#include "brave/browser/themes/brave_theme_service.h" | ||
#undef ThemeService | ||
#define ThemeService BraveThemeService | ||
#endif | ||
|
||
#include "../../../../../chrome/browser/themes/theme_service_factory.cc" |
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,13 @@ | ||
/* 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_theme_service.h" | ||
|
||
#undef ThemeService | ||
#define ThemeService BraveThemeService | ||
|
||
#include "../../../../../chrome/browser/themes/theme_service_win.h" | ||
|
||
#undef ThemeService | ||
#define ThemeService ThemeService |
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 was deleted.
Oops, something went wrong.
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,12 @@ | ||
diff --git a/chrome/browser/themes/theme_service_win.h b/chrome/browser/themes/theme_service_win.h | ||
index eba1cb2596d71b91e06183209503f3fc83b0e593..e6261a982859a6a66caa00d362f290d247ce7922 100644 | ||
--- a/chrome/browser/themes/theme_service_win.h | ||
+++ b/chrome/browser/themes/theme_service_win.h | ||
@@ -18,6 +18,7 @@ class ThemeServiceWin : public ThemeService { | ||
~ThemeServiceWin() override; | ||
|
||
private: | ||
+ friend class BraveThemeServiceWin; | ||
// ThemeService: | ||
bool ShouldUseNativeFrame() const override; | ||
SkColor GetDefaultColor(int id, bool incognito) const override; |
Oops, something went wrong.