Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 views::Textfield::OnFocus(); | 767 views::Textfield::OnFocus(); |
| 768 // TODO(oshima): Get control key state. | 768 // TODO(oshima): Get control key state. |
| 769 model()->OnSetFocus(false); | 769 model()->OnSetFocus(false); |
| 770 // Don't call controller()->OnSetFocus, this view has already acquired focus. | 770 // Don't call controller()->OnSetFocus, this view has already acquired focus. |
| 771 | 771 |
| 772 // Restore the selection we saved in OnBlur() if it's still valid. | 772 // Restore the selection we saved in OnBlur() if it's still valid. |
| 773 if (saved_selection_for_focus_change_.IsValid()) { | 773 if (saved_selection_for_focus_change_.IsValid()) { |
| 774 SelectRange(saved_selection_for_focus_change_); | 774 SelectRange(saved_selection_for_focus_change_); |
| 775 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); | 775 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); |
| 776 } | 776 } |
| 777 | |
| 778 // Re-focusing, keyword hint is visible. | |
|
Peter Kasting
2017/03/07 04:11:23
Nit: Use the same comment here as you changed to b
| |
| 779 if (model()->is_keyword_hint()) | |
| 780 location_bar_view_->Layout(); | |
| 777 } | 781 } |
| 778 | 782 |
| 779 void OmniboxViewViews::OnBlur() { | 783 void OmniboxViewViews::OnBlur() { |
| 780 // Save the user's existing selection to restore it later. | 784 // Save the user's existing selection to restore it later. |
| 781 saved_selection_for_focus_change_ = GetSelectedRange(); | 785 saved_selection_for_focus_change_ = GetSelectedRange(); |
| 782 | 786 |
| 783 views::Textfield::OnBlur(); | 787 views::Textfield::OnBlur(); |
| 784 model()->OnWillKillFocus(); | 788 model()->OnWillKillFocus(); |
| 785 | 789 |
| 786 // If ZeroSuggest is active, we may have refused to show an update to the | 790 // If ZeroSuggest is active, we may have refused to show an update to the |
| 787 // underlying permanent URL that happened while the popup was open, so | 791 // underlying permanent URL that happened while the popup was open, so |
| 788 // revert to ensure that update is shown now. Otherwise, make sure to call | 792 // revert to ensure that update is shown now. Otherwise, make sure to call |
| 789 // CloseOmniboxPopup() unconditionally, so that if ZeroSuggest is in the midst | 793 // CloseOmniboxPopup() unconditionally, so that if ZeroSuggest is in the midst |
| 790 // of running but hasn't yet opened the popup, it will be halted. | 794 // of running but hasn't yet opened the popup, it will be halted. |
| 791 if (!model()->user_input_in_progress() && model()->popup_model()->IsOpen()) | 795 if (!model()->user_input_in_progress() && model()->popup_model()->IsOpen()) |
| 792 RevertAll(); | 796 RevertAll(); |
| 793 else | 797 else |
| 794 CloseOmniboxPopup(); | 798 CloseOmniboxPopup(); |
| 795 | 799 |
| 796 // Tell the model to reset itself. | 800 // Tell the model to reset itself. |
| 797 model()->OnKillFocus(); | 801 model()->OnKillFocus(); |
| 798 | 802 |
| 799 // Make sure the beginning of the text is visible. | 803 // Make sure the beginning of the text is visible. |
| 800 SelectRange(gfx::Range(0)); | 804 SelectRange(gfx::Range(0)); |
| 801 | 805 |
| 806 // Focus changes can affect the visibility of any keyword hint. | |
| 807 if (model()->is_keyword_hint()) | |
| 808 location_bar_view_->Layout(); | |
| 809 | |
| 802 // The location bar needs to repaint without a focus ring. | 810 // The location bar needs to repaint without a focus ring. |
| 803 location_bar_view_->SchedulePaint(); | 811 location_bar_view_->SchedulePaint(); |
| 804 } | 812 } |
| 805 | 813 |
| 806 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { | 814 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { |
| 807 if (command_id == IDS_APP_PASTE) | 815 if (command_id == IDS_APP_PASTE) |
| 808 return !read_only() && !GetClipboardText().empty(); | 816 return !read_only() && !GetClipboardText().empty(); |
| 809 if (command_id == IDS_PASTE_AND_GO) | 817 if (command_id == IDS_PASTE_AND_GO) |
| 810 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); | 818 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); |
| 811 return Textfield::IsCommandIdEnabled(command_id) || | 819 return Textfield::IsCommandIdEnabled(command_id) || |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1065 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 1073 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
| 1066 | 1074 |
| 1067 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); | 1075 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); |
| 1068 | 1076 |
| 1069 // Minor note: We use IDC_ for command id here while the underlying textfield | 1077 // Minor note: We use IDC_ for command id here while the underlying textfield |
| 1070 // is using IDS_ for all its command ids. This is because views cannot depend | 1078 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1071 // on IDC_ for now. | 1079 // on IDC_ for now. |
| 1072 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1080 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1073 IDS_EDIT_SEARCH_ENGINES); | 1081 IDS_EDIT_SEARCH_ENGINES); |
| 1074 } | 1082 } |
| OLD | NEW |