| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/extensions/api/commands/command_service.h" | 17 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 18 #include "chrome/browser/extensions/extension_action.h" | 18 #include "chrome/browser/extensions/extension_action.h" |
| 19 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 19 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 20 #include "chrome/browser/extensions/extension_action_manager.h" | 20 #include "chrome/browser/extensions/extension_action_manager.h" |
| 21 #include "chrome/browser/extensions/extension_context_menu_model.h" | 21 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/extension_system.h" | 23 #include "chrome/browser/extensions/extension_system.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/sessions/session_tab_helper.h" | 25 #include "chrome/browser/sessions/session_tab_helper.h" |
| 26 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 28 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 28 #include "chrome/browser/ui/gtk/custom_button.h" | 29 #include "chrome/browser/ui/gtk/custom_button.h" |
| 29 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" | 30 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
| 30 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" | 31 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" |
| 31 #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h" | 32 #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h" |
| 32 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 33 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 33 #include "chrome/browser/ui/gtk/gtk_util.h" | 34 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 34 #include "chrome/browser/ui/gtk/hover_controller_gtk.h" | 35 #include "chrome/browser/ui/gtk/hover_controller_gtk.h" |
| 35 #include "chrome/browser/ui/gtk/menu_gtk.h" | 36 #include "chrome/browser/ui/gtk/menu_gtk.h" |
| 36 #include "chrome/browser/ui/gtk/view_id_util.h" | 37 #include "chrome/browser/ui/gtk/view_id_util.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 context_menu_model_ = | 248 context_menu_model_ = |
| 248 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this); | 249 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this); |
| 249 context_menu_.reset( | 250 context_menu_.reset( |
| 250 new MenuGtk(this, context_menu_model_.get())); | 251 new MenuGtk(this, context_menu_model_.get())); |
| 251 return context_menu_.get(); | 252 return context_menu_.get(); |
| 252 } | 253 } |
| 253 | 254 |
| 254 private: | 255 private: |
| 255 // Activate the browser action. | 256 // Activate the browser action. |
| 256 void Activate(GtkWidget* widget) { | 257 void Activate(GtkWidget* widget) { |
| 258 Activate(widget, true); |
| 259 } |
| 260 |
| 261 void Activate(GtkWidget* widget, bool allow_grant) { |
| 257 ExtensionToolbarModel* model = toolbar_->model(); | 262 ExtensionToolbarModel* model = toolbar_->model(); |
| 258 const Extension* extension = extension_; | 263 const Extension* extension = extension_; |
| 259 Browser* browser = toolbar_->browser(); | 264 Browser* browser = toolbar_->browser(); |
| 260 GURL popup_url; | 265 GURL popup_url; |
| 261 | 266 |
| 262 switch (model->ExecuteBrowserAction(extension, browser, &popup_url)) { | 267 switch (model->ExecuteBrowserAction( |
| 268 extension, browser, &popup_url, allow_grant)) { |
| 263 case ExtensionToolbarModel::ACTION_NONE: | 269 case ExtensionToolbarModel::ACTION_NONE: |
| 264 break; | 270 break; |
| 265 case ExtensionToolbarModel::ACTION_SHOW_POPUP: | 271 case ExtensionToolbarModel::ACTION_SHOW_POPUP: |
| 266 ExtensionPopupGtk::Show(popup_url, browser, widget, | 272 ExtensionPopupGtk::Show(popup_url, browser, widget, |
| 267 ExtensionPopupGtk::SHOW); | 273 ExtensionPopupGtk::SHOW); |
| 268 break; | 274 break; |
| 269 } | 275 } |
| 270 } | 276 } |
| 271 | 277 |
| 272 // MenuGtk::Delegate implementation. | 278 // MenuGtk::Delegate implementation. |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after 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...) Expand 10 before | Expand all | Expand 10 after 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 void 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 BrowserList::GetInstance(chrome::GetActiveDesktop())->GetLastActive() != |
| 785 browser_) { |
| 786 return; |
| 787 } |
| 788 |
| 789 BrowserActionButton* button = GetBrowserActionButton(extension); |
| 790 if (button == NULL || button->widget() == NULL) |
| 791 return; |
| 792 |
| 793 GtkWidget* anchor = button->widget(); |
| 794 if (!gtk_widget_get_visible(anchor)) |
| 795 anchor = button->toolbar_->chevron(); |
| 796 button->Activate(anchor, false); |
| 797 } |
| 798 |
| 771 void BrowserActionsToolbarGtk::ModelLoaded() { | 799 void BrowserActionsToolbarGtk::ModelLoaded() { |
| 772 SetContainerWidth(); | 800 SetContainerWidth(); |
| 773 } | 801 } |
| 774 | 802 |
| 775 void BrowserActionsToolbarGtk::AnimationProgressed( | 803 void BrowserActionsToolbarGtk::AnimationProgressed( |
| 776 const gfx::Animation* animation) { | 804 const gfx::Animation* animation) { |
| 777 int width = start_width_ + (desired_width_ - start_width_) * | 805 int width = start_width_ + (desired_width_ - start_width_) * |
| 778 animation->GetCurrentValue(); | 806 animation->GetCurrentValue(); |
| 779 gtk_widget_set_size_request(button_hbox_.get(), width, -1); | 807 gtk_widget_set_size_request(button_hbox_.get(), width, -1); |
| 780 | 808 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 NOTREACHED(); | 1098 NOTREACHED(); |
| 1071 return FALSE; | 1099 return FALSE; |
| 1072 } | 1100 } |
| 1073 | 1101 |
| 1074 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( | 1102 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( |
| 1075 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); | 1103 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); |
| 1076 if (profile_->IsOffTheRecord()) | 1104 if (profile_->IsOffTheRecord()) |
| 1077 item_index = model_->IncognitoIndexToOriginal(item_index); | 1105 item_index = model_->IncognitoIndexToOriginal(item_index); |
| 1078 | 1106 |
| 1079 const Extension* extension = model_->toolbar_items()[item_index].get(); | 1107 const Extension* extension = model_->toolbar_items()[item_index].get(); |
| 1080 ExtensionButtonMap::iterator it = extension_button_map_.find(extension->id()); | 1108 BrowserActionButton* button = GetBrowserActionButton(extension); |
| 1081 if (it == extension_button_map_.end()) { | 1109 if (button == NULL) { |
| 1082 NOTREACHED(); | 1110 NOTREACHED(); |
| 1083 return FALSE; | 1111 return FALSE; |
| 1084 } | 1112 } |
| 1085 | 1113 |
| 1086 MenuGtk* menu = it->second.get()->GetContextMenu(); | 1114 MenuGtk* menu = button->GetContextMenu(); |
| 1087 if (!menu) | 1115 if (!menu) |
| 1088 return FALSE; | 1116 return FALSE; |
| 1089 | 1117 |
| 1090 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 1118 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
| 1091 event->time); | 1119 event->time); |
| 1092 return TRUE; | 1120 return TRUE; |
| 1093 } | 1121 } |
| 1094 | 1122 |
| 1095 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 1123 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
| 1096 if (!resize_animation_.is_animating()) | 1124 if (!resize_animation_.is_animating()) |
| 1097 UpdateChevronVisibility(); | 1125 UpdateChevronVisibility(); |
| 1098 } | 1126 } |
| OLD | NEW |