Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Unified Diff: chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc

Issue 26350003: OLD: reland "views: change WrenchMenu to use each model's command ID's when creating MenuItemView's" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix integer overflow w/ kint32max, add test Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
index 0ab3291188a7d7226e938272c0ed03b7daf2ff2c..064e600fba982e44c4688fef6a60f9cab4462a3e 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
+++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/toolbar/wrench_menu_model.h"
#include "chrome/common/favicon/favicon_types.h"
#include "chrome/common/pref_names.h"
#include "grit/browser_resources.h"
@@ -52,8 +53,13 @@ namespace {
// These values must be bigger than the maximum possible number of items in
// menu, so that index of last menu item doesn't clash with this value when menu
// items are retrieved via GetIndexOfCommandId.
-const int kFirstTabCommandId = 100;
-const int kFirstWindowCommandId = 200;
+// The range of all command ID's used in RecentTabsSubMenuModel must be between
+// WrenchMenuModel::kMinRecentTabsCommandId i.e. 1001 and 1200
+// (WrenchMenuModel::kMaxRecentTabsCommandId) inclusively.
+const int kFirstTabCommandId = WrenchMenuModel::kMinRecentTabsCommandId;
+const int kFirstWindowCommandId = 1051;
+const int kMinDeviceNameCommandId = 1100;
+const int kMaxDeviceNameCommandId = 1110;
// The maximum number of recently closed entries to be shown in the menu.
const int kMaxRecentlyClosedEntries = 8;
@@ -82,6 +88,11 @@ bool IsWindowModelCommandId(int command_id) {
command_id < RecentTabsSubMenuModel::kRecentlyClosedHeaderCommandId;
}
+bool IsDeviceNameCommandId(int command_id) {
+ return command_id >= kMinDeviceNameCommandId &&
+ command_id <= kMaxDeviceNameCommandId;
+}
+
// Convert |tab_model_index| to command id of menu item.
int TabModelIndexToCommandId(int tab_model_index) {
int command_id = tab_model_index + kFirstTabCommandId;
@@ -146,9 +157,8 @@ struct RecentTabsSubMenuModel::TabNavigationItem {
GURL url;
};
-const int RecentTabsSubMenuModel::kRecentlyClosedHeaderCommandId = 500;
-const int RecentTabsSubMenuModel::kDisabledRecentlyClosedHeaderCommandId = 501;
-const int RecentTabsSubMenuModel::kDeviceNameCommandId = 1000;
+const int RecentTabsSubMenuModel::kRecentlyClosedHeaderCommandId = 1120;
+const int RecentTabsSubMenuModel::kDisabledRecentlyClosedHeaderCommandId = 1121;
RecentTabsSubMenuModel::RecentTabsSubMenuModel(
ui::AcceleratorProvider* accelerator_provider,
@@ -192,8 +202,8 @@ bool RecentTabsSubMenuModel::IsCommandIdChecked(int command_id) const {
bool RecentTabsSubMenuModel::IsCommandIdEnabled(int command_id) const {
if (command_id == kRecentlyClosedHeaderCommandId ||
command_id == kDisabledRecentlyClosedHeaderCommandId ||
- command_id == kDeviceNameCommandId ||
- command_id == IDC_RECENT_TABS_NO_DEVICE_TABS) {
+ command_id == IDC_RECENT_TABS_NO_DEVICE_TABS ||
+ IsDeviceNameCommandId(command_id)) {
return false;
}
return true;
@@ -224,8 +234,8 @@ void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) {
return;
}
- DCHECK_NE(kDeviceNameCommandId, command_id);
DCHECK_NE(IDC_RECENT_TABS_NO_DEVICE_TABS, command_id);
+ DCHECK(!IsDeviceNameCommandId(command_id));
WindowOpenDisposition disposition =
ui::DispositionFromEventFlags(event_flags);
@@ -282,8 +292,8 @@ void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) {
const gfx::Font* RecentTabsSubMenuModel::GetLabelFontAt(int index) const {
int command_id = GetCommandIdAt(index);
- if (command_id == kDeviceNameCommandId ||
- command_id == kRecentlyClosedHeaderCommandId) {
+ if (command_id == kRecentlyClosedHeaderCommandId ||
+ IsDeviceNameCommandId(command_id)) {
return &ResourceBundle::GetSharedInstance().GetFont(
ResourceBundle::BoldFont);
}
@@ -431,7 +441,7 @@ void RecentTabsSubMenuModel::BuildDevices() {
// Add the header for the device session.
DCHECK(!session->session_name.empty());
AddSeparator(ui::NORMAL_SEPARATOR);
- AddItem(kDeviceNameCommandId, UTF8ToUTF16(session->session_name));
+ AddItem(kMinDeviceNameCommandId + i, UTF8ToUTF16(session->session_name));
AddDeviceFavicon(GetItemCount() - 1, session->device_type);
// Build tab menu items from sorted session tabs.

Powered by Google App Engine
This is Rietveld 408576698