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. 4 5 #include "chrome/browser/themes/theme_service_aurax11.h" 6 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" 14 15 namespace { 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 views::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_(views::LinuxUI::instance()), 41 pref_service_(pref_service) {} 42 43 void NativeThemeX11::StartUsingTheme() { 44 if (linux_ui_) 45 linux_ui_->SetUseSystemTheme(true); 46 47 pref_service_->SetBoolean(prefs::kUsesSystemTheme, true); 48 } 49 50 void NativeThemeX11::StopUsingTheme() { 51 if (linux_ui_) 52 linux_ui_->SetUseSystemTheme(false); 53 54 pref_service_->SetBoolean(prefs::kUsesSystemTheme, false); 55 } 56 57 bool NativeThemeX11::GetColor(int id, SkColor* color) const { 58 return linux_ui_ && linux_ui_->GetColor(id, color); 59 } 60 61 gfx::Image NativeThemeX11::GetImageNamed(int id) { 62 return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image(); 63 } 64 65 bool NativeThemeX11::HasCustomImage(int id) const { 66 return linux_ui_ && linux_ui_->HasCustomImage(id); 67 } 68 69 NativeThemeX11::~NativeThemeX11() {} 70 71 } // namespace 72 73 ThemeServiceAuraX11::ThemeServiceAuraX11() {} 74 75 ThemeServiceAuraX11::~ThemeServiceAuraX11() {} 76 77 bool ThemeServiceAuraX11::ShouldInitWithNativeTheme() const { 78 return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); 79 } 80 81 void ThemeServiceAuraX11::SetNativeTheme() { 82 SetCustomDefaultTheme(new NativeThemeX11(profile()->GetPrefs())); 83 } 84 85 bool ThemeServiceAuraX11::UsingDefaultTheme() const { 86 return ThemeService::UsingDefaultTheme() && !UsingNativeTheme(); 87 } 88 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; 93 } 94