diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 17:59:46 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 17:59:46 +0000 |
commit | 3fae79d84a30dbe5a756f1a22debb3f269331bde (patch) | |
tree | d46408ced672af4de190f961a971e0030c23cd83 /views | |
parent | 5bc5c15301e555c7d22b27d2b30c56b6ca1770ac (diff) | |
download | chromium_src-3fae79d84a30dbe5a756f1a22debb3f269331bde.zip chromium_src-3fae79d84a30dbe5a756f1a22debb3f269331bde.tar.gz chromium_src-3fae79d84a30dbe5a756f1a22debb3f269331bde.tar.bz2 |
views: Change Menu API to string16.
BUG=68267
R=sky@chromium.org
Review URL: http://codereview.chromium.org/8354038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106522 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/menu/menu.cc | 25 | ||||
-rw-r--r-- | views/controls/menu/menu.h | 32 | ||||
-rw-r--r-- | views/controls/menu/menu_delegate.cc | 2 | ||||
-rw-r--r-- | views/controls/menu/menu_delegate.h | 2 | ||||
-rw-r--r-- | views/controls/menu/menu_gtk.cc | 8 | ||||
-rw-r--r-- | views/controls/menu/menu_gtk.h | 29 | ||||
-rw-r--r-- | views/controls/menu/menu_win.cc | 39 | ||||
-rw-r--r-- | views/controls/menu/menu_win.h | 44 |
8 files changed, 92 insertions, 89 deletions
diff --git a/views/controls/menu/menu.cc b/views/controls/menu/menu.cc index 479a545..20a9361 100644 --- a/views/controls/menu/menu.cc +++ b/views/controls/menu/menu.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,14 +32,14 @@ Menu::~Menu() { } void Menu::AppendMenuItem(int item_id, - const std::wstring& label, + const string16& label, MenuItemType type) { AddMenuItem(-1, item_id, label, type); } void Menu::AddMenuItem(int index, int item_id, - const std::wstring& label, + const string16& label, MenuItemType type) { if (type == SEPARATOR) AddSeparator(index); @@ -47,26 +47,27 @@ void Menu::AddMenuItem(int index, AddMenuItemInternal(index, item_id, label, SkBitmap(), type); } -Menu* Menu::AppendSubMenu(int item_id, const std::wstring& label) { +Menu* Menu::AppendSubMenu(int item_id, const string16& label) { return AddSubMenu(-1, item_id, label); } -Menu* Menu::AddSubMenu(int index, int item_id, const std::wstring& label) { +Menu* Menu::AddSubMenu(int index, int item_id, const string16& label) { return AddSubMenuWithIcon(index, item_id, label, SkBitmap()); } Menu* Menu::AppendSubMenuWithIcon(int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon) { return AddSubMenuWithIcon(-1, item_id, label, icon); } -void Menu::AppendMenuItemWithLabel(int item_id, const std::wstring& label) { +void Menu::AppendMenuItemWithLabel(int item_id, const string16& label) { AddMenuItemWithLabel(-1, item_id, label); } -void Menu::AddMenuItemWithLabel(int index, int item_id, - const std::wstring& label) { +void Menu::AddMenuItemWithLabel(int index, + int item_id, + const string16& label) { AddMenuItem(index, item_id, label, Menu::NORMAL); } @@ -75,7 +76,7 @@ void Menu::AppendDelegateMenuItem(int item_id) { } void Menu::AddDelegateMenuItem(int index, int item_id) { - AddMenuItem(index, item_id, std::wstring(), Menu::NORMAL); + AddMenuItem(index, item_id, string16(), Menu::NORMAL); } void Menu::AppendSeparator() { @@ -83,14 +84,14 @@ void Menu::AppendSeparator() { } void Menu::AppendMenuItemWithIcon(int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon) { AddMenuItemWithIcon(-1, item_id, label, icon); } void Menu::AddMenuItemWithIcon(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon) { AddMenuItemInternal(index, item_id, label, icon, Menu::NORMAL); } diff --git a/views/controls/menu/menu.h b/views/controls/menu/menu.h index 83b374f..9397684 100644 --- a/views/controls/menu/menu.h +++ b/views/controls/menu/menu.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTROLS_MENU_VIEWS_MENU_H_ -#define CONTROLS_MENU_VIEWS_MENU_H_ +#ifndef VIEWS_CONTROLS_MENU_MENU_H_ +#define VIEWS_CONTROLS_MENU_MENU_H_ #pragma once #include <string> @@ -114,7 +114,7 @@ class VIEWS_EXPORT Menu { virtual bool IsCommandEnabled(int id) const { return true; } - virtual bool GetContextualLabel(int id, std::wstring* out) const { + virtual bool GetContextualLabel(int id, string16* out) const { return false; } virtual void ExecuteCommand(int id) { @@ -173,35 +173,35 @@ class VIEWS_EXPORT Menu { // label The text label shown. // type The type of item. void AppendMenuItem(int item_id, - const std::wstring& label, + const string16& label, MenuItemType type); void AddMenuItem(int index, int item_id, - const std::wstring& label, + const string16& label, MenuItemType type); // Append a submenu to this menu. // The returned pointer is owned by this menu. Menu* AppendSubMenu(int item_id, - const std::wstring& label); - Menu* AddSubMenu(int index, int item_id, const std::wstring& label); + const string16& label); + Menu* AddSubMenu(int index, int item_id, const string16& label); // Append a submenu with an icon to this menu // The returned pointer is owned by this menu. // Unless the icon is empty, calling this function forces the Menu class // to draw the menu, instead of relying on Windows. Menu* AppendSubMenuWithIcon(int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon); virtual Menu* AddSubMenuWithIcon(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon) = 0; // This is a convenience for standard text label menu items where the label // is provided with this call. - void AppendMenuItemWithLabel(int item_id, const std::wstring& label); - void AddMenuItemWithLabel(int index, int item_id, const std::wstring& label); + void AppendMenuItemWithLabel(int item_id, const string16& label); + void AddMenuItemWithLabel(int index, int item_id, const string16& label); // This is a convenience for text label menu items where the label is // provided by the delegate. @@ -216,11 +216,11 @@ class VIEWS_EXPORT Menu { // needs an icon. Calling this function forces the Menu class to draw // the menu, instead of relying on Windows. void AppendMenuItemWithIcon(int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon); virtual void AddMenuItemWithIcon(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon); // Enables or disables the item with the specified id. @@ -228,7 +228,7 @@ class VIEWS_EXPORT Menu { virtual void EnableMenuItemAt(int index, bool enabled) = 0; // Sets menu label at specified index. - virtual void SetMenuLabel(int item_id, const std::wstring& label) = 0; + virtual void SetMenuLabel(int item_id, const string16& label) = 0; // Sets an icon for an item with a given item_id. Calling this function // also forces the Menu class to draw the menu, instead of relying on Windows. @@ -256,7 +256,7 @@ class VIEWS_EXPORT Menu { virtual void AddMenuItemInternal(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon, MenuItemType type) = 0; @@ -272,4 +272,4 @@ class VIEWS_EXPORT Menu { } // namespace views -#endif // CONTROLS_MENU_VIEWS_MENU_H_ +#endif // VIEWS_CONTROLS_MENU_MENU_H_ diff --git a/views/controls/menu/menu_delegate.cc b/views/controls/menu/menu_delegate.cc index cc0970d..f1f7488 100644 --- a/views/controls/menu/menu_delegate.cc +++ b/views/controls/menu/menu_delegate.cc @@ -44,7 +44,7 @@ bool MenuDelegate::IsCommandEnabled(int id) const { return true; } -bool MenuDelegate::GetContextualLabel(int id, std::wstring* out) const { +bool MenuDelegate::GetContextualLabel(int id, string16* out) const { return false; } diff --git a/views/controls/menu/menu_delegate.h b/views/controls/menu/menu_delegate.h index 6541b7a..700e4e84 100644 --- a/views/controls/menu/menu_delegate.h +++ b/views/controls/menu/menu_delegate.h @@ -91,7 +91,7 @@ class VIEWS_EXPORT MenuDelegate { // Controller virtual bool SupportsCommand(int id) const; virtual bool IsCommandEnabled(int id) const; - virtual bool GetContextualLabel(int id, std::wstring* out) const; + virtual bool GetContextualLabel(int id, string16* out) const; virtual void ExecuteCommand(int id) { } diff --git a/views/controls/menu/menu_gtk.cc b/views/controls/menu/menu_gtk.cc index c2abb44..cc7926e 100644 --- a/views/controls/menu/menu_gtk.cc +++ b/views/controls/menu/menu_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,7 +31,7 @@ MenuGtk::~MenuGtk() { Menu* MenuGtk::AddSubMenuWithIcon(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon) { NOTIMPLEMENTED(); return NULL; @@ -49,7 +49,7 @@ void MenuGtk::EnableMenuItemAt(int index, bool enabled) { NOTIMPLEMENTED(); } -void MenuGtk::SetMenuLabel(int item_id, const std::wstring& label) { +void MenuGtk::SetMenuLabel(int item_id, const string16& label) { NOTIMPLEMENTED(); } @@ -73,7 +73,7 @@ int MenuGtk::ItemCount() { void MenuGtk::AddMenuItemInternal(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon, MenuItemType type) { NOTIMPLEMENTED(); diff --git a/views/controls/menu/menu_gtk.h b/views/controls/menu/menu_gtk.h index f6f0876..3d20154 100644 --- a/views/controls/menu/menu_gtk.h +++ b/views/controls/menu/menu_gtk.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #pragma once #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "views/controls/menu/menu.h" namespace views { @@ -24,26 +25,26 @@ class MenuGtk : public Menu { MenuGtk(Delegate* d, AnchorPoint anchor, gfx::NativeView owner); virtual ~MenuGtk(); - // Menu overrides. + // Overridden from Menu: virtual Menu* AddSubMenuWithIcon(int index, int item_id, - const std::wstring& label, - const SkBitmap& icon); - virtual void AddSeparator(int index); - virtual void EnableMenuItemByID(int item_id, bool enabled); - virtual void EnableMenuItemAt(int index, bool enabled); - virtual void SetMenuLabel(int item_id, const std::wstring& label); - virtual bool SetIcon(const SkBitmap& icon, int item_id); - virtual void RunMenuAt(int x, int y); - virtual void Cancel(); - virtual int ItemCount(); + const string16& label, + const SkBitmap& icon) OVERRIDE; + virtual void AddSeparator(int index) OVERRIDE; + virtual void EnableMenuItemByID(int item_id, bool enabled) OVERRIDE; + virtual void EnableMenuItemAt(int index, bool enabled) OVERRIDE; + virtual void SetMenuLabel(int item_id, const string16& label) OVERRIDE; + virtual bool SetIcon(const SkBitmap& icon, int item_id) OVERRIDE; + virtual void RunMenuAt(int x, int y) OVERRIDE; + virtual void Cancel() OVERRIDE; + virtual int ItemCount() OVERRIDE; protected: virtual void AddMenuItemInternal(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon, - MenuItemType type); + MenuItemType type) OVERRIDE; DISALLOW_COPY_AND_ASSIGN(MenuGtk); }; diff --git a/views/controls/menu/menu_win.cc b/views/controls/menu/menu_win.cc index 3958c5d..1e92bc5 100644 --- a/views/controls/menu/menu_win.cc +++ b/views/controls/menu/menu_win.cc @@ -22,24 +22,24 @@ namespace views { // The width of an icon, including the pixels between the icon and // the item label. -static const int kIconWidth = 23; +const int kIconWidth = 23; // Margins between the top of the item and the label. -static const int kItemTopMargin = 3; +const int kItemTopMargin = 3; // Margins between the bottom of the item and the label. -static const int kItemBottomMargin = 4; +const int kItemBottomMargin = 4; // Margins between the left of the item and the icon. -static const int kItemLeftMargin = 4; +const int kItemLeftMargin = 4; // Margins between the right of the item and the label. -static const int kItemRightMargin = 10; +const int kItemRightMargin = 10; // The width for displaying the sub-menu arrow. -static const int kArrowWidth = 10; +const int kArrowWidth = 10; // Current active MenuHostWindow. If NULL, no menu is active. static MenuHostWindow* active_host_window = NULL; // The data of menu items needed to display. struct MenuWin::ItemData { - std::wstring label; + string16 label; SkBitmap icon; bool submenu; }; @@ -110,7 +110,7 @@ class MenuHostWindow : public ui::WindowImpl { if (data->submenu) lpmis->itemWidth += kArrowWidth; // If the label contains an accelerator, make room for tab. - if (data->label.find(L'\t') != std::wstring::npos) + if (data->label.find(L'\t') != string16::npos) lpmis->itemWidth += font.GetStringWidth(L" "); lpmis->itemHeight = font.GetHeight() + kItemBottomMargin + kItemTopMargin; } else { @@ -166,10 +166,10 @@ class MenuHostWindow : public ui::WindowImpl { // left and the accelerator on the right. // TODO(jungshik): This will break in RTL UI. Currently, he/ar use the // window system UI font and will not hit here. - std::wstring label = data->label; - std::wstring accel; - std::wstring::size_type tab_pos = label.find(L'\t'); - if (tab_pos != std::wstring::npos) { + string16 label = data->label; + string16 accel; + string16::size_type tab_pos = label.find(L'\t'); + if (tab_pos != string16::npos) { accel = label.substr(tab_pos); label = label.substr(0, tab_pos); } @@ -264,7 +264,7 @@ MenuWin::~MenuWin() { void MenuWin::AddMenuItemWithIcon(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon) { owner_draw_ = true; Menu::AddMenuItemWithIcon(index, item_id, label, icon); @@ -272,7 +272,7 @@ void MenuWin::AddMenuItemWithIcon(int index, Menu* MenuWin::AddSubMenuWithIcon(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon) { MenuWin* submenu = new MenuWin(this); submenus_.push_back(submenu); @@ -298,7 +298,7 @@ void MenuWin::EnableMenuItemAt(int index, bool enabled) { EnableMenuItem(menu_, index, MF_BYPOSITION | enable_flags); } -void MenuWin::SetMenuLabel(int item_id, const std::wstring& label) { +void MenuWin::SetMenuLabel(int item_id, const string16& label) { MENUITEMINFO mii = {0}; mii.cbSize = sizeof(mii); mii.fMask = MIIM_STRING; @@ -387,7 +387,7 @@ int MenuWin::ItemCount() { void MenuWin::AddMenuItemInternal(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon, MenuItemType type) { AddMenuItemInternal(index, item_id, label, icon, NULL, type); @@ -395,7 +395,7 @@ void MenuWin::AddMenuItemInternal(int index, void MenuWin::AddMenuItemInternal(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon, HMENU submenu, MenuItemType type) { @@ -439,8 +439,7 @@ void MenuWin::AddMenuItemInternal(int index, item_data_.push_back(data); data->submenu = submenu != NULL; - std::wstring actual_label(label.empty() ? - delegate()->GetLabel(item_id) : label); + string16 actual_label(label.empty() ? delegate()->GetLabel(item_id) : label); // Find out if there is a shortcut we need to append to the label. views::Accelerator accelerator(ui::VKEY_UNKNOWN, false, false, false); @@ -498,7 +497,7 @@ void MenuWin::SetMenuInfo() { // Validate the label. If there is a contextual label, use it, otherwise // default to the static label - std::wstring label; + string16 label; if (!delegate()->GetContextualLabel(id, &label)) label = labels_[i - sep_count]; diff --git a/views/controls/menu/menu_win.h b/views/controls/menu/menu_win.h index f50aec2..b5292f1 100644 --- a/views/controls/menu/menu_win.h +++ b/views/controls/menu/menu_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,10 +6,12 @@ #define CONTROLS_MENU_VIEWS_MENU_WIN_H_ #pragma once -#include <vector> #include <windows.h> +#include <vector> + #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "views/controls/menu/menu.h" namespace views { @@ -27,8 +29,6 @@ class MenuHostWindow; // /////////////////////////////////////////////////////////////////////////////// class MenuWin : public Menu { - friend class MenuHostWindow; - public: // Construct a Menu using the specified controller to determine command // state. @@ -46,23 +46,23 @@ class MenuWin : public Menu { explicit MenuWin(HMENU hmenu); virtual ~MenuWin(); - // Menu overrides. + // Overridden from Menu: virtual void AddMenuItemWithIcon(int index, int item_id, - const std::wstring& label, - const SkBitmap& icon); + const string16& label, + const SkBitmap& icon) OVERRIDE; virtual Menu* AddSubMenuWithIcon(int index, int item_id, - const std::wstring& label, - const SkBitmap& icon); - virtual void AddSeparator(int index); - virtual void EnableMenuItemByID(int item_id, bool enabled); - virtual void EnableMenuItemAt(int index, bool enabled); - virtual void SetMenuLabel(int item_id, const std::wstring& label); - virtual bool SetIcon(const SkBitmap& icon, int item_id); - virtual void RunMenuAt(int x, int y); - virtual void Cancel(); - virtual int ItemCount(); + const string16& label, + const SkBitmap& icon) OVERRIDE; + virtual void AddSeparator(int index) OVERRIDE; + virtual void EnableMenuItemByID(int item_id, bool enabled) OVERRIDE; + virtual void EnableMenuItemAt(int index, bool enabled) OVERRIDE; + virtual void SetMenuLabel(int item_id, const string16& label) OVERRIDE; + virtual bool SetIcon(const SkBitmap& icon, int item_id) OVERRIDE; + virtual void RunMenuAt(int x, int y) OVERRIDE; + virtual void Cancel() OVERRIDE; + virtual int ItemCount() OVERRIDE; virtual HMENU GetMenuHandle() const { return menu_; @@ -74,17 +74,19 @@ class MenuWin : public Menu { protected: virtual void AddMenuItemInternal(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon, - MenuItemType type); + MenuItemType type) OVERRIDE; private: + friend class MenuHostWindow; + // The data of menu items needed to display. struct ItemData; void AddMenuItemInternal(int index, int item_id, - const std::wstring& label, + const string16& label, const SkBitmap& icon, HMENU submenu, MenuItemType type); @@ -109,7 +111,7 @@ class MenuWin : public Menu { // This list is used to store the default labels for the menu items. // We may use contextual labels when RunMenu is called, so we must save // a copy of default ones here. - std::vector<std::wstring> labels_; + std::vector<string16> labels_; // A flag to indicate whether this menu will be drawn by the Menu class. // If it's true, all the menu items will be owner drawn. Otherwise, |