OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/extension_shelf_gtk.h" | 5 #include "chrome/browser/gtk/extension_shelf_gtk.h" |
6 | 6 |
7 #include "base/gfx/gtk_util.h" | 7 #include "base/gfx/gtk_util.h" |
8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
9 #include "chrome/browser/gtk/browser_window_gtk.h" | 9 #include "chrome/browser/gtk/browser_window_gtk.h" |
10 #include "chrome/browser/gtk/gtk_theme_provider.h" | 10 #include "chrome/browser/gtk/gtk_theme_provider.h" |
11 #include "chrome/browser/gtk/view_id_util.h" | 11 #include "chrome/browser/gtk/view_id_util.h" |
12 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
14 #include "grit/app_resources.h" | 14 #include "grit/app_resources.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
17 | 17 |
18 // Background color of the shelf. | |
19 static const GdkColor kBackgroundColor = GDK_COLOR_RGB(230, 237, 244); | |
20 | |
21 // Border color (the top pixel of the shelf). | 18 // Border color (the top pixel of the shelf). |
22 const GdkColor kBorderColor = GDK_COLOR_RGB(214, 214, 214); | 19 const GdkColor kBorderColor = GDK_COLOR_RGB(214, 214, 214); |
23 | 20 |
24 // Preferred height of the ExtensionShelfGtk. | 21 // Preferred height of the ExtensionShelfGtk. |
25 static const int kShelfHeight = 29; | 22 static const int kShelfHeight = 29; |
26 | 23 |
27 static const int kToolstripPadding = 2; | 24 static const int kToolstripPadding = 2; |
28 | 25 |
29 class ExtensionShelfGtk::Toolstrip { | 26 class ExtensionShelfGtk::Toolstrip { |
30 public: | 27 public: |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 void ExtensionShelfGtk::Observe(NotificationType type, | 158 void ExtensionShelfGtk::Observe(NotificationType type, |
162 const NotificationSource& source, | 159 const NotificationSource& source, |
163 const NotificationDetails& details) { | 160 const NotificationDetails& details) { |
164 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); | 161 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); |
165 if (theme_provider_->UseGtkTheme()) { | 162 if (theme_provider_->UseGtkTheme()) { |
166 GdkColor color = theme_provider_->GetBorderColor(); | 163 GdkColor color = theme_provider_->GetBorderColor(); |
167 gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &color); | 164 gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &color); |
168 } else { | 165 } else { |
169 gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &kBorderColor); | 166 gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &kBorderColor); |
170 } | 167 } |
| 168 |
| 169 GdkColor color = theme_provider_->GetGdkColor( |
| 170 BrowserThemeProvider::COLOR_TOOLBAR); |
| 171 gtk_widget_modify_bg(event_box_.get(), GTK_STATE_NORMAL, &color); |
| 172 |
| 173 // Reset the background images on all the individual toolstrips |
| 174 background_.reset(); |
| 175 InitBackground(); |
| 176 for (std::set<Toolstrip*>::iterator it = toolstrips_.begin(); |
| 177 it != toolstrips_.end(); ++it) { |
| 178 (*it)->SetBackground(*background_.get()); |
| 179 } |
171 } | 180 } |
172 | 181 |
173 void ExtensionShelfGtk::Init(Profile* profile) { | 182 void ExtensionShelfGtk::Init(Profile* profile) { |
174 top_border_ = gtk_event_box_new(); | 183 top_border_ = gtk_event_box_new(); |
175 gtk_widget_set_size_request(GTK_WIDGET(top_border_), 0, 1); | 184 gtk_widget_set_size_request(GTK_WIDGET(top_border_), 0, 1); |
176 | 185 |
177 // The event box provides a background for the shelf and is its top-level | 186 // The event box provides a background for the shelf and is its top-level |
178 // widget. | 187 // widget. |
179 event_box_.Own(gtk_event_box_new()); | 188 event_box_.Own(gtk_event_box_new()); |
180 ViewIDUtil::SetID(event_box_.get(), VIEW_ID_DEV_EXTENSION_SHELF); | 189 ViewIDUtil::SetID(event_box_.get(), VIEW_ID_DEV_EXTENSION_SHELF); |
181 gtk_widget_modify_bg(event_box_.get(), GTK_STATE_NORMAL, &kBackgroundColor); | |
182 | 190 |
183 shelf_hbox_ = gtk_hbox_new(FALSE, 0); | 191 shelf_hbox_ = gtk_hbox_new(FALSE, 0); |
184 | 192 |
185 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 193 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
186 gtk_box_pack_start(GTK_BOX(vbox), top_border_, FALSE, FALSE, 0); | 194 gtk_box_pack_start(GTK_BOX(vbox), top_border_, FALSE, FALSE, 0); |
187 gtk_box_pack_start(GTK_BOX(vbox), shelf_hbox_, FALSE, FALSE, 0); | 195 gtk_box_pack_start(GTK_BOX(vbox), shelf_hbox_, FALSE, FALSE, 0); |
188 | 196 |
189 gtk_container_add(GTK_CONTAINER(event_box_.get()), vbox); | 197 gtk_container_add(GTK_CONTAINER(event_box_.get()), vbox); |
190 | 198 |
191 theme_provider_->InitThemesFor(this); | 199 theme_provider_->InitThemesFor(this); |
192 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 200 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
193 NotificationService::AllSources()); | 201 NotificationService::AllSources()); |
194 | 202 |
195 LoadFromModel(); | 203 LoadFromModel(); |
196 model_->AddObserver(this); | 204 model_->AddObserver(this); |
197 } | 205 } |
198 | 206 |
199 void ExtensionShelfGtk::InitBackground() { | 207 void ExtensionShelfGtk::InitBackground() { |
200 if (background_.get()) | 208 if (background_.get()) |
201 return; | 209 return; |
| 210 |
| 211 GdkColor color = |
| 212 theme_provider_->GetGdkColor(BrowserThemeProvider::COLOR_TOOLBAR); |
| 213 |
202 background_.reset(new SkBitmap); | 214 background_.reset(new SkBitmap); |
203 background_->setConfig(SkBitmap::kARGB_8888_Config, 3, 3); | 215 background_->setConfig(SkBitmap::kARGB_8888_Config, 3, 3); |
204 background_->allocPixels(); | 216 background_->allocPixels(); |
205 background_->eraseRGB(kBackgroundColor.red >> 8, | 217 background_->eraseRGB(color.red >> 8, |
206 kBackgroundColor.green >> 8, | 218 color.green >> 8, |
207 kBackgroundColor.blue >> 8); | 219 color.blue >> 8); |
208 } | 220 } |
209 | 221 |
210 void ExtensionShelfGtk::AdjustHeight() { | 222 void ExtensionShelfGtk::AdjustHeight() { |
211 if (model_->empty() || toolstrips_.empty()) { | 223 if (model_->empty() || toolstrips_.empty()) { |
212 // It's possible that |model_| is not empty, but |toolstrips_| are empty | 224 // It's possible that |model_| is not empty, but |toolstrips_| are empty |
213 // when removing the last toolstrip. | 225 // when removing the last toolstrip. |
214 DCHECK(toolstrips_.empty()); | 226 DCHECK(toolstrips_.empty()); |
215 Hide(); | 227 Hide(); |
216 } else { | 228 } else { |
217 gtk_widget_set_size_request(shelf_hbox_, -1, kShelfHeight); | 229 gtk_widget_set_size_request(shelf_hbox_, -1, kShelfHeight); |
218 Show(); | 230 Show(); |
219 } | 231 } |
220 } | 232 } |
221 | 233 |
222 void ExtensionShelfGtk::LoadFromModel() { | 234 void ExtensionShelfGtk::LoadFromModel() { |
223 DCHECK(toolstrips_.empty()); | 235 DCHECK(toolstrips_.empty()); |
224 int count = model_->count(); | 236 int count = model_->count(); |
225 for (int i = 0; i < count; ++i) | 237 for (int i = 0; i < count; ++i) |
226 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); | 238 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); |
227 AdjustHeight(); | 239 AdjustHeight(); |
228 } | 240 } |
229 | 241 |
230 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { | 242 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { |
231 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); | 243 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); |
232 } | 244 } |
OLD | NEW |