Commit 8ea75e87 authored by Tommy C. Li's avatar Tommy C. Li Committed by Commit Bot

Omnibox UI Experiments: Show elided permanent URLs (when flag on)

This CL enables showing the elided permanent URLs when the flag is on.

It also restores the full URL on focus and puts back the elided one on
blur (assuming it hasn't been edited).

No selection adjustment logic exists in this CL.

Bug: 797354
Change-Id: I1fc6a8aa37aaf4582db2b6895a1292006da3114b
Reviewed-on: https://chromium-review.googlesource.com/882617
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532033}
parent f8e89bb9
...@@ -195,8 +195,8 @@ void OmniboxViewViews::OnTabChanged(const content::WebContents* web_contents) { ...@@ -195,8 +195,8 @@ void OmniboxViewViews::OnTabChanged(const content::WebContents* web_contents) {
UpdateSecurityLevel(); UpdateSecurityLevel();
const OmniboxState* state = static_cast<OmniboxState*>( const OmniboxState* state = static_cast<OmniboxState*>(
web_contents->GetUserData(&OmniboxState::kKey)); web_contents->GetUserData(&OmniboxState::kKey));
model()->RestoreState(controller()->GetToolbarModel()->GetFormattedFullURL(), model()->RestoreState(controller()->GetURLForDisplay(),
state ? &state->model_state : NULL); state ? &state->model_state : nullptr);
if (state) { if (state) {
// This assumes that the omnibox has already been focused or blurred as // This assumes that the omnibox has already been focused or blurred as
// appropriate; otherwise, a subsequent OnFocus() or OnBlur() call could // appropriate; otherwise, a subsequent OnFocus() or OnBlur() call could
...@@ -217,8 +217,8 @@ void OmniboxViewViews::ResetTabState(content::WebContents* web_contents) { ...@@ -217,8 +217,8 @@ void OmniboxViewViews::ResetTabState(content::WebContents* web_contents) {
void OmniboxViewViews::Update() { void OmniboxViewViews::Update() {
const security_state::SecurityLevel old_security_level = security_level_; const security_state::SecurityLevel old_security_level = security_level_;
UpdateSecurityLevel(); UpdateSecurityLevel();
if (model()->SetPermanentText(
controller()->GetToolbarModel()->GetFormattedFullURL())) { if (model()->SetPermanentText(controller()->GetURLForDisplay())) {
RevertAll(); RevertAll();
// Only select all when we have focus. If we don't have focus, selecting // Only select all when we have focus. If we don't have focus, selecting
...@@ -831,8 +831,7 @@ bool OmniboxViewViews::HandleAccessibleAction( ...@@ -831,8 +831,7 @@ bool OmniboxViewViews::HandleAccessibleAction(
void OmniboxViewViews::OnFocus() { void OmniboxViewViews::OnFocus() {
views::Textfield::OnFocus(); views::Textfield::OnFocus();
model()->SetPermanentText( model()->SetPermanentText(controller()->GetURLForDisplay());
controller()->GetToolbarModel()->GetFormattedFullURL());
// TODO(oshima): Get control key state. // TODO(oshima): Get control key state.
model()->OnSetFocus(false); model()->OnSetFocus(false);
// Don't call controller()->OnSetFocus, this view has already acquired focus. // Don't call controller()->OnSetFocus, this view has already acquired focus.
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include "components/omnibox/browser/omnibox_edit_controller.h" #include "components/omnibox/browser/omnibox_edit_controller.h"
#include "base/feature_list.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/toolbar/toolbar_model.h"
void OmniboxEditController::OnAutocompleteAccept( void OmniboxEditController::OnAutocompleteAccept(
const GURL& destination_url, const GURL& destination_url,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
...@@ -14,6 +18,13 @@ void OmniboxEditController::OnAutocompleteAccept( ...@@ -14,6 +18,13 @@ void OmniboxEditController::OnAutocompleteAccept(
transition_ = transition; transition_ = transition;
} }
base::string16 OmniboxEditController::GetURLForDisplay() {
return base::FeatureList::IsEnabled(
omnibox::kUIExperimentHideSteadyStateUrlSchemeAndSubdomains)
? GetToolbarModel()->GetURLForDisplay()
: GetToolbarModel()->GetFormattedFullURL();
}
OmniboxEditController::OmniboxEditController() OmniboxEditController::OmniboxEditController()
: disposition_(WindowOpenDisposition::CURRENT_TAB), : disposition_(WindowOpenDisposition::CURRENT_TAB),
transition_(ui::PageTransitionFromInt( transition_(ui::PageTransitionFromInt(
......
...@@ -31,6 +31,11 @@ class OmniboxEditController { ...@@ -31,6 +31,11 @@ class OmniboxEditController {
virtual ToolbarModel* GetToolbarModel() = 0; virtual ToolbarModel* GetToolbarModel() = 0;
virtual const ToolbarModel* GetToolbarModel() const = 0; virtual const ToolbarModel* GetToolbarModel() const = 0;
// Returns the text to display in the steady state, when the omnibox does not
// have focus. This may be a simplified version of the URL with destructive
// elisions applied - and is not suitable for editing.
base::string16 GetURLForDisplay();
protected: protected:
OmniboxEditController(); OmniboxEditController();
virtual ~OmniboxEditController(); virtual ~OmniboxEditController();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <utility> #include <utility>
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/feature_list.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include "components/omnibox/browser/omnibox_client.h" #include "components/omnibox/browser/omnibox_client.h"
#include "components/omnibox/browser/omnibox_edit_controller.h" #include "components/omnibox/browser/omnibox_edit_controller.h"
#include "components/omnibox/browser/omnibox_event_global_tracker.h" #include "components/omnibox/browser/omnibox_event_global_tracker.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_log.h" #include "components/omnibox/browser/omnibox_log.h"
#include "components/omnibox/browser/omnibox_navigation_observer.h" #include "components/omnibox/browser/omnibox_navigation_observer.h"
#include "components/omnibox/browser/omnibox_popup_model.h" #include "components/omnibox/browser/omnibox_popup_model.h"
...@@ -37,6 +39,7 @@ ...@@ -37,6 +39,7 @@
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_prepopulate_data.h" #include "components/search_engines/template_url_prepopulate_data.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/toolbar/toolbar_model.h"
#include "components/url_formatter/url_fixer.h" #include "components/url_formatter/url_fixer.h"
#include "third_party/metrics_proto/omnibox_event.pb.h" #include "third_party/metrics_proto/omnibox_event.pb.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
...@@ -901,6 +904,12 @@ void OmniboxEditModel::OnSetFocus(bool control_down) { ...@@ -901,6 +904,12 @@ void OmniboxEditModel::OnSetFocus(bool control_down) {
SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT);
control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP;
if (base::FeatureList::IsEnabled(
omnibox::kUIExperimentHideSteadyStateUrlSchemeAndSubdomains)) {
// Show the full URL if the user focuses the Omnibox.
SetPermanentText(controller()->GetToolbarModel()->GetFormattedFullURL());
}
// Try to get ZeroSuggest suggestions if a page is loaded and the user has // Try to get ZeroSuggest suggestions if a page is loaded and the user has
// not been typing in the omnibox. The |user_input_in_progress_| check is // not been typing in the omnibox. The |user_input_in_progress_| check is
// used to detect the case where this function is called after right-clicking // used to detect the case where this function is called after right-clicking
...@@ -935,6 +944,14 @@ void OmniboxEditModel::SetCaretVisibility(bool visible) { ...@@ -935,6 +944,14 @@ void OmniboxEditModel::SetCaretVisibility(bool visible) {
void OmniboxEditModel::OnWillKillFocus() { void OmniboxEditModel::OnWillKillFocus() {
if (user_input_in_progress_ || !in_revert_) if (user_input_in_progress_ || !in_revert_)
client_->OnInputStateChanged(); client_->OnInputStateChanged();
if (!user_input_in_progress_ &&
base::FeatureList::IsEnabled(
omnibox::kUIExperimentHideSteadyStateUrlSchemeAndSubdomains)) {
// If the user has not edited the input and is now leaving Omnibox focus,
// restore the elided URL as the permanent text.
RestoreState(controller()->GetURLForDisplay(), nullptr);
}
} }
void OmniboxEditModel::OnKillFocus() { void OmniboxEditModel::OnKillFocus() {
......
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