Commit 7e5306e0 authored by estade@chromium.org's avatar estade@chromium.org

Make all views platforms use 'new' (cros-style) wrench menu.

On ChromeOS, this patch should have no effect on the menu's appearance.

On Windows, this patch will give the menu the new style buttons, item placement, and item strings. The rows with buttons should be the same height before and after the patch (which is less than the height for ChromeOS).

BUG=365418

Review URL: https://codereview.chromium.org/431473003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287570 0039d316-1c4b-4281-b951-d872f2087c98
parent 93411828
...@@ -287,7 +287,7 @@ class ZoomLevelObserver { ...@@ -287,7 +287,7 @@ class ZoomLevelObserver {
- (void)createModel { - (void)createModel {
recentTabsMenuModelDelegate_.reset(); recentTabsMenuModelDelegate_.reset();
wrenchMenuModel_.reset( wrenchMenuModel_.reset(
new WrenchMenuModel(acceleratorDelegate_.get(), browser_, false)); new WrenchMenuModel(acceleratorDelegate_.get(), browser_));
[self setModel:wrenchMenuModel_.get()]; [self setModel:wrenchMenuModel_.get()];
buttonViewController_.reset( buttonViewController_.reset(
......
...@@ -277,13 +277,12 @@ void ToolsMenuModel::Build(Browser* browser) { ...@@ -277,13 +277,12 @@ void ToolsMenuModel::Build(Browser* browser) {
// WrenchMenuModel // WrenchMenuModel
WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider,
Browser* browser, Browser* browser)
bool is_new_menu)
: ui::SimpleMenuModel(this), : ui::SimpleMenuModel(this),
provider_(provider), provider_(provider),
browser_(browser), browser_(browser),
tab_strip_model_(browser_->tab_strip_model()) { tab_strip_model_(browser_->tab_strip_model()) {
Build(is_new_menu); Build();
UpdateZoomControls(); UpdateZoomControls();
content_zoom_subscription_ = content::HostZoomMap::GetForBrowserContext( content_zoom_subscription_ = content::HostZoomMap::GetForBrowserContext(
...@@ -526,7 +525,7 @@ bool WrenchMenuModel::ShouldShowNewIncognitoWindowMenuItem() { ...@@ -526,7 +525,7 @@ bool WrenchMenuModel::ShouldShowNewIncognitoWindowMenuItem() {
return !browser_->profile()->IsGuestSession(); return !browser_->profile()->IsGuestSession();
} }
void WrenchMenuModel::Build(bool is_new_menu) { void WrenchMenuModel::Build() {
#if defined(OS_WIN) #if defined(OS_WIN)
AddItem(IDC_VIEW_INCOMPATIBILITIES, AddItem(IDC_VIEW_INCOMPATIBILITIES,
l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES)); l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES));
...@@ -598,10 +597,7 @@ void WrenchMenuModel::Build(bool is_new_menu) { ...@@ -598,10 +597,7 @@ void WrenchMenuModel::Build(bool is_new_menu) {
// Append the full menu including separators. The final separator only gets // Append the full menu including separators. The final separator only gets
// appended when this is a touch menu - otherwise it would get added twice. // appended when this is a touch menu - otherwise it would get added twice.
CreateCutCopyPasteMenu(is_new_menu); CreateCutCopyPasteMenu();
if (!is_new_menu)
CreateZoomMenu(is_new_menu);
if (CommandLine::ForCurrentProcess()->HasSwitch( if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableDomDistiller)) { switches::kEnableDomDistiller)) {
...@@ -613,16 +609,7 @@ void WrenchMenuModel::Build(bool is_new_menu) { ...@@ -613,16 +609,7 @@ void WrenchMenuModel::Build(bool is_new_menu) {
AddItemWithStringId(IDC_PRINT, IDS_PRINT); AddItemWithStringId(IDC_PRINT, IDS_PRINT);
tools_menu_model_.reset(new ToolsMenuModel(this, browser_)); tools_menu_model_.reset(new ToolsMenuModel(this, browser_));
// In case of touch this is the last item. CreateZoomMenu();
if (!is_new_menu) {
AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_TOOLS_MENU,
tools_menu_model_.get());
}
if (is_new_menu)
CreateZoomMenu(is_new_menu);
else
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY);
AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS);
...@@ -674,11 +661,9 @@ void WrenchMenuModel::Build(bool is_new_menu) { ...@@ -674,11 +661,9 @@ void WrenchMenuModel::Build(bool is_new_menu) {
AddGlobalErrorMenuItems(); AddGlobalErrorMenuItems();
if (is_new_menu) { AddSeparator(ui::NORMAL_SEPARATOR);
AddSeparator(ui::NORMAL_SEPARATOR); AddSubMenuWithStringId(
AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_MORE_TOOLS_MENU, IDC_ZOOM_MENU, IDS_MORE_TOOLS_MENU, tools_menu_model_.get());
tools_menu_model_.get());
}
bool show_exit_menu = browser_defaults::kShowExitMenuItem; bool show_exit_menu = browser_defaults::kShowExitMenuItem;
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -750,8 +735,8 @@ void WrenchMenuModel::CreateExtensionToolbarOverflowMenu() { ...@@ -750,8 +735,8 @@ void WrenchMenuModel::CreateExtensionToolbarOverflowMenu() {
#endif // defined(TOOLKIT_VIEWS) #endif // defined(TOOLKIT_VIEWS)
} }
void WrenchMenuModel::CreateCutCopyPasteMenu(bool new_menu) { void WrenchMenuModel::CreateCutCopyPasteMenu() {
AddSeparator(new_menu ? ui::LOWER_SEPARATOR : ui::NORMAL_SEPARATOR); AddSeparator(ui::LOWER_SEPARATOR);
#if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) #if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS)
// WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the
...@@ -770,13 +755,12 @@ void WrenchMenuModel::CreateCutCopyPasteMenu(bool new_menu) { ...@@ -770,13 +755,12 @@ void WrenchMenuModel::CreateCutCopyPasteMenu(bool new_menu) {
AddItemWithStringId(IDC_PASTE, IDS_PASTE); AddItemWithStringId(IDC_PASTE, IDS_PASTE);
#endif #endif
if (new_menu) AddSeparator(ui::UPPER_SEPARATOR);
AddSeparator(ui::UPPER_SEPARATOR);
} }
void WrenchMenuModel::CreateZoomMenu(bool new_menu) { void WrenchMenuModel::CreateZoomMenu() {
// This menu needs to be enclosed by separators. // This menu needs to be enclosed by separators.
AddSeparator(new_menu ? ui::LOWER_SEPARATOR : ui::NORMAL_SEPARATOR); AddSeparator(ui::LOWER_SEPARATOR);
#if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) #if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS)
// WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the
...@@ -802,7 +786,7 @@ void WrenchMenuModel::CreateZoomMenu(bool new_menu) { ...@@ -802,7 +786,7 @@ void WrenchMenuModel::CreateZoomMenu(bool new_menu) {
AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN);
#endif #endif
AddSeparator(new_menu ? ui::UPPER_SEPARATOR : ui::NORMAL_SEPARATOR); AddSeparator(ui::UPPER_SEPARATOR);
} }
void WrenchMenuModel::UpdateZoomControls() { void WrenchMenuModel::UpdateZoomControls() {
......
...@@ -89,10 +89,7 @@ class WrenchMenuModel : public ui::SimpleMenuModel, ...@@ -89,10 +89,7 @@ class WrenchMenuModel : public ui::SimpleMenuModel,
static const int kMinRecentTabsCommandId = 1001; static const int kMinRecentTabsCommandId = 1001;
static const int kMaxRecentTabsCommandId = 1200; static const int kMaxRecentTabsCommandId = 1200;
// TODO: remove |is_new_menu|. WrenchMenuModel(ui::AcceleratorProvider* provider, Browser* browser);
WrenchMenuModel(ui::AcceleratorProvider* provider,
Browser* browser,
bool is_new_menu);
virtual ~WrenchMenuModel(); virtual ~WrenchMenuModel();
// Overridden for ButtonMenuItemModel::Delegate: // Overridden for ButtonMenuItemModel::Delegate:
...@@ -144,23 +141,20 @@ class WrenchMenuModel : public ui::SimpleMenuModel, ...@@ -144,23 +141,20 @@ class WrenchMenuModel : public ui::SimpleMenuModel,
WrenchMenuModel(); WrenchMenuModel();
void Build(bool is_new_menu); void Build();
void AddGlobalErrorMenuItems(); void AddGlobalErrorMenuItems();
// Appends everything needed for the clipboard menu: a menu break, the // Appends everything needed for the clipboard menu: a menu break, the
// clipboard menu content and the finalizing menu break. If the last break // clipboard menu content and the finalizing menu break.
// is not needed it can be suppressed by setting |new_menu| void CreateCutCopyPasteMenu();
// to false.
void CreateCutCopyPasteMenu(bool new_menu);
// Add a menu item for the extension icons. // Add a menu item for the extension icons.
void CreateExtensionToolbarOverflowMenu(); void CreateExtensionToolbarOverflowMenu();
// Appends everything needed for the zoom menu: a menu break, then the zoom // Appends everything needed for the zoom menu: a menu break, then the zoom
// menu content and then another menu break. If the new menu type is used, // menu content and then another menu break.
// |new_menu| should be set to true. void CreateZoomMenu();
void CreateZoomMenu(bool new_menu);
void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
......
...@@ -89,7 +89,7 @@ class TestWrenchMenuModel : public WrenchMenuModel { ...@@ -89,7 +89,7 @@ class TestWrenchMenuModel : public WrenchMenuModel {
public: public:
TestWrenchMenuModel(ui::AcceleratorProvider* provider, TestWrenchMenuModel(ui::AcceleratorProvider* provider,
Browser* browser) Browser* browser)
: WrenchMenuModel(provider, browser, false), : WrenchMenuModel(provider, browser),
execute_count_(0), execute_count_(0),
checked_count_(0), checked_count_(0),
enable_count_(0) { enable_count_(0) {
...@@ -176,7 +176,7 @@ TEST_F(WrenchMenuModelTest, GlobalError) { ...@@ -176,7 +176,7 @@ TEST_F(WrenchMenuModelTest, GlobalError) {
MenuError* error2 = new MenuError(command2); MenuError* error2 = new MenuError(command2);
service->AddGlobalError(error2); service->AddGlobalError(error2);
WrenchMenuModel model(this, browser(), false); WrenchMenuModel model(this, browser());
int index1 = model.GetIndexOfCommandId(command1); int index1 = model.GetIndexOfCommandId(command1);
EXPECT_GT(index1, -1); EXPECT_GT(index1, -1);
int index2 = model.GetIndexOfCommandId(command2); int index2 = model.GetIndexOfCommandId(command2);
......
...@@ -345,26 +345,15 @@ void ToolbarView::ShowAppMenu(bool for_drop) { ...@@ -345,26 +345,15 @@ void ToolbarView::ShowAppMenu(bool for_drop) {
if (wrench_menu_.get() && wrench_menu_->IsShowing()) if (wrench_menu_.get() && wrench_menu_->IsShowing())
return; return;
int run_flags = 0;
bool use_new_menu = false;
// TODO: remove this.
#if !defined(OS_LINUX) || defined(OS_CHROMEOS)
if (GetNativeTheme() == ui::NativeThemeAura::instance()) {
use_new_menu = true;
run_flags |= WrenchMenu::SUPPORTS_NEW_SEPARATORS | WrenchMenu::USE_NEW_MENU;
}
#endif
if (keyboard::KeyboardController::GetInstance() && if (keyboard::KeyboardController::GetInstance() &&
keyboard::KeyboardController::GetInstance()->keyboard_visible()) { keyboard::KeyboardController::GetInstance()->keyboard_visible()) {
keyboard::KeyboardController::GetInstance()->HideKeyboard( keyboard::KeyboardController::GetInstance()->HideKeyboard(
keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
} }
if (for_drop) wrench_menu_.reset(
run_flags |= WrenchMenu::FOR_DROP; new WrenchMenu(browser_, for_drop ? WrenchMenu::FOR_DROP : 0));
wrench_menu_.reset(new WrenchMenu(browser_, run_flags)); wrench_menu_model_.reset(new WrenchMenuModel(this, browser_));
wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, use_new_menu));
wrench_menu_->Init(wrench_menu_model_.get()); wrench_menu_->Init(wrench_menu_model_.get());
FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened());
......
...@@ -38,12 +38,8 @@ class WrenchMenu : public views::MenuDelegate, ...@@ -38,12 +38,8 @@ class WrenchMenu : public views::MenuDelegate,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
enum RunFlags { enum RunFlags {
// TODO: remove |USE_NEW_MENU| and |SUPPORTS_NEW_SEPARATORS|.
USE_NEW_MENU = 1 << 0,
SUPPORTS_NEW_SEPARATORS = 1 << 1,
// Indicates that the menu was opened for a drag-and-drop operation. // Indicates that the menu was opened for a drag-and-drop operation.
FOR_DROP = 1 << 2, FOR_DROP = 1 << 0,
}; };
WrenchMenu(Browser* browser, int run_flags); WrenchMenu(Browser* browser, int run_flags);
...@@ -60,7 +56,6 @@ class WrenchMenu : public views::MenuDelegate, ...@@ -60,7 +56,6 @@ class WrenchMenu : public views::MenuDelegate,
// Whether the menu is currently visible to the user. // Whether the menu is currently visible to the user.
bool IsShowing(); bool IsShowing();
bool use_new_menu() const { return (run_flags_ & USE_NEW_MENU) != 0; }
bool for_drop() const { return (run_flags_ & FOR_DROP) != 0; } bool for_drop() const { return (run_flags_ & FOR_DROP) != 0; }
void AddObserver(WrenchMenuObserver* observer); void AddObserver(WrenchMenuObserver* observer);
...@@ -121,10 +116,6 @@ class WrenchMenu : public views::MenuDelegate, ...@@ -121,10 +116,6 @@ class WrenchMenu : public views::MenuDelegate,
typedef std::pair<ui::MenuModel*,int> Entry; typedef std::pair<ui::MenuModel*,int> Entry;
typedef std::map<int,Entry> CommandIDToEntry; typedef std::map<int,Entry> CommandIDToEntry;
bool supports_new_separators() const {
return (run_flags_ & SUPPORTS_NEW_SEPARATORS) != 0;
}
// Populates |parent| with all the child menus in |model|. Recursively invokes // Populates |parent| with all the child menus in |model|. Recursively invokes
// |PopulateMenu| for any submenu. // |PopulateMenu| for any submenu.
void PopulateMenu(views::MenuItemView* parent, void PopulateMenu(views::MenuItemView* parent,
...@@ -135,16 +126,13 @@ class WrenchMenu : public views::MenuDelegate, ...@@ -135,16 +126,13 @@ class WrenchMenu : public views::MenuDelegate,
// - |menu_index|: position in |parent| to add the new item. // - |menu_index|: position in |parent| to add the new item.
// - |model_index|: position in |model| to retrieve information about the // - |model_index|: position in |model| to retrieve information about the
// new menu item. // new menu item.
// - |height|: For button containing menu items, a |height| override can be
// specified with a number bigger then 0.
// The returned item's MenuItemView::GetCommand() is the same as that of // The returned item's MenuItemView::GetCommand() is the same as that of
// |model|->GetCommandIdAt(|model_index|). // |model|->GetCommandIdAt(|model_index|).
views::MenuItemView* AddMenuItem(views::MenuItemView* parent, views::MenuItemView* AddMenuItem(views::MenuItemView* parent,
int menu_index, int menu_index,
ui::MenuModel* model, ui::MenuModel* model,
int model_index, int model_index,
ui::MenuModel::ItemType menu_type, ui::MenuModel::ItemType menu_type);
int height);
// Invoked from the cut/copy/paste menus. Cancels the current active menu and // Invoked from the cut/copy/paste menus. Cancels the current active menu and
// activates the menu item in |model| at |index|. // activates the menu item in |model| at |index|.
......
...@@ -73,6 +73,9 @@ void MenuConfig::Init(const NativeTheme* theme) { ...@@ -73,6 +73,9 @@ void MenuConfig::Init(const NativeTheme* theme) {
show_cues == TRUE); show_cues == TRUE);
SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &show_delay, 0); SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &show_delay, 0);
separator_upper_height = 5;
separator_lower_height = 7;
} }
// static // static
......
...@@ -24,8 +24,10 @@ class MenuSeparator : public View { ...@@ -24,8 +24,10 @@ class MenuSeparator : public View {
virtual gfx::Size GetPreferredSize() const OVERRIDE; virtual gfx::Size GetPreferredSize() const OVERRIDE;
private: private:
// Gets the bounds where the separator should be painted.
gfx::Rect GetPaintBounds();
void OnPaintAura(gfx::Canvas* canvas); void OnPaintAura(gfx::Canvas* canvas);
gfx::Size GetPreferredSizeAura() const;
// The type of the separator. // The type of the separator.
const ui::MenuSeparatorType type_; const ui::MenuSeparatorType type_;
......
...@@ -22,32 +22,9 @@ namespace views { ...@@ -22,32 +22,9 @@ namespace views {
void MenuSeparator::OnPaint(gfx::Canvas* canvas) { void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
OnPaintAura(canvas); OnPaintAura(canvas);
} }
gfx::Size MenuSeparator::GetPreferredSize() const {
return GetPreferredSizeAura();
}
#endif #endif
void MenuSeparator::OnPaintAura(gfx::Canvas* canvas) { gfx::Size MenuSeparator::GetPreferredSize() const {
int pos = 0;
switch (type_) {
case ui::LOWER_SEPARATOR:
pos = height() - kSeparatorHeight;
break;
case ui::SPACING_SEPARATOR:
return;
case ui::UPPER_SEPARATOR:
break;
default:
pos = height() / 2;
break;
}
canvas->FillRect(gfx::Rect(0, pos, width(), kSeparatorHeight),
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_MenuSeparatorColor));
}
gfx::Size MenuSeparator::GetPreferredSizeAura() const {
const MenuConfig& menu_config = parent_menu_item_->GetMenuConfig(); const MenuConfig& menu_config = parent_menu_item_->GetMenuConfig();
int height = menu_config.separator_height; int height = menu_config.separator_height;
switch(type_) { switch(type_) {
...@@ -68,4 +45,28 @@ gfx::Size MenuSeparator::GetPreferredSizeAura() const { ...@@ -68,4 +45,28 @@ gfx::Size MenuSeparator::GetPreferredSizeAura() const {
height); height);
} }
gfx::Rect MenuSeparator::GetPaintBounds() {
int pos = 0;
switch (type_) {
case ui::LOWER_SEPARATOR:
pos = height() - kSeparatorHeight;
break;
case ui::SPACING_SEPARATOR:
return gfx::Rect();
case ui::UPPER_SEPARATOR:
break;
default:
pos = height() / 2;
break;
}
return gfx::Rect(0, pos, width(), kSeparatorHeight);
}
void MenuSeparator::OnPaintAura(gfx::Canvas* canvas) {
canvas->FillRect(GetPaintBounds(),
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_MenuSeparatorColor));
}
} // namespace views } // namespace views
...@@ -25,7 +25,7 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) { ...@@ -25,7 +25,7 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
return; return;
} }
int start_x = 0; gfx::Rect separator_bounds = GetPaintBounds();
if (config.render_gutter) { if (config.render_gutter) {
// If render_gutter is true, we're on Vista and need to render the // If render_gutter is true, we're on Vista and need to render the
// gutter, then indent the separator from the gutter. // gutter, then indent the separator from the gutter.
...@@ -36,10 +36,9 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) { ...@@ -36,10 +36,9 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
config.native_theme->Paint( config.native_theme->Paint(
canvas->sk_canvas(), ui::NativeTheme::kMenuPopupGutter, canvas->sk_canvas(), ui::NativeTheme::kMenuPopupGutter,
ui::NativeTheme::kNormal, gutter_bounds, extra); ui::NativeTheme::kNormal, gutter_bounds, extra);
start_x = gutter_bounds.x() + config.gutter_width; separator_bounds.set_x(gutter_bounds.x() + config.gutter_width);
} }
gfx::Rect separator_bounds(start_x, 0, width(), height());
ui::NativeTheme::ExtraParams extra; ui::NativeTheme::ExtraParams extra;
extra.menu_separator.has_gutter = config.render_gutter; extra.menu_separator.has_gutter = config.render_gutter;
config.native_theme->Paint( config.native_theme->Paint(
...@@ -47,14 +46,4 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) { ...@@ -47,14 +46,4 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
ui::NativeTheme::kNormal, separator_bounds, extra); ui::NativeTheme::kNormal, separator_bounds, extra);
} }
gfx::Size MenuSeparator::GetPreferredSize() const {
const MenuConfig& config = parent_menu_item_->GetMenuConfig();
if (config.native_theme == ui::NativeThemeAura::instance())
return GetPreferredSizeAura();
return gfx::Size(10, // Just in case we're the only item in a menu.
config.separator_height);
}
} // namespace views } // namespace views
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment