diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 17:58:58 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 17:58:58 +0000 |
commit | 553c7af97cec49fa9655ce11b53eee72412925bc (patch) | |
tree | 1e6d36d14ab3f10883c39e3f5fe36e380798af2a /chrome/browser/ui | |
parent | 52186d0fad83b466f11165590f9b89fa549264d3 (diff) | |
download | chromium_src-553c7af97cec49fa9655ce11b53eee72412925bc.zip chromium_src-553c7af97cec49fa9655ce11b53eee72412925bc.tar.gz chromium_src-553c7af97cec49fa9655ce11b53eee72412925bc.tar.bz2 |
Store the omnibox start margin information in InstantService. When the omnibox bounds changes, InstantService notifies the observers about the margin change event. SearchTabHelper listens for the margin change event and sends a message to the underlying Instant page about the new start margin value.
As a prep to remove redundant Instant-related query params from search URLs, SearchTabHelper sends the margin information to the renderer process as soon as the navigation entry is committed.
BUG=247517
TEST=none
Review URL: https://codereview.chromium.org/148383012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.h | 7 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm | 10 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/location_bar_view_gtk.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_controller.cc | 17 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_controller.h | 17 | ||||
-rw-r--r-- | chrome/browser/ui/search/search_ipc_router_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/search/search_tab_helper.cc | 13 | ||||
-rw-r--r-- | chrome/browser/ui/search/search_tab_helper.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/views/location_bar/location_bar_view.cc | 7 |
10 files changed, 30 insertions, 66 deletions
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index 6cbab72..ddab454 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -117,10 +117,6 @@ void BrowserInstantController::TabDeactivated(content::WebContents* contents) { prerenderer->Cancel(); } -void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) { - instant_.SetOmniboxBounds(bounds); -} - //////////////////////////////////////////////////////////////////////////////// // BrowserInstantController, SearchModelObserver implementation: diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h index 6af5d03..d9c70ca 100644 --- a/chrome/browser/ui/browser_instant_controller.h +++ b/chrome/browser/ui/browser_instant_controller.h @@ -21,10 +21,6 @@ namespace content { class WebContents; } -namespace gfx { -class Rect; -} - class BrowserInstantController : public SearchModelObserver, public InstantServiceObserver { public: @@ -51,9 +47,6 @@ class BrowserInstantController : public SearchModelObserver, // Invoked by |browser_| when the active tab is about to be deactivated. void TabDeactivated(content::WebContents* contents); - // Sets the stored omnibox bounds. - void SetOmniboxBounds(const gfx::Rect& bounds); - private: // Overridden from search::SearchModelObserver: virtual void ModelChanged(const SearchModel::State& old_state, diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm index c86592f..5adbf62 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm @@ -22,6 +22,8 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/location_bar_controller.h" #include "chrome/browser/extensions/tab_helper.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" #include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" @@ -545,9 +547,11 @@ void LocationBarViewMac::OnChanged() { Layout(); - if (browser_->instant_controller()) { - browser_->instant_controller()->SetOmniboxBounds( - gfx::Rect(NSRectToCGRect([field_ frame]))); + InstantService* instant_service = + InstantServiceFactory::GetForProfile(profile()); + if (instant_service) { + gfx::Rect bounds(NSRectToCGRect([field_ frame])); + instant_service->OnOmniboxStartMarginChanged(bounds.x()); } } diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index 222302e..567891e 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -34,6 +34,8 @@ #include "chrome/browser/extensions/location_bar_controller.h" #include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/favicon/favicon_tab_helper.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" @@ -1120,9 +1122,11 @@ void LocationBarViewGtk::OnHboxSizeAllocate(GtkWidget* sender, hbox_width_ = allocation->width; UpdateEVCertificateLabelSize(); } - if (browser_ && browser_->instant_controller()) { - browser_->instant_controller()-> - SetOmniboxBounds(AllocationToRect(*allocation)); + InstantService* instant_service = + InstantServiceFactory::GetForProfile(profile()); + if (instant_service) { + instant_service->OnOmniboxStartMarginChanged( + AllocationToRect(*allocation).x()); } } diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc index 621dc00..93597b9 100644 --- a/chrome/browser/ui/search/instant_controller.cc +++ b/chrome/browser/ui/search/instant_controller.cc @@ -81,24 +81,12 @@ void EnsureSearchTermsAreSet(content::WebContents* contents, InstantController::InstantController(BrowserInstantController* browser) : browser_(browser), omnibox_focus_state_(OMNIBOX_FOCUS_NONE), - omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), - omnibox_bounds_(-1, -1, 0, 0) { + omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT) { } InstantController::~InstantController() { } -void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { - if (omnibox_bounds_ == bounds) - return; - - omnibox_bounds_ = bounds; - if (instant_tab_) { - SearchTabHelper::FromWebContents(instant_tab_->contents())-> - SetOmniboxStartMargin(omnibox_bounds_.x()); - } -} - void InstantController::SetSuggestionToPrefetch( const InstantSuggestion& suggestion) { if (instant_tab_ && @@ -255,9 +243,6 @@ void InstantController::ResetInstantTab() { void InstantController::UpdateInfoForInstantTab() { if (instant_tab_) { - SearchTabHelper::FromWebContents(instant_tab_->contents())-> - SetOmniboxStartMargin(omnibox_bounds_.x()); - // Update theme details. InstantService* instant_service = GetInstantService(); if (instant_service) { diff --git a/chrome/browser/ui/search/instant_controller.h b/chrome/browser/ui/search/instant_controller.h index 613ee25..2ffcdf0 100644 --- a/chrome/browser/ui/search/instant_controller.h +++ b/chrome/browser/ui/search/instant_controller.h @@ -19,7 +19,6 @@ #include "chrome/common/omnibox_focus_state.h" #include "chrome/common/search_types.h" #include "ui/gfx/native_widget_types.h" -#include "ui/gfx/rect.h" class BrowserInstantController; class GURL; @@ -31,10 +30,6 @@ namespace content { class WebContents; } -namespace gfx { -class Rect; -} - // Macro used for logging debug events. |message| should be a std::string. #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ controller->LogDebugEvent(message) @@ -53,9 +48,6 @@ class InstantController : public InstantPage::Delegate { explicit InstantController(BrowserInstantController* browser); virtual ~InstantController(); - // Sets the stored start-edge margin and width of the omnibox. - void SetOmniboxBounds(const gfx::Rect& bounds); - // Sends the current SearchProvider suggestion to the Instant page if any. void SetSuggestionToPrefetch(const InstantSuggestion& suggestion); @@ -95,11 +87,6 @@ class InstantController : public InstantPage::Delegate { return debug_events_; } - // Gets the stored start-edge margin and width of the omnibox. - const gfx::Rect omnibox_bounds() { - return omnibox_bounds_; - } - // Used by BrowserInstantController to notify InstantController about the // instant support change event for the active web contents. void InstantSupportChanged(InstantSupportState instant_support); @@ -181,10 +168,6 @@ class InstantController : public InstantPage::Delegate { // The search model mode for the active tab. SearchMode search_mode_; - // The start-edge margin and width of the omnibox, used by the page to align - // its suggestions with the omnibox. - gfx::Rect omnibox_bounds_; - // List of events and their timestamps, useful in debugging Instant behaviour. mutable std::list<std::pair<int64, std::string> > debug_events_; diff --git a/chrome/browser/ui/search/search_ipc_router_unittest.cc b/chrome/browser/ui/search/search_ipc_router_unittest.cc index f81f60d..a95fd12 100644 --- a/chrome/browser/ui/search/search_ipc_router_unittest.cc +++ b/chrome/browser/ui/search/search_ipc_router_unittest.cc @@ -738,8 +738,7 @@ TEST_F(SearchIPCRouterTest, SendSetOmniboxStartMargin) { .WillOnce(testing::Return(true)); process()->sink().ClearMessages(); - content::WebContents* contents = web_contents(); - GetSearchTabHelper(contents)->SetOmniboxStartMargin(92); + GetSearchIPCRouter().SetOmniboxStartMargin(92); EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxMarginChange::ID)); } @@ -751,8 +750,7 @@ TEST_F(SearchIPCRouterTest, DoNotSendSetOmniboxStartMargin) { .WillOnce(testing::Return(false)); process()->sink().ClearMessages(); - content::WebContents* contents = web_contents(); - GetSearchTabHelper(contents)->SetOmniboxStartMargin(92); + GetSearchIPCRouter().SetOmniboxStartMargin(92); EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxMarginChange::ID)); } diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc index 79419d7..133b9d1 100644 --- a/chrome/browser/ui/search/search_tab_helper.cc +++ b/chrome/browser/ui/search/search_tab_helper.cc @@ -213,10 +213,6 @@ void SearchTabHelper::SetSuggestionToPrefetch( ipc_router_.SetSuggestionToPrefetch(suggestion); } -void SearchTabHelper::SetOmniboxStartMargin(int start_margin) { - ipc_router_.SetOmniboxStartMargin(start_margin); -} - void SearchTabHelper::Submit(const base::string16& text) { ipc_router_.Submit(text); } @@ -326,10 +322,11 @@ void SearchTabHelper::NavigationEntryCommitted( if (!load_details.is_main_frame) return; - // TODO(kmadhusu): Set the page initial states (such as omnibox margin, etc) - // from here. Please refer to crbug.com/247517 for more details. if (chrome::ShouldAssignURLToInstantRenderer(web_contents_->GetURL(), profile())) { + InstantService* instant_service = + InstantServiceFactory::GetForProfile(profile()); + ipc_router_.SetOmniboxStartMargin(instant_service->omnibox_start_margin()); ipc_router_.SetDisplayInstantResults(); } @@ -388,6 +385,10 @@ void SearchTabHelper::MostVisitedItemsChanged( ipc_router_.SendMostVisitedItems(items_copy); } +void SearchTabHelper::OmniboxStartMarginChanged(int omnibox_start_margin) { + ipc_router_.SetOmniboxStartMargin(omnibox_start_margin); +} + void SearchTabHelper::MaybeRemoveMostVisitedItems( std::vector<InstantMostVisitedItem>* items) { // The code below uses APIs not available on Android and the experiment should diff --git a/chrome/browser/ui/search/search_tab_helper.h b/chrome/browser/ui/search/search_tab_helper.h index 90f1993..db05376 100644 --- a/chrome/browser/ui/search/search_tab_helper.h +++ b/chrome/browser/ui/search/search_tab_helper.h @@ -71,10 +71,6 @@ class SearchTabHelper : public content::WebContentsObserver, // Sends the current SearchProvider suggestion to the Instant page if any. void SetSuggestionToPrefetch(const InstantSuggestion& suggestion); - // Sends the omnibox start margin value to the Instant page. This is used by - // the page to align text or assets properly with the omnibox. - void SetOmniboxStartMargin(int start_margin); - // Tells the page that the user pressed Enter in the omnibox. void Submit(const base::string16& text); @@ -175,6 +171,7 @@ class SearchTabHelper : public content::WebContentsObserver, virtual void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) OVERRIDE; virtual void MostVisitedItemsChanged( const std::vector<InstantMostVisitedItem>& items) OVERRIDE; + virtual void OmniboxStartMarginChanged(int omnibox_start_margin) OVERRIDE; // Removes recommended URLs if a matching URL is already open in the Browser, // if the Most Visited Tile Placement experiment is enabled, and the client is diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index d2896918..d8c0d8a 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -21,6 +21,8 @@ #include "chrome/browser/extensions/location_bar_controller.h" #include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/favicon/favicon_tab_helper.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" #include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" @@ -1110,8 +1112,9 @@ void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { } void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { - if (browser_ && browser_->instant_controller() && parent()) - browser_->instant_controller()->SetOmniboxBounds(bounds()); + InstantServiceFactory::GetForProfile(profile())->OnOmniboxStartMarginChanged( + bounds().x()); + OmniboxPopupView* popup = omnibox_view_->model()->popup_model()->view(); if (popup->IsOpen()) popup->UpdatePopupAppearance(); |