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

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

Issue 11413217: Instant API: tell page whether the browser is capturing key strokes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@focus
Patch Set: Rebase and refactor. Created 8 years 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
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/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 if (event.key_code() == ui::VKEY_CONTROL) { 359 if (event.key_code() == ui::VKEY_CONTROL) {
360 // TODO(oshima): investigate if we need to support keyboard with two 360 // TODO(oshima): investigate if we need to support keyboard with two
361 // controls. 361 // controls.
362 model()->OnControlKeyChanged(false); 362 model()->OnControlKeyChanged(false);
363 return true; 363 return true;
364 } 364 }
365 return false; 365 return false;
366 } 366 }
367 367
368 void OmniboxViewViews::HandleMousePressEvent(const ui::MouseEvent& event) { 368 void OmniboxViewViews::HandleMousePressEvent(const ui::MouseEvent& event) {
369 select_all_on_mouse_release_ = 369 const bool is_left_or_right_click =
370 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 370 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton());
371 select_all_on_mouse_release_ = is_left_or_right_click &&
371 !textfield_->HasFocus(); 372 !textfield_->HasFocus();
372 // Restore caret visibility whenever the user clicks in the the omnibox. This 373 // Restore caret visibility whenever the user left or right clicks in the the
373 // is not always covered by OnSetFocus() because when clicking while the 374 // omnibox. This is not always covered by OnSetFocus() because when clicking
374 // omnibox has invisible focus does not trigger a new OnSetFocus() call. 375 // while the omnibox has invisible focus does not trigger a new OnSetFocus()
375 model()->SetCaretVisibility(true); 376 // call.
377 if (is_left_or_right_click &&
378 (!textfield_->HasFocus() || !model()->is_caret_visible()))
Peter Kasting 2012/12/06 06:02:30 This isn't right... select_all_on_mouse_release_ s
samarth 2012/12/06 16:15:50 Ah ok, makes sense. Done.
379 model()->SetCaretVisibility(true);
376 } 380 }
377 381
378 void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) { 382 void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) {
379 select_all_on_mouse_release_ = false; 383 select_all_on_mouse_release_ = false;
380 } 384 }
381 385
382 void OmniboxViewViews::HandleMouseReleaseEvent(const ui::MouseEvent& event) { 386 void OmniboxViewViews::HandleMouseReleaseEvent(const ui::MouseEvent& event) {
383 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 387 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
384 select_all_on_mouse_release_) { 388 select_all_on_mouse_release_) {
385 // Select all in the reverse direction so as not to scroll the caret 389 // Select all in the reverse direction so as not to scroll the caret
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 // the text, or in the middle of composition. 576 // the text, or in the middle of composition.
573 ui::Range sel; 577 ui::Range sel;
574 textfield_->GetSelectedRange(&sel); 578 textfield_->GetSelectedRange(&sel);
575 bool no_inline_autocomplete = 579 bool no_inline_autocomplete =
576 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); 580 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing();
577 581
578 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); 582 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete);
579 } 583 }
580 584
581 void OmniboxViewViews::SetFocus() { 585 void OmniboxViewViews::SetFocus() {
586 // In views-implementation, the focus is on textfield rather than OmniboxView.
587 textfield_->RequestFocus();
582 // Restore caret visibility if focused explicitly. We need to do this here 588 // Restore caret visibility if focused explicitly. We need to do this here
583 // because if we already have invisible focus, the RequestFocus() call below 589 // because if we already have invisible focus, the RequestFocus() call below
584 // will short-circuit, preventing us from reaching 590 // will short-circuit, preventing us from reaching
585 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when we 591 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when we
586 // didn't previously have focus. 592 // didn't previously have focus.
587 model()->SetCaretVisibility(true); 593 model()->SetCaretVisibility(true);
588 // In views-implementation, the focus is on textfield rather than OmniboxView.
589 textfield_->RequestFocus();
590 } 594 }
591 595
592 void OmniboxViewViews::ApplyCaretVisibility() { 596 void OmniboxViewViews::ApplyCaretVisibility() {
593 if (textfield_->cursor_color() != textfield_->background_color()) 597 if (textfield_->cursor_color() != textfield_->background_color())
594 visible_caret_color_ = textfield_->cursor_color(); 598 visible_caret_color_ = textfield_->cursor_color();
595 // Setting the color of the text cursor (caret) to the background color 599 // Setting the color of the text cursor (caret) to the background color
596 // effectively hides it. 600 // effectively hides it.
597 textfield_->SetCursorColor(model()->is_caret_visible() ? 601 textfield_->SetCursorColor(model()->is_caret_visible() ?
598 visible_caret_color_ : textfield_->background_color()); 602 visible_caret_color_ : textfield_->background_color());
599 } 603 }
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 if (!text.empty()) { 979 if (!text.empty()) {
976 // Record this paste, so we can do different behavior. 980 // Record this paste, so we can do different behavior.
977 model()->on_paste(); 981 model()->on_paste();
978 // Force a Paste operation to trigger the text_changed code in 982 // Force a Paste operation to trigger the text_changed code in
979 // OnAfterPossibleChange(), even if identical contents are pasted into the 983 // OnAfterPossibleChange(), even if identical contents are pasted into the
980 // text box. 984 // text box.
981 text_before_change_.clear(); 985 text_before_change_.clear();
982 textfield_->ReplaceSelection(text); 986 textfield_->ReplaceSelection(text);
983 } 987 }
984 } 988 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698