summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/toolbar
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 /chrome/browser/ui/toolbar
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 'chrome/browser/ui/toolbar')
-rw-r--r--chrome/browser/ui/toolbar/back_forward_menu_model.cc2
-rw-r--r--chrome/browser/ui/toolbar/back_forward_menu_model.h2
-rw-r--r--chrome/browser/ui/toolbar/wrench_menu_model.cc45
-rw-r--r--chrome/browser/ui/toolbar/wrench_menu_model.h3
4 files changed, 25 insertions, 27 deletions
diff --git a/chrome/browser/ui/toolbar/back_forward_menu_model.cc b/chrome/browser/ui/toolbar/back_forward_menu_model.cc
index 5ea279f..390dce0 100644
--- a/chrome/browser/ui/toolbar/back_forward_menu_model.cc
+++ b/chrome/browser/ui/toolbar/back_forward_menu_model.cc
@@ -87,7 +87,7 @@ string16 BackForwardMenuModel::GetLabelAt(int index) const {
return menu_text;
}
-bool BackForwardMenuModel::IsLabelDynamicAt(int index) const {
+bool BackForwardMenuModel::IsItemDynamicAt(int index) const {
// This object is only used for a single showing of a menu.
return false;
}
diff --git a/chrome/browser/ui/toolbar/back_forward_menu_model.h b/chrome/browser/ui/toolbar/back_forward_menu_model.h
index aba4688..1d669a0 100644
--- a/chrome/browser/ui/toolbar/back_forward_menu_model.h
+++ b/chrome/browser/ui/toolbar/back_forward_menu_model.h
@@ -48,7 +48,7 @@ class BackForwardMenuModel : public menus::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;
diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc
index 0efd669..cd8a114 100644
--- a/chrome/browser/ui/toolbar/wrench_menu_model.cc
+++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc
@@ -221,9 +221,6 @@ WrenchMenuModel::WrenchMenuModel(menus::AcceleratorProvider* provider,
Source<Profile>(browser_->profile()));
registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
NotificationService::AllSources());
- registrar_.Add(this,
- NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED,
- NotificationService::AllSources());
}
WrenchMenuModel::~WrenchMenuModel() {
@@ -235,7 +232,7 @@ bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const {
return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS;
}
-bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const {
+bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const {
return command_id == IDC_ZOOM_PERCENT_DISPLAY ||
#if defined(OS_MACOSX)
command_id == IDC_FULLSCREEN ||
@@ -244,6 +241,26 @@ bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const {
command_id == IDC_VIEW_BACKGROUND_PAGES;
}
+bool WrenchMenuModel::GetIconForCommandId(int command_id,
+ SkBitmap* bitmap) const {
+ switch (command_id) {
+ case IDC_VIEW_BACKGROUND_PAGES: {
+ int num_pages = BackgroundPageTracker::GetInstance()->
+ GetUnacknowledgedBackgroundPageCount();
+ if (num_pages > 0) {
+ *bitmap = GetBackgroundPageIcon();
+ return true;
+ } else {
+ // No icon.
+ return false;
+ }
+ }
+ default:
+ // No icon for other dynamic menu items.
+ return false;
+ }
+}
+
string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const {
switch (command_id) {
case IDC_SYNC_BOOKMARKS:
@@ -350,18 +367,6 @@ void WrenchMenuModel::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
switch (type.value) {
- case NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED: {
- int num_pages = BackgroundPageTracker::GetInstance()->
- GetUnacknowledgedBackgroundPageCount();
- if (num_pages > 0) {
- SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES),
- GetBackgroundPageIcon());
- } else {
- // Just set a blank icon (no icon).
- SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES), SkBitmap());
- }
- break;
- }
case NotificationType::ZOOM_LEVEL_CHANGED:
case NotificationType::NAV_ENTRY_COMMITTED:
UpdateZoomControls();
@@ -482,14 +487,6 @@ void WrenchMenuModel::Build() {
*rb.GetBitmapNamed(IDR_CONFLICT_MENU));
#endif
- // Add an icon to the View Background Pages item if there are unacknowledged
- // pages.
- if (BackgroundPageTracker::GetInstance()->
- GetUnacknowledgedBackgroundPageCount() > 0) {
- SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES),
- GetBackgroundPageIcon());
- }
-
AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE);
if (browser_defaults::kShowExitMenuItem) {
AddSeparator();
diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.h b/chrome/browser/ui/toolbar/wrench_menu_model.h
index e984a4b..2690ea9 100644
--- a/chrome/browser/ui/toolbar/wrench_menu_model.h
+++ b/chrome/browser/ui/toolbar/wrench_menu_model.h
@@ -82,8 +82,9 @@ class WrenchMenuModel : public menus::SimpleMenuModel,
virtual bool DoesCommandIdDismissMenu(int command_id) const;
// Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel:
- virtual bool IsLabelForCommandIdDynamic(int command_id) const;
+ virtual bool IsItemForCommandIdDynamic(int command_id) const;
virtual string16 GetLabelForCommandId(int command_id) const;
+ virtual bool GetIconForCommandId(int command_id, SkBitmap* icon) const;
virtual void ExecuteCommand(int command_id);
virtual bool IsCommandIdChecked(int command_id) const;
virtual bool IsCommandIdEnabled(int command_id) const;