Chromium Code Reviews| 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...) Expand 10 before | Expand all | Expand 10 after 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, bool should_grant) { |
|
Finnur
2013/10/18 10:31:01
I would copy the explanation of should_grant (in t
justinlin
2013/10/19 06:01:48
Hmm, this was already done, must be an older patch
| |
| 257 ExtensionToolbarModel* model = toolbar_->model(); | 257 ExtensionToolbarModel* model = toolbar_->model(); |
| 258 const Extension* extension = extension_; | 258 const Extension* extension = extension_; |
| 259 Browser* browser = toolbar_->browser(); | 259 Browser* browser = toolbar_->browser(); |
| 260 GURL popup_url; | 260 GURL popup_url; |
| 261 | 261 |
| 262 switch (model->ExecuteBrowserAction(extension, browser, &popup_url)) { | 262 switch (model->ExecuteBrowserAction( |
| 263 extension, browser, &popup_url, should_grant)) { | |
| 263 case ExtensionToolbarModel::ACTION_NONE: | 264 case ExtensionToolbarModel::ACTION_NONE: |
| 264 break; | 265 break; |
| 265 case ExtensionToolbarModel::ACTION_SHOW_POPUP: | 266 case ExtensionToolbarModel::ACTION_SHOW_POPUP: |
| 266 ExtensionPopupGtk::Show(popup_url, browser, widget, | 267 ExtensionPopupGtk::Show(popup_url, browser, widget, |
| 267 ExtensionPopupGtk::SHOW); | 268 ExtensionPopupGtk::SHOW); |
| 268 break; | 269 return true; |
| 269 } | 270 } |
| 271 return false; | |
| 270 } | 272 } |
| 271 | 273 |
| 272 // MenuGtk::Delegate implementation. | 274 // MenuGtk::Delegate implementation. |
| 273 virtual void StoppedShowing() OVERRIDE { | 275 virtual void StoppedShowing() OVERRIDE { |
| 274 if (enabled_) | 276 if (enabled_) |
| 275 button_->UnsetPaintOverride(); | 277 button_->UnsetPaintOverride(); |
| 276 else | 278 else |
| 277 button_->SetPaintOverride(GTK_STATE_INSENSITIVE); | 279 button_->SetPaintOverride(GTK_STATE_INSENSITIVE); |
| 278 | 280 |
| 279 // If the context menu was showing for the overflow menu, re-assert the | 281 // If the context menu was showing for the overflow menu, re-assert the |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 return FALSE; | 318 return FALSE; |
| 317 | 319 |
| 318 button->button_->SetPaintOverride(GTK_STATE_ACTIVE); | 320 button->button_->SetPaintOverride(GTK_STATE_ACTIVE); |
| 319 menu->PopupForWidget(widget, event->button, event->time); | 321 menu->PopupForWidget(widget, event->button, event->time); |
| 320 | 322 |
| 321 return TRUE; | 323 return TRUE; |
| 322 } | 324 } |
| 323 | 325 |
| 324 static void OnClicked(GtkWidget* widget, BrowserActionButton* button) { | 326 static void OnClicked(GtkWidget* widget, BrowserActionButton* button) { |
| 325 if (button->enabled_) | 327 if (button->enabled_) |
| 326 button->Activate(widget); | 328 button->Activate(widget, true); |
| 327 } | 329 } |
| 328 | 330 |
| 329 static gboolean OnExposeEvent(GtkWidget* widget, | 331 static gboolean OnExposeEvent(GtkWidget* widget, |
| 330 GdkEventExpose* event, | 332 GdkEventExpose* event, |
| 331 BrowserActionButton* button) { | 333 BrowserActionButton* button) { |
| 332 int tab_id = button->toolbar_->GetCurrentTabId(); | 334 int tab_id = button->toolbar_->GetCurrentTabId(); |
| 333 if (tab_id < 0) | 335 if (tab_id < 0) |
| 334 return FALSE; | 336 return FALSE; |
| 335 | 337 |
| 336 ExtensionAction* action = button->browser_action(); | 338 ExtensionAction* action = button->browser_action(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 357 static gboolean OnGtkAccelerator(GtkAccelGroup* accel_group, | 359 static gboolean OnGtkAccelerator(GtkAccelGroup* accel_group, |
| 358 GObject* acceleratable, | 360 GObject* acceleratable, |
| 359 guint keyval, | 361 guint keyval, |
| 360 GdkModifierType modifier, | 362 GdkModifierType modifier, |
| 361 BrowserActionButton* button) { | 363 BrowserActionButton* button) { |
| 362 // Open the popup for this extension. | 364 // Open the popup for this extension. |
| 363 GtkWidget* anchor = button->widget(); | 365 GtkWidget* anchor = button->widget(); |
| 364 // The anchor might be in the overflow menu. Then we point to the chevron. | 366 // The anchor might be in the overflow menu. Then we point to the chevron. |
| 365 if (!gtk_widget_get_visible(anchor)) | 367 if (!gtk_widget_get_visible(anchor)) |
| 366 anchor = button->toolbar_->chevron(); | 368 anchor = button->toolbar_->chevron(); |
| 367 button->Activate(anchor); | 369 button->Activate(anchor, true); |
| 368 return TRUE; | 370 return TRUE; |
| 369 } | 371 } |
| 370 | 372 |
| 371 // The handler for when the browser action is realized. |user_data| contains a | 373 // The handler for when the browser action is realized. |user_data| contains a |
| 372 // pointer to the BrowserAction shown. | 374 // pointer to the BrowserAction shown. |
| 373 static void OnRealize(GtkWidget* widget, void* user_data) { | 375 static void OnRealize(GtkWidget* widget, void* user_data) { |
| 374 BrowserActionButton* button = static_cast<BrowserActionButton*>(user_data); | 376 BrowserActionButton* button = static_cast<BrowserActionButton*>(user_data); |
| 375 button->ConnectBrowserActionPopupAccelerator(); | 377 button->ConnectBrowserActionPopupAccelerator(); |
| 376 } | 378 } |
| 377 | 379 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 signals_.Connect(button->widget(), "show", | 664 signals_.Connect(button->widget(), "show", |
| 663 G_CALLBACK(&OnButtonShowOrHideThunk), this); | 665 G_CALLBACK(&OnButtonShowOrHideThunk), this); |
| 664 signals_.Connect(button->widget(), "hide", | 666 signals_.Connect(button->widget(), "hide", |
| 665 G_CALLBACK(&OnButtonShowOrHideThunk), this); | 667 G_CALLBACK(&OnButtonShowOrHideThunk), this); |
| 666 | 668 |
| 667 gtk_widget_show(button->widget()); | 669 gtk_widget_show(button->widget()); |
| 668 | 670 |
| 669 UpdateVisibility(); | 671 UpdateVisibility(); |
| 670 } | 672 } |
| 671 | 673 |
| 674 BrowserActionButton* BrowserActionsToolbarGtk::GetBrowserActionButton( | |
| 675 const Extension* extension) { | |
| 676 ExtensionButtonMap::iterator it = extension_button_map_.find( | |
| 677 extension->id()); | |
| 678 return it == extension_button_map_.end() ? NULL : it->second.get(); | |
| 679 } | |
| 680 | |
| 672 GtkWidget* BrowserActionsToolbarGtk::GetBrowserActionWidget( | 681 GtkWidget* BrowserActionsToolbarGtk::GetBrowserActionWidget( |
| 673 const Extension* extension) { | 682 const Extension* extension) { |
| 674 ExtensionButtonMap::iterator it = extension_button_map_.find( | 683 BrowserActionButton* button = GetBrowserActionButton(extension); |
| 675 extension->id()); | 684 return button == NULL ? NULL : button->widget(); |
| 676 if (it == extension_button_map_.end()) | |
| 677 return NULL; | |
| 678 | |
| 679 return it->second.get()->widget(); | |
| 680 } | 685 } |
| 681 | 686 |
| 682 void BrowserActionsToolbarGtk::RemoveButtonForExtension( | 687 void BrowserActionsToolbarGtk::RemoveButtonForExtension( |
| 683 const Extension* extension) { | 688 const Extension* extension) { |
| 684 if (extension_button_map_.erase(extension->id())) | 689 if (extension_button_map_.erase(extension->id())) |
| 685 UpdateVisibility(); | 690 UpdateVisibility(); |
| 686 UpdateChevronVisibility(); | 691 UpdateChevronVisibility(); |
| 687 } | 692 } |
| 688 | 693 |
| 689 void BrowserActionsToolbarGtk::UpdateVisibility() { | 694 void BrowserActionsToolbarGtk::UpdateVisibility() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 761 NOTREACHED(); | 766 NOTREACHED(); |
| 762 return; | 767 return; |
| 763 } | 768 } |
| 764 | 769 |
| 765 if (profile_->IsOffTheRecord()) | 770 if (profile_->IsOffTheRecord()) |
| 766 index = model_->OriginalIndexToIncognito(index); | 771 index = model_->OriginalIndexToIncognito(index); |
| 767 | 772 |
| 768 gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), button_widget, index); | 773 gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), button_widget, index); |
| 769 } | 774 } |
| 770 | 775 |
| 776 bool BrowserActionsToolbarGtk::BrowserActionShowPopup( | |
| 777 const Extension* extension) { | |
| 778 // Do not override other popups and only show in active window. | |
| 779 if (ExtensionPopupGtk::get_current_extension_popup() || | |
| 780 !browser_->window()->IsActive()) { | |
| 781 return false; | |
| 782 } | |
| 783 | |
| 784 BrowserActionButton* button = GetBrowserActionButton(extension); | |
| 785 if (button == NULL || button->widget() == NULL) | |
| 786 return false; | |
| 787 | |
| 788 GtkWidget* anchor = button->widget(); | |
| 789 if (!gtk_widget_get_visible(anchor)) | |
| 790 anchor = button->toolbar_->chevron(); | |
| 791 return button->Activate(anchor, false); | |
| 792 } | |
| 793 | |
| 771 void BrowserActionsToolbarGtk::ModelLoaded() { | 794 void BrowserActionsToolbarGtk::ModelLoaded() { |
| 772 SetContainerWidth(); | 795 SetContainerWidth(); |
| 773 } | 796 } |
| 774 | 797 |
| 775 void BrowserActionsToolbarGtk::AnimationProgressed( | 798 void BrowserActionsToolbarGtk::AnimationProgressed( |
| 776 const gfx::Animation* animation) { | 799 const gfx::Animation* animation) { |
| 777 int width = start_width_ + (desired_width_ - start_width_) * | 800 int width = start_width_ + (desired_width_ - start_width_) * |
| 778 animation->GetCurrentValue(); | 801 animation->GetCurrentValue(); |
| 779 gtk_widget_set_size_request(button_hbox_.get(), width, -1); | 802 gtk_widget_set_size_request(button_hbox_.get(), width, -1); |
| 780 | 803 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 800 bool BrowserActionsToolbarGtk::GetAcceleratorForCommandId( | 823 bool BrowserActionsToolbarGtk::GetAcceleratorForCommandId( |
| 801 int command_id, | 824 int command_id, |
| 802 ui::Accelerator* accelerator) { | 825 ui::Accelerator* accelerator) { |
| 803 return false; | 826 return false; |
| 804 } | 827 } |
| 805 | 828 |
| 806 void BrowserActionsToolbarGtk::ExecuteCommand(int command_id, int event_flags) { | 829 void BrowserActionsToolbarGtk::ExecuteCommand(int command_id, int event_flags) { |
| 807 const Extension* extension = model_->toolbar_items()[command_id].get(); | 830 const Extension* extension = model_->toolbar_items()[command_id].get(); |
| 808 GURL popup_url; | 831 GURL popup_url; |
| 809 | 832 |
| 810 switch (model_->ExecuteBrowserAction(extension, browser(), &popup_url)) { | 833 switch (model_->ExecuteBrowserAction( |
| 834 extension,browser(), &popup_url, true)) { | |
| 811 case ExtensionToolbarModel::ACTION_NONE: | 835 case ExtensionToolbarModel::ACTION_NONE: |
| 812 break; | 836 break; |
| 813 case ExtensionToolbarModel::ACTION_SHOW_POPUP: | 837 case ExtensionToolbarModel::ACTION_SHOW_POPUP: |
| 814 ExtensionPopupGtk::Show(popup_url, browser(), chevron(), | 838 ExtensionPopupGtk::Show(popup_url, browser(), chevron(), |
| 815 ExtensionPopupGtk::SHOW); | 839 ExtensionPopupGtk::SHOW); |
| 816 break; | 840 break; |
| 817 } | 841 } |
| 818 } | 842 } |
| 819 | 843 |
| 820 void BrowserActionsToolbarGtk::StoppedShowing() { | 844 void BrowserActionsToolbarGtk::StoppedShowing() { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1070 NOTREACHED(); | 1094 NOTREACHED(); |
| 1071 return FALSE; | 1095 return FALSE; |
| 1072 } | 1096 } |
| 1073 | 1097 |
| 1074 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( | 1098 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( |
| 1075 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); | 1099 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); |
| 1076 if (profile_->IsOffTheRecord()) | 1100 if (profile_->IsOffTheRecord()) |
| 1077 item_index = model_->IncognitoIndexToOriginal(item_index); | 1101 item_index = model_->IncognitoIndexToOriginal(item_index); |
| 1078 | 1102 |
| 1079 const Extension* extension = model_->toolbar_items()[item_index].get(); | 1103 const Extension* extension = model_->toolbar_items()[item_index].get(); |
| 1080 ExtensionButtonMap::iterator it = extension_button_map_.find(extension->id()); | 1104 BrowserActionButton* button = GetBrowserActionButton(extension); |
| 1081 if (it == extension_button_map_.end()) { | 1105 if (button == NULL) { |
| 1082 NOTREACHED(); | 1106 NOTREACHED(); |
| 1083 return FALSE; | 1107 return FALSE; |
| 1084 } | 1108 } |
| 1085 | 1109 |
| 1086 MenuGtk* menu = it->second.get()->GetContextMenu(); | 1110 MenuGtk* menu = button->GetContextMenu(); |
| 1087 if (!menu) | 1111 if (!menu) |
| 1088 return FALSE; | 1112 return FALSE; |
| 1089 | 1113 |
| 1090 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 1114 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
| 1091 event->time); | 1115 event->time); |
| 1092 return TRUE; | 1116 return TRUE; |
| 1093 } | 1117 } |
| 1094 | 1118 |
| 1095 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 1119 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
| 1096 if (!resize_animation_.is_animating()) | 1120 if (!resize_animation_.is_animating()) |
| 1097 UpdateChevronVisibility(); | 1121 UpdateChevronVisibility(); |
| 1098 } | 1122 } |
| OLD | NEW |