Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/themes/theme_service_aurax11.h" | 5 #include "chrome/browser/themes/theme_service_aurax11.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/themes/custom_theme_supplier.h" | |
| 10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 11 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
| 12 #include "ui/linux_ui/linux_ui.h" | 13 #include "ui/linux_ui/linux_ui.h" |
| 13 | 14 |
| 14 ThemeServiceAuraX11::ThemeServiceAuraX11() | 15 namespace { |
| 15 : use_system_theme_(false) { | 16 |
| 17 class NativeThemeX11 : public CustomThemeSupplier { | |
| 18 public: | |
| 19 explicit NativeThemeX11(PrefService* pref_service); | |
| 20 | |
| 21 // Overridden from CustomThemeSupplier: | |
| 22 virtual void StartUsingTheme() OVERRIDE; | |
| 23 virtual void StopUsingTheme() OVERRIDE; | |
| 24 virtual gfx::Image GetImageNamed(int id) OVERRIDE; | |
|
pkotwicz
2013/07/19 18:33:20
GetImageNamed() should be below GetColor() to matc
Adrian Kuegel
2013/07/22 12:58:08
Done.
| |
| 25 virtual bool GetColor(int id, SkColor* color) const OVERRIDE; | |
| 26 virtual bool HasCustomImage(int id) const OVERRIDE; | |
| 27 | |
| 28 private: | |
| 29 virtual ~NativeThemeX11(); | |
| 30 | |
| 31 // These pointers are not owned by us. | |
| 32 const ui::LinuxUI* const linux_ui_; | |
| 33 PrefService* const pref_service_; | |
| 34 | |
| 35 DISALLOW_COPY_AND_ASSIGN(NativeThemeX11); | |
| 36 }; | |
| 37 | |
| 38 NativeThemeX11::NativeThemeX11(PrefService* pref_service) | |
| 39 : CustomThemeSupplier(NATIVE_X11), | |
| 40 linux_ui_(ui::LinuxUI::instance()), | |
| 41 pref_service_(pref_service) {} | |
| 42 | |
| 43 NativeThemeX11::~NativeThemeX11() {} | |
|
pkotwicz
2013/07/19 18:33:20
Nit: Put the destructor last to match order define
Adrian Kuegel
2013/07/22 12:58:08
Done.
| |
| 44 | |
| 45 void NativeThemeX11::StartUsingTheme() { | |
| 46 pref_service_->SetBoolean(prefs::kUsesSystemTheme, true); | |
| 16 } | 47 } |
| 17 | 48 |
| 49 void NativeThemeX11::StopUsingTheme() { | |
| 50 pref_service_->SetBoolean(prefs::kUsesSystemTheme, false); | |
| 51 } | |
| 52 | |
| 53 gfx::Image NativeThemeX11::GetImageNamed(int id) { | |
| 54 return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image(); | |
| 55 } | |
| 56 | |
| 57 bool NativeThemeX11::GetColor(int id, SkColor* color) const { | |
| 58 return linux_ui_ && linux_ui_->GetColor(id, color); | |
| 59 } | |
| 60 | |
| 61 bool NativeThemeX11::HasCustomImage(int id) const { | |
| 62 return linux_ui_ && linux_ui_->HasCustomImage(id); | |
| 63 } | |
| 64 | |
| 65 } // namespace | |
| 66 | |
| 67 ThemeServiceAuraX11::ThemeServiceAuraX11() {} | |
| 68 | |
| 18 ThemeServiceAuraX11::~ThemeServiceAuraX11() {} | 69 ThemeServiceAuraX11::~ThemeServiceAuraX11() {} |
| 19 | 70 |
| 20 void ThemeServiceAuraX11::Init(Profile* profile) { | 71 bool ThemeServiceAuraX11::ShouldInitWithNativeTheme() { |
| 21 registrar_.Init(profile->GetPrefs()); | 72 return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
| 22 registrar_.Add(prefs::kUsesSystemTheme, | |
| 23 base::Bind(&ThemeServiceAuraX11::OnUsesSystemThemeChanged, | |
| 24 base::Unretained(this))); | |
| 25 use_system_theme_ = profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); | |
| 26 | |
| 27 ThemeService::Init(profile); | |
| 28 } | |
| 29 | |
| 30 gfx::Image ThemeServiceAuraX11::GetImageNamed(int id) const { | |
| 31 const ui::LinuxUI* linux_ui = ui::LinuxUI::instance(); | |
| 32 if (use_system_theme_ && linux_ui) { | |
| 33 gfx::Image image = linux_ui->GetThemeImageNamed(id); | |
| 34 if (!image.IsEmpty()) | |
| 35 return image; | |
| 36 } | |
| 37 | |
| 38 return ThemeService::GetImageNamed(id); | |
| 39 } | |
| 40 | |
| 41 SkColor ThemeServiceAuraX11::GetColor(int id) const { | |
| 42 const ui::LinuxUI* linux_ui = ui::LinuxUI::instance(); | |
| 43 SkColor color; | |
| 44 if (use_system_theme_ && linux_ui && linux_ui->GetColor(id, &color)) | |
| 45 return color; | |
| 46 | |
| 47 return ThemeService::GetColor(id); | |
| 48 } | |
| 49 | |
| 50 bool ThemeServiceAuraX11::HasCustomImage(int id) const { | |
| 51 const ui::LinuxUI* linux_ui = ui::LinuxUI::instance(); | |
| 52 if (use_system_theme_ && linux_ui) | |
| 53 return linux_ui->HasCustomImage(id); | |
| 54 | |
| 55 return ThemeService::HasCustomImage(id); | |
| 56 } | |
| 57 | |
| 58 void ThemeServiceAuraX11::SetTheme(const extensions::Extension* extension) { | |
| 59 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); | |
| 60 ThemeService::SetTheme(extension); | |
| 61 } | |
| 62 | |
| 63 void ThemeServiceAuraX11::UseDefaultTheme() { | |
| 64 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); | |
| 65 ThemeService::UseDefaultTheme(); | |
| 66 } | 73 } |
| 67 | 74 |
| 68 void ThemeServiceAuraX11::SetNativeTheme() { | 75 void ThemeServiceAuraX11::SetNativeTheme() { |
| 69 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); | 76 ThemeService::SetCustomDefaultTheme( |
|
pkotwicz
2013/07/19 18:33:20
Nit: You do not need to prepend SetCustomDefaultTh
Adrian Kuegel
2013/07/22 12:58:08
Right. Done.
| |
| 70 ClearAllThemeData(); | 77 new NativeThemeX11(profile()->GetPrefs())); |
| 71 NotifyThemeChanged(); | |
| 72 } | 78 } |
| 73 | 79 |
| 74 bool ThemeServiceAuraX11::UsingDefaultTheme() const { | 80 bool ThemeServiceAuraX11::UsingDefaultTheme() const { |
| 75 return !use_system_theme_ && ThemeService::UsingDefaultTheme(); | 81 return ThemeService::UsingDefaultTheme() && !UsingNativeTheme(); |
| 76 } | 82 } |
| 77 | 83 |
| 78 bool ThemeServiceAuraX11::UsingNativeTheme() const { | 84 bool ThemeServiceAuraX11::UsingNativeTheme() const { |
| 79 return use_system_theme_; | 85 return GetThemeSupplier() && |
| 86 GetThemeSupplier()->GetThemeType() == CustomThemeSupplier::NATIVE_X11; | |
| 80 } | 87 } |
| 81 | |
| 82 void ThemeServiceAuraX11::OnUsesSystemThemeChanged() { | |
| 83 use_system_theme_ = | |
| 84 profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); | |
| 85 } | |
| OLD | NEW |