Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: chrome/browser/themes/theme_service_aurax11.cc

Issue 19471005: Add custom default theme support and create a managed user default theme. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bugs. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_provider.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 CustomThemeProvider {
18 public:
19 explicit NativeThemeX11(PrefService* pref_service);
20
21 // Overridden from CustomThemeProvider:
22 virtual void StartUsingTheme() OVERRIDE;
23 virtual void StopUsingTheme() OVERRIDE;
24 virtual gfx::Image GetImageNamed(int id) OVERRIDE;
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 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.
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 : CustomThemeProvider(NATIVE_X11),
40 linux_ui_(ui::LinuxUI::instance()),
41 pref_service_(pref_service) {}
42
43 NativeThemeX11::~NativeThemeX11() {}
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 void ThemeServiceAuraX11::Init(Profile* profile) {
21 registrar_.Init(profile->GetPrefs()); 72 ThemeService::Init(profile);
22 registrar_.Add(prefs::kUsesSystemTheme,
23 base::Bind(&ThemeServiceAuraX11::OnUsesSystemThemeChanged,
24 base::Unretained(this)));
25 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
26 73
27 ThemeService::Init(profile); 74 if (profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme))
28 } 75 SetNativeTheme();
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 } 76 }
67 77
68 void ThemeServiceAuraX11::SetNativeTheme() { 78 void ThemeServiceAuraX11::SetNativeTheme() {
69 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); 79 ThemeService::SetCustomDefaultTheme(
70 ClearAllThemeData(); 80 new NativeThemeX11(profile()->GetPrefs()));
71 NotifyThemeChanged();
72 }
73
74 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.
75 return !use_system_theme_ && ThemeService::UsingDefaultTheme();
76 } 81 }
77 82
78 bool ThemeServiceAuraX11::UsingNativeTheme() const { 83 bool ThemeServiceAuraX11::UsingNativeTheme() const {
79 return use_system_theme_; 84 return GetThemeProvider() &&
85 GetThemeProvider()->GetThemeType() == CustomThemeProvider::NATIVE_X11;
80 } 86 }
81
82 void ThemeServiceAuraX11::OnUsesSystemThemeChanged() {
83 use_system_theme_ =
84 profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme);
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698