Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / themes / theme_service_aurax11.cc
blob1e596e32dad0bbbb96e77acdebf40c7f955eac76
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
3 // found in the LICENSE file.
5 #include "chrome/browser/themes/theme_service_aurax11.h"
7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/themes/custom_theme_supplier.h"
11 #include "chrome/common/pref_names.h"
12 #include "ui/gfx/image/image.h"
13 #include "ui/views/linux_ui/linux_ui.h"
15 namespace {
17 class NativeThemeX11 : public CustomThemeSupplier {
18 public:
19 explicit NativeThemeX11(PrefService* pref_service);
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;
28 private:
29 virtual ~NativeThemeX11();
31 // These pointers are not owned by us.
32 views::LinuxUI* const linux_ui_;
33 PrefService* const pref_service_;
35 DISALLOW_COPY_AND_ASSIGN(NativeThemeX11);
38 NativeThemeX11::NativeThemeX11(PrefService* pref_service)
39 : CustomThemeSupplier(NATIVE_X11),
40 linux_ui_(views::LinuxUI::instance()),
41 pref_service_(pref_service) {}
43 void NativeThemeX11::StartUsingTheme() {
44 if (linux_ui_)
45 linux_ui_->SetUseSystemTheme(true);
47 pref_service_->SetBoolean(prefs::kUsesSystemTheme, true);
50 void NativeThemeX11::StopUsingTheme() {
51 if (linux_ui_)
52 linux_ui_->SetUseSystemTheme(false);
54 pref_service_->SetBoolean(prefs::kUsesSystemTheme, false);
57 bool NativeThemeX11::GetColor(int id, SkColor* color) const {
58 return linux_ui_ && linux_ui_->GetColor(id, color);
61 gfx::Image NativeThemeX11::GetImageNamed(int id) {
62 return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image();
65 bool NativeThemeX11::HasCustomImage(int id) const {
66 return linux_ui_ && linux_ui_->HasCustomImage(id);
69 NativeThemeX11::~NativeThemeX11() {}
71 } // namespace
73 ThemeServiceAuraX11::ThemeServiceAuraX11() {}
75 ThemeServiceAuraX11::~ThemeServiceAuraX11() {}
77 bool ThemeServiceAuraX11::ShouldInitWithNativeTheme() const {
78 return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme);
81 void ThemeServiceAuraX11::SetNativeTheme() {
82 SetCustomDefaultTheme(new NativeThemeX11(profile()->GetPrefs()));
85 bool ThemeServiceAuraX11::UsingDefaultTheme() const {
86 return ThemeService::UsingDefaultTheme() && !UsingNativeTheme();
89 bool ThemeServiceAuraX11::UsingNativeTheme() const {
90 const CustomThemeSupplier* theme_supplier = get_theme_supplier();
91 return theme_supplier &&
92 theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11;