diff options
-rw-r--r-- | app/menus/button_menu_item_model.cc | 26 | ||||
-rw-r--r-- | app/menus/button_menu_item_model.h | 21 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 18 | ||||
-rw-r--r-- | chrome/browser/wrench_menu_model.cc | 14 |
4 files changed, 39 insertions, 40 deletions
diff --git a/app/menus/button_menu_item_model.cc b/app/menus/button_menu_item_model.cc index fd19fc8..19cbdab3 100644 --- a/app/menus/button_menu_item_model.cc +++ b/app/menus/button_menu_item_model.cc @@ -15,33 +15,27 @@ ButtonMenuItemModel::ButtonMenuItemModel( delegate_(delegate) { } -void ButtonMenuItemModel::AddItemWithStringId(int command_id, int string_id) { +void ButtonMenuItemModel::AddGroupItemWithStringId( + int command_id, int string_id) { Item item = { command_id, TYPE_BUTTON, l10n_util::GetStringUTF16(string_id), - -1, -1}; - items_.push_back(item); -} - -void ButtonMenuItemModel::AddItemWithStringIdAndGroup( - int command_id, int string_id, int group) { - Item item = { command_id, TYPE_BUTTON, l10n_util::GetStringUTF16(string_id), - -1, group }; + -1, true }; items_.push_back(item); } void ButtonMenuItemModel::AddItemWithImage(int command_id, int icon_idr) { - Item item = { command_id, TYPE_BUTTON, string16(), icon_idr, -1 }; + Item item = { command_id, TYPE_BUTTON, string16(), icon_idr, false }; items_.push_back(item); } void ButtonMenuItemModel::AddButtonLabel(int command_id, int string_id) { Item item = { command_id, TYPE_BUTTON_LABEL, - l10n_util::GetStringUTF16(string_id), -1, -1 }; + l10n_util::GetStringUTF16(string_id), -1, false }; items_.push_back(item); } void ButtonMenuItemModel::AddSpace() { - Item item = { 0, TYPE_SPACE, string16(), -1, -1 }; + Item item = { 0, TYPE_SPACE, string16(), -1, false }; items_.push_back(item); } @@ -78,12 +72,8 @@ bool ButtonMenuItemModel::GetIconAt(int index, int* icon_idr) const { return true; } -bool ButtonMenuItemModel::GetGroupAt(int index, int* group) const { - if (items_[index].group == -1) - return false; - - *group = items_[index].group; - return true; +bool ButtonMenuItemModel::PartOfGroup(int index) const { + return items_[index].part_of_group; } void ButtonMenuItemModel::ActivatedCommand(int command_id) { diff --git a/app/menus/button_menu_item_model.h b/app/menus/button_menu_item_model.h index 46ad8a6..640642a 100644 --- a/app/menus/button_menu_item_model.h +++ b/app/menus/button_menu_item_model.h @@ -14,10 +14,6 @@ namespace menus { // A model representing the rows of buttons that should be inserted in a button // containing menu item. -// -// TODO(erg): There are still two major pieces missing from this model. It -// needs to be able to group buttons together so they all have the same -// width. class ButtonMenuItemModel { public: // Types of buttons. @@ -43,12 +39,9 @@ class ButtonMenuItemModel { ButtonMenuItemModel(int string_id, ButtonMenuItemModel::Delegate* delegate); - // Adds a button that will emit |command_id|. - void AddItemWithStringId(int command_id, int string_id); - - // Adds a button that will emit |command_id|. Sizes for all items with the - // same |group| id will be set to the largest item in the group. - void AddItemWithStringIdAndGroup(int command_id, int string_id, int group); + // Adds a button that will emit |command_id|. All buttons created through + // this method will have the same size, based on the largest button. + void AddGroupItemWithStringId(int command_id, int string_id); // Adds a button that has an icon instead of a label. void AddItemWithImage(int command_id, int icon_idr); @@ -80,9 +73,9 @@ class ButtonMenuItemModel { // sets the IDR |icon|. bool GetIconAt(int index, int* icon) const; - // If the button at |index| should have its size equalized as part of a - // group, returns true and sets the group number |group|. - bool GetGroupAt(int index, int* group) const; + // If the button at |index| should have its size equalized along with all + // other items that have their PartOfGroup bit set. + bool PartOfGroup(int index) const; // Called from implementations. void ActivatedCommand(int command_id); @@ -98,7 +91,7 @@ class ButtonMenuItemModel { ButtonType type; string16 label; int icon_idr; - int group; + bool part_of_group; }; std::vector<Item> items_; diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 179b8d6..5bdebea 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -377,14 +377,17 @@ GtkWidget* MenuGtk::BuildButtomMenuItem(menus::ButtonMenuItemModel* model, g_signal_connect(menu_item, "button-pushed", G_CALLBACK(OnMenuButtonPressed), this); + GtkSizeGroup* group = NULL; for (int i = 0; i < model->GetItemCount(); ++i) { + GtkWidget* button = NULL; + switch (model->GetTypeAt(i)) { case menus::ButtonMenuItemModel::TYPE_SPACE: { gtk_custom_menu_item_add_space(GTK_CUSTOM_MENU_ITEM(menu_item)); break; } case menus::ButtonMenuItemModel::TYPE_BUTTON: { - GtkWidget* button = gtk_custom_menu_item_add_button( + button = gtk_custom_menu_item_add_button( GTK_CUSTOM_MENU_ITEM(menu_item), model->GetCommandIdAt(i)); @@ -402,7 +405,7 @@ GtkWidget* MenuGtk::BuildButtomMenuItem(menus::ButtonMenuItemModel* model, break; } case menus::ButtonMenuItemModel::TYPE_BUTTON_LABEL: { - GtkWidget* button = gtk_custom_menu_item_add_button_label( + button = gtk_custom_menu_item_add_button_label( GTK_CUSTOM_MENU_ITEM(menu_item), model->GetCommandIdAt(i)); gtk_button_set_label( @@ -413,6 +416,17 @@ GtkWidget* MenuGtk::BuildButtomMenuItem(menus::ButtonMenuItemModel* model, break; } } + + if (button && model->PartOfGroup(i)) { + if (!group) + group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + + gtk_size_group_add_widget(group, button); + } + } + + if (group) { + g_object_unref(group); } return menu_item; diff --git a/chrome/browser/wrench_menu_model.cc b/chrome/browser/wrench_menu_model.cc index 28c7315..78e1929 100644 --- a/chrome/browser/wrench_menu_model.cc +++ b/chrome/browser/wrench_menu_model.cc @@ -94,7 +94,7 @@ static bool CalculateEnabled() { std::string value = cl->GetSwitchValueASCII(switches::kNewWrenchMenu); return value.empty() || value == "true"; } -#if defined(TOOLKIT_VIEWS) +#if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) return true; #else return false; @@ -193,9 +193,9 @@ void WrenchMenuModel::Build() { AddSeparator(); #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) edit_menu_item_model_.reset(new menus::ButtonMenuItemModel(IDS_EDIT, this)); - edit_menu_item_model_->AddItemWithStringId(IDC_CUT, IDS_CUT); - edit_menu_item_model_->AddItemWithStringId(IDC_COPY, IDS_COPY); - edit_menu_item_model_->AddItemWithStringId(IDC_PASTE, IDS_PASTE); + edit_menu_item_model_->AddGroupItemWithStringId(IDC_CUT, IDS_CUT); + edit_menu_item_model_->AddGroupItemWithStringId(IDC_COPY, IDS_COPY); + edit_menu_item_model_->AddGroupItemWithStringId(IDC_PASTE, IDS_PASTE); AddButtonItem(0, edit_menu_item_model_.get()); #else // TODO(port): Move to the above. @@ -206,10 +206,12 @@ void WrenchMenuModel::Build() { #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) zoom_menu_item_model_.reset( new menus::ButtonMenuItemModel(IDS_ZOOM_MENU, this)); - zoom_menu_item_model_->AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS2); + zoom_menu_item_model_->AddGroupItemWithStringId( + IDC_ZOOM_PLUS, IDS_ZOOM_PLUS2); zoom_menu_item_model_->AddButtonLabel(IDC_ZOOM_PERCENT_DISPLAY, IDS_ZOOM_PLUS2); - zoom_menu_item_model_->AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS2); + zoom_menu_item_model_->AddGroupItemWithStringId( + IDC_ZOOM_MINUS, IDS_ZOOM_MINUS2); zoom_menu_item_model_->AddSpace(); zoom_menu_item_model_->AddItemWithImage( IDC_FULLSCREEN, IDR_FULLSCREEN_MENU_BUTTON); |