| 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/browser_actions_toolbar_gtk.h" | 5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "app/gfx/canvas_paint.h" | 10 #include "app/gfx/canvas_paint.h" |
| 11 #include "app/gfx/gtk_util.h" | 11 #include "app/gfx/gtk_util.h" |
| 12 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/extensions/extension_browser_event_router.h" | 13 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 14 #include "chrome/browser/extensions/extensions_service.h" | 14 #include "chrome/browser/extensions/extensions_service.h" |
| 15 #include "chrome/browser/extensions/image_loading_tracker.h" | 15 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 16 #include "chrome/browser/gtk/extension_popup_gtk.h" | 16 #include "chrome/browser/gtk/extension_popup_gtk.h" |
| 17 #include "chrome/browser/gtk/gtk_chrome_button.h" | 17 #include "chrome/browser/gtk/gtk_chrome_button.h" |
| 18 #include "chrome/browser/gtk/gtk_theme_provider.h" | 18 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/notification_details.h" | 21 #include "chrome/common/notification_details.h" |
| 22 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
| 23 #include "chrome/common/notification_source.h" | 23 #include "chrome/common/notification_source.h" |
| 24 #include "chrome/common/notification_type.h" | 24 #include "chrome/common/notification_type.h" |
| 25 | 25 |
| 26 // The size of each button on the toolbar. | 26 // The size of each button on the toolbar. |
| 27 static const int kButtonSize = 29; | 27 static const int kButtonSize = 29; |
| 28 | 28 |
| 29 // The padding between browser action buttons. Visually, the actual number of |
| 30 // "empty" (non-drawing) pixels is this value + 2 when adjacent browser icons |
| 31 // use their maximum allowed size. |
| 32 static const int kBrowserActionButtonPadding = 3; |
| 33 |
| 29 class BrowserActionButton : public NotificationObserver, | 34 class BrowserActionButton : public NotificationObserver, |
| 30 public ImageLoadingTracker::Observer { | 35 public ImageLoadingTracker::Observer { |
| 31 public: | 36 public: |
| 32 BrowserActionButton(Browser* browser, Extension* extension) | 37 BrowserActionButton(Browser* browser, Extension* extension) |
| 33 : browser_(browser), | 38 : browser_(browser), |
| 34 extension_(extension), | 39 extension_(extension), |
| 35 button_(gtk_chrome_button_new()) { | 40 button_(gtk_chrome_button_new()) { |
| 36 DCHECK(extension_->browser_action()); | 41 DCHECK(extension_->browser_action()); |
| 37 | 42 |
| 38 gtk_widget_set_size_request(button_.get(), kButtonSize, kButtonSize); | 43 gtk_widget_set_size_request(button_.get(), kButtonSize, kButtonSize); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // Icons for all the different states the button can be in. These will be NULL | 162 // Icons for all the different states the button can be in. These will be NULL |
| 158 // while they are loading. | 163 // while they are loading. |
| 159 std::vector<GdkPixbuf*> browser_action_icons_; | 164 std::vector<GdkPixbuf*> browser_action_icons_; |
| 160 | 165 |
| 161 NotificationRegistrar registrar_; | 166 NotificationRegistrar registrar_; |
| 162 }; | 167 }; |
| 163 | 168 |
| 164 BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser) | 169 BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser) |
| 165 : browser_(browser), | 170 : browser_(browser), |
| 166 profile_(browser->profile()), | 171 profile_(browser->profile()), |
| 167 hbox_(gtk_hbox_new(0, FALSE)) { | 172 hbox_(gtk_hbox_new(FALSE, kBrowserActionButtonPadding)) { |
| 168 ExtensionsService* extension_service = profile_->GetExtensionsService(); | 173 ExtensionsService* extension_service = profile_->GetExtensionsService(); |
| 169 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 174 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 170 Source<ExtensionsService>(extension_service)); | 175 Source<ExtensionsService>(extension_service)); |
| 171 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 176 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 172 Source<ExtensionsService>(extension_service)); | 177 Source<ExtensionsService>(extension_service)); |
| 173 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, | 178 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, |
| 174 Source<ExtensionsService>(extension_service)); | 179 Source<ExtensionsService>(extension_service)); |
| 175 | 180 |
| 176 CreateAllButtons(); | 181 CreateAllButtons(); |
| 177 } | 182 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 if (extension_button_map_.erase(extension->id())) | 237 if (extension_button_map_.erase(extension->id())) |
| 233 UpdateVisibility(); | 238 UpdateVisibility(); |
| 234 } | 239 } |
| 235 | 240 |
| 236 void BrowserActionsToolbarGtk::UpdateVisibility() { | 241 void BrowserActionsToolbarGtk::UpdateVisibility() { |
| 237 if (button_count() == 0) | 242 if (button_count() == 0) |
| 238 gtk_widget_hide(widget()); | 243 gtk_widget_hide(widget()); |
| 239 else | 244 else |
| 240 gtk_widget_show(widget()); | 245 gtk_widget_show(widget()); |
| 241 } | 246 } |
| OLD | NEW |