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