[OriginChip] Show the URL on Esc key pressed

This change makes it so hitting the Esc while the omnibox has focus shows the URL unless search term replacement is being performed, in which case we revert to the original search terms.

This holds for both the hide-on-mouse-release and hide-on-input options.  For the latter, this means that a click in the omnibox will also hide the origin chip.  This supports the case where the user is trying to get at the URL and forgets to click on the origin chip or misses it due to existing muscle memory.  In this case, an Esc will show the URL as users are accustomed to.

In no case will hitting Esc cause the origin chip to reappear.

BUG=349497

Review URL: https://codereview.chromium.org/214613003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260173 0039d316-1c4b-4281-b951-d872f2087c98
parent 23ea9094
...@@ -501,24 +501,15 @@ void OmniboxEditModel::SetInputInProgress(bool in_progress) { ...@@ -501,24 +501,15 @@ void OmniboxEditModel::SetInputInProgress(bool in_progress) {
time_user_first_modified_omnibox_ = base::TimeTicks::Now(); time_user_first_modified_omnibox_ = base::TimeTicks::Now();
content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress")); content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress"));
autocomplete_controller()->ResetSession(); autocomplete_controller()->ResetSession();
// Once the user starts editing, re-enable URL replacement, so that it will
// kick in if applicable once the edit is committed or reverted. (While the
// edit is in progress, this won't have a visible effect.)
controller_->GetToolbarModel()->set_url_replacement_enabled(true);
} }
// The following code handles three cases: // The following code handles two cases:
// * For HIDE_ON_USER_INPUT, it hides the chip when user input begins. // * For HIDE_ON_USER_INPUT, it hides the chip when user input begins.
// * For HIDE_ON_MOUSE_RELEASE, which only hides the chip on mouse release if // * For HIDE_ON_MOUSE_RELEASE, which only hides the chip on mouse release if
// the omnibox is empty, it handles the "omnibox was not empty" case by // the omnibox is empty, it handles the "omnibox was not empty" case by
// acting like HIDE_ON_USER_INPUT. (If the omnibox was empty, it // acting like HIDE_ON_USER_INPUT.
// effectively no-ops.) if (chrome::ShouldDisplayOriginChipV2() && in_progress)
// * For both hide behaviors, it allows the chip to be reshown once input controller()->GetToolbarModel()->set_origin_chip_enabled(false);
// ends. (The chip won't actually be re-shown until there's no pending
// typed navigation; see OriginChipView::ShouldShow() and
// OriginChipDecoration::ShouldShow().)
if (chrome::ShouldDisplayOriginChipV2())
controller()->GetToolbarModel()->set_origin_chip_enabled(!in_progress);
controller_->GetToolbarModel()->set_input_in_progress(in_progress); controller_->GetToolbarModel()->set_input_in_progress(in_progress);
controller_->Update(NULL); controller_->Update(NULL);
...@@ -970,6 +961,15 @@ bool OmniboxEditModel::OnEscapeKeyPressed() { ...@@ -970,6 +961,15 @@ bool OmniboxEditModel::OnEscapeKeyPressed() {
view_->Update(); view_->Update();
} }
// When using the origin chip, hitting escape to revert all should either
// display the URL (when search term replacement would not be performed for
// this page) or the search terms (when it would). To accomplish this,
// we'll need to disable URL replacement iff it's currently enabled and
// search term replacement wouldn't normally happen.
bool should_disable_url_replacement =
controller_->GetToolbarModel()->url_replacement_enabled() &&
!controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(true);
// If the user wasn't editing, but merely had focus in the edit, allow <esc> // If the user wasn't editing, but merely had focus in the edit, allow <esc>
// to be processed as an accelerator, so it can still be used to stop a load. // to be processed as an accelerator, so it can still be used to stop a load.
// When the permanent text isn't all selected we still fall through to the // When the permanent text isn't all selected we still fall through to the
...@@ -977,8 +977,8 @@ bool OmniboxEditModel::OnEscapeKeyPressed() { ...@@ -977,8 +977,8 @@ bool OmniboxEditModel::OnEscapeKeyPressed() {
// <esc> to quickly replace all the text; this matches IE. // <esc> to quickly replace all the text; this matches IE.
const bool has_zero_suggest_match = match.provider && const bool has_zero_suggest_match = match.provider &&
(match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST);
if (!has_zero_suggest_match && !user_input_in_progress_ && if (!has_zero_suggest_match && !should_disable_url_replacement &&
view_->IsSelectAll()) !user_input_in_progress_ && view_->IsSelectAll())
return false; return false;
if (!user_text_.empty()) { if (!user_text_.empty()) {
...@@ -986,7 +986,12 @@ bool OmniboxEditModel::OnEscapeKeyPressed() { ...@@ -986,7 +986,12 @@ bool OmniboxEditModel::OnEscapeKeyPressed() {
OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE,
OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS);
} }
view_->RevertAll();
if (should_disable_url_replacement) {
controller_->GetToolbarModel()->set_url_replacement_enabled(false);
UpdatePermanentText();
}
view_->RevertWithoutResettingSearchTermReplacement();
view_->SelectAll(true); view_->SelectAll(true);
return true; return true;
} }
......
...@@ -1832,9 +1832,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, ...@@ -1832,9 +1832,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
EXPECT_EQ(url_c, omnibox_view->GetText()); EXPECT_EQ(url_c, omnibox_view->GetText());
} }
IN_PROC_BROWSER_TEST_F(OmniboxViewTest, InputResetsSearchTermReplacement) { IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) {
browser()->toolbar_model()->set_url_replacement_enabled(false); browser()->toolbar_model()->set_url_replacement_enabled(true);
chrome::FocusLocationBar(browser()); chrome::FocusLocationBar(browser());
ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0)); ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0));
EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled());
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment