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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 #endif | 131 #endif |
| 132 | 132 |
| 133 // Explicitly teardown members which have a reference to us. Just to be safe | 133 // Explicitly teardown members which have a reference to us. Just to be safe |
| 134 // we want them to be destroyed before destroying any other internal state. | 134 // we want them to be destroyed before destroying any other internal state. |
| 135 popup_view_.reset(); | 135 popup_view_.reset(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void OmniboxViewViews::Init() { | 138 void OmniboxViewViews::Init() { |
| 139 set_controller(this); | 139 set_controller(this); |
| 140 SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 140 SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
| 141 | 141 |
|
Peter Kasting
2017/04/17 19:03:52
Nit: Blank line here unnecessary
simonhong
2017/04/17 19:51:01
Done.
| |
| 142 GetRenderText()->SetElideBehavior(gfx::ELIDE_TAIL); | |
| 143 | |
| 142 if (popup_window_mode_) | 144 if (popup_window_mode_) |
| 143 SetReadOnly(true); | 145 SetReadOnly(true); |
| 144 | 146 |
| 145 if (location_bar_view_) { | 147 if (location_bar_view_) { |
| 146 // Initialize the popup view using the same font. | 148 // Initialize the popup view using the same font. |
| 147 popup_view_.reset(OmniboxPopupContentsView::Create( | 149 popup_view_.reset(OmniboxPopupContentsView::Create( |
| 148 GetFontList(), this, model(), location_bar_view_)); | 150 GetFontList(), this, model(), location_bar_view_)); |
| 149 } | 151 } |
| 150 | 152 |
| 151 // Override the default FocusableBorder from Textfield, since the | 153 // Override the default FocusableBorder from Textfield, since the |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 } | 744 } |
| 743 InsertOrReplaceText(action_data.value); | 745 InsertOrReplaceText(action_data.value); |
| 744 TextChanged(); | 746 TextChanged(); |
| 745 return true; | 747 return true; |
| 746 } | 748 } |
| 747 | 749 |
| 748 return Textfield::HandleAccessibleAction(action_data); | 750 return Textfield::HandleAccessibleAction(action_data); |
| 749 } | 751 } |
| 750 | 752 |
| 751 void OmniboxViewViews::OnFocus() { | 753 void OmniboxViewViews::OnFocus() { |
| 754 GetRenderText()->SetElideBehavior(gfx::NO_ELIDE); | |
|
Peter Kasting
2017/04/17 19:03:52
Nit: Both here and in OnBlur() I'd attempt to call
simonhong
2017/04/17 19:51:01
Done.
| |
| 755 | |
| 752 views::Textfield::OnFocus(); | 756 views::Textfield::OnFocus(); |
| 753 // TODO(oshima): Get control key state. | 757 // TODO(oshima): Get control key state. |
| 754 model()->OnSetFocus(false); | 758 model()->OnSetFocus(false); |
| 755 // Don't call controller()->OnSetFocus, this view has already acquired focus. | 759 // Don't call controller()->OnSetFocus, this view has already acquired focus. |
| 756 | 760 |
| 757 // Restore the selection we saved in OnBlur() if it's still valid. | 761 // Restore the selection we saved in OnBlur() if it's still valid. |
| 758 if (saved_selection_for_focus_change_.IsValid()) { | 762 if (saved_selection_for_focus_change_.IsValid()) { |
| 759 SelectRange(saved_selection_for_focus_change_); | 763 SelectRange(saved_selection_for_focus_change_); |
| 760 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); | 764 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); |
| 761 } | 765 } |
| 762 | 766 |
| 763 // Focus changes can affect the visibility of any keyword hint. | 767 // Focus changes can affect the visibility of any keyword hint. |
| 764 if (model()->is_keyword_hint()) | 768 if (model()->is_keyword_hint()) |
| 765 location_bar_view_->Layout(); | 769 location_bar_view_->Layout(); |
| 766 } | 770 } |
|
Peter Kasting
2017/04/17 19:03:53
Do we need to schedule a paint here or is changing
simonhong
2017/04/17 19:51:01
It's guaranteed.
When getting text or properties f
| |
| 767 | 771 |
| 768 void OmniboxViewViews::OnBlur() { | 772 void OmniboxViewViews::OnBlur() { |
| 773 GetRenderText()->SetElideBehavior(gfx::ELIDE_TAIL); | |
| 774 | |
| 769 // Save the user's existing selection to restore it later. | 775 // Save the user's existing selection to restore it later. |
| 770 saved_selection_for_focus_change_ = GetSelectedRange(); | 776 saved_selection_for_focus_change_ = GetSelectedRange(); |
| 771 | 777 |
| 772 views::Textfield::OnBlur(); | 778 views::Textfield::OnBlur(); |
| 773 model()->OnWillKillFocus(); | 779 model()->OnWillKillFocus(); |
| 774 | 780 |
| 775 // If ZeroSuggest is active, we may have refused to show an update to the | 781 // If ZeroSuggest is active, we may have refused to show an update to the |
| 776 // underlying permanent URL that happened while the popup was open, so | 782 // underlying permanent URL that happened while the popup was open, so |
| 777 // revert to ensure that update is shown now. Otherwise, make sure to call | 783 // revert to ensure that update is shown now. Otherwise, make sure to call |
| 778 // CloseOmniboxPopup() unconditionally, so that if ZeroSuggest is in the midst | 784 // CloseOmniboxPopup() unconditionally, so that if ZeroSuggest is in the midst |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1058 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 1064 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
| 1059 | 1065 |
| 1060 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); | 1066 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); |
| 1061 | 1067 |
| 1062 // Minor note: We use IDC_ for command id here while the underlying textfield | 1068 // Minor note: We use IDC_ for command id here while the underlying textfield |
| 1063 // is using IDS_ for all its command ids. This is because views cannot depend | 1069 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1064 // on IDC_ for now. | 1070 // on IDC_ for now. |
| 1065 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1071 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1066 IDS_EDIT_SEARCH_ENGINES); | 1072 IDS_EDIT_SEARCH_ENGINES); |
| 1067 } | 1073 } |
| OLD | NEW |