diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 17:06:21 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 17:06:21 +0000 |
commit | 7209cb729d172a9aa8999dac0c9f6bd80f23c4c2 (patch) | |
tree | 5b0c62d482856faf0982378528031c1c8c4c9eff /app | |
parent | 7838c2502799cbfe33ba16575b0e7d0b03740dd1 (diff) | |
download | chromium_src-7209cb729d172a9aa8999dac0c9f6bd80f23c4c2.zip chromium_src-7209cb729d172a9aa8999dac0c9f6bd80f23c4c2.tar.gz chromium_src-7209cb729d172a9aa8999dac0c9f6bd80f23c4c2.tar.bz2 |
GTK: Cleanups to the new wrench menu.
- Make the rendering for multiple buttons pretty by unifying sequnces of
buttons.
- Add the zoom label control and make the wrench menu model listen for
notifications about zoom percentage changing.
- Fixes crash that would have gone away once this was taken out from behind a flag
BUG=45757
TEST=none
Review URL: http://codereview.chromium.org/2799043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/menus/button_menu_item_model.cc | 37 | ||||
-rw-r--r-- | app/menus/button_menu_item_model.h | 35 |
2 files changed, 55 insertions, 17 deletions
diff --git a/app/menus/button_menu_item_model.cc b/app/menus/button_menu_item_model.cc index c5064fb..fd19fc8 100644 --- a/app/menus/button_menu_item_model.cc +++ b/app/menus/button_menu_item_model.cc @@ -17,18 +17,31 @@ ButtonMenuItemModel::ButtonMenuItemModel( void ButtonMenuItemModel::AddItemWithStringId(int command_id, int string_id) { Item item = { command_id, TYPE_BUTTON, l10n_util::GetStringUTF16(string_id), - SIDE_BOTH, -1 }; + -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 }; items_.push_back(item); } void ButtonMenuItemModel::AddItemWithImage(int command_id, int icon_idr) { - Item item = { command_id, TYPE_BUTTON, string16(), SIDE_BOTH, icon_idr }; + Item item = { command_id, TYPE_BUTTON, string16(), icon_idr, -1 }; + 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 }; items_.push_back(item); } void ButtonMenuItemModel::AddSpace() { - Item item = { 0, TYPE_SPACE, string16(), SIDE_NONE, -1 }; + Item item = { 0, TYPE_SPACE, string16(), -1, -1 }; items_.push_back(item); } @@ -45,7 +58,15 @@ int ButtonMenuItemModel::GetCommandIdAt(int index) const { return items_[index].command_id; } -const string16& ButtonMenuItemModel::GetLabelAt(int index) const { +bool ButtonMenuItemModel::IsLabelDynamicAt(int index) const { + if (delegate_) + return delegate_->IsLabelForCommandIdDynamic(GetCommandIdAt(index)); + return false; +} + +string16 ButtonMenuItemModel::GetLabelAt(int index) const { + if (IsLabelDynamicAt(index)) + return delegate_->GetLabelForCommandId(GetCommandIdAt(index)); return items_[index].label; } @@ -57,6 +78,14 @@ 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; +} + void ButtonMenuItemModel::ActivatedCommand(int command_id) { if (delegate_) delegate_->ExecuteCommand(command_id); diff --git a/app/menus/button_menu_item_model.h b/app/menus/button_menu_item_model.h index b8418d1..46ad8a6 100644 --- a/app/menus/button_menu_item_model.h +++ b/app/menus/button_menu_item_model.h @@ -17,22 +17,14 @@ namespace menus { // // 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. ButtonSides needs to be used to communicate how buttons are squashed -// together. +// width. class ButtonMenuItemModel { public: // Types of buttons. enum ButtonType { TYPE_SPACE, - TYPE_BUTTON - }; - - // Which sides of the button are visible. - enum ButtonSides { - SIDE_NONE = 0, - SIDE_LEFT = 1 << 0, - SIDE_RIGHT = 1 << 1, - SIDE_BOTH = SIDE_LEFT | SIDE_RIGHT + TYPE_BUTTON, + TYPE_BUTTON_LABEL }; class Delegate { @@ -54,9 +46,18 @@ class ButtonMenuItemModel { // 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 has an icon instead of a label. void AddItemWithImage(int command_id, int icon_idr); + // Adds a non-clickable button with a desensitized label that doesn't do + // anything. Usually combined with IsLabelForCommandIdDynamic() to add + // information. + void AddButtonLabel(int command_id, int string_id); + // Adds a small horizontal space. void AddSpace(); @@ -69,12 +70,20 @@ class ButtonMenuItemModel { // Changes a position into a command ID. int GetCommandIdAt(int index) const; - const string16& GetLabelAt(int index) const; + // Whether the label for item |index| changes. + bool IsLabelDynamicAt(int index) const; + + // Returns the current label value for the button at |index|. + string16 GetLabelAt(int index) const; // If the button at |index| should have an icon instead, returns true and // 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; + // Called from implementations. void ActivatedCommand(int command_id); @@ -88,8 +97,8 @@ class ButtonMenuItemModel { int command_id; ButtonType type; string16 label; - int sides; int icon_idr; + int group; }; std::vector<Item> items_; |