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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. |
256 void Activate(GtkWidget* widget) { | 256 void Activate(GtkWidget* widget) { |
| 257 Activate(widget, true); |
| 258 } |
| 259 |
| 260 void Activate(GtkWidget* widget, bool allow_grant) { |
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 break; |
269 } | 274 } |
270 } | 275 } |
271 | 276 |
272 // MenuGtk::Delegate implementation. | 277 // MenuGtk::Delegate implementation. |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 signals_.Connect(button->widget(), "show", | 667 signals_.Connect(button->widget(), "show", |
663 G_CALLBACK(&OnButtonShowOrHideThunk), this); | 668 G_CALLBACK(&OnButtonShowOrHideThunk), this); |
664 signals_.Connect(button->widget(), "hide", | 669 signals_.Connect(button->widget(), "hide", |
665 G_CALLBACK(&OnButtonShowOrHideThunk), this); | 670 G_CALLBACK(&OnButtonShowOrHideThunk), this); |
666 | 671 |
667 gtk_widget_show(button->widget()); | 672 gtk_widget_show(button->widget()); |
668 | 673 |
669 UpdateVisibility(); | 674 UpdateVisibility(); |
670 } | 675 } |
671 | 676 |
| 677 BrowserActionButton* BrowserActionsToolbarGtk::GetBrowserActionButton( |
| 678 const Extension* extension) { |
| 679 ExtensionButtonMap::iterator it = extension_button_map_.find( |
| 680 extension->id()); |
| 681 return it == extension_button_map_.end() ? NULL : it->second.get(); |
| 682 } |
| 683 |
672 GtkWidget* BrowserActionsToolbarGtk::GetBrowserActionWidget( | 684 GtkWidget* BrowserActionsToolbarGtk::GetBrowserActionWidget( |
673 const Extension* extension) { | 685 const Extension* extension) { |
674 ExtensionButtonMap::iterator it = extension_button_map_.find( | 686 BrowserActionButton* button = GetBrowserActionButton(extension); |
675 extension->id()); | 687 return button == NULL ? NULL : button->widget(); |
676 if (it == extension_button_map_.end()) | |
677 return NULL; | |
678 | |
679 return it->second.get()->widget(); | |
680 } | 688 } |
681 | 689 |
682 void BrowserActionsToolbarGtk::RemoveButtonForExtension( | 690 void BrowserActionsToolbarGtk::RemoveButtonForExtension( |
683 const Extension* extension) { | 691 const Extension* extension) { |
684 if (extension_button_map_.erase(extension->id())) | 692 if (extension_button_map_.erase(extension->id())) |
685 UpdateVisibility(); | 693 UpdateVisibility(); |
686 UpdateChevronVisibility(); | 694 UpdateChevronVisibility(); |
687 } | 695 } |
688 | 696 |
689 void BrowserActionsToolbarGtk::UpdateVisibility() { | 697 void BrowserActionsToolbarGtk::UpdateVisibility() { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 NOTREACHED(); | 769 NOTREACHED(); |
762 return; | 770 return; |
763 } | 771 } |
764 | 772 |
765 if (profile_->IsOffTheRecord()) | 773 if (profile_->IsOffTheRecord()) |
766 index = model_->OriginalIndexToIncognito(index); | 774 index = model_->OriginalIndexToIncognito(index); |
767 | 775 |
768 gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), button_widget, index); | 776 gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), button_widget, index); |
769 } | 777 } |
770 | 778 |
| 779 void BrowserActionsToolbarGtk::BrowserActionShowPopup( |
| 780 const Extension* extension) { |
| 781 // Do not override other popups and only show in active window. |
| 782 if (ExtensionPopupGtk::get_current_extension_popup() || |
| 783 !browser_->window()->IsActive()) { |
| 784 return; |
| 785 } |
| 786 |
| 787 BrowserActionButton* button = GetBrowserActionButton(extension); |
| 788 if (button == NULL || button->widget() == NULL) |
| 789 return; |
| 790 |
| 791 GtkWidget* anchor = button->widget(); |
| 792 if (!gtk_widget_get_visible(anchor)) |
| 793 anchor = button->toolbar_->chevron(); |
| 794 button->Activate(anchor, false); |
| 795 } |
| 796 |
771 void BrowserActionsToolbarGtk::ModelLoaded() { | 797 void BrowserActionsToolbarGtk::ModelLoaded() { |
772 SetContainerWidth(); | 798 SetContainerWidth(); |
773 } | 799 } |
774 | 800 |
775 void BrowserActionsToolbarGtk::AnimationProgressed( | 801 void BrowserActionsToolbarGtk::AnimationProgressed( |
776 const gfx::Animation* animation) { | 802 const gfx::Animation* animation) { |
777 int width = start_width_ + (desired_width_ - start_width_) * | 803 int width = start_width_ + (desired_width_ - start_width_) * |
778 animation->GetCurrentValue(); | 804 animation->GetCurrentValue(); |
779 gtk_widget_set_size_request(button_hbox_.get(), width, -1); | 805 gtk_widget_set_size_request(button_hbox_.get(), width, -1); |
780 | 806 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 NOTREACHED(); | 1096 NOTREACHED(); |
1071 return FALSE; | 1097 return FALSE; |
1072 } | 1098 } |
1073 | 1099 |
1074 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( | 1100 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( |
1075 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); | 1101 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); |
1076 if (profile_->IsOffTheRecord()) | 1102 if (profile_->IsOffTheRecord()) |
1077 item_index = model_->IncognitoIndexToOriginal(item_index); | 1103 item_index = model_->IncognitoIndexToOriginal(item_index); |
1078 | 1104 |
1079 const Extension* extension = model_->toolbar_items()[item_index].get(); | 1105 const Extension* extension = model_->toolbar_items()[item_index].get(); |
1080 ExtensionButtonMap::iterator it = extension_button_map_.find(extension->id()); | 1106 BrowserActionButton* button = GetBrowserActionButton(extension); |
1081 if (it == extension_button_map_.end()) { | 1107 if (button == NULL) { |
1082 NOTREACHED(); | 1108 NOTREACHED(); |
1083 return FALSE; | 1109 return FALSE; |
1084 } | 1110 } |
1085 | 1111 |
1086 MenuGtk* menu = it->second.get()->GetContextMenu(); | 1112 MenuGtk* menu = button->GetContextMenu(); |
1087 if (!menu) | 1113 if (!menu) |
1088 return FALSE; | 1114 return FALSE; |
1089 | 1115 |
1090 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 1116 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
1091 event->time); | 1117 event->time); |
1092 return TRUE; | 1118 return TRUE; |
1093 } | 1119 } |
1094 | 1120 |
1095 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 1121 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
1096 if (!resize_animation_.is_animating()) | 1122 if (!resize_animation_.is_animating()) |
1097 UpdateChevronVisibility(); | 1123 UpdateChevronVisibility(); |
1098 } | 1124 } |
OLD | NEW |