Home | History | Annotate | Download | only in themes
      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/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   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);
     45 }
     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 
     69 ThemeServiceAuraX11::~ThemeServiceAuraX11() {}
     70 
     71 bool ThemeServiceAuraX11::ShouldInitWithNativeTheme() const {
     72   return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme);
     73 }
     74 
     75 void ThemeServiceAuraX11::SetNativeTheme() {
     76   SetCustomDefaultTheme(new NativeThemeX11(profile()->GetPrefs()));
     77 }
     78 
     79 bool ThemeServiceAuraX11::UsingDefaultTheme() const {
     80   return ThemeService::UsingDefaultTheme() && !UsingNativeTheme();
     81 }
     82 
     83 bool ThemeServiceAuraX11::UsingNativeTheme() const {
     84   const CustomThemeSupplier* theme_supplier = get_theme_supplier();
     85   return theme_supplier &&
     86          theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11;
     87 }
     88