blob: 258053eb991cfeb54737f2c8fafce3d8f41365aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/themes/theme_service_aurax11.h"
#include "base/bind.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/custom_theme_supplier.h"
#include "chrome/common/pref_names.h"
#include "ui/gfx/image/image.h"
#include "ui/native_theme/native_theme_aura.h"
#include "ui/views/linux_ui/linux_ui.h"
namespace {
class SystemThemeX11 : public CustomThemeSupplier {
public:
explicit SystemThemeX11(PrefService* pref_service);
// Overridden from CustomThemeSupplier:
virtual void StartUsingTheme() OVERRIDE;
virtual void StopUsingTheme() OVERRIDE;
virtual bool GetColor(int id, SkColor* color) const OVERRIDE;
virtual gfx::Image GetImageNamed(int id) OVERRIDE;
virtual bool HasCustomImage(int id) const OVERRIDE;
private:
virtual ~SystemThemeX11();
// These pointers are not owned by us.
views::LinuxUI* const linux_ui_;
PrefService* const pref_service_;
DISALLOW_COPY_AND_ASSIGN(SystemThemeX11);
};
SystemThemeX11::SystemThemeX11(PrefService* pref_service)
: CustomThemeSupplier(NATIVE_X11),
linux_ui_(views::LinuxUI::instance()),
pref_service_(pref_service) {}
void SystemThemeX11::StartUsingTheme() {
pref_service_->SetBoolean(prefs::kUsesSystemTheme, true);
// Have the former theme notify its observers of change.
ui::NativeThemeAura::instance()->NotifyObservers();
}
void SystemThemeX11::StopUsingTheme() {
pref_service_->SetBoolean(prefs::kUsesSystemTheme, false);
// Have the former theme notify its observers of change.
if (linux_ui_)
linux_ui_->GetNativeTheme(NULL)->NotifyObservers();
}
bool SystemThemeX11::GetColor(int id, SkColor* color) const {
return linux_ui_ && linux_ui_->GetColor(id, color);
}
gfx::Image SystemThemeX11::GetImageNamed(int id) {
return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image();
}
bool SystemThemeX11::HasCustomImage(int id) const {
return linux_ui_ && linux_ui_->HasCustomImage(id);
}
SystemThemeX11::~SystemThemeX11() {}
} // namespace
ThemeServiceAuraX11::ThemeServiceAuraX11() {}
ThemeServiceAuraX11::~ThemeServiceAuraX11() {}
bool ThemeServiceAuraX11::ShouldInitWithSystemTheme() const {
return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme);
}
void ThemeServiceAuraX11::UseSystemTheme() {
SetCustomDefaultTheme(new SystemThemeX11(profile()->GetPrefs()));
}
bool ThemeServiceAuraX11::IsSystemThemeDistinctFromDefaultTheme() const {
return true;
}
bool ThemeServiceAuraX11::UsingDefaultTheme() const {
return ThemeService::UsingDefaultTheme() && !UsingSystemTheme();
}
bool ThemeServiceAuraX11::UsingSystemTheme() const {
const CustomThemeSupplier* theme_supplier = get_theme_supplier();
return theme_supplier &&
theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11;
}
|