diff options
author | melevin@chromium.org <melevin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-28 02:25:09 +0000 |
---|---|---|
committer | melevin@chromium.org <melevin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-28 02:25:09 +0000 |
commit | fcde79a4e5a876c28d0157897fcf2632bd880d5a (patch) | |
tree | 5d9c66b62a9beb889bf5d82b4b41ddd44cd425b2 /chrome/browser | |
parent | b018c3ce863fadbae1c18fb7851cef0b6e34d077 (diff) | |
download | chromium_src-fcde79a4e5a876c28d0157897fcf2632bd880d5a.zip chromium_src-fcde79a4e5a876c28d0157897fcf2632bd880d5a.tar.gz chromium_src-fcde79a4e5a876c28d0157897fcf2632bd880d5a.tar.bz2 |
Change the SearchBox API from using the start/end margins of the location bar to using the start margin and width. This change is necessary to avoid accounting for the presence of the scrollbar in the search page JavaScript.
BUG=153403
Review URL: https://chromiumcodereview.appspot.com/12047107
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 21 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 12 | ||||
-rw-r--r-- | chrome/browser/instant/instant_extended_browsertest.cc | 38 | ||||
-rw-r--r-- | chrome/browser/instant/instant_page.cc | 5 | ||||
-rw-r--r-- | chrome/browser/instant/instant_page.h | 7 | ||||
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.h | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/location_bar/location_bar_view.cc | 9 |
8 files changed, 63 insertions, 37 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 9725d5e..624e081 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -203,8 +203,6 @@ InstantController::InstantController(chrome::BrowserInstantController* browser, last_transition_type_(content::PAGE_TRANSITION_LINK), last_match_was_search_(false), omnibox_focus_state_(OMNIBOX_FOCUS_NONE), - start_margin_(0), - end_margin_(0), allow_preview_to_show_search_suggestions_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { } @@ -467,18 +465,17 @@ void InstantController::SetPopupBounds(const gfx::Rect& bounds) { } } -void InstantController::SetMarginSize(int start, int end) { - if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) +void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { + if (!extended_enabled_ || omnibox_bounds_ == bounds) return; - start_margin_ = start; - end_margin_ = end; + omnibox_bounds_ = bounds; if (overlay_) - overlay_->SetMarginSize(start_margin_, end_margin_); + overlay_->SetOmniboxBounds(omnibox_bounds_); if (ntp_) - ntp_->SetMarginSize(start_margin_, end_margin_); + ntp_->SetOmniboxBounds(omnibox_bounds_); if (instant_tab_) - instant_tab_->SetMarginSize(start_margin_, end_margin_); + instant_tab_->SetOmniboxBounds(omnibox_bounds_); } void InstantController::HandleAutocompleteResults( @@ -896,11 +893,11 @@ void InstantController::InstantPageRenderViewCreated( overlay_->SetDisplayInstantResults(instant_enabled_); overlay_->KeyCaptureChanged( omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); - overlay_->SetMarginSize(start_margin_, end_margin_); + overlay_->SetOmniboxBounds(omnibox_bounds_); overlay_->InitializeFonts(); } else if (IsContentsFrom(ntp(), contents)) { ntp_->SetDisplayInstantResults(instant_enabled_); - ntp_->SetMarginSize(start_margin_, end_margin_); + ntp_->SetOmniboxBounds(omnibox_bounds_); ntp_->InitializeFonts(); } else { NOTREACHED(); @@ -1230,7 +1227,7 @@ void InstantController::ResetInstantTab() { // Update theme info for this tab. browser_->UpdateThemeInfo(false); instant_tab_->SetDisplayInstantResults(instant_enabled_); - instant_tab_->SetMarginSize(start_margin_, end_margin_); + instant_tab_->SetOmniboxBounds(omnibox_bounds_); instant_tab_->InitializeFonts(); StartListeningToMostVisitedChanges(); instant_tab_->KeyCaptureChanged( diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index def4880..e9e1d5f 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -101,8 +101,8 @@ class InstantController : public InstantPage::Delegate, // Sets the bounds of the omnibox popup, in screen coordinates. void SetPopupBounds(const gfx::Rect& bounds); - // Sets the start and end margins of the omnibox text area. - void SetMarginSize(int start, int end); + // Sets the stored start-edge margin and width of the omnibox. + void SetOmniboxBounds(const gfx::Rect& bounds); // Send autocomplete results from |providers| to the preview page. void HandleAutocompleteResults( @@ -401,11 +401,9 @@ class InstantController : public InstantPage::Delegate, // Last popup bounds passed to the page. gfx::Rect last_popup_bounds_; - // Size of the start-edge omnibox text area margin. - int start_margin_; - - // Size of the end-edge omnibox text area margin. - int end_margin_; + // The start-edge margin and width of the omnibox, used by the page to align + // its suggestions with the omnibox. + gfx::Rect omnibox_bounds_; // Timer used to update the bounds of the omnibox popup. base::OneShotTimer<InstantController> update_bounds_timer_; diff --git a/chrome/browser/instant/instant_extended_browsertest.cc b/chrome/browser/instant/instant_extended_browsertest.cc index f0fc514..9e03d54 100644 --- a/chrome/browser/instant/instant_extended_browsertest.cc +++ b/chrome/browser/instant/instant_extended_browsertest.cc @@ -4,6 +4,7 @@ #include <sstream> +#include "base/prefs/pref_service.h" #include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/instant/instant_commit_type.h" #include "chrome/browser/instant/instant_ntp.h" @@ -12,9 +13,11 @@ #include "chrome/browser/instant/instant_service_factory.h" #include "chrome/browser/instant/instant_tab.h" #include "chrome/browser/instant/instant_test_utils.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/search/search.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/ui_test_utils.h" @@ -718,3 +721,38 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { // Make sure we have the same number of items as before. EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); } + +// Only implemented in Views currently: http://crbug.com/164723 +#if defined(OS_WIN) || defined(OS_CHROMEOS) +#define MAYBE_HomeButtonAffectsMargin HomeButtonAffectsMargin +#else +#define MAYBE_HomeButtonAffectsMargin DISABLED_HomeButtonAffectsMargin +#endif +// Check that toggling the state of the home button changes the start-edge +// margin and width. +IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) { + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + + // Get the current value of the start-edge margin and width. + int start_margin; + int width; + content::WebContents* preview_tab = instant()->GetPreviewContents(); + EXPECT_TRUE(GetIntFromJS(preview_tab, "chrome.searchBox.startMargin", + &start_margin)); + EXPECT_TRUE(GetIntFromJS(preview_tab, "chrome.searchBox.width", &width)); + + // Toggle the home button visibility pref. + PrefService* profile_prefs = browser()->profile()->GetPrefs(); + bool show_home = profile_prefs->GetBoolean(prefs::kShowHomeButton); + profile_prefs->SetBoolean(prefs::kShowHomeButton, !show_home); + + // Make sure the margin and width changed. + int new_start_margin; + int new_width; + EXPECT_TRUE(GetIntFromJS(preview_tab, "chrome.searchBox.startMargin", + &new_start_margin)); + EXPECT_TRUE(GetIntFromJS(preview_tab, "chrome.searchBox.width", &new_width)); + EXPECT_NE(start_margin, new_start_margin); + EXPECT_NE(width, new_width); + EXPECT_EQ(new_width - width, start_margin - new_start_margin); +} diff --git a/chrome/browser/instant/instant_page.cc b/chrome/browser/instant/instant_page.cc index 85f5699..ba79353 100644 --- a/chrome/browser/instant/instant_page.cc +++ b/chrome/browser/instant/instant_page.cc @@ -36,8 +36,9 @@ void InstantPage::SetPopupBounds(const gfx::Rect& bounds) { Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds)); } -void InstantPage::SetMarginSize(const int start, const int end) { - Send(new ChromeViewMsg_SearchBoxMarginChange(routing_id(), start, end)); +void InstantPage::SetOmniboxBounds(const gfx::Rect& bounds) { + Send(new ChromeViewMsg_SearchBoxMarginChange( + routing_id(), bounds.x(), bounds.width())); } void InstantPage::InitializeFonts() { diff --git a/chrome/browser/instant/instant_page.h b/chrome/browser/instant/instant_page.h index f0167c2..1260beb1 100644 --- a/chrome/browser/instant/instant_page.h +++ b/chrome/browser/instant/instant_page.h @@ -131,10 +131,9 @@ class InstantPage : public content::WebContentsObserver { // by the omnibox dropdown. void SetPopupBounds(const gfx::Rect& bounds); - // Tells the page the start and end margins of the omnibox (in screen - // coordinates). This is used by the page to align text or assets properly - // with the omnibox. - void SetMarginSize(int start, int end); + // Tells the page the bounds of the omnibox (in screen coordinates). This is + // used by the page to align text or assets properly with the omnibox. + void SetOmniboxBounds(const gfx::Rect& bounds); // Tells the page about the font information. void InitializeFonts(); diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index 1027ece..2d17390 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -248,8 +248,8 @@ void BrowserInstantController::OpenURL( false)); } -void BrowserInstantController::SetMarginSize(int start, int end) { - instant_.SetMarginSize(start, end); +void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) { + instant_.SetOmniboxBounds(bounds); } void BrowserInstantController::ResetInstant() { diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h index 965fe43..80cfde0 100644 --- a/chrome/browser/ui/browser_instant_controller.h +++ b/chrome/browser/ui/browser_instant_controller.h @@ -109,8 +109,8 @@ class BrowserInstantController : public content::NotificationObserver, content::PageTransition transition, WindowOpenDisposition disposition); - // Sets the start and end margins of the omnibox text area. - void SetMarginSize(int start, int end); + // Sets the stored omnibox bounds. + void SetOmniboxBounds(const gfx::Rect& bounds); private: // Sets the value of |instant_| based on value from profile. Invoked 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 e8a8d68..68306ee 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -1275,14 +1275,7 @@ bool LocationBarView::HasFocus() const { void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { if (browser_ && browser_->instant_controller() && parent()) { - // Pass the side margins of the location bar to the Instant Controller. - const gfx::Rect bounds = GetBoundsInScreen(); - const gfx::Rect parent_bounds = parent()->GetBoundsInScreen(); - int start = bounds.x() - parent_bounds.x(); - int end = parent_bounds.right() - bounds.right(); - if (base::i18n::IsRTL()) - std::swap(start, end); - browser_->instant_controller()->SetMarginSize(start, end); + browser_->instant_controller()->SetOmniboxBounds(bounds()); } } |