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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_win.cc

Issue 122027: Remove the Menu object, converting all the remaining callers to use Menu2. I'... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h"
6 6
7 #include <locale> 7 #include <locale>
8 8
9 #include "app/gfx/canvas.h" 9 #include "app/gfx/canvas.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 23 matching lines...) Expand all
34 #include "chrome/browser/search_engines/template_url_model.h" 34 #include "chrome/browser/search_engines/template_url_model.h"
35 #include "chrome/browser/tab_contents/tab_contents.h" 35 #include "chrome/browser/tab_contents/tab_contents.h"
36 #include "chrome/browser/views/location_bar_view.h" 36 #include "chrome/browser/views/location_bar_view.h"
37 #include "chrome/common/gfx/utils.h" 37 #include "chrome/common/gfx/utils.h"
38 #include "chrome/common/notification_service.h" 38 #include "chrome/common/notification_service.h"
39 #include "googleurl/src/url_util.h" 39 #include "googleurl/src/url_util.h"
40 #include "grit/generated_resources.h" 40 #include "grit/generated_resources.h"
41 #include "skia/ext/skia_utils_win.h" 41 #include "skia/ext/skia_utils_win.h"
42 #include "views/drag_utils.h" 42 #include "views/drag_utils.h"
43 #include "views/focus/focus_util_win.h" 43 #include "views/focus/focus_util_win.h"
44 #include "views/widget/widget.h"
44 45
45 #pragma comment(lib, "oleacc.lib") // Needed for accessibility support. 46 #pragma comment(lib, "oleacc.lib") // Needed for accessibility support.
46 47
47 /////////////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////////////
48 // AutocompleteEditModel 49 // AutocompleteEditModel
49 50
50 // A single AutocompleteController used solely for making synchronous calls to 51 // A single AutocompleteController used solely for making synchronous calls to
51 // determine how to deal with the clipboard contents for Paste And Go 52 // determine how to deal with the clipboard contents for Paste And Go
52 // functionality. We avoid using the popup's controller here because we don't 53 // functionality. We avoid using the popup's controller here because we don't
53 // want to interrupt in-progress queries or modify the popup state just 54 // want to interrupt in-progress queries or modify the popup state just
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 ::ReleaseDC(NULL, dc); 462 ::ReleaseDC(NULL, dc);
462 463
463 // Set the default character style -- adjust to our desired baseline and make 464 // Set the default character style -- adjust to our desired baseline and make
464 // text grey. 465 // text grey.
465 CHARFORMAT cf = {0}; 466 CHARFORMAT cf = {0};
466 cf.dwMask = CFM_OFFSET | CFM_COLOR; 467 cf.dwMask = CFM_OFFSET | CFM_COLOR;
467 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; 468 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel;
468 cf.crTextColor = GetSysColor(COLOR_GRAYTEXT); 469 cf.crTextColor = GetSysColor(COLOR_GRAYTEXT);
469 SetDefaultCharFormat(cf); 470 SetDefaultCharFormat(cf);
470 471
471 // Set up context menu.
472 context_menu_.reset(views::Menu::Create(this, views::Menu::TOPLEFT, m_hWnd));
473 if (popup_window_mode_) {
474 context_menu_->AppendMenuItemWithLabel(IDS_COPY,
475 l10n_util::GetString(IDS_COPY));
476 } else {
477 context_menu_->AppendMenuItemWithLabel(IDS_UNDO,
478 l10n_util::GetString(IDS_UNDO));
479 context_menu_->AppendSeparator();
480 context_menu_->AppendMenuItemWithLabel(IDS_CUT,
481 l10n_util::GetString(IDS_CUT));
482 context_menu_->AppendMenuItemWithLabel(IDS_COPY,
483 l10n_util::GetString(IDS_COPY));
484 context_menu_->AppendMenuItemWithLabel(IDS_PASTE,
485 l10n_util::GetString(IDS_PASTE));
486 // GetContextualLabel() will override this next label with the
487 // IDS_PASTE_AND_SEARCH label as needed.
488 context_menu_->AppendMenuItemWithLabel(
489 IDS_PASTE_AND_GO, l10n_util::GetString(IDS_PASTE_AND_GO));
490 context_menu_->AppendSeparator();
491 context_menu_->AppendMenuItemWithLabel(
492 IDS_SELECT_ALL, l10n_util::GetString(IDS_SELECT_ALL));
493 context_menu_->AppendSeparator();
494 context_menu_->AppendMenuItemWithLabel(
495 IDS_EDIT_SEARCH_ENGINES, l10n_util::GetString(IDS_EDIT_SEARCH_ENGINES));
496 }
497
498 // By default RichEdit has a drop target. Revoke it so that we can install our 472 // By default RichEdit has a drop target. Revoke it so that we can install our
499 // own. Revoke takes care of deleting the existing one. 473 // own. Revoke takes care of deleting the existing one.
500 RevokeDragDrop(m_hWnd); 474 RevokeDragDrop(m_hWnd);
501 475
502 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when 476 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when
503 // done so that we don't have to explicitly. 477 // done so that we don't have to explicitly.
504 if (!popup_window_mode_) { 478 if (!popup_window_mode_) {
505 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this); 479 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this);
506 RegisterDragDrop(m_hWnd, drop_target.get()); 480 RegisterDragDrop(m_hWnd, drop_target.get());
507 } 481 }
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 if (msg == WM_CAPTURECHANGED) { 921 if (msg == WM_CAPTURECHANGED) {
948 SendMessage(msg, 0, NULL); 922 SendMessage(msg, 0, NULL);
949 return; 923 return;
950 } 924 }
951 925
952 CPoint client_point(screen_point); 926 CPoint client_point(screen_point);
953 ::MapWindowPoints(NULL, m_hWnd, &client_point, 1); 927 ::MapWindowPoints(NULL, m_hWnd, &client_point, 1);
954 SendMessage(msg, flags, MAKELPARAM(client_point.x, client_point.y)); 928 SendMessage(msg, flags, MAKELPARAM(client_point.x, client_point.y));
955 } 929 }
956 930
957 bool AutocompleteEditViewWin::IsCommandEnabled(int id) const { 931 bool AutocompleteEditViewWin::IsCommandIdChecked(int command_id) const {
958 switch (id) { 932 return false;
933 }
934
935 bool AutocompleteEditViewWin::IsCommandIdEnabled(int command_id) const {
936 switch (command_id) {
959 case IDS_UNDO: return !!CanUndo(); 937 case IDS_UNDO: return !!CanUndo();
960 case IDS_CUT: return !!CanCut(); 938 case IDC_CUT: return !!CanCut();
961 case IDS_COPY: return !!CanCopy(); 939 case IDC_COPY: return !!CanCopy();
962 case IDS_PASTE: return !!CanPaste(); 940 case IDC_PASTE: return !!CanPaste();
963 case IDS_PASTE_AND_GO: return CanPasteAndGo(GetClipboardText()); 941 case IDS_PASTE_AND_GO: return CanPasteAndGo(GetClipboardText());
964 case IDS_SELECT_ALL: return !!CanSelectAll(); 942 case IDS_SELECT_ALL: return !!CanSelectAll();
965 case IDS_EDIT_SEARCH_ENGINES: 943 case IDS_EDIT_SEARCH_ENGINES:
966 return command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); 944 return command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES);
967 default: NOTREACHED(); return false; 945 default: NOTREACHED(); return false;
968 } 946 }
969 } 947 }
970 948
971 bool AutocompleteEditViewWin::GetContextualLabel(int id, 949 bool AutocompleteEditViewWin::GetAcceleratorForCommandId(
972 std::wstring* out) const { 950 int command_id,
973 if ((id != IDS_PASTE_AND_GO) || 951 views::Accelerator* accelerator) {
974 // No need to change the default IDS_PASTE_AND_GO label unless this is a 952 return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator);
975 // search.
976 !model_->is_paste_and_search())
977 return false;
978
979 out->assign(l10n_util::GetString(IDS_PASTE_AND_SEARCH));
980 return true;
981 } 953 }
982 954
983 void AutocompleteEditViewWin::ExecuteCommand(int id) { 955 bool AutocompleteEditViewWin::IsLabelForCommandIdDynamic(int command_id) const {
956 // No need to change the default IDS_PASTE_AND_GO label unless this is a
957 // search.
958 return command_id == IDS_PASTE_AND_GO;
959 }
960
961 std::wstring AutocompleteEditViewWin::GetLabelForCommandId(
962 int command_id) const {
963 DCHECK(command_id == IDS_PASTE_AND_GO);
964 return l10n_util::GetString(model_->is_paste_and_search() ?
965 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO);
966 }
967
968 void AutocompleteEditViewWin::ExecuteCommand(int command_id) {
984 ScopedFreeze freeze(this, GetTextObjectModel()); 969 ScopedFreeze freeze(this, GetTextObjectModel());
985 if (id == IDS_PASTE_AND_GO) { 970 if (command_id == IDS_PASTE_AND_GO) {
986 // This case is separate from the switch() below since we don't want to wrap 971 // This case is separate from the switch() below since we don't want to wrap
987 // it in OnBefore/AfterPossibleChange() calls. 972 // it in OnBefore/AfterPossibleChange() calls.
988 model_->PasteAndGo(); 973 model_->PasteAndGo();
989 return; 974 return;
990 } 975 }
991 976
992 OnBeforePossibleChange(); 977 OnBeforePossibleChange();
993 switch (id) { 978 switch (command_id) {
994 case IDS_UNDO: 979 case IDS_UNDO:
995 Undo(); 980 Undo();
996 break; 981 break;
997 982
998 case IDS_CUT: 983 case IDC_CUT:
999 Cut(); 984 Cut();
1000 break; 985 break;
1001 986
1002 case IDS_COPY: 987 case IDC_COPY:
1003 Copy(); 988 Copy();
1004 break; 989 break;
1005 990
1006 case IDS_PASTE: 991 case IDC_PASTE:
1007 Paste(); 992 Paste();
1008 break; 993 break;
1009 994
1010 case IDS_SELECT_ALL: 995 case IDS_SELECT_ALL:
1011 SelectAll(false); 996 SelectAll(false);
1012 break; 997 break;
1013 998
1014 case IDS_EDIT_SEARCH_ENGINES: 999 case IDS_EDIT_SEARCH_ENGINES:
1015 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); 1000 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES);
1016 break; 1001 break;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 1151
1167 if (ch == VK_TAB) { 1152 if (ch == VK_TAB) {
1168 // Don't add tabs to the input. 1153 // Don't add tabs to the input.
1169 return; 1154 return;
1170 } 1155 }
1171 1156
1172 HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags); 1157 HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags);
1173 } 1158 }
1174 1159
1175 void AutocompleteEditViewWin::OnContextMenu(HWND window, const CPoint& point) { 1160 void AutocompleteEditViewWin::OnContextMenu(HWND window, const CPoint& point) {
1161 BuildContextMenu();
1176 if (point.x == -1 || point.y == -1) { 1162 if (point.x == -1 || point.y == -1) {
1177 POINT p; 1163 POINT p;
1178 GetCaretPos(&p); 1164 GetCaretPos(&p);
1179 MapWindowPoints(HWND_DESKTOP, &p, 1); 1165 MapWindowPoints(HWND_DESKTOP, &p, 1);
1180 context_menu_->RunMenuAt(p.x, p.y); 1166 context_menu_->RunContextMenuAt(gfx::Point(p));
1181 } else { 1167 } else {
1182 context_menu_->RunMenuAt(point.x, point.y); 1168 context_menu_->RunContextMenuAt(gfx::Point(point));
1183 } 1169 }
1184 } 1170 }
1185 1171
1186 void AutocompleteEditViewWin::OnCopy() { 1172 void AutocompleteEditViewWin::OnCopy() {
1187 const std::wstring text(GetSelectedText()); 1173 const std::wstring text(GetSelectedText());
1188 if (text.empty()) 1174 if (text.empty())
1189 return; 1175 return;
1190 1176
1191 ScopedClipboardWriter scw(g_browser_process->clipboard()); 1177 ScopedClipboardWriter scw(g_browser_process->clipboard());
1192 scw.WriteText(text); 1178 scw.WriteText(text);
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 } 2308 }
2323 2309
2324 void AutocompleteEditViewWin::RepaintDropHighlight(int position) { 2310 void AutocompleteEditViewWin::RepaintDropHighlight(int position) {
2325 if ((position != -1) && (position <= GetTextLength())) { 2311 if ((position != -1) && (position <= GetTextLength())) {
2326 const POINT min_loc(PosFromChar(position)); 2312 const POINT min_loc(PosFromChar(position));
2327 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, 2313 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_,
2328 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_}; 2314 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_};
2329 InvalidateRect(&highlight_bounds, false); 2315 InvalidateRect(&highlight_bounds, false);
2330 } 2316 }
2331 } 2317 }
2318
2319 void AutocompleteEditViewWin::BuildContextMenu() {
2320 if (context_menu_contents_.get())
2321 return;
2322
2323 context_menu_contents_.reset(new views::SimpleMenuModel(this));
2324 // Set up context menu.
2325 if (popup_window_mode_) {
2326 context_menu_contents_->AddItemWithStringId(IDS_COPY, IDS_COPY);
2327 } else {
2328 context_menu_contents_->AddItemWithStringId(IDS_UNDO, IDS_UNDO);
2329 context_menu_contents_->AddSeparator();
2330 context_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT);
2331 context_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY);
2332 context_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE);
2333 // GetContextualLabel() will override this next label with the
2334 // IDS_PASTE_AND_SEARCH label as needed.
2335 context_menu_contents_->AddItemWithStringId(IDS_PASTE_AND_GO,
2336 IDS_PASTE_AND_GO);
2337 context_menu_contents_->AddSeparator();
2338 context_menu_contents_->AddItemWithStringId(IDS_SELECT_ALL, IDS_SELECT_ALL);
2339 context_menu_contents_->AddSeparator();
2340 context_menu_contents_->AddItemWithStringId(IDS_EDIT_SEARCH_ENGINES,
2341 IDS_EDIT_SEARCH_ENGINES);
2342 }
2343 context_menu_.reset(new views::Menu2(context_menu_contents_.get()));
2344 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_win.h ('k') | chrome/browser/autocomplete/search_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698