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 {
- (void)createModel {
recentTabsMenuModelDelegate_.reset();
wrenchMenuModel_.reset(
new WrenchMenuModel(acceleratorDelegate_.get(), browser_, false));
new WrenchMenuModel(acceleratorDelegate_.get(), browser_));
[self setModel:wrenchMenuModel_.get()];
buttonViewController_.reset(
......
......@@ -277,13 +277,12 @@ void ToolsMenuModel::Build(Browser* browser) {
// WrenchMenuModel
WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider,
Browser* browser,
bool is_new_menu)
Browser* browser)
: ui::SimpleMenuModel(this),
provider_(provider),
browser_(browser),
tab_strip_model_(browser_->tab_strip_model()) {
Build(is_new_menu);
Build();
UpdateZoomControls();
content_zoom_subscription_ = content::HostZoomMap::GetForBrowserContext(
......@@ -526,7 +525,7 @@ bool WrenchMenuModel::ShouldShowNewIncognitoWindowMenuItem() {
return !browser_->profile()->IsGuestSession();
}
void WrenchMenuModel::Build(bool is_new_menu) {
void WrenchMenuModel::Build() {
#if defined(OS_WIN)
AddItem(IDC_VIEW_INCOMPATIBILITIES,
l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES));
......@@ -598,10 +597,7 @@ void WrenchMenuModel::Build(bool is_new_menu) {
// Append the full menu including separators. The final separator only gets
// appended when this is a touch menu - otherwise it would get added twice.
CreateCutCopyPasteMenu(is_new_menu);
if (!is_new_menu)
CreateZoomMenu(is_new_menu);
CreateCutCopyPasteMenu();
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableDomDistiller)) {
......@@ -613,16 +609,7 @@ void WrenchMenuModel::Build(bool is_new_menu) {
AddItemWithStringId(IDC_PRINT, IDS_PRINT);
tools_menu_model_.reset(new ToolsMenuModel(this, browser_));
// In case of touch this is the last item.
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);
CreateZoomMenu();
AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY);
AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS);
......@@ -674,11 +661,9 @@ void WrenchMenuModel::Build(bool is_new_menu) {
AddGlobalErrorMenuItems();
if (is_new_menu) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_MORE_TOOLS_MENU,
tools_menu_model_.get());
}
AddSeparator(ui::NORMAL_SEPARATOR);
AddSubMenuWithStringId(
IDC_ZOOM_MENU, IDS_MORE_TOOLS_MENU, tools_menu_model_.get());
bool show_exit_menu = browser_defaults::kShowExitMenuItem;
#if defined(OS_WIN)
......@@ -750,8 +735,8 @@ void WrenchMenuModel::CreateExtensionToolbarOverflowMenu() {
#endif // defined(TOOLKIT_VIEWS)
}
void WrenchMenuModel::CreateCutCopyPasteMenu(bool new_menu) {
AddSeparator(new_menu ? ui::LOWER_SEPARATOR : ui::NORMAL_SEPARATOR);
void WrenchMenuModel::CreateCutCopyPasteMenu() {
AddSeparator(ui::LOWER_SEPARATOR);
#if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS)
// WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the
......@@ -770,13 +755,12 @@ void WrenchMenuModel::CreateCutCopyPasteMenu(bool new_menu) {
AddItemWithStringId(IDC_PASTE, IDS_PASTE);
#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.
AddSeparator(new_menu ? ui::LOWER_SEPARATOR : ui::NORMAL_SEPARATOR);
AddSeparator(ui::LOWER_SEPARATOR);
#if defined(OS_POSIX) && !defined(TOOLKIT_VIEWS)
// WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the
......@@ -802,7 +786,7 @@ void WrenchMenuModel::CreateZoomMenu(bool new_menu) {
AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN);
#endif
AddSeparator(new_menu ? ui::UPPER_SEPARATOR : ui::NORMAL_SEPARATOR);
AddSeparator(ui::UPPER_SEPARATOR);
}
void WrenchMenuModel::UpdateZoomControls() {
......
......@@ -89,10 +89,7 @@ class WrenchMenuModel : public ui::SimpleMenuModel,
static const int kMinRecentTabsCommandId = 1001;
static const int kMaxRecentTabsCommandId = 1200;
// TODO: remove |is_new_menu|.
WrenchMenuModel(ui::AcceleratorProvider* provider,
Browser* browser,
bool is_new_menu);
WrenchMenuModel(ui::AcceleratorProvider* provider, Browser* browser);
virtual ~WrenchMenuModel();
// Overridden for ButtonMenuItemModel::Delegate:
......@@ -144,23 +141,20 @@ class WrenchMenuModel : public ui::SimpleMenuModel,
WrenchMenuModel();
void Build(bool is_new_menu);
void Build();
void AddGlobalErrorMenuItems();
// Appends everything needed for the clipboard menu: a menu break, the
// clipboard menu content and the finalizing menu break. If the last break
// is not needed it can be suppressed by setting |new_menu|
// to false.
void CreateCutCopyPasteMenu(bool new_menu);
// clipboard menu content and the finalizing menu break.
void CreateCutCopyPasteMenu();
// Add a menu item for the extension icons.
void CreateExtensionToolbarOverflowMenu();
// 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,
// |new_menu| should be set to true.
void CreateZoomMenu(bool new_menu);
// menu content and then another menu break.
void CreateZoomMenu();
void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
......
......@@ -89,7 +89,7 @@ class TestWrenchMenuModel : public WrenchMenuModel {
public:
TestWrenchMenuModel(ui::AcceleratorProvider* provider,
Browser* browser)
: WrenchMenuModel(provider, browser, false),
: WrenchMenuModel(provider, browser),
execute_count_(0),
checked_count_(0),
enable_count_(0) {
......@@ -176,7 +176,7 @@ TEST_F(WrenchMenuModelTest, GlobalError) {
MenuError* error2 = new MenuError(command2);
service->AddGlobalError(error2);
WrenchMenuModel model(this, browser(), false);
WrenchMenuModel model(this, browser());
int index1 = model.GetIndexOfCommandId(command1);
EXPECT_GT(index1, -1);
int index2 = model.GetIndexOfCommandId(command2);
......
......@@ -345,26 +345,15 @@ void ToolbarView::ShowAppMenu(bool for_drop) {
if (wrench_menu_.get() && wrench_menu_->IsShowing())
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() &&
keyboard::KeyboardController::GetInstance()->keyboard_visible()) {
keyboard::KeyboardController::GetInstance()->HideKeyboard(
keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
}
if (for_drop)
run_flags |= WrenchMenu::FOR_DROP;
wrench_menu_.reset(new WrenchMenu(browser_, run_flags));
wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, use_new_menu));
wrench_menu_.reset(
new WrenchMenu(browser_, for_drop ? WrenchMenu::FOR_DROP : 0));
wrench_menu_model_.reset(new WrenchMenuModel(this, browser_));
wrench_menu_->Init(wrench_menu_model_.get());
FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened());
......
......@@ -38,12 +38,8 @@ class WrenchMenu : public views::MenuDelegate,
public content::NotificationObserver {
public:
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.
FOR_DROP = 1 << 2,
FOR_DROP = 1 << 0,
};
WrenchMenu(Browser* browser, int run_flags);
......@@ -60,7 +56,6 @@ class WrenchMenu : public views::MenuDelegate,
// Whether the menu is currently visible to the user.
bool IsShowing();
bool use_new_menu() const { return (run_flags_ & USE_NEW_MENU) != 0; }
bool for_drop() const { return (run_flags_ & FOR_DROP) != 0; }
void AddObserver(WrenchMenuObserver* observer);
......@@ -121,10 +116,6 @@ class WrenchMenu : public views::MenuDelegate,
typedef std::pair<ui::MenuModel*,int> Entry;
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
// |PopulateMenu| for any submenu.
void PopulateMenu(views::MenuItemView* parent,
......@@ -135,16 +126,13 @@ class WrenchMenu : public views::MenuDelegate,
// - |menu_index|: position in |parent| to add the new item.
// - |model_index|: position in |model| to retrieve information about the
// 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
// |model|->GetCommandIdAt(|model_index|).
views::MenuItemView* AddMenuItem(views::MenuItemView* parent,
int menu_index,
ui::MenuModel* model,
int model_index,
ui::MenuModel::ItemType menu_type,
int height);
ui::MenuModel::ItemType menu_type);
// Invoked from the cut/copy/paste menus. Cancels the current active menu and
// activates the menu item in |model| at |index|.
......
......@@ -73,6 +73,9 @@ void MenuConfig::Init(const NativeTheme* theme) {
show_cues == TRUE);
SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &show_delay, 0);
separator_upper_height = 5;
separator_lower_height = 7;
}
// static
......
......@@ -24,8 +24,10 @@ class MenuSeparator : public View {
virtual gfx::Size GetPreferredSize() const OVERRIDE;
private:
// Gets the bounds where the separator should be painted.
gfx::Rect GetPaintBounds();
void OnPaintAura(gfx::Canvas* canvas);
gfx::Size GetPreferredSizeAura() const;
// The type of the separator.
const ui::MenuSeparatorType type_;
......
......@@ -22,32 +22,9 @@ namespace views {
void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
OnPaintAura(canvas);
}
gfx::Size MenuSeparator::GetPreferredSize() const {
return GetPreferredSizeAura();
}
#endif
void MenuSeparator::OnPaintAura(gfx::Canvas* canvas) {
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 {
gfx::Size MenuSeparator::GetPreferredSize() const {
const MenuConfig& menu_config = parent_menu_item_->GetMenuConfig();
int height = menu_config.separator_height;
switch(type_) {
......@@ -68,4 +45,28 @@ gfx::Size MenuSeparator::GetPreferredSizeAura() const {
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
......@@ -25,7 +25,7 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
return;
}
int start_x = 0;
gfx::Rect separator_bounds = GetPaintBounds();
if (config.render_gutter) {
// If render_gutter is true, we're on Vista and need to render the
// gutter, then indent the separator from the gutter.
......@@ -36,10 +36,9 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
config.native_theme->Paint(
canvas->sk_canvas(), ui::NativeTheme::kMenuPopupGutter,
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;
extra.menu_separator.has_gutter = config.render_gutter;
config.native_theme->Paint(
......@@ -47,14 +46,4 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
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
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