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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_win.cc

Issue 10704074: "Paste and go" state was being calculated wrong on views (at least). Fix by making this calculatio… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/omnibox/omnibox_view_win.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <locale> 8 #include <locale>
9 #include <string> 9 #include <string>
10 10
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 if ((string_drop_position != -1 || !in_drag) && data.GetString(&text)) { 1019 if ((string_drop_position != -1 || !in_drag) && data.GetString(&text)) {
1020 DCHECK(string_drop_position == -1 || 1020 DCHECK(string_drop_position == -1 ||
1021 ((string_drop_position >= 0) && 1021 ((string_drop_position >= 0) &&
1022 (string_drop_position <= GetTextLength()))); 1022 (string_drop_position <= GetTextLength())));
1023 if (in_drag) { 1023 if (in_drag) {
1024 if (event.source_operations()== ui::DragDropTypes::DRAG_MOVE) 1024 if (event.source_operations()== ui::DragDropTypes::DRAG_MOVE)
1025 MoveSelectedText(string_drop_position); 1025 MoveSelectedText(string_drop_position);
1026 else 1026 else
1027 InsertText(string_drop_position, text); 1027 InsertText(string_drop_position, text);
1028 } else { 1028 } else {
1029 PasteAndGo(CollapseWhitespace(text, true)); 1029 string16 collapsed_text(CollapseWhitespace(text, true));
1030 if (model_->CanPasteAndGo(collapsed_text))
1031 model_->PasteAndGo(collapsed_text);
1030 } 1032 }
1031 return CopyOrLinkDragOperation(event.source_operations()); 1033 return CopyOrLinkDragOperation(event.source_operations());
1032 } 1034 }
1033 } 1035 }
1034 1036
1035 return ui::DragDropTypes::DRAG_NONE; 1037 return ui::DragDropTypes::DRAG_NONE;
1036 } 1038 }
1037 1039
1038 void OmniboxViewWin::PasteAndGo(const string16& text) {
1039 if (CanPasteAndGo(text))
1040 model_->PasteAndGo();
1041 }
1042
1043 bool OmniboxViewWin::SkipDefaultKeyEventProcessing( 1040 bool OmniboxViewWin::SkipDefaultKeyEventProcessing(
1044 const views::KeyEvent& event) { 1041 const views::KeyEvent& event) {
1045 ui::KeyboardCode key = event.key_code(); 1042 ui::KeyboardCode key = event.key_code();
1046 // We don't process ALT + numpad digit as accelerators, they are used for 1043 // We don't process ALT + numpad digit as accelerators, they are used for
1047 // entering special characters. We do translate alt-home. 1044 // entering special characters. We do translate alt-home.
1048 if (event.IsAltDown() && (key != ui::VKEY_HOME) && 1045 if (event.IsAltDown() && (key != ui::VKEY_HOME) &&
1049 views::NativeTextfieldWin::IsNumPadDigit(key, 1046 views::NativeTextfieldWin::IsNumPadDigit(key,
1050 (event.flags() & ui::EF_EXTENDED) != 0)) 1047 (event.flags() & ui::EF_EXTENDED) != 0))
1051 return true; 1048 return true;
1052 1049
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 bool OmniboxViewWin::IsCommandIdChecked(int command_id) const { 1101 bool OmniboxViewWin::IsCommandIdChecked(int command_id) const {
1105 return false; 1102 return false;
1106 } 1103 }
1107 1104
1108 bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { 1105 bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const {
1109 switch (command_id) { 1106 switch (command_id) {
1110 case IDS_UNDO: return !!CanUndo(); 1107 case IDS_UNDO: return !!CanUndo();
1111 case IDC_CUT: return !!CanCut(); 1108 case IDC_CUT: return !!CanCut();
1112 case IDC_COPY: return !!CanCopy(); 1109 case IDC_COPY: return !!CanCopy();
1113 case IDC_PASTE: return !!CanPaste(); 1110 case IDC_PASTE: return !!CanPaste();
1114 case IDS_PASTE_AND_GO: return CanPasteAndGo(GetClipboardText()); 1111 case IDS_PASTE_AND_GO: return model_->CanPasteAndGo(GetClipboardText());
1115 case IDS_SELECT_ALL: return !!CanSelectAll(); 1112 case IDS_SELECT_ALL: return !!CanSelectAll();
1116 case IDS_EDIT_SEARCH_ENGINES: 1113 case IDS_EDIT_SEARCH_ENGINES:
1117 return command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); 1114 return command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES);
1118 default: 1115 default:
1119 NOTREACHED(); 1116 NOTREACHED();
1120 return false; 1117 return false;
1121 } 1118 }
1122 } 1119 }
1123 1120
1124 bool OmniboxViewWin::GetAcceleratorForCommandId( 1121 bool OmniboxViewWin::GetAcceleratorForCommandId(
1125 int command_id, 1122 int command_id,
1126 ui::Accelerator* accelerator) { 1123 ui::Accelerator* accelerator) {
1127 return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator); 1124 return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator);
1128 } 1125 }
1129 1126
1130 bool OmniboxViewWin::IsItemForCommandIdDynamic(int command_id) const { 1127 bool OmniboxViewWin::IsItemForCommandIdDynamic(int command_id) const {
1131 // No need to change the default IDS_PASTE_AND_GO label unless this is a 1128 // No need to change the default IDS_PASTE_AND_GO label unless this is a
1132 // search. 1129 // search.
1133 return command_id == IDS_PASTE_AND_GO; 1130 return command_id == IDS_PASTE_AND_GO;
1134 } 1131 }
1135 1132
1136 string16 OmniboxViewWin::GetLabelForCommandId(int command_id) const { 1133 string16 OmniboxViewWin::GetLabelForCommandId(int command_id) const {
1137 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); 1134 DCHECK_EQ(IDS_PASTE_AND_GO, command_id);
1138 return l10n_util::GetStringUTF16(model_->is_paste_and_search() ? 1135 return l10n_util::GetStringUTF16(
1136 model_->IsPasteAndSearch(GetClipboardText()) ?
1139 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); 1137 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO);
1140 } 1138 }
1141 1139
1142 void OmniboxViewWin::ExecuteCommand(int command_id) { 1140 void OmniboxViewWin::ExecuteCommand(int command_id) {
1143 ScopedFreeze freeze(this, GetTextObjectModel()); 1141 ScopedFreeze freeze(this, GetTextObjectModel());
1144 if (command_id == IDS_PASTE_AND_GO) { 1142 if (command_id == IDS_PASTE_AND_GO) {
1145 // This case is separate from the switch() below since we don't want to wrap 1143 // This case is separate from the switch() below since we don't want to wrap
1146 // it in OnBefore/AfterPossibleChange() calls. 1144 // it in OnBefore/AfterPossibleChange() calls.
1147 model_->PasteAndGo(); 1145 model_->PasteAndGo(GetClipboardText());
1148 return; 1146 return;
1149 } 1147 }
1150 1148
1151 OnBeforePossibleChange(); 1149 OnBeforePossibleChange();
1152 switch (command_id) { 1150 switch (command_id) {
1153 case IDS_UNDO: 1151 case IDS_UNDO:
1154 Undo(); 1152 Undo();
1155 break; 1153 break;
1156 1154
1157 case IDC_CUT: 1155 case IDC_CUT:
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 LineTo(hdc, clip_rect.left, clip_rect.bottom); 2453 LineTo(hdc, clip_rect.left, clip_rect.bottom);
2456 DeleteObject(SelectObject(hdc, last_pen)); 2454 DeleteObject(SelectObject(hdc, last_pen));
2457 } 2455 }
2458 2456
2459 void OmniboxViewWin::TextChanged() { 2457 void OmniboxViewWin::TextChanged() {
2460 ScopedFreeze freeze(this, GetTextObjectModel()); 2458 ScopedFreeze freeze(this, GetTextObjectModel());
2461 EmphasizeURLComponents(); 2459 EmphasizeURLComponents();
2462 model_->OnChanged(); 2460 model_->OnChanged();
2463 } 2461 }
2464 2462
2465 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const {
2466 return !popup_window_mode_ && model_->CanPasteAndGo(text);
2467 }
2468
2469 ITextDocument* OmniboxViewWin::GetTextObjectModel() const { 2463 ITextDocument* OmniboxViewWin::GetTextObjectModel() const {
2470 if (!text_object_model_) { 2464 if (!text_object_model_) {
2471 // This is lazily initialized, instead of being initialized in the 2465 // This is lazily initialized, instead of being initialized in the
2472 // constructor, in order to avoid hurting startup performance. 2466 // constructor, in order to avoid hurting startup performance.
2473 base::win::ScopedComPtr<IRichEditOle, NULL> ole_interface; 2467 base::win::ScopedComPtr<IRichEditOle, NULL> ole_interface;
2474 ole_interface.Attach(GetOleInterface()); 2468 ole_interface.Attach(GetOleInterface());
2475 if (ole_interface) { 2469 if (ole_interface) {
2476 ole_interface.QueryInterface( 2470 ole_interface.QueryInterface(
2477 __uuidof(ITextDocument), 2471 __uuidof(ITextDocument),
2478 reinterpret_cast<void**>(&text_object_model_)); 2472 reinterpret_cast<void**>(&text_object_model_));
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2671 // PosFromChar(i) might return 0 when i is greater than 1. 2665 // PosFromChar(i) might return 0 when i is greater than 1.
2672 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2666 return font_.GetStringWidth(text) + GetHorizontalMargin();
2673 } 2667 }
2674 2668
2675 bool OmniboxViewWin::IsCaretAtEnd() const { 2669 bool OmniboxViewWin::IsCaretAtEnd() const {
2676 long length = GetTextLength(); 2670 long length = GetTextLength();
2677 CHARRANGE sel; 2671 CHARRANGE sel;
2678 GetSelection(sel); 2672 GetSelection(sel);
2679 return sel.cpMin == sel.cpMax && sel.cpMin == length; 2673 return sel.cpMin == sel.cpMax && sel.cpMin == length;
2680 } 2674 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698