diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-12 20:44:28 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-12 20:44:28 +0000 |
commit | cdb4266b62202b44eb1fb36877398c2cb5504917 (patch) | |
tree | 60f5de9c0460d67cd7150ba5f2e33499892c38b2 /chrome/browser/autocomplete | |
parent | f148ed7a47e14416efd1cc2666ea331fbcf5aa42 (diff) | |
download | chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.zip chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.tar.gz chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.tar.bz2 |
Remove the Menu object, converting all the remaining callers to use Menu2. I'll rename Menu2->Menu afterwards.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/122027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_win.cc | 111 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_win.h | 22 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider.cc | 6 |
3 files changed, 80 insertions, 59 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 7aac332..0bc4f6c 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -41,6 +41,7 @@ #include "skia/ext/skia_utils_win.h" #include "views/drag_utils.h" #include "views/focus/focus_util_win.h" +#include "views/widget/widget.h" #pragma comment(lib, "oleacc.lib") // Needed for accessibility support. @@ -468,33 +469,6 @@ AutocompleteEditViewWin::AutocompleteEditViewWin( cf.crTextColor = GetSysColor(COLOR_GRAYTEXT); SetDefaultCharFormat(cf); - // Set up context menu. - context_menu_.reset(views::Menu::Create(this, views::Menu::TOPLEFT, m_hWnd)); - if (popup_window_mode_) { - context_menu_->AppendMenuItemWithLabel(IDS_COPY, - l10n_util::GetString(IDS_COPY)); - } else { - context_menu_->AppendMenuItemWithLabel(IDS_UNDO, - l10n_util::GetString(IDS_UNDO)); - context_menu_->AppendSeparator(); - context_menu_->AppendMenuItemWithLabel(IDS_CUT, - l10n_util::GetString(IDS_CUT)); - context_menu_->AppendMenuItemWithLabel(IDS_COPY, - l10n_util::GetString(IDS_COPY)); - context_menu_->AppendMenuItemWithLabel(IDS_PASTE, - l10n_util::GetString(IDS_PASTE)); - // GetContextualLabel() will override this next label with the - // IDS_PASTE_AND_SEARCH label as needed. - context_menu_->AppendMenuItemWithLabel( - IDS_PASTE_AND_GO, l10n_util::GetString(IDS_PASTE_AND_GO)); - context_menu_->AppendSeparator(); - context_menu_->AppendMenuItemWithLabel( - IDS_SELECT_ALL, l10n_util::GetString(IDS_SELECT_ALL)); - context_menu_->AppendSeparator(); - context_menu_->AppendMenuItemWithLabel( - IDS_EDIT_SEARCH_ENGINES, l10n_util::GetString(IDS_EDIT_SEARCH_ENGINES)); - } - // By default RichEdit has a drop target. Revoke it so that we can install our // own. Revoke takes care of deleting the existing one. RevokeDragDrop(m_hWnd); @@ -954,12 +928,16 @@ void AutocompleteEditViewWin::HandleExternalMsg(UINT msg, SendMessage(msg, flags, MAKELPARAM(client_point.x, client_point.y)); } -bool AutocompleteEditViewWin::IsCommandEnabled(int id) const { - switch (id) { +bool AutocompleteEditViewWin::IsCommandIdChecked(int command_id) const { + return false; +} + +bool AutocompleteEditViewWin::IsCommandIdEnabled(int command_id) const { + switch (command_id) { case IDS_UNDO: return !!CanUndo(); - case IDS_CUT: return !!CanCut(); - case IDS_COPY: return !!CanCopy(); - case IDS_PASTE: return !!CanPaste(); + case IDC_CUT: return !!CanCut(); + case IDC_COPY: return !!CanCopy(); + case IDC_PASTE: return !!CanPaste(); case IDS_PASTE_AND_GO: return CanPasteAndGo(GetClipboardText()); case IDS_SELECT_ALL: return !!CanSelectAll(); case IDS_EDIT_SEARCH_ENGINES: @@ -968,21 +946,28 @@ bool AutocompleteEditViewWin::IsCommandEnabled(int id) const { } } -bool AutocompleteEditViewWin::GetContextualLabel(int id, - std::wstring* out) const { - if ((id != IDS_PASTE_AND_GO) || - // No need to change the default IDS_PASTE_AND_GO label unless this is a - // search. - !model_->is_paste_and_search()) - return false; +bool AutocompleteEditViewWin::GetAcceleratorForCommandId( + int command_id, + views::Accelerator* accelerator) { + return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator); +} - out->assign(l10n_util::GetString(IDS_PASTE_AND_SEARCH)); - return true; +bool AutocompleteEditViewWin::IsLabelForCommandIdDynamic(int command_id) const { + // No need to change the default IDS_PASTE_AND_GO label unless this is a + // search. + return command_id == IDS_PASTE_AND_GO; } -void AutocompleteEditViewWin::ExecuteCommand(int id) { +std::wstring AutocompleteEditViewWin::GetLabelForCommandId( + int command_id) const { + DCHECK(command_id == IDS_PASTE_AND_GO); + return l10n_util::GetString(model_->is_paste_and_search() ? + IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); +} + +void AutocompleteEditViewWin::ExecuteCommand(int command_id) { ScopedFreeze freeze(this, GetTextObjectModel()); - if (id == IDS_PASTE_AND_GO) { + if (command_id == IDS_PASTE_AND_GO) { // This case is separate from the switch() below since we don't want to wrap // it in OnBefore/AfterPossibleChange() calls. model_->PasteAndGo(); @@ -990,20 +975,20 @@ void AutocompleteEditViewWin::ExecuteCommand(int id) { } OnBeforePossibleChange(); - switch (id) { + switch (command_id) { case IDS_UNDO: Undo(); break; - case IDS_CUT: + case IDC_CUT: Cut(); break; - case IDS_COPY: + case IDC_COPY: Copy(); break; - case IDS_PASTE: + case IDC_PASTE: Paste(); break; @@ -1173,13 +1158,14 @@ void AutocompleteEditViewWin::OnChar(TCHAR ch, UINT repeat_count, UINT flags) { } void AutocompleteEditViewWin::OnContextMenu(HWND window, const CPoint& point) { + BuildContextMenu(); if (point.x == -1 || point.y == -1) { POINT p; GetCaretPos(&p); MapWindowPoints(HWND_DESKTOP, &p, 1); - context_menu_->RunMenuAt(p.x, p.y); + context_menu_->RunContextMenuAt(gfx::Point(p)); } else { - context_menu_->RunMenuAt(point.x, point.y); + context_menu_->RunContextMenuAt(gfx::Point(point)); } } @@ -2329,3 +2315,30 @@ void AutocompleteEditViewWin::RepaintDropHighlight(int position) { InvalidateRect(&highlight_bounds, false); } } + +void AutocompleteEditViewWin::BuildContextMenu() { + if (context_menu_contents_.get()) + return; + + context_menu_contents_.reset(new views::SimpleMenuModel(this)); + // Set up context menu. + if (popup_window_mode_) { + context_menu_contents_->AddItemWithStringId(IDS_COPY, IDS_COPY); + } else { + context_menu_contents_->AddItemWithStringId(IDS_UNDO, IDS_UNDO); + context_menu_contents_->AddSeparator(); + context_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT); + context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); + context_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE); + // GetContextualLabel() will override this next label with the + // IDS_PASTE_AND_SEARCH label as needed. + context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO, + IDS_PASTE_AND_GO); + context_menu_contents_->AddSeparator(); + context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL); + context_menu_contents_->AddSeparator(); + context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES, + IDS_EDIT_SEARCH_ENGINES); + } + context_menu_.reset(new views::Menu2(context_menu_contents_.get())); +} diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h index 822ebea..0c91820 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h @@ -19,7 +19,7 @@ #include "chrome/browser/toolbar_model.h" #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" #include "chrome/common/page_transition_types.h" -#include "views/controls/menu/menu.h" +#include "views/controls/menu/simple_menu_model.h" #include "webkit/glue/window_open_disposition.h" class AutocompletePopupModel; @@ -44,7 +44,7 @@ class AutocompleteEditViewWin CWinTraits<WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_NOHIDESEL> >, public CRichEditCommands<AutocompleteEditViewWin>, - public views::Menu::Delegate, + public views::SimpleMenuModel::Delegate, public AutocompleteEditView { public: struct State { @@ -179,10 +179,14 @@ class AutocompleteEditViewWin DEFAULT_REFLECTION_HANDLER() // avoids black margin area END_MSG_MAP() - // Menu::Delegate - virtual bool IsCommandEnabled(int id) const; - virtual bool GetContextualLabel(int id, std::wstring* out) const; - virtual void ExecuteCommand(int id); + // SimpleMenuModel::Delegate + virtual bool IsCommandIdChecked(int command_id) const; + virtual bool IsCommandIdEnabled(int command_id) const; + virtual bool GetAcceleratorForCommandId(int command_id, + views::Accelerator* accelerator); + virtual bool IsLabelForCommandIdDynamic(int command_id) const; + virtual std::wstring GetLabelForCommandId(int command_id) const; + virtual void ExecuteCommand(int command_id); private: // This object freezes repainting of the edit until the object is destroyed. @@ -357,6 +361,9 @@ class AutocompleteEditViewWin // text. void RepaintDropHighlight(int position); + // Generates the context menu for the edit field. + void BuildContextMenu(); + scoped_ptr<AutocompleteEditModel> model_; scoped_ptr<AutocompletePopupView> popup_view_; @@ -426,7 +433,8 @@ class AutocompleteEditViewWin CHARRANGE saved_selection_for_focus_change_; // The context menu for the edit. - scoped_ptr<views::Menu> context_menu_; + scoped_ptr<views::SimpleMenuModel> context_menu_contents_; + scoped_ptr<views::Menu2> context_menu_; // Font we're using. We keep a reference to make sure the font supplied to // the constructor doesn't go away before we do. diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index d3d91ca..8a6d305 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -716,15 +716,15 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string, // looks odd if both the first and last s are highlighted. if (input_position != 0) { match.contents_class.push_back( - ACMatchClassification(0, ACMatchClassification::MATCH)); + ACMatchClassification(0, ACMatchClassification::NONE)); } match.contents_class.push_back( - ACMatchClassification(input_position, ACMatchClassification::NONE)); + ACMatchClassification(input_position, ACMatchClassification::DIM)); size_t next_fragment_position = input_position + input_text.length(); if (next_fragment_position < query_string.length()) { match.contents_class.push_back( ACMatchClassification(next_fragment_position, - ACMatchClassification::MATCH)); + ACMatchClassification::NONE)); } } } else { |