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

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: Fixed comments, mouse handling logic. 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 select_all_on_mouse_release_ =
370 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 370 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
371 !textfield_->HasFocus(); 371 (!textfield_->HasFocus() || !model()->is_caret_visible());
372 // Restore caret visibility whenever the user clicks in the the omnibox. This 372 // Restore caret visibility whenever the user clicks in the omnibox in a way
373 // is not always covered by OnSetFocus() because when clicking while the 373 // that would give it focus. We must handle this case separately here because
374 // omnibox has invisible focus does not trigger a new OnSetFocus() call. 374 // if the omnibox currently has invisible focus, the mouse event won't trigger
375 model()->SetCaretVisibility(true); 375 // either SetFocus() or OmniboxEditModel::OnSetFocus().
376 if (select_all_on_mouse_release_)
377 model()->SetCaretVisibility(true);
376 } 378 }
377 379
378 void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) { 380 void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) {
379 select_all_on_mouse_release_ = false; 381 select_all_on_mouse_release_ = false;
380 } 382 }
381 383
382 void OmniboxViewViews::HandleMouseReleaseEvent(const ui::MouseEvent& event) { 384 void OmniboxViewViews::HandleMouseReleaseEvent(const ui::MouseEvent& event) {
383 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && 385 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
384 select_all_on_mouse_release_) { 386 select_all_on_mouse_release_) {
385 // Select all in the reverse direction so as not to scroll the caret 387 // 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. 574 // the text, or in the middle of composition.
573 ui::Range sel; 575 ui::Range sel;
574 textfield_->GetSelectedRange(&sel); 576 textfield_->GetSelectedRange(&sel);
575 bool no_inline_autocomplete = 577 bool no_inline_autocomplete =
576 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); 578 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing();
577 579
578 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); 580 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete);
579 } 581 }
580 582
581 void OmniboxViewViews::SetFocus() { 583 void OmniboxViewViews::SetFocus() {
582 // Restore caret visibility if focused explicitly. We need to do this here
583 // because if we already have invisible focus, the RequestFocus() call below
584 // will short-circuit, preventing us from reaching
585 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when we
586 // didn't previously have focus.
587 model()->SetCaretVisibility(true);
588 // In views-implementation, the focus is on textfield rather than OmniboxView. 584 // In views-implementation, the focus is on textfield rather than OmniboxView.
589 textfield_->RequestFocus(); 585 textfield_->RequestFocus();
586 // Restore caret visibility if focus is explicitly requested. This is
587 // necessary because if we already have invisible focus, the RequestFocus()
588 // call above will short-circuit, preventing us from reaching
589 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when the
590 // omnibox regains focus after losing focus.
591 model()->SetCaretVisibility(true);
590 } 592 }
591 593
592 void OmniboxViewViews::ApplyCaretVisibility() { 594 void OmniboxViewViews::ApplyCaretVisibility() {
593 if (textfield_->cursor_color() != textfield_->background_color()) 595 if (textfield_->cursor_color() != textfield_->background_color())
594 visible_caret_color_ = textfield_->cursor_color(); 596 visible_caret_color_ = textfield_->cursor_color();
595 // Setting the color of the text cursor (caret) to the background color 597 // Setting the color of the text cursor (caret) to the background color
596 // effectively hides it. 598 // effectively hides it.
597 textfield_->SetCursorColor(model()->is_caret_visible() ? 599 textfield_->SetCursorColor(model()->is_caret_visible() ?
598 visible_caret_color_ : textfield_->background_color()); 600 visible_caret_color_ : textfield_->background_color());
599 } 601 }
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 if (!text.empty()) { 977 if (!text.empty()) {
976 // Record this paste, so we can do different behavior. 978 // Record this paste, so we can do different behavior.
977 model()->on_paste(); 979 model()->on_paste();
978 // Force a Paste operation to trigger the text_changed code in 980 // Force a Paste operation to trigger the text_changed code in
979 // OnAfterPossibleChange(), even if identical contents are pasted into the 981 // OnAfterPossibleChange(), even if identical contents are pasted into the
980 // text box. 982 // text box.
981 text_before_change_.clear(); 983 text_before_change_.clear();
982 textfield_->ReplaceSelection(text); 984 textfield_->ReplaceSelection(text);
983 } 985 }
984 } 986 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698