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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 G_CALLBACK(OnDragMotionThunk), this); | 623 G_CALLBACK(OnDragMotionThunk), this); |
624 } | 624 } |
625 | 625 |
626 void BrowserActionsToolbarGtk::CreateAllButtons() { | 626 void BrowserActionsToolbarGtk::CreateAllButtons() { |
627 extension_button_map_.clear(); | 627 extension_button_map_.clear(); |
628 | 628 |
629 int i = 0; | 629 int i = 0; |
630 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); | 630 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); |
631 for (extensions::ExtensionList::const_iterator iter = toolbar_items.begin(); | 631 for (extensions::ExtensionList::const_iterator iter = toolbar_items.begin(); |
632 iter != toolbar_items.end(); ++iter) { | 632 iter != toolbar_items.end(); ++iter) { |
633 CreateButtonForExtension(*iter, i++); | 633 CreateButtonForExtension(*iter.get(), i++); |
634 } | 634 } |
635 } | 635 } |
636 | 636 |
637 void BrowserActionsToolbarGtk::SetContainerWidth() { | 637 void BrowserActionsToolbarGtk::SetContainerWidth() { |
638 int showing_actions = model_->GetVisibleIconCount(); | 638 int showing_actions = model_->GetVisibleIconCount(); |
639 if (showing_actions >= 0) | 639 if (showing_actions >= 0) |
640 SetButtonHBoxWidth(WidthForIconCount(showing_actions)); | 640 SetButtonHBoxWidth(WidthForIconCount(showing_actions)); |
641 } | 641 } |
642 | 642 |
643 void BrowserActionsToolbarGtk::CreateButtonForExtension( | 643 void BrowserActionsToolbarGtk::CreateButtonForExtension( |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 void BrowserActionsToolbarGtk::AnimationEnded(const ui::Animation* animation) { | 792 void BrowserActionsToolbarGtk::AnimationEnded(const ui::Animation* animation) { |
793 gtk_widget_set_size_request(button_hbox_.get(), desired_width_, -1); | 793 gtk_widget_set_size_request(button_hbox_.get(), desired_width_, -1); |
794 UpdateChevronVisibility(); | 794 UpdateChevronVisibility(); |
795 } | 795 } |
796 | 796 |
797 bool BrowserActionsToolbarGtk::IsCommandIdChecked(int command_id) const { | 797 bool BrowserActionsToolbarGtk::IsCommandIdChecked(int command_id) const { |
798 return false; | 798 return false; |
799 } | 799 } |
800 | 800 |
801 bool BrowserActionsToolbarGtk::IsCommandIdEnabled(int command_id) const { | 801 bool BrowserActionsToolbarGtk::IsCommandIdEnabled(int command_id) const { |
802 const Extension* extension = model_->toolbar_items()[command_id]; | 802 const Extension* extension = model_->toolbar_items()[command_id].get(); |
803 return ExtensionActionManager::Get(profile_)-> | 803 return ExtensionActionManager::Get(profile_)-> |
804 GetBrowserAction(*extension)->GetIsVisible(GetCurrentTabId()); | 804 GetBrowserAction(*extension)->GetIsVisible(GetCurrentTabId()); |
805 } | 805 } |
806 | 806 |
807 bool BrowserActionsToolbarGtk::GetAcceleratorForCommandId( | 807 bool BrowserActionsToolbarGtk::GetAcceleratorForCommandId( |
808 int command_id, | 808 int command_id, |
809 ui::Accelerator* accelerator) { | 809 ui::Accelerator* accelerator) { |
810 return false; | 810 return false; |
811 } | 811 } |
812 | 812 |
813 void BrowserActionsToolbarGtk::ExecuteCommand(int command_id) { | 813 void BrowserActionsToolbarGtk::ExecuteCommand(int command_id) { |
814 const Extension* extension = model_->toolbar_items()[command_id]; | 814 const Extension* extension = model_->toolbar_items()[command_id].get(); |
815 GURL popup_url; | 815 GURL popup_url; |
816 | 816 |
817 switch (model_->ExecuteBrowserAction(extension, browser(), &popup_url)) { | 817 switch (model_->ExecuteBrowserAction(extension, browser(), &popup_url)) { |
818 case ExtensionToolbarModel::ACTION_NONE: | 818 case ExtensionToolbarModel::ACTION_NONE: |
819 break; | 819 break; |
820 case ExtensionToolbarModel::ACTION_SHOW_POPUP: | 820 case ExtensionToolbarModel::ACTION_SHOW_POPUP: |
821 ExtensionPopupGtk::Show(popup_url, browser(), chevron(), | 821 ExtensionPopupGtk::Show(popup_url, browser(), chevron(), |
822 ExtensionPopupGtk::SHOW); | 822 ExtensionPopupGtk::SHOW); |
823 break; | 823 break; |
824 } | 824 } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 overflow_menu_model_.reset(new SimpleMenuModel(this)); | 1035 overflow_menu_model_.reset(new SimpleMenuModel(this)); |
1036 | 1036 |
1037 int visible_icon_count = | 1037 int visible_icon_count = |
1038 gtk_chrome_shrinkable_hbox_get_visible_child_count( | 1038 gtk_chrome_shrinkable_hbox_get_visible_child_count( |
1039 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); | 1039 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); |
1040 for (int i = visible_icon_count; i < button_count(); ++i) { | 1040 for (int i = visible_icon_count; i < button_count(); ++i) { |
1041 int model_index = i; | 1041 int model_index = i; |
1042 if (profile_->IsOffTheRecord()) | 1042 if (profile_->IsOffTheRecord()) |
1043 model_index = model_->IncognitoIndexToOriginal(i); | 1043 model_index = model_->IncognitoIndexToOriginal(i); |
1044 | 1044 |
1045 const Extension* extension = model_->toolbar_items()[model_index]; | 1045 const Extension* extension = model_->toolbar_items()[model_index].get(); |
1046 BrowserActionButton* button = extension_button_map_[extension->id()].get(); | 1046 BrowserActionButton* button = extension_button_map_[extension->id()].get(); |
1047 | 1047 |
1048 overflow_menu_model_->AddItem(model_index, UTF8ToUTF16(extension->name())); | 1048 overflow_menu_model_->AddItem(model_index, UTF8ToUTF16(extension->name())); |
1049 overflow_menu_model_->SetIcon(overflow_menu_model_->GetItemCount() - 1, | 1049 overflow_menu_model_->SetIcon(overflow_menu_model_->GetItemCount() - 1, |
1050 button->GetIcon()); | 1050 button->GetIcon()); |
1051 | 1051 |
1052 // TODO(estade): set the menu item's tooltip. | 1052 // TODO(estade): set the menu item's tooltip. |
1053 } | 1053 } |
1054 | 1054 |
1055 overflow_menu_.reset(new MenuGtk(this, overflow_menu_model_.get())); | 1055 overflow_menu_.reset(new MenuGtk(this, overflow_menu_model_.get())); |
(...skipping 19 matching lines...) Expand all Loading... |
1075 if (item_index == -1) { | 1075 if (item_index == -1) { |
1076 NOTREACHED(); | 1076 NOTREACHED(); |
1077 return FALSE; | 1077 return FALSE; |
1078 } | 1078 } |
1079 | 1079 |
1080 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( | 1080 item_index += gtk_chrome_shrinkable_hbox_get_visible_child_count( |
1081 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); | 1081 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); |
1082 if (profile_->IsOffTheRecord()) | 1082 if (profile_->IsOffTheRecord()) |
1083 item_index = model_->IncognitoIndexToOriginal(item_index); | 1083 item_index = model_->IncognitoIndexToOriginal(item_index); |
1084 | 1084 |
1085 const Extension* extension = model_->toolbar_items()[item_index]; | 1085 const Extension* extension = model_->toolbar_items()[item_index].get(); |
1086 ExtensionButtonMap::iterator it = extension_button_map_.find( | 1086 ExtensionButtonMap::iterator it = extension_button_map_.find( |
1087 extension->id()); | 1087 extension->id()); |
1088 if (it == extension_button_map_.end()) { | 1088 if (it == extension_button_map_.end()) { |
1089 NOTREACHED(); | 1089 NOTREACHED(); |
1090 return FALSE; | 1090 return FALSE; |
1091 } | 1091 } |
1092 | 1092 |
1093 MenuGtk* menu = it->second.get()->GetContextMenu(); | 1093 MenuGtk* menu = it->second.get()->GetContextMenu(); |
1094 if (!menu) | 1094 if (!menu) |
1095 return FALSE; | 1095 return FALSE; |
1096 | 1096 |
1097 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 1097 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
1098 event->time); | 1098 event->time); |
1099 return TRUE; | 1099 return TRUE; |
1100 } | 1100 } |
1101 | 1101 |
1102 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 1102 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
1103 if (!resize_animation_.is_animating()) | 1103 if (!resize_animation_.is_animating()) |
1104 UpdateChevronVisibility(); | 1104 UpdateChevronVisibility(); |
1105 } | 1105 } |
OLD | NEW |