OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/browser_actions_toolbar_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 234 matching lines...) Loading... | |
245 return NULL; | 245 return NULL; |
246 | 246 |
247 context_menu_model_ = | 247 context_menu_model_ = |
248 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this); | 248 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this); |
249 context_menu_.reset( | 249 context_menu_.reset( |
250 new MenuGtk(this, context_menu_model_.get())); | 250 new MenuGtk(this, context_menu_model_.get())); |
251 return context_menu_.get(); | 251 return context_menu_.get(); |
252 } | 252 } |
253 | 253 |
254 private: | 254 private: |
255 // Activate the browser action. | 255 // Activate the browser action. Returns true if a popup was shown. |
256 void Activate(GtkWidget* widget) { | 256 bool Activate(GtkWidget* widget) { |
257 return Activate(widget, true); | |
258 } | |
259 | |
260 bool Activate(GtkWidget* widget, bool allow_grant) { | |
Finnur
2013/10/17 14:58:34
Same here (avoid forking the function just to add
| |
257 ExtensionToolbarModel* model = toolbar_->model(); | 261 ExtensionToolbarModel* model = toolbar_->model(); |
258 const Extension* extension = extension_; | 262 const Extension* extension = extension_; |
259 Browser* browser = toolbar_->browser(); | 263 Browser* browser = toolbar_->browser(); |
260 GURL popup_url; | 264 GURL popup_url; |
261 | 265 |
262 switch (model->ExecuteBrowserAction(extension, browser, &popup_url)) { | 266 switch (model->ExecuteBrowserAction( |
267 extension, browser, &popup_url, allow_grant)) { | |
263 case ExtensionToolbarModel::ACTION_NONE: | 268 case ExtensionToolbarModel::ACTION_NONE: |
264 break; | 269 break; |
265 case ExtensionToolbarModel::ACTION_SHOW_POPUP: | 270 case ExtensionToolbarModel::ACTION_SHOW_POPUP: |
266 ExtensionPopupGtk::Show(popup_url, browser, widget, | 271 ExtensionPopupGtk::Show(popup_url, browser, widget, |
267 ExtensionPopupGtk::SHOW); | 272 ExtensionPopupGtk::SHOW); |
268 break; | 273 return true; |
269 } | 274 } |
275 return false; | |
270 } | 276 } |
271 | 277 |
272 // MenuGtk::Delegate implementation. | 278 // MenuGtk::Delegate implementation. |
273 virtual void StoppedShowing() OVERRIDE { | 279 virtual void StoppedShowing() OVERRIDE { |
274 if (enabled_) | 280 if (enabled_) |
275 button_->UnsetPaintOverride(); | 281 button_->UnsetPaintOverride(); |
276 else | 282 else |
277 button_->SetPaintOverride(GTK_STATE_INSENSITIVE); | 283 button_->SetPaintOverride(GTK_STATE_INSENSITIVE); |
278 | 284 |
279 // If the context menu was showing for the overflow menu, re-assert the | 285 // If the context menu was showing for the overflow menu, re-assert the |
(...skipping 382 matching lines...) Loading... | |
662 signals_.Connect(button->widget(), "show", | 668 signals_.Connect(button->widget(), "show", |
663 G_CALLBACK(&OnButtonShowOrHideThunk), this); | 669 G_CALLBACK(&OnButtonShowOrHideThunk), this); |
664 signals_.Connect(button->widget(), "hide", | 670 signals_.Connect(button->widget(), "hide", |
665 G_CALLBACK(&OnButtonShowOrHideThunk), this); | 671 G_CALLBACK(&OnButtonShowOrHideThunk), this); |
666 | 672 |
667 gtk_widget_show(button->widget()); | 673 gtk_widget_show(button->widget()); |
668 | 674 |
669 UpdateVisibility(); | 675 UpdateVisibility(); |
670 } | 676 } |
671 | 677 |
678 BrowserActionButton* BrowserActionsToolbarGtk::GetBrowserActionButton( | |
679 const Extension* extension) { | |
680 ExtensionButtonMap::iterator it = extension_button_map_.find( | |
681 extension->id()); | |
682 return it == extension_button_map_.end() ? NULL : it->second.get(); | |
683 } | |
684 | |
672 GtkWidget* BrowserActionsToolbarGtk::GetBrowserActionWidget( | 685 GtkWidget* BrowserActionsToolbarGtk::GetBrowserActionWidget( |
673 const Extension* extension) { | 686 const Extension* extension) { |
674 ExtensionButtonMap::iterator it = extension_button_map_.find( | 687 BrowserActionButton* button = GetBrowserActionButton(extension); |
675 extension->id()); | 688 return button == NULL ? NULL : button->widget(); |
676 if (it == extension_button_map_.end()) | |
677 return NULL; | |
678 | |
679 return it->second.get()->widget(); | |
680 } | 689 } |
681 | 690 |
682 void BrowserActionsToolbarGtk::RemoveButtonForExtension( | 691 void BrowserActionsToolbarGtk::RemoveButtonForExtension( |
683 const Extension* extension) { | 692 const Extension* extension) { |
684 if (extension_button_map_.erase(extension->id())) | 693 if (extension_button_map_.erase(extension->id())) |
685 UpdateVisibility(); | 694 UpdateVisibility(); |
686 UpdateChevronVisibility(); | 695 UpdateChevronVisibility(); |
687 } | 696 } |
688 | 697 |
689 void BrowserActionsToolbarGtk::UpdateVisibility() { | 698 void BrowserActionsToolbarGtk::UpdateVisibility() { |
(...skipping 71 matching lines...) Loading... | |
761 NOTREACHED(); | 770 NOTREACHED(); |
762 return; | 771 return; |
763 } | 772 } |
764 | 773 |
765 if (profile_->IsOffTheRecord()) | 774 if (profile_->IsOffTheRecord()) |
766 index = model_->OriginalIndexToIncognito(index); | 775 index = model_->OriginalIndexToIncognito(index); |
767 | 776 |
768 gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), button_widget, index); | 777 gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), button_widget, index); |
769 } | 778 } |
770 | 779 |
780 bool BrowserActionsToolbarGtk::BrowserActionShowPopup( | |
781 const Extension* extension) { | |
782 // Do not override other popups and only show in active window. | |
783 if (ExtensionPopupGtk::get_current_extension_popup() || | |
784 !browser_->window()->IsActive()) { | |
785 return false; | |
786 } | |
787 | |
788 BrowserActionButton* button = GetBrowserActionButton(extension); | |
789 if (button == NULL || button->widget() == NULL) | |
790 return false; | |
791 | |
792 GtkWidget* anchor = button->widget(); | |
793 if (!gtk_widget_get_visible(anchor)) | |
794 anchor = button->toolbar_->chevron(); | |
795 return button->Activate(anchor, false); | |
796 } | |
797 | |
771 void BrowserActionsToolbarGtk::ModelLoaded() { | 798 void BrowserActionsToolbarGtk::ModelLoaded() { |
772 SetContainerWidth(); | 799 SetContainerWidth(); |
773 } | 800 } |
774 | 801 |
775 void BrowserActionsToolbarGtk::AnimationProgressed( | 802 void BrowserActionsToolbarGtk::AnimationProgressed( |
776 const gfx::Animation* animation) { | 803 const gfx::Animation* animation) { |
777 int width = start_width_ + (desired_width_ - start_width_) * | 804 int width = start_width_ + (desired_width_ - start_width_) * |
778 animation->GetCurrentValue(); | 805 animation->GetCurrentValue(); |
779 gtk_widget_set_size_request(button_hbox_.get(), width, -1); | 806 gtk_widget_set_size_request(button_hbox_.get(), width, -1); |
780 | 807 |
(...skipping 289 matching lines...) Loading... | |
1070 NOTREACHED(); | 1097 NOTREACHED(); |
1071 return FALSE; | 1098 return FALSE; |
1072 } | 1099 } |
1073 | 1100 |
1074 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( | 1101 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( |
1075 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); | 1102 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); |
1076 if (profile_->IsOffTheRecord()) | 1103 if (profile_->IsOffTheRecord()) |
1077 item_index = model_->IncognitoIndexToOriginal(item_index); | 1104 item_index = model_->IncognitoIndexToOriginal(item_index); |
1078 | 1105 |
1079 const Extension* extension = model_->toolbar_items()[item_index].get(); | 1106 const Extension* extension = model_->toolbar_items()[item_index].get(); |
1080 ExtensionButtonMap::iterator it = extension_button_map_.find(extension->id()); | 1107 BrowserActionButton* button = GetBrowserActionButton(extension); |
1081 if (it == extension_button_map_.end()) { | 1108 if (button == NULL) { |
1082 NOTREACHED(); | 1109 NOTREACHED(); |
1083 return FALSE; | 1110 return FALSE; |
1084 } | 1111 } |
1085 | 1112 |
1086 MenuGtk* menu = it->second.get()->GetContextMenu(); | 1113 MenuGtk* menu = button->GetContextMenu(); |
1087 if (!menu) | 1114 if (!menu) |
1088 return FALSE; | 1115 return FALSE; |
1089 | 1116 |
1090 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 1117 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
1091 event->time); | 1118 event->time); |
1092 return TRUE; | 1119 return TRUE; |
1093 } | 1120 } |
1094 | 1121 |
1095 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 1122 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
1096 if (!resize_animation_.is_animating()) | 1123 if (!resize_animation_.is_animating()) |
1097 UpdateChevronVisibility(); | 1124 UpdateChevronVisibility(); |
1098 } | 1125 } |
OLD | NEW |