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 "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 Loading... |
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_(new ExtensionShelfModel(browser)) { | 70 model_(browser->extension_shelf_model()) { |
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 model_->RemoveObserver(this); | 78 if (model_) |
| 79 model_->RemoveObserver(this); |
79 event_box_.Destroy(); | 80 event_box_.Destroy(); |
80 } | 81 } |
81 | 82 |
82 void ExtensionShelfGtk::AddShelfToBox(GtkWidget* box) { | 83 void ExtensionShelfGtk::AddShelfToBox(GtkWidget* box) { |
83 gtk_box_pack_end(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0); | 84 gtk_box_pack_end(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0); |
84 } | 85 } |
85 | 86 |
86 void ExtensionShelfGtk::Show() { | 87 void ExtensionShelfGtk::Show() { |
87 gtk_widget_show_all(event_box_.get()); | 88 gtk_widget_show_all(event_box_.get()); |
88 } | 89 } |
(...skipping 23 matching lines...) Expand all Loading... |
112 AdjustHeight(); | 113 AdjustHeight(); |
113 } | 114 } |
114 | 115 |
115 void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* host, | 116 void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* host, |
116 int from_index, | 117 int from_index, |
117 int to_index) { | 118 int to_index) { |
118 // TODO(phajdan.jr): Implement reordering toolstrips. | 119 // TODO(phajdan.jr): Implement reordering toolstrips. |
119 AdjustHeight(); | 120 AdjustHeight(); |
120 } | 121 } |
121 | 122 |
122 void ExtensionShelfGtk::ToolstripChangedAt(ExtensionHost* host, | 123 void ExtensionShelfGtk::ToolstripChanged( |
123 int index) { | 124 ExtensionShelfModel::iterator toolstrip) { |
124 // TODO(phajdan.jr): Implement changing toolstrips. | 125 // TODO(phajdan.jr): Implement changing toolstrips. |
125 AdjustHeight(); | 126 AdjustHeight(); |
126 } | 127 } |
127 | 128 |
128 void ExtensionShelfGtk::ExtensionShelfEmpty() { | 129 void ExtensionShelfGtk::ExtensionShelfEmpty() { |
129 AdjustHeight(); | 130 AdjustHeight(); |
130 } | 131 } |
131 | 132 |
132 void ExtensionShelfGtk::ShelfModelReloaded() { | 133 void ExtensionShelfGtk::ShelfModelReloaded() { |
133 for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin(); | 134 for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin(); |
134 iter != toolstrips_.end(); ++iter) { | 135 iter != toolstrips_.end(); ++iter) { |
135 (*iter)->RemoveToolstripFromBox(shelf_hbox_); | 136 (*iter)->RemoveToolstripFromBox(shelf_hbox_); |
136 delete *iter; | 137 delete *iter; |
137 } | 138 } |
138 toolstrips_.clear(); | 139 toolstrips_.clear(); |
139 LoadFromModel(); | 140 LoadFromModel(); |
140 } | 141 } |
141 | 142 |
| 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 |
142 void ExtensionShelfGtk::Init(Profile* profile) { | 155 void ExtensionShelfGtk::Init(Profile* profile) { |
143 event_box_.Own(gtk_event_box_new()); | 156 event_box_.Own(gtk_event_box_new()); |
144 | 157 |
145 shelf_hbox_ = gtk_hbox_new(FALSE, 0); | 158 shelf_hbox_ = gtk_hbox_new(FALSE, 0); |
146 gtk_widget_set_app_paintable(shelf_hbox_, TRUE); | 159 gtk_widget_set_app_paintable(shelf_hbox_, TRUE); |
147 g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event", | 160 g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event", |
148 G_CALLBACK(&OnHBoxExpose), this); | 161 G_CALLBACK(&OnHBoxExpose), this); |
149 gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_); | 162 gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_); |
150 | 163 |
151 LoadFromModel(); | 164 LoadFromModel(); |
(...skipping 28 matching lines...) Expand all Loading... |
180 } else { | 193 } else { |
181 gtk_widget_set_size_request(event_box_.get(), -1, kShelfHeight); | 194 gtk_widget_set_size_request(event_box_.get(), -1, kShelfHeight); |
182 Show(); | 195 Show(); |
183 } | 196 } |
184 } | 197 } |
185 | 198 |
186 void ExtensionShelfGtk::LoadFromModel() { | 199 void ExtensionShelfGtk::LoadFromModel() { |
187 DCHECK(toolstrips_.empty()); | 200 DCHECK(toolstrips_.empty()); |
188 int count = model_->count(); | 201 int count = model_->count(); |
189 for (int i = 0; i < count; ++i) | 202 for (int i = 0; i < count; ++i) |
190 ToolstripInsertedAt(model_->ToolstripAt(i), i); | 203 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); |
191 AdjustHeight(); | 204 AdjustHeight(); |
192 } | 205 } |
193 | 206 |
194 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { | 207 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { |
195 return static_cast<Toolstrip*>(model_->ToolstripDataAt(index)); | 208 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); |
196 } | 209 } |
197 | 210 |
198 // static | 211 // static |
199 gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget, | 212 gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget, |
200 GdkEventExpose* event, | 213 GdkEventExpose* event, |
201 ExtensionShelfGtk* bar) { | 214 ExtensionShelfGtk* bar) { |
202 // Paint the background theme image. | 215 // Paint the background theme image. |
203 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 216 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
204 cairo_rectangle(cr, event->area.x, event->area.y, | 217 cairo_rectangle(cr, event->area.x, event->area.y, |
205 event->area.width, event->area.height); | 218 event->area.width, event->area.height); |
206 cairo_clip(cr); | 219 cairo_clip(cr); |
207 bar->InitBackground(); | 220 bar->InitBackground(); |
208 bar->background_ninebox_->RenderTopCenterStrip( | 221 bar->background_ninebox_->RenderTopCenterStrip( |
209 cr, event->area.x, event->area.y, | 222 cr, event->area.x, event->area.y, |
210 event->area.x + event->area.width); | 223 event->area.x + event->area.width); |
211 cairo_destroy(cr); | 224 cairo_destroy(cr); |
212 | 225 |
213 return FALSE; // Propagate expose to children. | 226 return FALSE; // Propagate expose to children. |
214 } | 227 } |
OLD | NEW |