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

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

Issue 2373773002: Fix a bug that viewed Omnibox hint when hint loses focus (Closed)
Patch Set: Revise code indentation and add comment Created 4 years, 2 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
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 <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 profile_(profile), 121 profile_(profile),
122 popup_window_mode_(popup_window_mode), 122 popup_window_mode_(popup_window_mode),
123 security_level_(security_state::SecurityStateModel::NONE), 123 security_level_(security_state::SecurityStateModel::NONE),
124 saved_selection_for_focus_change_(gfx::Range::InvalidRange()), 124 saved_selection_for_focus_change_(gfx::Range::InvalidRange()),
125 ime_composing_before_change_(false), 125 ime_composing_before_change_(false),
126 delete_at_end_pressed_(false), 126 delete_at_end_pressed_(false),
127 location_bar_view_(location_bar), 127 location_bar_view_(location_bar),
128 ime_candidate_window_open_(false), 128 ime_candidate_window_open_(false),
129 select_all_on_mouse_release_(false), 129 select_all_on_mouse_release_(false),
130 select_all_on_gesture_tap_(false), 130 select_all_on_gesture_tap_(false),
131 weak_ptr_factory_(this) { 131 weak_ptr_factory_(this){
Peter Kasting 2016/09/30 22:47:26 Do not remove space
132 SetBorder(views::Border::NullBorder()); 132 SetBorder(views::Border::NullBorder());
133 set_id(VIEW_ID_OMNIBOX); 133 set_id(VIEW_ID_OMNIBOX);
134 SetFontList(font_list); 134 SetFontList(font_list);
135 } 135 }
136 136
137 OmniboxViewViews::~OmniboxViewViews() { 137 OmniboxViewViews::~OmniboxViewViews() {
138 #if defined(OS_CHROMEOS) 138 #if defined(OS_CHROMEOS)
139 chromeos::input_method::InputMethodManager::Get()-> 139 chromeos::input_method::InputMethodManager::Get()->
140 RemoveCandidateWindowObserver(this); 140 RemoveCandidateWindowObserver(this);
141 #endif 141 #endif
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 views::Textfield::OnFocus(); 759 views::Textfield::OnFocus();
760 // TODO(oshima): Get control key state. 760 // TODO(oshima): Get control key state.
761 model()->OnSetFocus(false); 761 model()->OnSetFocus(false);
762 // Don't call controller()->OnSetFocus, this view has already acquired focus. 762 // Don't call controller()->OnSetFocus, this view has already acquired focus.
763 763
764 // Restore the selection we saved in OnBlur() if it's still valid. 764 // Restore the selection we saved in OnBlur() if it's still valid.
765 if (saved_selection_for_focus_change_.IsValid()) { 765 if (saved_selection_for_focus_change_.IsValid()) {
766 SelectRange(saved_selection_for_focus_change_); 766 SelectRange(saved_selection_for_focus_change_);
767 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); 767 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
768 } 768 }
769
770 // Re-focusing, hint is visible
771 if (model()->is_keyword_hint())
772 location_bar_view_->Layout();
Peter Kasting 2016/09/30 22:47:26 Why make these calls here and not in the LocationB
769 } 773 }
770 774
771 void OmniboxViewViews::OnBlur() { 775 void OmniboxViewViews::OnBlur() {
772 // Save the user's existing selection to restore it later. 776 // Save the user's existing selection to restore it later.
773 saved_selection_for_focus_change_ = GetSelectedRange(); 777 saved_selection_for_focus_change_ = GetSelectedRange();
774 778
775 views::Textfield::OnBlur(); 779 views::Textfield::OnBlur();
776 model()->OnWillKillFocus(); 780 model()->OnWillKillFocus();
777 781
778 // If ZeroSuggest is active, we may have refused to show an update to the 782 // If ZeroSuggest is active, we may have refused to show an update to the
779 // underlying permanent URL that happened while the popup was open, so 783 // underlying permanent URL that happened while the popup was open, so
780 // revert to ensure that update is shown now. Otherwise, make sure to call 784 // revert to ensure that update is shown now. Otherwise, make sure to call
781 // CloseOmniboxPopup() unconditionally, so that if ZeroSuggest is in the midst 785 // CloseOmniboxPopup() unconditionally, so that if ZeroSuggest is in the midst
782 // of running but hasn't yet opened the popup, it will be halted. 786 // of running but hasn't yet opened the popup, it will be halted.
783 if (!model()->user_input_in_progress() && model()->popup_model()->IsOpen()) 787 if (!model()->user_input_in_progress() && model()->popup_model()->IsOpen())
784 RevertAll(); 788 RevertAll();
785 else 789 else
786 CloseOmniboxPopup(); 790 CloseOmniboxPopup();
787 791
788 // Tell the model to reset itself. 792 // Tell the model to reset itself.
789 model()->OnKillFocus(); 793 model()->OnKillFocus();
790 794
791 // Make sure the beginning of the text is visible. 795 // Make sure the beginning of the text is visible.
792 SelectRange(gfx::Range(0)); 796 SelectRange(gfx::Range(0));
793 797
794 // The location bar needs to repaint without a focus ring. 798 // The location bar needs to repaint without a focus ring.
795 if (ui::MaterialDesignController::IsModeMaterial()) 799 if (ui::MaterialDesignController::IsModeMaterial())
796 location_bar_view_->SchedulePaint(); 800 location_bar_view_->SchedulePaint();
801
802 // Hint is being visible. If losing focus, hint is invisible.
803 if (model()->is_keyword_hint())
804 location_bar_view_->Layout();
797 } 805 }
798 806
799 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { 807 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
800 if (command_id == IDS_APP_PASTE) 808 if (command_id == IDS_APP_PASTE)
801 return !read_only() && !GetClipboardText().empty(); 809 return !read_only() && !GetClipboardText().empty();
802 if (command_id == IDS_PASTE_AND_GO) 810 if (command_id == IDS_PASTE_AND_GO)
803 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); 811 return !read_only() && model()->CanPasteAndGo(GetClipboardText());
804 return Textfield::IsCommandIdEnabled(command_id) || 812 return Textfield::IsCommandIdEnabled(command_id) ||
805 location_bar_view_->command_updater()->IsCommandEnabled(command_id); 813 location_bar_view_->command_updater()->IsCommandEnabled(command_id);
806 } 814 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); 1084 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
1077 1085
1078 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); 1086 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
1079 1087
1080 // Minor note: We use IDC_ for command id here while the underlying textfield 1088 // Minor note: We use IDC_ for command id here while the underlying textfield
1081 // is using IDS_ for all its command ids. This is because views cannot depend 1089 // is using IDS_ for all its command ids. This is because views cannot depend
1082 // on IDC_ for now. 1090 // on IDC_ for now.
1083 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1091 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1084 IDS_EDIT_SEARCH_ENGINES); 1092 IDS_EDIT_SEARCH_ENGINES);
1085 } 1093 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698