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 "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/gtk/browser_window_gtk.h" | 9 #include "chrome/browser/gtk/browser_window_gtk.h" |
9 #include "chrome/browser/gtk/gtk_theme_provider.h" | 10 #include "chrome/browser/gtk/gtk_theme_provider.h" |
10 #include "chrome/browser/gtk/nine_box.h" | |
11 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" | |
12 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
12 #include "chrome/common/notification_service.h" | |
13 #include "grit/app_resources.h" | 13 #include "grit/app_resources.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
16 | 16 |
17 // Background color of the shelf. | |
18 static const GdkColor kBackgroundColor = GDK_COLOR_RGB(230, 237, 244); | |
19 | |
20 // Border color (the top pixel of the shelf). | |
21 const GdkColor kBorderColor = GDK_COLOR_RGB(214, 214, 214); | |
22 | |
17 // Preferred height of the ExtensionShelfGtk. | 23 // Preferred height of the ExtensionShelfGtk. |
18 static const int kShelfHeight = 29; | 24 static const int kShelfHeight = 29; |
19 | 25 |
20 static const int kToolstripPadding = 2; | 26 static const int kToolstripPadding = 2; |
21 | 27 |
22 class ExtensionShelfGtk::Toolstrip { | 28 class ExtensionShelfGtk::Toolstrip { |
23 public: | 29 public: |
24 explicit Toolstrip(ExtensionHost* host) | 30 explicit Toolstrip(ExtensionHost* host) |
25 : host_(host), | 31 : host_(host), |
26 extension_name_(host_->extension()->name()) { | 32 extension_name_(host_->extension()->name()) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 iter != toolstrips_.end(); ++iter) { | 144 iter != toolstrips_.end(); ++iter) { |
139 (*iter)->RemoveToolstripFromBox(shelf_hbox_); | 145 (*iter)->RemoveToolstripFromBox(shelf_hbox_); |
140 delete *iter; | 146 delete *iter; |
141 } | 147 } |
142 toolstrips_.clear(); | 148 toolstrips_.clear(); |
143 | 149 |
144 model_->RemoveObserver(this); | 150 model_->RemoveObserver(this); |
145 model_ = NULL; | 151 model_ = NULL; |
146 } | 152 } |
147 | 153 |
154 void ExtensionShelfGtk::Observe(NotificationType type, | |
155 const NotificationSource& source, | |
156 const NotificationDetails& details) { | |
157 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); | |
158 if (theme_provider_->UseGtkTheme()) { | |
159 GdkColor color = theme_provider_->GetBorderColor(); | |
160 gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &color); | |
161 } else { | |
162 gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &kBorderColor); | |
163 } | |
164 } | |
165 | |
148 void ExtensionShelfGtk::Init(Profile* profile) { | 166 void ExtensionShelfGtk::Init(Profile* profile) { |
167 top_border_ = gtk_event_box_new(); | |
168 gtk_widget_set_size_request(GTK_WIDGET(top_border_), 0, 1); | |
169 | |
170 // The event box provides a background for the shelf and is its top-level | |
171 // widget. | |
149 event_box_.Own(gtk_event_box_new()); | 172 event_box_.Own(gtk_event_box_new()); |
173 gtk_widget_modify_bg(event_box_.get(), GTK_STATE_NORMAL, &kBackgroundColor); | |
Elliot Glaysher
2009/08/26 21:42:39
A question: Why is this a hardcoded value instead
| |
150 | 174 |
151 shelf_hbox_ = gtk_hbox_new(FALSE, 0); | 175 shelf_hbox_ = gtk_hbox_new(FALSE, 0); |
152 gtk_widget_set_app_paintable(shelf_hbox_, TRUE); | 176 |
153 g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event", | 177 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
154 G_CALLBACK(&OnHBoxExpose), this); | 178 gtk_box_pack_start(GTK_BOX(vbox), top_border_, FALSE, FALSE, 0); |
155 gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_); | 179 gtk_box_pack_start(GTK_BOX(vbox), shelf_hbox_, FALSE, FALSE, 0); |
180 | |
181 gtk_container_add(GTK_CONTAINER(event_box_.get()), vbox); | |
182 | |
183 theme_provider_->InitThemesFor(this); | |
184 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | |
185 NotificationService::AllSources()); | |
156 | 186 |
157 LoadFromModel(); | 187 LoadFromModel(); |
158 model_->AddObserver(this); | 188 model_->AddObserver(this); |
159 } | 189 } |
160 | 190 |
161 void ExtensionShelfGtk::AdjustHeight() { | 191 void ExtensionShelfGtk::AdjustHeight() { |
162 if (model_->empty() || toolstrips_.empty()) { | 192 if (model_->empty() || toolstrips_.empty()) { |
163 // It's possible that |model_| is not empty, but |toolstrips_| are empty | 193 // It's possible that |model_| is not empty, but |toolstrips_| are empty |
164 // when removing the last toolstrip. | 194 // when removing the last toolstrip. |
165 DCHECK(toolstrips_.empty()); | 195 DCHECK(toolstrips_.empty()); |
166 Hide(); | 196 Hide(); |
167 } else { | 197 } else { |
168 gtk_widget_set_size_request(event_box_.get(), -1, kShelfHeight); | 198 gtk_widget_set_size_request(shelf_hbox_, -1, kShelfHeight); |
169 Show(); | 199 Show(); |
170 } | 200 } |
171 } | 201 } |
172 | 202 |
173 void ExtensionShelfGtk::LoadFromModel() { | 203 void ExtensionShelfGtk::LoadFromModel() { |
174 DCHECK(toolstrips_.empty()); | 204 DCHECK(toolstrips_.empty()); |
175 int count = model_->count(); | 205 int count = model_->count(); |
176 for (int i = 0; i < count; ++i) | 206 for (int i = 0; i < count; ++i) |
177 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); | 207 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); |
178 AdjustHeight(); | 208 AdjustHeight(); |
179 } | 209 } |
180 | 210 |
181 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { | 211 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { |
182 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); | 212 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); |
183 } | 213 } |
184 | |
185 // static | |
186 gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget, | |
187 GdkEventExpose* event, | |
188 ExtensionShelfGtk* bar) { | |
189 // Paint the background theme image. | |
190 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | |
191 cairo_rectangle(cr, event->area.x, event->area.y, | |
192 event->area.width, event->area.height); | |
193 cairo_clip(cr); | |
194 gfx::Point tabstrip_origin = | |
195 static_cast<BrowserWindowGtk*>(bar->browser_->window())-> | |
196 tabstrip()->GetTabStripOriginForWidget(widget); | |
197 GdkPixbuf* background = bar->browser_->profile()->GetThemeProvider()-> | |
198 GetPixbufNamed(IDR_THEME_TOOLBAR); | |
199 gdk_cairo_set_source_pixbuf(cr, background, | |
200 tabstrip_origin.x(), tabstrip_origin.y()); | |
201 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | |
202 cairo_rectangle(cr, tabstrip_origin.x(), tabstrip_origin.y(), | |
203 event->area.x + event->area.width - tabstrip_origin.x(), | |
204 gdk_pixbuf_get_height(background)); | |
205 cairo_fill(cr); | |
206 cairo_destroy(cr); | |
207 | |
208 return FALSE; // Propagate expose to children. | |
209 } | |
OLD | NEW |