Chromium Code Reviews| Index: chrome/browser/ui/views/omnibox/omnibox_view_views.cc |
| diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc |
| index 94a93c12ce9687e8fb8519dc54b6f1b606317b60..28193a4bdf2392721a5e06e75e5acfee7570d484 100644 |
| --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc |
| +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc |
| @@ -224,7 +224,8 @@ OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, |
| delete_at_end_pressed_(false), |
| location_bar_view_(location_bar), |
| ime_candidate_window_open_(false), |
| - select_all_on_mouse_release_(false) { |
| + select_all_on_mouse_release_(false), |
| + visible_caret_color_(SK_ColorBLACK) { |
| } |
| OmniboxViewViews::~OmniboxViewViews() { |
| @@ -445,7 +446,7 @@ void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// OmniboxViewViews, AutocopmleteEditView implementation: |
| +// OmniboxViewViews, AutocompleteEditView implementation: |
| void OmniboxViewViews::SaveStateToTab(WebContents* tab) { |
| DCHECK(tab); |
| @@ -485,6 +486,7 @@ void OmniboxViewViews::Update(const WebContents* contents) { |
| contents->GetUserData(&kAutocompleteEditStateKey)); |
| if (state) { |
| model()->RestoreState(state->model_state); |
| + ApplyFocusVisibility(); |
| // Move the marks for the cursor and the other end of the selection to |
| // the previously-saved offsets (but preserve PRIMARY). |
| @@ -574,6 +576,16 @@ void OmniboxViewViews::UpdatePopup() { |
| } |
| void OmniboxViewViews::SetFocus() { |
| + model()->set_is_focus_visible(true); |
| + ApplyFocusVisibility(); |
| + // In views-implementation, the focus is on textfield rather than OmniboxView. |
| + textfield_->RequestFocus(); |
| +} |
| + |
| +void OmniboxViewViews::SetInvisibleFocus() { |
| + DLOG(0) << "SetInvisibleFocus"; |
|
Peter Kasting
2012/12/01 01:48:31
Don't check this in.
Mathieu
2012/12/03 02:29:04
Done.
|
| + model()->set_is_focus_visible(false); |
| + ApplyFocusVisibility(); |
| // In views-implementation, the focus is on textfield rather than OmniboxView. |
| textfield_->RequestFocus(); |
| } |
| @@ -604,6 +616,10 @@ void OmniboxViewViews::OnRevertTemporaryText() { |
| } |
| void OmniboxViewViews::OnBeforePossibleChange() { |
| + // Since this is called when the user directly clicks on the omnibox |
| + // 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
|
| + model()->set_is_focus_visible(true); |
| + ApplyFocusVisibility(); |
| // Record our state. |
| text_before_change_ = GetText(); |
| textfield_->GetSelectedRange(&sel_before_change_); |
| @@ -941,3 +957,13 @@ void OmniboxViewViews::OnPaste() { |
| textfield_->ReplaceSelection(text); |
| } |
| } |
| + |
| +void OmniboxViewViews::ApplyFocusVisibility() { |
| + if (textfield_->cursor_color() != textfield_->background_color()) { |
| + visible_caret_color_ = textfield_->cursor_color(); |
| + } |
| + // Setting the color of the text cursor (caret) to the background color |
| + // effectively hides it. |
| + textfield_->SetCursorColor(model()->is_focus_visible() ? |
| + visible_caret_color_ : textfield_->background_color()); |
| +} |