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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 if (url.is_valid()) | 82 if (url.is_valid()) |
83 return StripJavascriptSchemas(base::UTF8ToUTF16(url.spec())); | 83 return StripJavascriptSchemas(base::UTF8ToUTF16(url.spec())); |
84 } | 84 } |
85 | 85 |
86 return base::string16(); | 86 return base::string16(); |
87 } | 87 } |
88 | 88 |
89 OmniboxView::~OmniboxView() { | 89 OmniboxView::~OmniboxView() { |
90 } | 90 } |
91 | 91 |
92 void OmniboxView::HandleOriginChipMouseRelease() { | |
93 // Only hide if there isn't any current text in the Omnibox (e.g. search | |
94 // terms). | |
95 if (controller()->GetToolbarModel()->GetText().empty()) | |
96 controller()->HideOriginChip(); | |
97 } | |
98 | |
99 void OmniboxView::OnDidKillFocus() { | |
100 if (chrome::ShouldDisplayOriginChip() && !model()->user_input_in_progress()) | |
101 controller()->ShowOriginChip(); | |
102 } | |
103 | |
104 void OmniboxView::OpenMatch(const AutocompleteMatch& match, | 92 void OmniboxView::OpenMatch(const AutocompleteMatch& match, |
105 WindowOpenDisposition disposition, | 93 WindowOpenDisposition disposition, |
106 const GURL& alternate_nav_url, | 94 const GURL& alternate_nav_url, |
107 const base::string16& pasted_text, | 95 const base::string16& pasted_text, |
108 size_t selected_line) { | 96 size_t selected_line) { |
109 // Invalid URLs such as chrome://history can end up here. | 97 // Invalid URLs such as chrome://history can end up here. |
110 if (!match.destination_url.is_valid() || !model_) | 98 if (!match.destination_url.is_valid() || !model_) |
111 return; | 99 return; |
112 model_->OpenMatch( | 100 model_->OpenMatch( |
113 match, disposition, alternate_nav_url, pasted_text, selected_line); | 101 match, disposition, alternate_nav_url, pasted_text, selected_line); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 const base::string16& display_text, | 148 const base::string16& display_text, |
161 bool update_popup) { | 149 bool update_popup) { |
162 if (model_.get()) | 150 if (model_.get()) |
163 model_->SetUserText(text); | 151 model_->SetUserText(text); |
164 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, | 152 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, |
165 true); | 153 true); |
166 } | 154 } |
167 | 155 |
168 void OmniboxView::ShowURL() { | 156 void OmniboxView::ShowURL() { |
169 SetFocus(); | 157 SetFocus(); |
170 controller_->GetToolbarModel()->set_origin_chip_enabled(false); | |
171 controller_->GetToolbarModel()->set_url_replacement_enabled(false); | 158 controller_->GetToolbarModel()->set_url_replacement_enabled(false); |
172 model_->UpdatePermanentText(); | 159 model_->UpdatePermanentText(); |
173 RevertWithoutResettingSearchTermReplacement(); | 160 RevertWithoutResettingSearchTermReplacement(); |
174 SelectAll(true); | 161 SelectAll(true); |
175 } | 162 } |
176 | 163 |
177 void OmniboxView::HideURL() { | 164 void OmniboxView::HideURL() { |
178 controller_->GetToolbarModel()->set_origin_chip_enabled(true); | |
179 controller_->GetToolbarModel()->set_url_replacement_enabled(true); | 165 controller_->GetToolbarModel()->set_url_replacement_enabled(true); |
180 model_->UpdatePermanentText(); | 166 model_->UpdatePermanentText(); |
181 RevertWithoutResettingSearchTermReplacement(); | 167 RevertWithoutResettingSearchTermReplacement(); |
182 } | 168 } |
183 | 169 |
184 void OmniboxView::RevertAll() { | 170 void OmniboxView::RevertAll() { |
185 controller_->GetToolbarModel()->set_origin_chip_enabled(true); | |
186 controller_->GetToolbarModel()->set_url_replacement_enabled(true); | 171 controller_->GetToolbarModel()->set_url_replacement_enabled(true); |
187 RevertWithoutResettingSearchTermReplacement(); | 172 RevertWithoutResettingSearchTermReplacement(); |
188 } | 173 } |
189 | 174 |
190 void OmniboxView::RevertWithoutResettingSearchTermReplacement() { | 175 void OmniboxView::RevertWithoutResettingSearchTermReplacement() { |
191 CloseOmniboxPopup(); | 176 CloseOmniboxPopup(); |
192 if (model_.get()) | 177 if (model_.get()) |
193 model_->Revert(); | 178 model_->Revert(); |
194 TextChanged(); | 179 TextChanged(); |
195 } | 180 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // |profile| can be NULL in tests. | 212 // |profile| can be NULL in tests. |
228 if (profile) | 213 if (profile) |
229 model_.reset(new OmniboxEditModel(this, controller, profile)); | 214 model_.reset(new OmniboxEditModel(this, controller, profile)); |
230 } | 215 } |
231 | 216 |
232 void OmniboxView::TextChanged() { | 217 void OmniboxView::TextChanged() { |
233 EmphasizeURLComponents(); | 218 EmphasizeURLComponents(); |
234 if (model_.get()) | 219 if (model_.get()) |
235 model_->OnChanged(); | 220 model_->OnChanged(); |
236 } | 221 } |
OLD | NEW |