Chromium Code Reviews| Index: chrome/browser/themes/theme_service_aurax11.cc |
| diff --git a/chrome/browser/themes/theme_service_aurax11.cc b/chrome/browser/themes/theme_service_aurax11.cc |
| index fe1c3de8d4deac2e0b02877a185ecdcc17888704..3fb9e0578a11937bbbb7cda9f20ae8926414d799 100644 |
| --- a/chrome/browser/themes/theme_service_aurax11.cc |
| +++ b/chrome/browser/themes/theme_service_aurax11.cc |
| @@ -7,79 +7,80 @@ |
| #include "base/bind.h" |
| #include "base/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/themes/custom_theme_provider.h" |
| #include "chrome/common/pref_names.h" |
| #include "ui/gfx/image/image.h" |
| #include "ui/linux_ui/linux_ui.h" |
| -ThemeServiceAuraX11::ThemeServiceAuraX11() |
| - : use_system_theme_(false) { |
| -} |
| +namespace { |
| -ThemeServiceAuraX11::~ThemeServiceAuraX11() {} |
| +class NativeThemeX11 : public CustomThemeProvider { |
| + public: |
| + explicit NativeThemeX11(PrefService* pref_service); |
| -void ThemeServiceAuraX11::Init(Profile* profile) { |
| - registrar_.Init(profile->GetPrefs()); |
| - registrar_.Add(prefs::kUsesSystemTheme, |
| - base::Bind(&ThemeServiceAuraX11::OnUsesSystemThemeChanged, |
| - base::Unretained(this))); |
| - use_system_theme_ = profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
|
pkotwicz
2013/07/19 05:54:13
kUsesSystemTheme confuses me. I will dig deeper to
Adrian Kuegel
2013/07/19 13:54:39
I hadn't looked into it, I just tried to replicate
pkotwicz
2013/07/19 18:33:20
I understand now.
For some context, I was confused
|
| + // Overridden from CustomThemeProvider: |
| + virtual void StartUsingTheme() OVERRIDE; |
| + virtual void StopUsingTheme() OVERRIDE; |
| + virtual gfx::Image GetImageNamed(int id) OVERRIDE; |
| + virtual bool GetColor(int id, SkColor* color) const OVERRIDE; |
| + virtual bool HasCustomImage(int id) const OVERRIDE; |
| - ThemeService::Init(profile); |
| -} |
| + private: |
| + virtual ~NativeThemeX11(); |
| -gfx::Image ThemeServiceAuraX11::GetImageNamed(int id) const { |
| - const ui::LinuxUI* linux_ui = ui::LinuxUI::instance(); |
| - if (use_system_theme_ && linux_ui) { |
| - gfx::Image image = linux_ui->GetThemeImageNamed(id); |
| - if (!image.IsEmpty()) |
| - return image; |
| - } |
| + // These are just reference pointers. |
|
pkotwicz
2013/07/19 05:54:13
Nit: comment that the pointers are not owned inste
Adrian Kuegel
2013/07/19 13:54:39
Done.
|
| + const ui::LinuxUI* const linux_ui_; |
| + PrefService* const pref_service_; |
| - return ThemeService::GetImageNamed(id); |
| -} |
| + DISALLOW_COPY_AND_ASSIGN(NativeThemeX11); |
| +}; |
| -SkColor ThemeServiceAuraX11::GetColor(int id) const { |
| - const ui::LinuxUI* linux_ui = ui::LinuxUI::instance(); |
| - SkColor color; |
| - if (use_system_theme_ && linux_ui && linux_ui->GetColor(id, &color)) |
| - return color; |
| +NativeThemeX11::NativeThemeX11(PrefService* pref_service) |
| + : CustomThemeProvider(NATIVE_X11), |
| + linux_ui_(ui::LinuxUI::instance()), |
| + pref_service_(pref_service) {} |
| - return ThemeService::GetColor(id); |
| -} |
| +NativeThemeX11::~NativeThemeX11() {} |
| -bool ThemeServiceAuraX11::HasCustomImage(int id) const { |
| - const ui::LinuxUI* linux_ui = ui::LinuxUI::instance(); |
| - if (use_system_theme_ && linux_ui) |
| - return linux_ui->HasCustomImage(id); |
| +void NativeThemeX11::StartUsingTheme() { |
| + pref_service_->SetBoolean(prefs::kUsesSystemTheme, true); |
| +} |
| - return ThemeService::HasCustomImage(id); |
| +void NativeThemeX11::StopUsingTheme() { |
| + pref_service_->SetBoolean(prefs::kUsesSystemTheme, false); |
| } |
| -void ThemeServiceAuraX11::SetTheme(const extensions::Extension* extension) { |
| - profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); |
| - ThemeService::SetTheme(extension); |
| +gfx::Image NativeThemeX11::GetImageNamed(int id) { |
| + return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image(); |
| } |
| -void ThemeServiceAuraX11::UseDefaultTheme() { |
| - profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); |
| - ThemeService::UseDefaultTheme(); |
| +bool NativeThemeX11::GetColor(int id, SkColor* color) const { |
| + return linux_ui_ && linux_ui_->GetColor(id, color); |
| } |
| -void ThemeServiceAuraX11::SetNativeTheme() { |
| - profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); |
| - ClearAllThemeData(); |
| - NotifyThemeChanged(); |
| +bool NativeThemeX11::HasCustomImage(int id) const { |
| + return linux_ui_ && linux_ui_->HasCustomImage(id); |
| } |
| -bool ThemeServiceAuraX11::UsingDefaultTheme() const { |
|
pkotwicz
2013/07/19 05:54:13
You still need to override UsingDefaultTheme().
Adrian Kuegel
2013/07/19 13:54:39
Done.
|
| - return !use_system_theme_ && ThemeService::UsingDefaultTheme(); |
| +} // namespace |
| + |
| +ThemeServiceAuraX11::ThemeServiceAuraX11() {} |
| + |
| +ThemeServiceAuraX11::~ThemeServiceAuraX11() {} |
| + |
| +void ThemeServiceAuraX11::Init(Profile* profile) { |
| + ThemeService::Init(profile); |
| + |
| + if (profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) |
| + SetNativeTheme(); |
| } |
| -bool ThemeServiceAuraX11::UsingNativeTheme() const { |
| - return use_system_theme_; |
| +void ThemeServiceAuraX11::SetNativeTheme() { |
| + ThemeService::SetCustomDefaultTheme( |
| + new NativeThemeX11(profile()->GetPrefs())); |
| } |
| -void ThemeServiceAuraX11::OnUsesSystemThemeChanged() { |
| - use_system_theme_ = |
| - profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
| +bool ThemeServiceAuraX11::UsingNativeTheme() const { |
| + return GetThemeProvider() && |
| + GetThemeProvider()->GetThemeType() == CustomThemeProvider::NATIVE_X11; |
| } |