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

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

Issue 159763: Rolling back change 22245. (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: 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
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"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 void ExtensionShelfGtk::Toolstrip::Init() { 62 void ExtensionShelfGtk::Toolstrip::Init() {
63 label_.Own(gtk_label_new(extension_name_.c_str())); 63 label_.Own(gtk_label_new(extension_name_.c_str()));
64 gtk_widget_show_all(label_.get()); 64 gtk_widget_show_all(label_.get());
65 } 65 }
66 66
67 ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser) 67 ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser)
68 : browser_(browser), 68 : browser_(browser),
69 theme_provider_(GtkThemeProvider::GetFrom(profile)), 69 theme_provider_(GtkThemeProvider::GetFrom(profile)),
70 model_(browser->extension_shelf_model()) { 70 model_(new ExtensionShelfModel(browser)) {
71 Init(profile); 71 Init(profile);
72 72
73 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, 73 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
74 NotificationService::AllSources()); 74 NotificationService::AllSources());
75 } 75 }
76 76
77 ExtensionShelfGtk::~ExtensionShelfGtk() { 77 ExtensionShelfGtk::~ExtensionShelfGtk() {
78 if (model_) 78 model_->RemoveObserver(this);
79 model_->RemoveObserver(this);
80 event_box_.Destroy(); 79 event_box_.Destroy();
81 } 80 }
82 81
83 void ExtensionShelfGtk::AddShelfToBox(GtkWidget* box) { 82 void ExtensionShelfGtk::AddShelfToBox(GtkWidget* box) {
84 gtk_box_pack_end(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0); 83 gtk_box_pack_end(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0);
85 } 84 }
86 85
87 void ExtensionShelfGtk::Show() { 86 void ExtensionShelfGtk::Show() {
88 gtk_widget_show_all(event_box_.get()); 87 gtk_widget_show_all(event_box_.get());
89 } 88 }
(...skipping 23 matching lines...) Expand all
113 AdjustHeight(); 112 AdjustHeight();
114 } 113 }
115 114
116 void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* host, 115 void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* host,
117 int from_index, 116 int from_index,
118 int to_index) { 117 int to_index) {
119 // TODO(phajdan.jr): Implement reordering toolstrips. 118 // TODO(phajdan.jr): Implement reordering toolstrips.
120 AdjustHeight(); 119 AdjustHeight();
121 } 120 }
122 121
123 void ExtensionShelfGtk::ToolstripChanged( 122 void ExtensionShelfGtk::ToolstripChangedAt(ExtensionHost* host,
124 ExtensionShelfModel::iterator toolstrip) { 123 int index) {
125 // TODO(phajdan.jr): Implement changing toolstrips. 124 // TODO(phajdan.jr): Implement changing toolstrips.
126 AdjustHeight(); 125 AdjustHeight();
127 } 126 }
128 127
129 void ExtensionShelfGtk::ExtensionShelfEmpty() { 128 void ExtensionShelfGtk::ExtensionShelfEmpty() {
130 AdjustHeight(); 129 AdjustHeight();
131 } 130 }
132 131
133 void ExtensionShelfGtk::ShelfModelReloaded() { 132 void ExtensionShelfGtk::ShelfModelReloaded() {
134 for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin(); 133 for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin();
135 iter != toolstrips_.end(); ++iter) { 134 iter != toolstrips_.end(); ++iter) {
136 (*iter)->RemoveToolstripFromBox(shelf_hbox_); 135 (*iter)->RemoveToolstripFromBox(shelf_hbox_);
137 delete *iter; 136 delete *iter;
138 } 137 }
139 toolstrips_.clear(); 138 toolstrips_.clear();
140 LoadFromModel(); 139 LoadFromModel();
141 } 140 }
142 141
143 void ExtensionShelfGtk::ShelfModelDeleting() {
144 for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin();
145 iter != toolstrips_.end(); ++iter) {
146 (*iter)->RemoveToolstripFromBox(shelf_hbox_);
147 delete *iter;
148 }
149 toolstrips_.clear();
150
151 model_->RemoveObserver(this);
152 model_ = NULL;
153 }
154
155 void ExtensionShelfGtk::Init(Profile* profile) { 142 void ExtensionShelfGtk::Init(Profile* profile) {
156 event_box_.Own(gtk_event_box_new()); 143 event_box_.Own(gtk_event_box_new());
157 144
158 shelf_hbox_ = gtk_hbox_new(FALSE, 0); 145 shelf_hbox_ = gtk_hbox_new(FALSE, 0);
159 gtk_widget_set_app_paintable(shelf_hbox_, TRUE); 146 gtk_widget_set_app_paintable(shelf_hbox_, TRUE);
160 g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event", 147 g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event",
161 G_CALLBACK(&OnHBoxExpose), this); 148 G_CALLBACK(&OnHBoxExpose), this);
162 gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_); 149 gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_);
163 150
164 LoadFromModel(); 151 LoadFromModel();
(...skipping 28 matching lines...) Expand all
193 } else { 180 } else {
194 gtk_widget_set_size_request(event_box_.get(), -1, kShelfHeight); 181 gtk_widget_set_size_request(event_box_.get(), -1, kShelfHeight);
195 Show(); 182 Show();
196 } 183 }
197 } 184 }
198 185
199 void ExtensionShelfGtk::LoadFromModel() { 186 void ExtensionShelfGtk::LoadFromModel() {
200 DCHECK(toolstrips_.empty()); 187 DCHECK(toolstrips_.empty());
201 int count = model_->count(); 188 int count = model_->count();
202 for (int i = 0; i < count; ++i) 189 for (int i = 0; i < count; ++i)
203 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); 190 ToolstripInsertedAt(model_->ToolstripAt(i), i);
204 AdjustHeight(); 191 AdjustHeight();
205 } 192 }
206 193
207 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { 194 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) {
208 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); 195 return static_cast<Toolstrip*>(model_->ToolstripDataAt(index));
209 } 196 }
210 197
211 // static 198 // static
212 gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget, 199 gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget,
213 GdkEventExpose* event, 200 GdkEventExpose* event,
214 ExtensionShelfGtk* bar) { 201 ExtensionShelfGtk* bar) {
215 // Paint the background theme image. 202 // Paint the background theme image.
216 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); 203 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
217 cairo_rectangle(cr, event->area.x, event->area.y, 204 cairo_rectangle(cr, event->area.x, event->area.y,
218 event->area.width, event->area.height); 205 event->area.width, event->area.height);
219 cairo_clip(cr); 206 cairo_clip(cr);
220 bar->InitBackground(); 207 bar->InitBackground();
221 bar->background_ninebox_->RenderTopCenterStrip( 208 bar->background_ninebox_->RenderTopCenterStrip(
222 cr, event->area.x, event->area.y, 209 cr, event->area.x, event->area.y,
223 event->area.x + event->area.width); 210 event->area.x + event->area.width);
224 cairo_destroy(cr); 211 cairo_destroy(cr);
225 212
226 return FALSE; // Propagate expose to children. 213 return FALSE; // Propagate expose to children.
227 } 214 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/extension_shelf_gtk.h ('k') | chrome/browser/views/extensions/extension_shelf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698