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

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: Don't call NotifyThemeChanged if not ready. Created 7 years, 4 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_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 bool GetColor(int id, SkColor* color) const OVERRIDE;
25 virtual gfx::Image GetImageNamed(int id) 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 void NativeThemeX11::StartUsingTheme() {
44 pref_service_->SetBoolean(prefs::kUsesSystemTheme, true);
16 } 45 }
17 46
47 void NativeThemeX11::StopUsingTheme() {
48 pref_service_->SetBoolean(prefs::kUsesSystemTheme, false);
49 }
50
51 bool NativeThemeX11::GetColor(int id, SkColor* color) const {
52 return linux_ui_ && linux_ui_->GetColor(id, color);
53 }
54
55 gfx::Image NativeThemeX11::GetImageNamed(int id) {
56 return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image();
57 }
58
59 bool NativeThemeX11::HasCustomImage(int id) const {
60 return linux_ui_ && linux_ui_->HasCustomImage(id);
61 }
62
63 NativeThemeX11::~NativeThemeX11() {}
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() const {
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 SetCustomDefaultTheme(new NativeThemeX11(profile()->GetPrefs()));
70 ClearAllThemeData();
71 NotifyThemeChanged();
72 } 77 }
73 78
74 bool ThemeServiceAuraX11::UsingDefaultTheme() const { 79 bool ThemeServiceAuraX11::UsingDefaultTheme() const {
75 return !use_system_theme_ && ThemeService::UsingDefaultTheme(); 80 return ThemeService::UsingDefaultTheme() && !UsingNativeTheme();
76 } 81 }
77 82
78 bool ThemeServiceAuraX11::UsingNativeTheme() const { 83 bool ThemeServiceAuraX11::UsingNativeTheme() const {
79 return use_system_theme_; 84 const CustomThemeSupplier* theme_supplier = get_theme_supplier();
85 return theme_supplier &&
86 theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11;
80 } 87 }
81
82 void ThemeServiceAuraX11::OnUsesSystemThemeChanged() {
83 use_system_theme_ =
84 profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme);
85 }
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service_aurax11.h ('k') | chrome/browser/themes/theme_service_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698