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/browser/themes/custom_theme_supplier.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
13 #include "ui/views/linux_ui/linux_ui.h" | 13 #include "ui/views/linux_ui/linux_ui.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class NativeThemeX11 : public CustomThemeSupplier { | 17 class SystemThemeX11 : public CustomThemeSupplier { |
18 public: | 18 public: |
19 explicit NativeThemeX11(PrefService* pref_service); | 19 explicit SystemThemeX11(PrefService* pref_service); |
20 | 20 |
21 // Overridden from CustomThemeSupplier: | 21 // Overridden from CustomThemeSupplier: |
22 virtual void StartUsingTheme() OVERRIDE; | 22 virtual void StartUsingTheme() OVERRIDE; |
23 virtual void StopUsingTheme() OVERRIDE; | 23 virtual void StopUsingTheme() OVERRIDE; |
24 virtual bool GetColor(int id, SkColor* color) const OVERRIDE; | 24 virtual bool GetColor(int id, SkColor* color) const OVERRIDE; |
25 virtual gfx::Image GetImageNamed(int id) OVERRIDE; | 25 virtual gfx::Image GetImageNamed(int id) OVERRIDE; |
26 virtual bool HasCustomImage(int id) const OVERRIDE; | 26 virtual bool HasCustomImage(int id) const OVERRIDE; |
27 | 27 |
28 private: | 28 private: |
29 virtual ~NativeThemeX11(); | 29 virtual ~SystemThemeX11(); |
30 | 30 |
31 // These pointers are not owned by us. | 31 // These pointers are not owned by us. |
32 views::LinuxUI* const linux_ui_; | 32 views::LinuxUI* const linux_ui_; |
33 PrefService* const pref_service_; | 33 PrefService* const pref_service_; |
34 | 34 |
35 DISALLOW_COPY_AND_ASSIGN(NativeThemeX11); | 35 DISALLOW_COPY_AND_ASSIGN(SystemThemeX11); |
36 }; | 36 }; |
37 | 37 |
38 NativeThemeX11::NativeThemeX11(PrefService* pref_service) | 38 SystemThemeX11::SystemThemeX11(PrefService* pref_service) |
39 : CustomThemeSupplier(NATIVE_X11), | 39 : CustomThemeSupplier(NATIVE_X11), |
40 linux_ui_(views::LinuxUI::instance()), | 40 linux_ui_(views::LinuxUI::instance()), |
41 pref_service_(pref_service) {} | 41 pref_service_(pref_service) {} |
42 | 42 |
43 void NativeThemeX11::StartUsingTheme() { | 43 void SystemThemeX11::StartUsingTheme() { |
44 pref_service_->SetBoolean(prefs::kUsesSystemTheme, true); | 44 pref_service_->SetBoolean(prefs::kUsesSystemTheme, true); |
45 } | 45 } |
46 | 46 |
47 void NativeThemeX11::StopUsingTheme() { | 47 void SystemThemeX11::StopUsingTheme() { |
48 pref_service_->SetBoolean(prefs::kUsesSystemTheme, false); | 48 pref_service_->SetBoolean(prefs::kUsesSystemTheme, false); |
49 } | 49 } |
50 | 50 |
51 bool NativeThemeX11::GetColor(int id, SkColor* color) const { | 51 bool SystemThemeX11::GetColor(int id, SkColor* color) const { |
52 return linux_ui_ && linux_ui_->GetColor(id, color); | 52 return linux_ui_ && linux_ui_->GetColor(id, color); |
53 } | 53 } |
54 | 54 |
55 gfx::Image NativeThemeX11::GetImageNamed(int id) { | 55 gfx::Image SystemThemeX11::GetImageNamed(int id) { |
56 return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image(); | 56 return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image(); |
57 } | 57 } |
58 | 58 |
59 bool NativeThemeX11::HasCustomImage(int id) const { | 59 bool SystemThemeX11::HasCustomImage(int id) const { |
60 return linux_ui_ && linux_ui_->HasCustomImage(id); | 60 return linux_ui_ && linux_ui_->HasCustomImage(id); |
61 } | 61 } |
62 | 62 |
63 NativeThemeX11::~NativeThemeX11() {} | 63 SystemThemeX11::~SystemThemeX11() {} |
64 | 64 |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 ThemeServiceAuraX11::ThemeServiceAuraX11() { | 67 ThemeServiceAuraX11::ThemeServiceAuraX11() { |
68 views::LinuxUI* linux_ui = views::LinuxUI::instance(); | 68 views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
69 if (linux_ui) | 69 if (linux_ui) |
70 linux_ui->AddNativeThemeChangeObserver(this); | 70 linux_ui->AddSystemThemeChangeObserver(this); |
71 } | 71 } |
72 | 72 |
73 ThemeServiceAuraX11::~ThemeServiceAuraX11() { | 73 ThemeServiceAuraX11::~ThemeServiceAuraX11() { |
74 views::LinuxUI* linux_ui = views::LinuxUI::instance(); | 74 views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
75 if (linux_ui) | 75 if (linux_ui) |
76 linux_ui->RemoveNativeThemeChangeObserver(this); | 76 linux_ui->RemoveSystemThemeChangeObserver(this); |
77 } | 77 } |
78 | 78 |
79 bool ThemeServiceAuraX11::ShouldInitWithNativeTheme() const { | 79 bool ThemeServiceAuraX11::ShouldInitWithSystemTheme() const { |
80 return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); | 80 return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
81 } | 81 } |
82 | 82 |
83 void ThemeServiceAuraX11::SetNativeTheme() { | 83 void ThemeServiceAuraX11::UseSystemTheme() { |
84 SetCustomDefaultTheme(new NativeThemeX11(profile()->GetPrefs())); | 84 SetCustomDefaultTheme(new SystemThemeX11(profile()->GetPrefs())); |
85 } | 85 } |
86 | 86 |
87 bool ThemeServiceAuraX11::UsingDefaultTheme() const { | 87 bool ThemeServiceAuraX11::UsingDefaultTheme() const { |
88 return ThemeService::UsingDefaultTheme() && !UsingNativeTheme(); | 88 return ThemeService::UsingDefaultTheme() && !UsingSystemTheme(); |
89 } | 89 } |
90 | 90 |
91 bool ThemeServiceAuraX11::UsingNativeTheme() const { | 91 bool ThemeServiceAuraX11::UsingSystemTheme() const { |
92 const CustomThemeSupplier* theme_supplier = get_theme_supplier(); | 92 const CustomThemeSupplier* theme_supplier = get_theme_supplier(); |
93 return theme_supplier && | 93 return theme_supplier && |
94 theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11; | 94 theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11; |
95 } | 95 } |
96 | 96 |
97 void ThemeServiceAuraX11::OnNativeThemeChanged() { | 97 void ThemeServiceAuraX11::OnSystemThemeChanged() { |
98 if (UsingNativeTheme()) | 98 if (UsingSystemTheme()) |
99 NotifyThemeChanged(); | 99 NotifyThemeChanged(); |
100 } | 100 } |
OLD | NEW |