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

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

Issue 214613003: [OriginChip] Show the URL on Esc key pressed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser test Created 6 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 } 494 }
495 495
496 if (user_input_in_progress_ == in_progress) 496 if (user_input_in_progress_ == in_progress)
497 return; 497 return;
498 498
499 user_input_in_progress_ = in_progress; 499 user_input_in_progress_ = in_progress;
500 if (user_input_in_progress_) { 500 if (user_input_in_progress_) {
501 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); 501 time_user_first_modified_omnibox_ = base::TimeTicks::Now();
502 content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress")); 502 content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress"));
503 autocomplete_controller()->ResetSession(); 503 autocomplete_controller()->ResetSession();
504 // Once the user starts editing, re-enable URL replacement, so that it will
505 // kick in if applicable once the edit is committed or reverted. (While the
506 // edit is in progress, this won't have a visible effect.)
507 controller_->GetToolbarModel()->set_url_replacement_enabled(true);
508 } 504 }
509 505
510 // The following code handles three cases: 506 // The following code handles two cases:
511 // * For HIDE_ON_USER_INPUT, it hides the chip when user input begins. 507 // * For HIDE_ON_USER_INPUT, it hides the chip when user input begins.
512 // * For HIDE_ON_MOUSE_RELEASE, which only hides the chip on mouse release if 508 // * For HIDE_ON_MOUSE_RELEASE, which only hides the chip on mouse release if
513 // the omnibox is empty, it handles the "omnibox was not empty" case by 509 // the omnibox is empty, it handles the "omnibox was not empty" case by
514 // acting like HIDE_ON_USER_INPUT. (If the omnibox was empty, it 510 // acting like HIDE_ON_USER_INPUT.
515 // effectively no-ops.) 511 if (chrome::ShouldDisplayOriginChipV2() && in_progress)
516 // * For both hide behaviors, it allows the chip to be reshown once input 512 controller()->GetToolbarModel()->set_origin_chip_enabled(false);
517 // ends. (The chip won't actually be re-shown until there's no pending
518 // typed navigation; see OriginChipView::ShouldShow() and
519 // OriginChipDecoration::ShouldShow().)
520 if (chrome::ShouldDisplayOriginChipV2())
521 controller()->GetToolbarModel()->set_origin_chip_enabled(!in_progress);
522 513
523 controller_->GetToolbarModel()->set_input_in_progress(in_progress); 514 controller_->GetToolbarModel()->set_input_in_progress(in_progress);
524 controller_->Update(NULL); 515 controller_->Update(NULL);
525 516
526 if (user_input_in_progress_ || !in_revert_) 517 if (user_input_in_progress_ || !in_revert_)
527 delegate_->OnInputStateChanged(); 518 delegate_->OnInputStateChanged();
528 } 519 }
529 520
530 void OmniboxEditModel::Revert() { 521 void OmniboxEditModel::Revert() {
531 SetInputInProgress(false); 522 SetInputInProgress(false);
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 } 954 }
964 } 955 }
965 956
966 // We do not clear the pending entry from the omnibox when a load is first 957 // We do not clear the pending entry from the omnibox when a load is first
967 // stopped. If the user presses Escape while stopped, we clear it. 958 // stopped. If the user presses Escape while stopped, we clear it.
968 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { 959 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) {
969 delegate_->GetNavigationController().DiscardNonCommittedEntries(); 960 delegate_->GetNavigationController().DiscardNonCommittedEntries();
970 view_->Update(); 961 view_->Update();
971 } 962 }
972 963
964 // When using the origin chip, hitting escape to revert all should either
965 // display the URL (when search term replacement would not be performed for
966 // this page) or the search terms (when it would). To accomplish this,
967 // we'll need to disable URL replacement iff it's currently enabled and
968 // search term replacement wouldn't normally happen.
969 bool should_disable_url_replacement =
970 controller_->GetToolbarModel()->url_replacement_enabled() &&
971 !controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(true);
972
973 // If the user wasn't editing, but merely had focus in the edit, allow <esc> 973 // If the user wasn't editing, but merely had focus in the edit, allow <esc>
974 // to be processed as an accelerator, so it can still be used to stop a load. 974 // to be processed as an accelerator, so it can still be used to stop a load.
975 // When the permanent text isn't all selected we still fall through to the 975 // When the permanent text isn't all selected we still fall through to the
976 // SelectAll() call below so users can arrow around in the text and then hit 976 // SelectAll() call below so users can arrow around in the text and then hit
977 // <esc> to quickly replace all the text; this matches IE. 977 // <esc> to quickly replace all the text; this matches IE.
978 const bool has_zero_suggest_match = match.provider && 978 const bool has_zero_suggest_match = match.provider &&
979 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); 979 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST);
980 if (!has_zero_suggest_match && !user_input_in_progress_ && 980 if (!has_zero_suggest_match && !should_disable_url_replacement &&
981 view_->IsSelectAll()) 981 !user_input_in_progress_ && view_->IsSelectAll())
982 return false; 982 return false;
983 983
984 if (!user_text_.empty()) { 984 if (!user_text_.empty()) {
985 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, 985 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram,
986 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, 986 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE,
987 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); 987 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS);
988 } 988 }
989 view_->RevertAll(); 989
990 if (should_disable_url_replacement) {
991 controller_->GetToolbarModel()->set_url_replacement_enabled(false);
992 UpdatePermanentText();
993 }
994 view_->RevertWithoutResettingSearchTermReplacement();
990 view_->SelectAll(true); 995 view_->SelectAll(true);
991 return true; 996 return true;
992 } 997 }
993 998
994 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { 999 void OmniboxEditModel::OnControlKeyChanged(bool pressed) {
995 if (pressed == (control_key_state_ == UP)) 1000 if (pressed == (control_key_state_ == UP))
996 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; 1001 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP;
997 } 1002 }
998 1003
999 void OmniboxEditModel::OnPaste() { 1004 void OmniboxEditModel::OnPaste() {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 // Update state and notify view if the omnibox has focus and the caret 1441 // Update state and notify view if the omnibox has focus and the caret
1437 // visibility changed. 1442 // visibility changed.
1438 const bool was_caret_visible = is_caret_visible(); 1443 const bool was_caret_visible = is_caret_visible();
1439 focus_state_ = state; 1444 focus_state_ = state;
1440 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1445 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1441 is_caret_visible() != was_caret_visible) 1446 is_caret_visible() != was_caret_visible)
1442 view_->ApplyCaretVisibility(); 1447 view_->ApplyCaretVisibility();
1443 1448
1444 delegate_->OnFocusChanged(focus_state_, reason); 1449 delegate_->OnFocusChanged(focus_state_, reason);
1445 } 1450 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698