OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/gtk/extension_shelf_gtk.h" |
| 6 |
| 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 9 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 10 #include "chrome/browser/gtk/nine_box.h" |
| 11 #include "chrome/browser/profile.h" |
| 12 #include "chrome/common/notification_service.h" |
| 13 #include "grit/app_resources.h" |
| 14 #include "grit/generated_resources.h" |
| 15 #include "grit/theme_resources.h" |
| 16 |
| 17 ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser) |
| 18 : browser_(browser), |
| 19 theme_provider_(GtkThemeProvider::GetFrom(profile)), |
| 20 model_(new ExtensionShelfModel(browser)) { |
| 21 Init(profile); |
| 22 |
| 23 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 24 NotificationService::AllSources()); |
| 25 } |
| 26 |
| 27 ExtensionShelfGtk::~ExtensionShelfGtk() { |
| 28 model_->RemoveObserver(this); |
| 29 event_box_.Destroy(); |
| 30 } |
| 31 |
| 32 void ExtensionShelfGtk::AddShelfToBox(GtkWidget* box) { |
| 33 gtk_box_pack_end(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0); |
| 34 } |
| 35 |
| 36 void ExtensionShelfGtk::Show() { |
| 37 gtk_widget_show_all(event_box_.get()); |
| 38 } |
| 39 |
| 40 void ExtensionShelfGtk::Hide() { |
| 41 gtk_widget_hide(event_box_.get()); |
| 42 } |
| 43 |
| 44 void ExtensionShelfGtk::ToolstripInsertedAt(ExtensionHost* toolstrip, |
| 45 int index) { |
| 46 AdjustHeight(); |
| 47 } |
| 48 |
| 49 void ExtensionShelfGtk::ToolstripRemovingAt(ExtensionHost* toolstrip, |
| 50 int index) { |
| 51 AdjustHeight(); |
| 52 } |
| 53 |
| 54 void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* toolstrip, |
| 55 int from_index, |
| 56 int to_index) { |
| 57 AdjustHeight(); |
| 58 } |
| 59 |
| 60 void ExtensionShelfGtk::ToolstripChangedAt(ExtensionHost* toolstrip, |
| 61 int index) { |
| 62 AdjustHeight(); |
| 63 } |
| 64 |
| 65 void ExtensionShelfGtk::ExtensionShelfEmpty() { |
| 66 AdjustHeight(); |
| 67 } |
| 68 |
| 69 void ExtensionShelfGtk::ShelfModelReloaded() { |
| 70 AdjustHeight(); |
| 71 } |
| 72 |
| 73 void ExtensionShelfGtk::Init(Profile* profile) { |
| 74 event_box_.Own(gtk_event_box_new()); |
| 75 |
| 76 shelf_hbox_ = gtk_hbox_new(FALSE, 0); |
| 77 gtk_widget_set_app_paintable(shelf_hbox_, TRUE); |
| 78 g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event", |
| 79 G_CALLBACK(&OnHBoxExpose), this); |
| 80 gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_); |
| 81 |
| 82 label_ = gtk_label_new("(extension shelf will appear here)"); |
| 83 gtk_box_pack_start(GTK_BOX(shelf_hbox_), label_, |
| 84 TRUE, TRUE, 0); |
| 85 |
| 86 AdjustHeight(); |
| 87 |
| 88 model_->AddObserver(this); |
| 89 } |
| 90 |
| 91 void ExtensionShelfGtk::Observe(NotificationType type, |
| 92 const NotificationSource& source, |
| 93 const NotificationDetails& details) { |
| 94 if (type == NotificationType::BROWSER_THEME_CHANGED) { |
| 95 // TODO(phajdan.jr): Handle theme changes. |
| 96 } else { |
| 97 NOTREACHED() << "unexpected notification"; |
| 98 } |
| 99 } |
| 100 |
| 101 void ExtensionShelfGtk::InitBackground() { |
| 102 if (background_ninebox_.get()) |
| 103 return; |
| 104 |
| 105 background_ninebox_.reset(new NineBox( |
| 106 browser_->profile()->GetThemeProvider(), |
| 107 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); |
| 108 } |
| 109 |
| 110 void ExtensionShelfGtk::AdjustHeight() { |
| 111 int target_height = model_->empty() ? 0 : event_box_->requisition.height; |
| 112 gtk_widget_set_size_request(event_box_.get(), -1, target_height); |
| 113 } |
| 114 |
| 115 // static |
| 116 gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget, |
| 117 GdkEventExpose* event, |
| 118 ExtensionShelfGtk* bar) { |
| 119 // Paint the background theme image. |
| 120 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
| 121 cairo_rectangle(cr, event->area.x, event->area.y, |
| 122 event->area.width, event->area.height); |
| 123 cairo_clip(cr); |
| 124 bar->InitBackground(); |
| 125 bar->background_ninebox_->RenderTopCenterStrip( |
| 126 cr, event->area.x, event->area.y, |
| 127 event->area.x + event->area.width); |
| 128 cairo_destroy(cr); |
| 129 |
| 130 return FALSE; // Propagate expose to children. |
| 131 } |
OLD | NEW |