summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-15 06:48:55 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-15 06:48:55 +0000
commit0b282f9e8acb6b4b945df8121814a4cfba71dc32 (patch)
tree97182e3f900fbc6b86a6c1c4cb3542cfa3a216d7 /app
parent7e6db17fdb7a995f70249881c399e522e69fb257 (diff)
downloadchromium_src-0b282f9e8acb6b4b945df8121814a4cfba71dc32.zip
chromium_src-0b282f9e8acb6b4b945df8121814a4cfba71dc32.tar.gz
chromium_src-0b282f9e8acb6b4b945df8121814a4cfba71dc32.tar.bz2
Change menus on OSX to update the icon dynamically.
Change MenuModel::IsLabelDynamicAt() to IsItemDynamicAt() to reflect its true purpose. Add SimpleMenuModel::GetIconForCommandId() to enable dynamic icons. Update OSX menu_controller code to update the icon for dynamic menu items when the menu is opened, to match the windows behavior. BUG=66508 TEST=MenuControllerTest.Dynamic Review URL: http://codereview.chromium.org/5697005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69234 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/menus/button_menu_item_model.cc8
-rw-r--r--app/menus/button_menu_item_model.h6
-rw-r--r--app/menus/menu_model.h9
-rw-r--r--app/menus/simple_menu_model.cc16
-rw-r--r--app/menus/simple_menu_model.h9
5 files changed, 30 insertions, 18 deletions
diff --git a/app/menus/button_menu_item_model.cc b/app/menus/button_menu_item_model.cc
index a7fbcde..3d44b1b 100644
--- a/app/menus/button_menu_item_model.cc
+++ b/app/menus/button_menu_item_model.cc
@@ -8,7 +8,7 @@
namespace menus {
-bool ButtonMenuItemModel::Delegate::IsLabelForCommandIdDynamic(
+bool ButtonMenuItemModel::Delegate::IsItemForCommandIdDynamic(
int command_id) const {
return false;
}
@@ -82,14 +82,14 @@ int ButtonMenuItemModel::GetCommandIdAt(int index) const {
return items_[index].command_id;
}
-bool ButtonMenuItemModel::IsLabelDynamicAt(int index) const {
+bool ButtonMenuItemModel::IsItemDynamicAt(int index) const {
if (delegate_)
- return delegate_->IsLabelForCommandIdDynamic(GetCommandIdAt(index));
+ return delegate_->IsItemForCommandIdDynamic(GetCommandIdAt(index));
return false;
}
string16 ButtonMenuItemModel::GetLabelAt(int index) const {
- if (IsLabelDynamicAt(index))
+ if (IsItemDynamicAt(index))
return delegate_->GetLabelForCommandId(GetCommandIdAt(index));
return items_[index].label;
}
diff --git a/app/menus/button_menu_item_model.h b/app/menus/button_menu_item_model.h
index 265359b..4b4c98c 100644
--- a/app/menus/button_menu_item_model.h
+++ b/app/menus/button_menu_item_model.h
@@ -26,7 +26,7 @@ class ButtonMenuItemModel {
class Delegate {
public:
// Some command ids have labels that change over time.
- virtual bool IsLabelForCommandIdDynamic(int command_id) const;
+ virtual bool IsItemForCommandIdDynamic(int command_id) const;
virtual string16 GetLabelForCommandId(int command_id) const;
// Performs the action associated with the specified command id.
@@ -49,7 +49,7 @@ class ButtonMenuItemModel {
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
+ // anything. Usually combined with IsItemForCommandIdDynamic() to add
// information.
void AddButtonLabel(int command_id, int string_id);
@@ -66,7 +66,7 @@ class ButtonMenuItemModel {
int GetCommandIdAt(int index) const;
// Whether the label for item |index| changes.
- bool IsLabelDynamicAt(int index) const;
+ bool IsItemDynamicAt(int index) const;
// Returns the current label value for the button at |index|.
string16 GetLabelAt(int index) const;
diff --git a/app/menus/menu_model.h b/app/menus/menu_model.h
index 62732cd..7648da4 100644
--- a/app/menus/menu_model.h
+++ b/app/menus/menu_model.h
@@ -63,10 +63,11 @@ class MenuModel {
// Returns the label of the item at the specified index.
virtual string16 GetLabelAt(int index) const = 0;
- // Returns true if the label at the specified index can change over the course
- // of the menu's lifetime. If this function returns true, the label of the
- // menu item will be updated each time the menu is shown.
- virtual bool IsLabelDynamicAt(int index) const = 0;
+ // Returns true if the menu item (label/icon) at the specified index can
+ // change over the course of the menu's lifetime. If this function returns
+ // true, the label and icon of the menu item will be updated each time the
+ // menu is shown.
+ virtual bool IsItemDynamicAt(int index) const = 0;
// Returns the font use for the label at the specified index.
// If NULL, then use default font.
diff --git a/app/menus/simple_menu_model.cc b/app/menus/simple_menu_model.cc
index b645b09..427bbf1 100644
--- a/app/menus/simple_menu_model.cc
+++ b/app/menus/simple_menu_model.cc
@@ -28,7 +28,7 @@ bool SimpleMenuModel::Delegate::IsCommandIdVisible(int command_id) const {
return true;
}
-bool SimpleMenuModel::Delegate::IsLabelForCommandIdDynamic(
+bool SimpleMenuModel::Delegate::IsItemForCommandIdDynamic(
int command_id) const {
return false;
}
@@ -37,6 +37,11 @@ string16 SimpleMenuModel::Delegate::GetLabelForCommandId(int command_id) const {
return string16();
}
+bool SimpleMenuModel::Delegate::GetIconForCommandId(
+ int command_id, SkBitmap* bitmap) const {
+ return false;
+}
+
void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) {
}
@@ -201,14 +206,14 @@ int SimpleMenuModel::GetCommandIdAt(int index) const {
}
string16 SimpleMenuModel::GetLabelAt(int index) const {
- if (IsLabelDynamicAt(index))
+ if (IsItemDynamicAt(index))
return delegate_->GetLabelForCommandId(GetCommandIdAt(index));
return items_.at(FlipIndex(index)).label;
}
-bool SimpleMenuModel::IsLabelDynamicAt(int index) const {
+bool SimpleMenuModel::IsItemDynamicAt(int index) const {
if (delegate_)
- return delegate_->IsLabelForCommandIdDynamic(GetCommandIdAt(index));
+ return delegate_->IsItemForCommandIdDynamic(GetCommandIdAt(index));
return false;
}
@@ -235,6 +240,9 @@ int SimpleMenuModel::GetGroupIdAt(int index) const {
}
bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const {
+ if (IsItemDynamicAt(index))
+ return delegate_->GetIconForCommandId(GetCommandIdAt(index), icon);
+
if (items_[index].icon.isNull())
return false;
diff --git a/app/menus/simple_menu_model.h b/app/menus/simple_menu_model.h
index 149791c..cd4cd46 100644
--- a/app/menus/simple_menu_model.h
+++ b/app/menus/simple_menu_model.h
@@ -34,9 +34,12 @@ class SimpleMenuModel : public MenuModel {
int command_id,
menus::Accelerator* accelerator) = 0;
- // Some command ids have labels that change over time.
- virtual bool IsLabelForCommandIdDynamic(int command_id) const;
+ // Some command ids have labels and icons that change over time.
+ virtual bool IsItemForCommandIdDynamic(int command_id) const;
virtual string16 GetLabelForCommandId(int command_id) const;
+ // Gets the icon for the item with the specified id, returning true if there
+ // is an icon, false otherwise.
+ virtual bool GetIconForCommandId(int command_id, SkBitmap* icon) const;
// Notifies the delegate that the item with the specified command id was
// visually highlighted within the menu.
@@ -100,7 +103,7 @@ class SimpleMenuModel : public MenuModel {
virtual ItemType GetTypeAt(int index) const;
virtual int GetCommandIdAt(int index) const;
virtual string16 GetLabelAt(int index) const;
- virtual bool IsLabelDynamicAt(int index) const;
+ virtual bool IsItemDynamicAt(int index) const;
virtual bool GetAcceleratorAt(int index,
menus::Accelerator* accelerator) const;
virtual bool IsItemCheckedAt(int index) const;