OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "chrome/browser/themes/theme_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
26 #include "grit/ui_resources.h" | 26 #include "grit/ui_resources.h" |
27 #include "ui/base/layout.h" | 27 #include "ui/base/layout.h" |
28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
29 #include "ui/gfx/image/image_skia.h" | 29 #include "ui/gfx/image/image_skia.h" |
30 | 30 |
31 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
32 #include "ui/base/win/shell.h" | 32 #include "ui/base/win/shell.h" |
33 #endif | 33 #endif |
34 | 34 |
35 #if defined(USE_AURA) && !defined(USE_ASH) && defined(OS_LINUX) | |
36 #include "ui/linux_ui/linux_ui.h" | |
37 #endif | |
38 | |
39 using content::BrowserThread; | 35 using content::BrowserThread; |
40 using content::UserMetricsAction; | 36 using content::UserMetricsAction; |
41 using extensions::Extension; | 37 using extensions::Extension; |
42 using ui::ResourceBundle; | 38 using ui::ResourceBundle; |
43 | 39 |
44 typedef ThemeProperties Properties; | 40 typedef ThemeProperties Properties; |
45 | 41 |
46 // The default theme if we haven't installed a theme yet or if we've clicked | 42 // The default theme if we haven't installed a theme yet or if we've clicked |
47 // the "Use Classic" button. | 43 // the "Use Classic" button. |
48 const char* ThemeService::kDefaultThemeID = ""; | 44 const char* ThemeService::kDefaultThemeID = ""; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 97 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
102 } | 98 } |
103 | 99 |
104 gfx::Image ThemeService::GetImageNamed(int id) const { | 100 gfx::Image ThemeService::GetImageNamed(int id) const { |
105 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
106 | 102 |
107 gfx::Image image; | 103 gfx::Image image; |
108 if (theme_pack_.get()) | 104 if (theme_pack_.get()) |
109 image = theme_pack_->GetImageNamed(id); | 105 image = theme_pack_->GetImageNamed(id); |
110 | 106 |
111 #if defined(USE_AURA) && !defined(USE_ASH) && defined(OS_LINUX) | |
112 const ui::LinuxUI* linux_ui = ui::LinuxUI::instance(); | |
113 if (image.IsEmpty() && linux_ui) | |
114 image = linux_ui->GetThemeImageNamed(id); | |
115 #endif | |
116 | |
117 if (image.IsEmpty()) | 107 if (image.IsEmpty()) |
118 image = rb_.GetNativeImageNamed(id); | 108 image = rb_.GetNativeImageNamed(id); |
119 | 109 |
120 return image; | 110 return image; |
121 } | 111 } |
122 | 112 |
123 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { | 113 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { |
124 gfx::Image image = GetImageNamed(id); | 114 gfx::Image image = GetImageNamed(id); |
125 if (image.IsEmpty()) | 115 if (image.IsEmpty()) |
126 return NULL; | 116 return NULL; |
127 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns | 117 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns |
128 // its images const. GetImageSkiaNamed() also should but has many callsites. | 118 // its images const. GetImageSkiaNamed() also should but has many callsites. |
129 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); | 119 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); |
130 } | 120 } |
131 | 121 |
132 SkColor ThemeService::GetColor(int id) const { | 122 SkColor ThemeService::GetColor(int id) const { |
133 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
134 | 124 |
135 SkColor color; | 125 SkColor color; |
136 if (theme_pack_.get() && theme_pack_->GetColor(id, &color)) | 126 if (theme_pack_.get() && theme_pack_->GetColor(id, &color)) |
137 return color; | 127 return color; |
138 | 128 |
139 #if defined(USE_AURA) && !defined(USE_ASH) && defined(OS_LINUX) | |
140 const ui::LinuxUI* linux_ui = ui::LinuxUI::instance(); | |
141 if (linux_ui && linux_ui->GetColor(id, &color)) | |
142 return color; | |
143 #endif | |
144 | |
145 // For backward compat with older themes, some newer colors are generated from | 129 // For backward compat with older themes, some newer colors are generated from |
146 // older ones if they are missing. | 130 // older ones if they are missing. |
147 switch (id) { | 131 switch (id) { |
148 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: | 132 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: |
149 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); | 133 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); |
150 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: | 134 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: |
151 return GetColor(Properties::COLOR_NTP_TEXT); | 135 return GetColor(Properties::COLOR_NTP_TEXT); |
152 case Properties::COLOR_NTP_SECTION_HEADER_RULE: | 136 case Properties::COLOR_NTP_SECTION_HEADER_RULE: |
153 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); | 137 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); |
154 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: | 138 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 void ThemeService::OnInfobarDestroyed() { | 410 void ThemeService::OnInfobarDestroyed() { |
427 number_of_infobars_--; | 411 number_of_infobars_--; |
428 | 412 |
429 if (number_of_infobars_ == 0) | 413 if (number_of_infobars_ == 0) |
430 RemoveUnusedThemes(); | 414 RemoveUnusedThemes(); |
431 } | 415 } |
432 | 416 |
433 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 417 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
434 return theme_syncable_service_.get(); | 418 return theme_syncable_service_.get(); |
435 } | 419 } |
OLD | NEW |