| 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 "base/gfx/gtk_util.h" |
| 8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
| 9 #include "chrome/browser/gtk/browser_window_gtk.h" | 9 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 10 #include "chrome/browser/gtk/gtk_theme_provider.h" | 10 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 explicit Toolstrip(ExtensionHost* host) | 30 explicit Toolstrip(ExtensionHost* host) |
| 31 : host_(host), | 31 : host_(host), |
| 32 extension_name_(host_->extension()->name()) { | 32 extension_name_(host_->extension()->name()) { |
| 33 DCHECK(host_->view()); | 33 DCHECK(host_->view()); |
| 34 Init(); | 34 Init(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void AddToolstripToBox(GtkWidget* box); | 37 void AddToolstripToBox(GtkWidget* box); |
| 38 void RemoveToolstripFromBox(GtkWidget* box); | 38 void RemoveToolstripFromBox(GtkWidget* box); |
| 39 | 39 |
| 40 void SetBackground(const SkBitmap& background) { |
| 41 host_->view()->SetBackground(background); |
| 42 } |
| 43 |
| 40 private: | 44 private: |
| 41 void Init(); | 45 void Init(); |
| 42 | 46 |
| 43 gfx::NativeView native_view() { | 47 gfx::NativeView native_view() { |
| 44 return host_->view()->native_view(); | 48 return host_->view()->native_view(); |
| 45 } | 49 } |
| 46 | 50 |
| 47 ExtensionHost* host_; | 51 ExtensionHost* host_; |
| 48 | 52 |
| 49 const std::string extension_name_; | 53 const std::string extension_name_; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 void ExtensionShelfGtk::Show() { | 90 void ExtensionShelfGtk::Show() { |
| 87 gtk_widget_show_all(event_box_.get()); | 91 gtk_widget_show_all(event_box_.get()); |
| 88 } | 92 } |
| 89 | 93 |
| 90 void ExtensionShelfGtk::Hide() { | 94 void ExtensionShelfGtk::Hide() { |
| 91 gtk_widget_hide(event_box_.get()); | 95 gtk_widget_hide(event_box_.get()); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void ExtensionShelfGtk::ToolstripInsertedAt(ExtensionHost* host, | 98 void ExtensionShelfGtk::ToolstripInsertedAt(ExtensionHost* host, |
| 95 int index) { | 99 int index) { |
| 100 InitBackground(); |
| 96 Toolstrip* toolstrip = new Toolstrip(host); | 101 Toolstrip* toolstrip = new Toolstrip(host); |
| 102 toolstrip->SetBackground(*background_.get()); |
| 97 toolstrip->AddToolstripToBox(shelf_hbox_); | 103 toolstrip->AddToolstripToBox(shelf_hbox_); |
| 98 toolstrips_.insert(toolstrip); | 104 toolstrips_.insert(toolstrip); |
| 99 model_->SetToolstripDataAt(index, toolstrip); | 105 model_->SetToolstripDataAt(index, toolstrip); |
| 100 | 106 |
| 101 AdjustHeight(); | 107 AdjustHeight(); |
| 102 } | 108 } |
| 103 | 109 |
| 104 void ExtensionShelfGtk::ToolstripRemovingAt(ExtensionHost* host, | 110 void ExtensionShelfGtk::ToolstripRemovingAt(ExtensionHost* host, |
| 105 int index) { | 111 int index) { |
| 106 Toolstrip* toolstrip = ToolstripAtIndex(index); | 112 Toolstrip* toolstrip = ToolstripAtIndex(index); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 gtk_container_add(GTK_CONTAINER(event_box_.get()), vbox); | 187 gtk_container_add(GTK_CONTAINER(event_box_.get()), vbox); |
| 182 | 188 |
| 183 theme_provider_->InitThemesFor(this); | 189 theme_provider_->InitThemesFor(this); |
| 184 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 190 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 185 NotificationService::AllSources()); | 191 NotificationService::AllSources()); |
| 186 | 192 |
| 187 LoadFromModel(); | 193 LoadFromModel(); |
| 188 model_->AddObserver(this); | 194 model_->AddObserver(this); |
| 189 } | 195 } |
| 190 | 196 |
| 197 void ExtensionShelfGtk::InitBackground() { |
| 198 if (background_.get()) |
| 199 return; |
| 200 background_.reset(new SkBitmap); |
| 201 background_->setConfig(SkBitmap::kARGB_8888_Config, 3, 3); |
| 202 background_->allocPixels(); |
| 203 background_->eraseRGB(kBackgroundColor.red >> 8, |
| 204 kBackgroundColor.green >> 8, |
| 205 kBackgroundColor.blue >> 8); |
| 206 } |
| 207 |
| 191 void ExtensionShelfGtk::AdjustHeight() { | 208 void ExtensionShelfGtk::AdjustHeight() { |
| 192 if (model_->empty() || toolstrips_.empty()) { | 209 if (model_->empty() || toolstrips_.empty()) { |
| 193 // It's possible that |model_| is not empty, but |toolstrips_| are empty | 210 // It's possible that |model_| is not empty, but |toolstrips_| are empty |
| 194 // when removing the last toolstrip. | 211 // when removing the last toolstrip. |
| 195 DCHECK(toolstrips_.empty()); | 212 DCHECK(toolstrips_.empty()); |
| 196 Hide(); | 213 Hide(); |
| 197 } else { | 214 } else { |
| 198 gtk_widget_set_size_request(shelf_hbox_, -1, kShelfHeight); | 215 gtk_widget_set_size_request(shelf_hbox_, -1, kShelfHeight); |
| 199 Show(); | 216 Show(); |
| 200 } | 217 } |
| 201 } | 218 } |
| 202 | 219 |
| 203 void ExtensionShelfGtk::LoadFromModel() { | 220 void ExtensionShelfGtk::LoadFromModel() { |
| 204 DCHECK(toolstrips_.empty()); | 221 DCHECK(toolstrips_.empty()); |
| 205 int count = model_->count(); | 222 int count = model_->count(); |
| 206 for (int i = 0; i < count; ++i) | 223 for (int i = 0; i < count; ++i) |
| 207 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); | 224 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); |
| 208 AdjustHeight(); | 225 AdjustHeight(); |
| 209 } | 226 } |
| 210 | 227 |
| 211 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { | 228 ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) { |
| 212 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); | 229 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); |
| 213 } | 230 } |
| OLD | NEW |