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

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

Issue 11418144: [Search] Implementation of the invisible focus on Windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@samarthlatest
Patch Set: ws 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 bool popup_window_mode, 217 bool popup_window_mode,
218 LocationBarView* location_bar) 218 LocationBarView* location_bar)
219 : OmniboxView(profile, controller, toolbar_model, command_updater), 219 : OmniboxView(profile, controller, toolbar_model, command_updater),
220 textfield_(NULL), 220 textfield_(NULL),
221 popup_window_mode_(popup_window_mode), 221 popup_window_mode_(popup_window_mode),
222 security_level_(ToolbarModel::NONE), 222 security_level_(ToolbarModel::NONE),
223 ime_composing_before_change_(false), 223 ime_composing_before_change_(false),
224 delete_at_end_pressed_(false), 224 delete_at_end_pressed_(false),
225 location_bar_view_(location_bar), 225 location_bar_view_(location_bar),
226 ime_candidate_window_open_(false), 226 ime_candidate_window_open_(false),
227 select_all_on_mouse_release_(false) { 227 select_all_on_mouse_release_(false),
228 visible_caret_color_(SK_ColorBLACK) {
228 } 229 }
229 230
230 OmniboxViewViews::~OmniboxViewViews() { 231 OmniboxViewViews::~OmniboxViewViews() {
231 #if defined(OS_CHROMEOS) 232 #if defined(OS_CHROMEOS)
232 chromeos::input_method::InputMethodManager::GetInstance()-> 233 chromeos::input_method::InputMethodManager::GetInstance()->
233 RemoveCandidateWindowObserver(this); 234 RemoveCandidateWindowObserver(this);
234 #endif 235 #endif
235 236
236 // Explicitly teardown members which have a reference to us. Just to be safe 237 // Explicitly teardown members which have a reference to us. Just to be safe
237 // we want them to be destroyed before destroying any other internal state. 238 // we want them to be destroyed before destroying any other internal state.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 std::string OmniboxViewViews::GetClassName() const { 439 std::string OmniboxViewViews::GetClassName() const {
439 return kViewClassName; 440 return kViewClassName;
440 } 441 }
441 442
442 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { 443 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) {
443 if (popup_view_->IsOpen()) 444 if (popup_view_->IsOpen())
444 popup_view_->UpdatePopupAppearance(); 445 popup_view_->UpdatePopupAppearance();
445 } 446 }
446 447
447 //////////////////////////////////////////////////////////////////////////////// 448 ////////////////////////////////////////////////////////////////////////////////
448 // OmniboxViewViews, AutocopmleteEditView implementation: 449 // OmniboxViewViews, AutocompleteEditView implementation:
449 450
450 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { 451 void OmniboxViewViews::SaveStateToTab(WebContents* tab) {
451 DCHECK(tab); 452 DCHECK(tab);
452 453
453 // We don't want to keep the IME status, so force quit the current 454 // We don't want to keep the IME status, so force quit the current
454 // session here. It may affect the selection status, so order is 455 // session here. It may affect the selection status, so order is
455 // also important. 456 // also important.
456 if (textfield_->IsIMEComposing()) { 457 if (textfield_->IsIMEComposing()) {
457 textfield_->GetTextInputClient()->ConfirmCompositionText(); 458 textfield_->GetTextInputClient()->ConfirmCompositionText();
458 textfield_->GetInputMethod()->CancelComposition(textfield_); 459 textfield_->GetInputMethod()->CancelComposition(textfield_);
(...skipping 19 matching lines...) Expand all
478 479
479 // TODO(oshima): Copied from gtk implementation which is 480 // TODO(oshima): Copied from gtk implementation which is
480 // slightly different from WIN impl. Find out the correct implementation 481 // slightly different from WIN impl. Find out the correct implementation
481 // for views-implementation. 482 // for views-implementation.
482 if (contents) { 483 if (contents) {
483 RevertAll(); 484 RevertAll();
484 const AutocompleteEditState* state = static_cast<AutocompleteEditState*>( 485 const AutocompleteEditState* state = static_cast<AutocompleteEditState*>(
485 contents->GetUserData(&kAutocompleteEditStateKey)); 486 contents->GetUserData(&kAutocompleteEditStateKey));
486 if (state) { 487 if (state) {
487 model()->RestoreState(state->model_state); 488 model()->RestoreState(state->model_state);
489 ApplyFocusVisibility();
488 490
489 // Move the marks for the cursor and the other end of the selection to 491 // Move the marks for the cursor and the other end of the selection to
490 // the previously-saved offsets (but preserve PRIMARY). 492 // the previously-saved offsets (but preserve PRIMARY).
491 textfield_->SelectSelectionModel(state->view_state.selection_model); 493 textfield_->SelectSelectionModel(state->view_state.selection_model);
492 // We do not carry over the current edit history to another tab. 494 // We do not carry over the current edit history to another tab.
493 // TODO(oshima): consider saving/restoring edit history. 495 // TODO(oshima): consider saving/restoring edit history.
494 textfield_->ClearEditHistory(); 496 textfield_->ClearEditHistory();
495 } 497 }
496 } else if (visibly_changed_permanent_text) { 498 } else if (visibly_changed_permanent_text) {
497 RevertAll(); 499 RevertAll();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // the text, or in the middle of composition. 569 // the text, or in the middle of composition.
568 ui::Range sel; 570 ui::Range sel;
569 textfield_->GetSelectedRange(&sel); 571 textfield_->GetSelectedRange(&sel);
570 bool no_inline_autocomplete = 572 bool no_inline_autocomplete =
571 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); 573 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing();
572 574
573 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); 575 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete);
574 } 576 }
575 577
576 void OmniboxViewViews::SetFocus() { 578 void OmniboxViewViews::SetFocus() {
579 model()->set_is_focus_visible(true);
580 ApplyFocusVisibility();
577 // In views-implementation, the focus is on textfield rather than OmniboxView. 581 // In views-implementation, the focus is on textfield rather than OmniboxView.
578 textfield_->RequestFocus(); 582 textfield_->RequestFocus();
579 } 583 }
584
585 void OmniboxViewViews::SetInvisibleFocus() {
586 DLOG(0) << "SetInvisibleFocus";
Peter Kasting 2012/12/01 01:48:31 Don't check this in.
Mathieu 2012/12/03 02:29:04 Done.
587 model()->set_is_focus_visible(false);
588 ApplyFocusVisibility();
589 // In views-implementation, the focus is on textfield rather than OmniboxView.
590 textfield_->RequestFocus();
591 }
580 592
581 void OmniboxViewViews::OnTemporaryTextMaybeChanged( 593 void OmniboxViewViews::OnTemporaryTextMaybeChanged(
582 const string16& display_text, 594 const string16& display_text,
583 bool save_original_selection) { 595 bool save_original_selection) {
584 if (save_original_selection) 596 if (save_original_selection)
585 textfield_->GetSelectedRange(&saved_temporary_selection_); 597 textfield_->GetSelectedRange(&saved_temporary_selection_);
586 598
587 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); 599 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true);
588 } 600 }
589 601
590 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( 602 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged(
591 const string16& display_text, 603 const string16& display_text,
592 size_t user_text_length) { 604 size_t user_text_length) {
593 if (display_text == GetText()) 605 if (display_text == GetText())
594 return false; 606 return false;
595 ui::Range range(display_text.size(), user_text_length); 607 ui::Range range(display_text.size(), user_text_length);
596 SetTextAndSelectedRange(display_text, range); 608 SetTextAndSelectedRange(display_text, range);
597 TextChanged(); 609 TextChanged();
598 return true; 610 return true;
599 } 611 }
600 612
601 void OmniboxViewViews::OnRevertTemporaryText() { 613 void OmniboxViewViews::OnRevertTemporaryText() {
602 textfield_->SelectRange(saved_temporary_selection_); 614 textfield_->SelectRange(saved_temporary_selection_);
603 TextChanged(); 615 TextChanged();
604 } 616 }
605 617
606 void OmniboxViewViews::OnBeforePossibleChange() { 618 void OmniboxViewViews::OnBeforePossibleChange() {
619 // Since this is called when the user directly clicks on the omnibox
620 // regardless of its focus state, we reset the focus to visible.
Peter Kasting 2012/12/01 01:48:31 This is an odd place to put this comment. Clicks
Mathieu 2012/12/03 02:29:04 The comment wasn't explicit enough, my bad. We als
621 model()->set_is_focus_visible(true);
622 ApplyFocusVisibility();
607 // Record our state. 623 // Record our state.
608 text_before_change_ = GetText(); 624 text_before_change_ = GetText();
609 textfield_->GetSelectedRange(&sel_before_change_); 625 textfield_->GetSelectedRange(&sel_before_change_);
610 ime_composing_before_change_ = textfield_->IsIMEComposing(); 626 ime_composing_before_change_ = textfield_->IsIMEComposing();
611 } 627 }
612 628
613 bool OmniboxViewViews::OnAfterPossibleChange() { 629 bool OmniboxViewViews::OnAfterPossibleChange() {
614 ui::Range new_sel; 630 ui::Range new_sel;
615 textfield_->GetSelectedRange(&new_sel); 631 textfield_->GetSelectedRange(&new_sel);
616 632
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 if (!text.empty()) { 950 if (!text.empty()) {
935 // Record this paste, so we can do different behavior. 951 // Record this paste, so we can do different behavior.
936 model()->on_paste(); 952 model()->on_paste();
937 // Force a Paste operation to trigger the text_changed code in 953 // Force a Paste operation to trigger the text_changed code in
938 // OnAfterPossibleChange(), even if identical contents are pasted into the 954 // OnAfterPossibleChange(), even if identical contents are pasted into the
939 // text box. 955 // text box.
940 text_before_change_.clear(); 956 text_before_change_.clear();
941 textfield_->ReplaceSelection(text); 957 textfield_->ReplaceSelection(text);
942 } 958 }
943 } 959 }
960
961 void OmniboxViewViews::ApplyFocusVisibility() {
962 if (textfield_->cursor_color() != textfield_->background_color()) {
963 visible_caret_color_ = textfield_->cursor_color();
964 }
965 // Setting the color of the text cursor (caret) to the background color
966 // effectively hides it.
967 textfield_->SetCursorColor(model()->is_focus_visible() ?
968 visible_caret_color_ : textfield_->background_color());
969 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698