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

Side by Side Diff: components/omnibox/browser/omnibox_edit_model.cc

Issue 2242213008: Remove url_replacement logic from Omnibox/ToolbarModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_show_url
Patch Set: Created 4 years, 4 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/omnibox/browser/omnibox_edit_model.h" 5 #include "components/omnibox/browser/omnibox_edit_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 137
138 // OmniboxEditModel::State ---------------------------------------------------- 138 // OmniboxEditModel::State ----------------------------------------------------
139 139
140 OmniboxEditModel::State::State(bool user_input_in_progress, 140 OmniboxEditModel::State::State(bool user_input_in_progress,
141 const base::string16& user_text, 141 const base::string16& user_text,
142 const base::string16& gray_text, 142 const base::string16& gray_text,
143 const base::string16& keyword, 143 const base::string16& keyword,
144 bool is_keyword_hint, 144 bool is_keyword_hint,
145 KeywordModeEntryMethod keyword_mode_entry_method, 145 KeywordModeEntryMethod keyword_mode_entry_method,
146 bool url_replacement_enabled,
147 OmniboxFocusState focus_state, 146 OmniboxFocusState focus_state,
148 FocusSource focus_source, 147 FocusSource focus_source,
149 const AutocompleteInput& autocomplete_input) 148 const AutocompleteInput& autocomplete_input)
150 : user_input_in_progress(user_input_in_progress), 149 : user_input_in_progress(user_input_in_progress),
151 user_text(user_text), 150 user_text(user_text),
152 gray_text(gray_text), 151 gray_text(gray_text),
153 keyword(keyword), 152 keyword(keyword),
154 is_keyword_hint(is_keyword_hint), 153 is_keyword_hint(is_keyword_hint),
155 keyword_mode_entry_method(keyword_mode_entry_method), 154 keyword_mode_entry_method(keyword_mode_entry_method),
156 url_replacement_enabled(url_replacement_enabled),
157 focus_state(focus_state), 155 focus_state(focus_state),
158 focus_source(focus_source), 156 focus_source(focus_source),
159 autocomplete_input(autocomplete_input) { 157 autocomplete_input(autocomplete_input) {
160 } 158 }
161 159
162 OmniboxEditModel::State::State(const State& other) = default; 160 OmniboxEditModel::State::State(const State& other) = default;
163 161
164 OmniboxEditModel::State::~State() { 162 OmniboxEditModel::State::~State() {
165 } 163 }
166 164
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } else { 204 } else {
207 InternalSetUserText(display_text); 205 InternalSetUserText(display_text);
208 } 206 }
209 } 207 }
210 208
211 UMA_HISTOGRAM_BOOLEAN("Omnibox.SaveStateForTabSwitch.UserInputInProgress", 209 UMA_HISTOGRAM_BOOLEAN("Omnibox.SaveStateForTabSwitch.UserInputInProgress",
212 user_input_in_progress_); 210 user_input_in_progress_);
213 return State( 211 return State(
214 user_input_in_progress_, user_text_, view_->GetGrayTextAutocompletion(), 212 user_input_in_progress_, user_text_, view_->GetGrayTextAutocompletion(),
215 keyword_, is_keyword_hint_, keyword_mode_entry_method_, 213 keyword_, is_keyword_hint_, keyword_mode_entry_method_,
216 controller_->GetToolbarModel()->url_replacement_enabled(),
217 focus_state_, focus_source_, input_); 214 focus_state_, focus_source_, input_);
218 } 215 }
219 216
220 void OmniboxEditModel::RestoreState(const State* state) { 217 void OmniboxEditModel::RestoreState(const State* state) {
221 // We need to update the permanent text correctly and revert the view 218 // We need to update the permanent text correctly and revert the view
222 // regardless of whether there is saved state. 219 // regardless of whether there is saved state.
223 bool url_replacement_enabled = !state || state->url_replacement_enabled;
224 controller_->GetToolbarModel()->set_url_replacement_enabled(
225 url_replacement_enabled);
226 permanent_text_ = controller_->GetToolbarModel()->GetFormattedURL(nullptr); 220 permanent_text_ = controller_->GetToolbarModel()->GetFormattedURL(nullptr);
227 // Don't muck with the search term replacement state, as we've just set it 221 view_->RevertAll();
228 // correctly.
229 view_->RevertWithoutResettingSearchTermReplacement();
230 // Restore the autocomplete controller's input, or clear it if this is a new 222 // Restore the autocomplete controller's input, or clear it if this is a new
231 // tab. 223 // tab.
232 input_ = state ? state->autocomplete_input : AutocompleteInput(); 224 input_ = state ? state->autocomplete_input : AutocompleteInput();
233 if (!state) 225 if (!state)
234 return; 226 return;
235 227
236 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); 228 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH);
237 focus_source_ = state->focus_source; 229 focus_source_ = state->focus_source;
238 // Restore any user editing. 230 // Restore any user editing.
239 if (state->user_input_in_progress) { 231 if (state->user_input_in_progress) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // to make any change to the edit. While auto-commits modify the underlying 271 // to make any change to the edit. While auto-commits modify the underlying
280 // permanent URL, they're intended to have no effect on the user's editing 272 // permanent URL, they're intended to have no effect on the user's editing
281 // process -- before and after the auto-commit, the omnibox should show the 273 // process -- before and after the auto-commit, the omnibox should show the
282 // same user text and the same instant suggestion, even if the auto-commit 274 // same user text and the same instant suggestion, even if the auto-commit
283 // happens while the edit doesn't have focus. 275 // happens while the edit doesn't have focus.
284 base::string16 new_permanent_text = 276 base::string16 new_permanent_text =
285 controller_->GetToolbarModel()->GetFormattedURL(nullptr); 277 controller_->GetToolbarModel()->GetFormattedURL(nullptr);
286 base::string16 gray_text = view_->GetGrayTextAutocompletion(); 278 base::string16 gray_text = view_->GetGrayTextAutocompletion();
287 const bool visibly_changed_permanent_text = 279 const bool visibly_changed_permanent_text =
288 (permanent_text_ != new_permanent_text) && 280 (permanent_text_ != new_permanent_text) &&
289 (!has_focus() || 281 (!has_focus() || (!user_input_in_progress_ && !PopupIsOpen())) &&
290 (!user_input_in_progress_ && !PopupIsOpen() && 282 (gray_text.empty() || new_permanent_text != user_text_ + gray_text);
Peter Kasting 2016/08/19 22:40:06 BTW, would you be averse to sticking all the "gray
Marc Treib 2016/08/22 08:45:55 Not averse as such, but as much as I like removing
291 controller_->GetToolbarModel()->url_replacement_enabled())) &&
292 (gray_text.empty() ||
293 new_permanent_text != user_text_ + gray_text);
294 283
295 permanent_text_ = new_permanent_text; 284 permanent_text_ = new_permanent_text;
296 return visibly_changed_permanent_text; 285 return visibly_changed_permanent_text;
297 } 286 }
298 287
299 GURL OmniboxEditModel::PermanentURL() { 288 GURL OmniboxEditModel::PermanentURL() {
300 return url_formatter::FixupURL(base::UTF16ToUTF8(permanent_text_), 289 return url_formatter::FixupURL(base::UTF16ToUTF8(permanent_text_),
301 std::string()); 290 std::string());
302 } 291 }
303 292
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 // Update state and notify view if the omnibox has focus and the caret 1491 // Update state and notify view if the omnibox has focus and the caret
1503 // visibility changed. 1492 // visibility changed.
1504 const bool was_caret_visible = is_caret_visible(); 1493 const bool was_caret_visible = is_caret_visible();
1505 focus_state_ = state; 1494 focus_state_ = state;
1506 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1495 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1507 is_caret_visible() != was_caret_visible) 1496 is_caret_visible() != was_caret_visible)
1508 view_->ApplyCaretVisibility(); 1497 view_->ApplyCaretVisibility();
1509 1498
1510 client_->OnFocusChanged(focus_state_, reason); 1499 client_->OnFocusChanged(focus_state_, reason);
1511 } 1500 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698