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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 23804002: Make OmniboxEditModel::UpdatePermanentText() fetch the new text itself rather (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 "chrome/browser/ui/omnibox/omnibox_edit_model.h" 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 if (!match.destination_url.is_valid()) { 245 if (!match.destination_url.is_valid()) {
246 GetInfoForCurrentText(&match, alternate_nav_url); 246 GetInfoForCurrentText(&match, alternate_nav_url);
247 } else if (alternate_nav_url) { 247 } else if (alternate_nav_url) {
248 *alternate_nav_url = AutocompleteResult::ComputeAlternateNavUrl( 248 *alternate_nav_url = AutocompleteResult::ComputeAlternateNavUrl(
249 autocomplete_controller()->input(), match); 249 autocomplete_controller()->input(), match);
250 } 250 }
251 return match; 251 return match;
252 } 252 }
253 253
254 bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) { 254 bool OmniboxEditModel::UpdatePermanentText() {
255 // When there's a new URL, and the user is not editing anything or the edit 255 // When there's a new URL, and the user is not editing anything or the edit
256 // doesn't have focus, we want to revert the edit to show the new URL. (The 256 // doesn't have focus, we want to revert the edit to show the new URL. (The
257 // common case where the edit doesn't have focus is when the user has started 257 // common case where the edit doesn't have focus is when the user has started
258 // an edit and then abandoned it and clicked a link on the page.) 258 // an edit and then abandoned it and clicked a link on the page.)
259 // 259 //
260 // If the page is auto-committing gray text, however, we generally don't want 260 // If the page is auto-committing gray text, however, we generally don't want
261 // to make any change to the edit. While auto-commits modify the underlying 261 // to make any change to the edit. While auto-commits modify the underlying
262 // permanent URL, they're intended to have no effect on the user's editing 262 // permanent URL, they're intended to have no effect on the user's editing
263 // process -- before and after the auto-commit, the omnibox should show the 263 // process -- before and after the auto-commit, the omnibox should show the
264 // same user text and the same instant suggestion, even if the auto-commit 264 // same user text and the same instant suggestion, even if the auto-commit
265 // happens while the edit doesn't have focus. 265 // happens while the edit doesn't have focus.
266 string16 new_permanent_text = controller_->GetToolbarModel()->GetText(true);
266 string16 gray_text = view_->GetGrayTextAutocompletion(); 267 string16 gray_text = view_->GetGrayTextAutocompletion();
267 const bool visibly_changed_permanent_text = 268 const bool visibly_changed_permanent_text =
268 (permanent_text_ != new_permanent_text) && 269 (permanent_text_ != new_permanent_text) &&
269 (!has_focus() || 270 (!has_focus() ||
270 (!user_input_in_progress_ && !popup_model()->IsOpen())) && 271 (!user_input_in_progress_ && !popup_model()->IsOpen())) &&
271 (gray_text.empty() || 272 (gray_text.empty() ||
272 new_permanent_text != user_text_ + gray_text); 273 new_permanent_text != user_text_ + gray_text);
273 274
274 permanent_text_ = new_permanent_text; 275 permanent_text_ = new_permanent_text;
275 return visibly_changed_permanent_text; 276 return visibly_changed_permanent_text;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 UMA_HISTOGRAM_ENUMERATION("Omnibox.SearchEngine", 718 UMA_HISTOGRAM_ENUMERATION("Omnibox.SearchEngine",
718 template_url->prepopulate_id(), 719 template_url->prepopulate_id(),
719 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); 720 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID);
720 } 721 }
721 722
722 // Get the current text before we call RevertAll() which will clear it. 723 // Get the current text before we call RevertAll() which will clear it.
723 string16 current_text = GetViewText(); 724 string16 current_text = GetViewText();
724 725
725 if (disposition != NEW_BACKGROUND_TAB) { 726 if (disposition != NEW_BACKGROUND_TAB) {
726 base::AutoReset<bool> tmp(&in_revert_, true); 727 base::AutoReset<bool> tmp(&in_revert_, true);
727 view_->RevertAll(); // Revert the box to its unedited state 728 view_->RevertAll(); // Revert the box to its unedited state.
728 } 729 }
729 730
730 if (match.type == AutocompleteMatchType::EXTENSION_APP) { 731 if (match.type == AutocompleteMatchType::EXTENSION_APP) {
731 ExtensionAppProvider::LaunchAppFromOmnibox(match, profile_, disposition); 732 ExtensionAppProvider::LaunchAppFromOmnibox(match, profile_, disposition);
732 } else { 733 } else {
733 base::TimeDelta query_formulation_time = 734 base::TimeDelta query_formulation_time =
734 base::TimeTicks::Now() - time_user_first_modified_omnibox_; 735 base::TimeTicks::Now() - time_user_first_modified_omnibox_;
735 const GURL destination_url = autocomplete_controller()-> 736 const GURL destination_url = autocomplete_controller()->
736 GetDestinationURL(match, query_formulation_time); 737 GetDestinationURL(match, query_formulation_time);
737 738
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 instant->OmniboxFocusChanged(state, reason, NULL); 1349 instant->OmniboxFocusChanged(state, reason, NULL);
1349 1350
1350 // Update state and notify view if the omnibox has focus and the caret 1351 // Update state and notify view if the omnibox has focus and the caret
1351 // visibility changed. 1352 // visibility changed.
1352 const bool was_caret_visible = is_caret_visible(); 1353 const bool was_caret_visible = is_caret_visible();
1353 focus_state_ = state; 1354 focus_state_ = state;
1354 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1355 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1355 is_caret_visible() != was_caret_visible) 1356 is_caret_visible() != was_caret_visible)
1356 view_->ApplyCaretVisibility(); 1357 view_->ApplyCaretVisibility();
1357 } 1358 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_edit_model.h ('k') | chrome/browser/ui/omnibox/omnibox_edit_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698