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 // This file defines helper functions shared by the various implementations | 5 // This file defines helper functions shared by the various implementations |
6 // of OmniboxView. | 6 // of OmniboxView. |
7 | 7 |
8 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 8 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 OmniboxView::~OmniboxView() { | 87 OmniboxView::~OmniboxView() { |
88 } | 88 } |
89 | 89 |
90 void OmniboxView::HandleOriginChipMouseRelease() { | 90 void OmniboxView::HandleOriginChipMouseRelease() { |
91 // HIDE_ON_MOUSE_RELEASE only hides if there isn't any current text in the | 91 // HIDE_ON_MOUSE_RELEASE only hides if there isn't any current text in the |
92 // Omnibox (e.g. search terms). | 92 // Omnibox (e.g. search terms). |
93 if ((chrome::GetOriginChipV2HideTrigger() == | 93 if ((chrome::GetOriginChipV2HideTrigger() == |
94 chrome::ORIGIN_CHIP_V2_HIDE_ON_MOUSE_RELEASE) && | 94 chrome::ORIGIN_CHIP_V2_HIDE_ON_MOUSE_RELEASE) && |
95 controller()->GetToolbarModel()->GetText().empty()) { | 95 controller()->GetToolbarModel()->GetText().empty()) { |
96 controller()->GetToolbarModel()->set_origin_chip_enabled(false); | 96 controller()->HideOriginChip(); |
97 controller()->OnChanged(); | |
98 } | 97 } |
99 } | 98 } |
100 | 99 |
101 void OmniboxView::OnDidKillFocus() { | 100 void OmniboxView::OnDidKillFocus() { |
102 // If user input is not in progress, re-enable the origin chip and URL | |
103 // replacement. This addresses the case where the URL was shown by a call | |
104 // to ShowURL(). If the Omnibox achieved focus by other means, the calls to | |
105 // set_url_replacement_enabled, UpdatePermanentText and RevertAll are not | |
106 // required (a call to OnChanged would be sufficient) but do no harm. | |
107 if (chrome::ShouldDisplayOriginChipV2() && | 101 if (chrome::ShouldDisplayOriginChipV2() && |
108 !model()->user_input_in_progress()) { | 102 !model()->user_input_in_progress()) { |
109 controller()->GetToolbarModel()->set_origin_chip_enabled(true); | 103 controller()->ShowOriginChip(); |
110 controller()->GetToolbarModel()->set_url_replacement_enabled(true); | |
111 model()->UpdatePermanentText(); | |
112 RevertAll(); | |
113 } | 104 } |
114 } | 105 } |
115 | 106 |
116 void OmniboxView::OpenMatch(const AutocompleteMatch& match, | 107 void OmniboxView::OpenMatch(const AutocompleteMatch& match, |
117 WindowOpenDisposition disposition, | 108 WindowOpenDisposition disposition, |
118 const GURL& alternate_nav_url, | 109 const GURL& alternate_nav_url, |
119 const base::string16& pasted_text, | 110 const base::string16& pasted_text, |
120 size_t selected_line) { | 111 size_t selected_line) { |
121 // Invalid URLs such as chrome://history can end up here. | 112 // Invalid URLs such as chrome://history can end up here. |
122 if (match.destination_url.is_valid() && model_) { | 113 if (match.destination_url.is_valid() && model_) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 162 |
172 void OmniboxView::ShowURL() { | 163 void OmniboxView::ShowURL() { |
173 SetFocus(); | 164 SetFocus(); |
174 controller_->GetToolbarModel()->set_origin_chip_enabled(false); | 165 controller_->GetToolbarModel()->set_origin_chip_enabled(false); |
175 controller_->GetToolbarModel()->set_url_replacement_enabled(false); | 166 controller_->GetToolbarModel()->set_url_replacement_enabled(false); |
176 model_->UpdatePermanentText(); | 167 model_->UpdatePermanentText(); |
177 RevertWithoutResettingSearchTermReplacement(); | 168 RevertWithoutResettingSearchTermReplacement(); |
178 SelectAll(true); | 169 SelectAll(true); |
179 } | 170 } |
180 | 171 |
| 172 void OmniboxView::HideURL() { |
| 173 controller_->GetToolbarModel()->set_origin_chip_enabled(true); |
| 174 controller_->GetToolbarModel()->set_url_replacement_enabled(true); |
| 175 model_->UpdatePermanentText(); |
| 176 RevertWithoutResettingSearchTermReplacement(); |
| 177 } |
| 178 |
181 void OmniboxView::RevertAll() { | 179 void OmniboxView::RevertAll() { |
182 controller_->GetToolbarModel()->set_url_replacement_enabled(true); | 180 controller_->GetToolbarModel()->set_url_replacement_enabled(true); |
183 RevertWithoutResettingSearchTermReplacement(); | 181 RevertWithoutResettingSearchTermReplacement(); |
184 } | 182 } |
185 | 183 |
186 void OmniboxView::RevertWithoutResettingSearchTermReplacement() { | 184 void OmniboxView::RevertWithoutResettingSearchTermReplacement() { |
187 CloseOmniboxPopup(); | 185 CloseOmniboxPopup(); |
188 if (model_.get()) | 186 if (model_.get()) |
189 model_->Revert(); | 187 model_->Revert(); |
190 TextChanged(); | 188 TextChanged(); |
(...skipping 28 matching lines...) Expand all Loading... |
219 // |profile| can be NULL in tests. | 217 // |profile| can be NULL in tests. |
220 if (profile) | 218 if (profile) |
221 model_.reset(new OmniboxEditModel(this, controller, profile)); | 219 model_.reset(new OmniboxEditModel(this, controller, profile)); |
222 } | 220 } |
223 | 221 |
224 void OmniboxView::TextChanged() { | 222 void OmniboxView::TextChanged() { |
225 EmphasizeURLComponents(); | 223 EmphasizeURLComponents(); |
226 if (model_.get()) | 224 if (model_.get()) |
227 model_->OnChanged(); | 225 model_->OnChanged(); |
228 } | 226 } |
OLD | NEW |