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

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

Issue 191783002: Reorder View Textfield and Omnibox overrides. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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) 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_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 #if defined(OS_CHROMEOS) 177 #if defined(OS_CHROMEOS)
178 chromeos::input_method::InputMethodManager::Get()-> 178 chromeos::input_method::InputMethodManager::Get()->
179 AddCandidateWindowObserver(this); 179 AddCandidateWindowObserver(this);
180 #endif 180 #endif
181 } 181 }
182 182
183 //////////////////////////////////////////////////////////////////////////////// 183 ////////////////////////////////////////////////////////////////////////////////
184 // OmniboxViewViews, views::Textfield implementation: 184 // OmniboxViewViews, views::Textfield implementation:
185 185
186 void OmniboxViewViews::AboutToRequestFocusFromTabTraversal(bool reverse) {
187 if (chrome::GetOriginChipV2HideTrigger() ==
188 chrome::ORIGIN_CHIP_V2_HIDE_ON_MOUSE_RELEASE) {
189 controller()->GetToolbarModel()->set_origin_chip_enabled(false);
190 controller()->OnChanged();
191 }
192 }
193
194 const char* OmniboxViewViews::GetClassName() const { 186 const char* OmniboxViewViews::GetClassName() const {
195 return kViewClassName; 187 return kViewClassName;
196 } 188 }
197 189
198 void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) {
199 if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) {
200 select_all_on_gesture_tap_ = true;
201
202 // If we're trying to select all on tap, invalidate any saved selection lest
203 // restoring it fights with the "select all" action.
204 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
205 }
206
207 if (select_all_on_gesture_tap_ && event->type() == ui::ET_GESTURE_TAP)
208 SelectAll(false);
209
210 if (event->type() == ui::ET_GESTURE_TAP ||
211 event->type() == ui::ET_GESTURE_TAP_CANCEL ||
212 event->type() == ui::ET_GESTURE_TWO_FINGER_TAP ||
213 event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
214 event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
215 event->type() == ui::ET_GESTURE_LONG_PRESS ||
216 event->type() == ui::ET_GESTURE_LONG_TAP) {
217 select_all_on_gesture_tap_ = false;
218 }
219
220 views::Textfield::OnGestureEvent(event);
221 }
222
223 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) {
224 location_bar_view_->GetAccessibleState(state);
225 state->role = ui::AX_ROLE_TEXT_FIELD;
226 }
227
228 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { 190 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
229 select_all_on_mouse_release_ = 191 select_all_on_mouse_release_ =
230 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 192 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
231 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE)); 193 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE));
232 if (select_all_on_mouse_release_) { 194 if (select_all_on_mouse_release_) {
233 // Restore caret visibility whenever the user clicks in the omnibox in a way 195 // Restore caret visibility whenever the user clicks in the omnibox in a way
234 // that would give it focus. We must handle this case separately here 196 // that would give it focus. We must handle this case separately here
235 // because if the omnibox currently has invisible focus, the mouse event 197 // because if the omnibox currently has invisible focus, the mouse event
236 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus(). 198 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus().
237 model()->SetCaretVisibility(true); 199 model()->SetCaretVisibility(true);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event); 304 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event);
343 } 305 }
344 306
345 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { 307 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) {
346 // The omnibox contents may change while the control key is pressed. 308 // The omnibox contents may change while the control key is pressed.
347 if (event.key_code() == ui::VKEY_CONTROL) 309 if (event.key_code() == ui::VKEY_CONTROL)
348 model()->OnControlKeyChanged(false); 310 model()->OnControlKeyChanged(false);
349 return views::Textfield::OnKeyReleased(event); 311 return views::Textfield::OnKeyReleased(event);
350 } 312 }
351 313
314 void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) {
315 if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) {
316 select_all_on_gesture_tap_ = true;
317
318 // If we're trying to select all on tap, invalidate any saved selection lest
319 // restoring it fights with the "select all" action.
320 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
321 }
322
323 if (select_all_on_gesture_tap_ && event->type() == ui::ET_GESTURE_TAP)
324 SelectAll(false);
325
326 if (event->type() == ui::ET_GESTURE_TAP ||
327 event->type() == ui::ET_GESTURE_TAP_CANCEL ||
328 event->type() == ui::ET_GESTURE_TWO_FINGER_TAP ||
329 event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
330 event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
331 event->type() == ui::ET_GESTURE_LONG_PRESS ||
332 event->type() == ui::ET_GESTURE_LONG_TAP) {
333 select_all_on_gesture_tap_ = false;
334 }
335
336 views::Textfield::OnGestureEvent(event);
337 }
338
339 void OmniboxViewViews::AboutToRequestFocusFromTabTraversal(bool reverse) {
340 if (chrome::GetOriginChipV2HideTrigger() ==
341 chrome::ORIGIN_CHIP_V2_HIDE_ON_MOUSE_RELEASE) {
342 controller()->GetToolbarModel()->set_origin_chip_enabled(false);
343 controller()->OnChanged();
344 }
345 }
346
352 bool OmniboxViewViews::SkipDefaultKeyEventProcessing( 347 bool OmniboxViewViews::SkipDefaultKeyEventProcessing(
353 const ui::KeyEvent& event) { 348 const ui::KeyEvent& event) {
354 if (views::FocusManager::IsTabTraversalKeyEvent(event) && 349 if (views::FocusManager::IsTabTraversalKeyEvent(event) &&
355 ((model()->is_keyword_hint() && !event.IsShiftDown()) || 350 ((model()->is_keyword_hint() && !event.IsShiftDown()) ||
356 model()->popup_model()->IsOpen())) { 351 model()->popup_model()->IsOpen())) {
357 return true; 352 return true;
358 } 353 }
359 return Textfield::SkipDefaultKeyEventProcessing(event); 354 return Textfield::SkipDefaultKeyEventProcessing(event);
360 } 355 }
361 356
357 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) {
358 location_bar_view_->GetAccessibleState(state);
359 state->role = ui::AX_ROLE_TEXT_FIELD;
360 }
361
362 bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) { 362 bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) {
363 // This must run before acclerator handling invokes a focus change on tab. 363 // This must run before acclerator handling invokes a focus change on tab.
364 // Note the parallel with SkipDefaultKeyEventProcessing above. 364 // Note the parallel with SkipDefaultKeyEventProcessing above.
365 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { 365 if (views::FocusManager::IsTabTraversalKeyEvent(event)) {
366 if (model()->is_keyword_hint() && !event.IsShiftDown()) { 366 if (model()->is_keyword_hint() && !event.IsShiftDown()) {
367 model()->AcceptKeyword(ENTERED_KEYWORD_MODE_VIA_TAB); 367 model()->AcceptKeyword(ENTERED_KEYWORD_MODE_VIA_TAB);
368 return true; 368 return true;
369 } 369 }
370 if (model()->popup_model()->IsOpen()) { 370 if (model()->popup_model()->IsOpen()) {
371 if (event.IsShiftDown() && 371 if (event.IsShiftDown() &&
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 const base::string16 text(GetClipboardText()); 1019 const base::string16 text(GetClipboardText());
1020 if (!text.empty()) { 1020 if (!text.empty()) {
1021 // Record this paste, so we can do different behavior. 1021 // Record this paste, so we can do different behavior.
1022 model()->OnPaste(); 1022 model()->OnPaste();
1023 // Force a Paste operation to trigger the text_changed code in 1023 // Force a Paste operation to trigger the text_changed code in
1024 // OnAfterPossibleChange(), even if identical contents are pasted. 1024 // OnAfterPossibleChange(), even if identical contents are pasted.
1025 text_before_change_.clear(); 1025 text_before_change_.clear();
1026 InsertOrReplaceText(text); 1026 InsertOrReplaceText(text);
1027 } 1027 }
1028 } 1028 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | ui/views/controls/textfield/textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698