Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/gtk/extension_shelf_gtk.cc

Issue 173030: Port more browser focus tests to linux.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: working on windows Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
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 "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/gtk/browser_window_gtk.h" 8 #include "chrome/browser/gtk/browser_window_gtk.h"
9 #include "chrome/browser/gtk/gtk_theme_provider.h" 9 #include "chrome/browser/gtk/gtk_theme_provider.h"
10 #include "chrome/browser/gtk/nine_box.h" 10 #include "chrome/browser/gtk/nine_box.h"
11 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h"
11 #include "chrome/browser/profile.h" 12 #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 // Preferred height of the ExtensionShelfGtk. 17 // Preferred height of the ExtensionShelfGtk.
18 static const int kShelfHeight = 29; 18 static const int kShelfHeight = 29;
19 19
20 static const int kToolstripPadding = 2; 20 static const int kToolstripPadding = 2;
21 21
22 class ExtensionShelfGtk::Toolstrip { 22 class ExtensionShelfGtk::Toolstrip {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void ExtensionShelfGtk::Toolstrip::Init() { 58 void ExtensionShelfGtk::Toolstrip::Init() {
59 host_->view()->set_is_toolstrip(true); 59 host_->view()->set_is_toolstrip(true);
60 gtk_widget_show_all(native_view()); 60 gtk_widget_show_all(native_view());
61 } 61 }
62 62
63 ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser) 63 ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser)
64 : browser_(browser), 64 : browser_(browser),
65 theme_provider_(GtkThemeProvider::GetFrom(profile)), 65 theme_provider_(GtkThemeProvider::GetFrom(profile)),
66 model_(browser->extension_shelf_model()) { 66 model_(browser->extension_shelf_model()) {
67 Init(profile); 67 Init(profile);
68
69 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
70 NotificationService::AllSources());
71 } 68 }
72 69
73 ExtensionShelfGtk::~ExtensionShelfGtk() { 70 ExtensionShelfGtk::~ExtensionShelfGtk() {
74 if (model_) 71 if (model_)
75 model_->RemoveObserver(this); 72 model_->RemoveObserver(this);
76 event_box_.Destroy(); 73 event_box_.Destroy();
77 } 74 }
78 75
79 void ExtensionShelfGtk::AddShelfToBox(GtkWidget* box) { 76 void ExtensionShelfGtk::AddShelfToBox(GtkWidget* box) {
80 gtk_box_pack_end(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0); 77 gtk_box_pack_end(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 shelf_hbox_ = gtk_hbox_new(FALSE, 0); 151 shelf_hbox_ = gtk_hbox_new(FALSE, 0);
155 gtk_widget_set_app_paintable(shelf_hbox_, TRUE); 152 gtk_widget_set_app_paintable(shelf_hbox_, TRUE);
156 g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event", 153 g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event",
157 G_CALLBACK(&OnHBoxExpose), this); 154 G_CALLBACK(&OnHBoxExpose), this);
158 gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_); 155 gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_);
159 156
160 LoadFromModel(); 157 LoadFromModel();
161 model_->AddObserver(this); 158 model_->AddObserver(this);
162 } 159 }
163 160
164 void ExtensionShelfGtk::Observe(NotificationType type,
165 const NotificationSource& source,
166 const NotificationDetails& details) {
167 if (type == NotificationType::BROWSER_THEME_CHANGED) {
168 // TODO(phajdan.jr): Handle theme changes.
169 } else {
170 NOTREACHED() << "unexpected notification";
171 }
172 }
173
174 void ExtensionShelfGtk::InitBackground() {
175 if (background_ninebox_.get())
176 return;
177
178 background_ninebox_.reset(new NineBox(
179 browser_->profile()->GetThemeProvider(),
180 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0));
181 }
182
183 void ExtensionShelfGtk::AdjustHeight() { 161 void ExtensionShelfGtk::AdjustHeight() {
184 if (model_->empty() || toolstrips_.empty()) { 162 if (model_->empty() || toolstrips_.empty()) {
185 // It's possible that |model_| is not empty, but |toolstrips_| are empty 163 // It's possible that |model_| is not empty, but |toolstrips_| are empty
186 // when removing the last toolstrip. 164 // when removing the last toolstrip.
187 DCHECK(toolstrips_.empty()); 165 DCHECK(toolstrips_.empty());
188 Hide(); 166 Hide();
189 } else { 167 } else {
190 gtk_widget_set_size_request(event_box_.get(), -1, kShelfHeight); 168 gtk_widget_set_size_request(event_box_.get(), -1, kShelfHeight);
191 Show(); 169 Show();
192 } 170 }
(...skipping 13 matching lines...) Expand all
206 184
207 // static 185 // static
208 gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget, 186 gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget,
209 GdkEventExpose* event, 187 GdkEventExpose* event,
210 ExtensionShelfGtk* bar) { 188 ExtensionShelfGtk* bar) {
211 // Paint the background theme image. 189 // Paint the background theme image.
212 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); 190 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
213 cairo_rectangle(cr, event->area.x, event->area.y, 191 cairo_rectangle(cr, event->area.x, event->area.y,
214 event->area.width, event->area.height); 192 event->area.width, event->area.height);
215 cairo_clip(cr); 193 cairo_clip(cr);
216 bar->InitBackground(); 194 gfx::Point tabstrip_origin =
217 bar->background_ninebox_->RenderTopCenterStrip( 195 static_cast<BrowserWindowGtk*>(bar->browser_->window())->
218 cr, event->area.x, event->area.y, 196 tabstrip()->GetTabStripOriginForWidget(widget);
219 event->area.x + event->area.width); 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);
220 cairo_destroy(cr); 206 cairo_destroy(cr);
221 207
222 return FALSE; // Propagate expose to children. 208 return FALSE; // Propagate expose to children.
223 } 209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698