diff options
author | melevin@chromium.org <melevin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-14 01:11:04 +0000 |
---|---|---|
committer | melevin@chromium.org <melevin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-14 01:11:04 +0000 |
commit | ec4aad544c94b17ad2a01537e5bbbec5cd4d13d4 (patch) | |
tree | 95bc5a69c4627ec014856268fbc077f56a3472d2 /chrome/browser | |
parent | e34dc5abef02c60b672ba0fae814233682bbbd01 (diff) | |
download | chromium_src-ec4aad544c94b17ad2a01537e5bbbec5cd4d13d4.zip chromium_src-ec4aad544c94b17ad2a01537e5bbbec5cd4d13d4.tar.gz chromium_src-ec4aad544c94b17ad2a01537e5bbbec5cd4d13d4.tar.bz2 |
Implement the Instant extended API startMargin, endMargin, and rtl properties and the onmarginchange event for Views only.
BUG=153403
Review URL: https://chromiumcodereview.appspot.com/11359198
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173028 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/instant/instant_client.cc | 8 | ||||
-rw-r--r-- | chrome/browser/instant/instant_client.h | 5 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 38 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 27 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 8 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.h | 3 | ||||
-rw-r--r-- | chrome/browser/instant/instant_tab.cc | 4 | ||||
-rw-r--r-- | chrome/browser/instant/instant_tab.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.h | 3 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm | 2 | ||||
-rw-r--r-- | chrome/browser/ui/omnibox/omnibox_edit_model.cc | 8 | ||||
-rw-r--r-- | chrome/browser/ui/omnibox/omnibox_edit_model.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/views/location_bar/location_bar_view.cc | 15 | ||||
-rw-r--r-- | chrome/browser/ui/views/location_bar/location_bar_view.h | 1 |
15 files changed, 99 insertions, 33 deletions
diff --git a/chrome/browser/instant/instant_client.cc b/chrome/browser/instant/instant_client.cc index 1582a97..aa46868 100644 --- a/chrome/browser/instant/instant_client.cc +++ b/chrome/browser/instant/instant_client.cc @@ -36,8 +36,12 @@ void InstantClient::Cancel(const string16& text) { Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text)); } -void InstantClient::SetOmniboxBounds(const gfx::Rect& bounds) { - Send(new ChromeViewMsg_SearchBoxResize(routing_id(), bounds)); +void InstantClient::SetPopupBounds(const gfx::Rect& bounds) { + Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds)); +} + +void InstantClient::SetMarginSize(const int start, const int end) { + Send(new ChromeViewMsg_SearchBoxMarginChange(routing_id(), start, end)); } void InstantClient::DetermineIfPageSupportsInstant() { diff --git a/chrome/browser/instant/instant_client.h b/chrome/browser/instant/instant_client.h index 8a4b54f..0f44868 100644 --- a/chrome/browser/instant/instant_client.h +++ b/chrome/browser/instant/instant_client.h @@ -99,7 +99,10 @@ class InstantClient : public content::WebContentsObserver { // Tells the page the bounds of the omnibox dropdown (in screen coordinates). // This is used by the page to offset the results to avoid them being covered // by the omnibox dropdown. - void SetOmniboxBounds(const gfx::Rect& bounds); + void SetPopupBounds(const gfx::Rect& bounds); + + // Tells the page what size start and end margins to use. + void SetMarginSize(const int start, const int end); // Tells the renderer to determine if the page supports the Instant API, which // results in a call to InstantSupportDetermined() when the reply is received. diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 6dbc404..7ec753c 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -157,6 +157,8 @@ 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) { } @@ -354,24 +356,36 @@ bool InstantController::Update(const AutocompleteMatch& match, // TODO(tonyg): This method only fires when the omnibox bounds change. It also // needs to fire when the preview bounds change (e.g.: open/close info bar). -void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { +void InstantController::SetPopupBounds(const gfx::Rect& bounds) { if (!extended_enabled_ && !instant_enabled_) return; - if (omnibox_bounds_ == bounds) + if (popup_bounds_ == bounds) return; - omnibox_bounds_ = bounds; - if (omnibox_bounds_.height() > last_omnibox_bounds_.height()) { + popup_bounds_ = bounds; + if (popup_bounds_.height() > last_popup_bounds_.height()) { update_bounds_timer_.Stop(); - SendBoundsToPage(); + SendPopupBoundsToPage(); } else if (!update_bounds_timer_.IsRunning()) { update_bounds_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, - &InstantController::SendBoundsToPage); + &InstantController::SendPopupBoundsToPage); } } +void InstantController::SetMarginSize(int start, int end) { + if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) + return; + + start_margin_ = start; + end_margin_ = end; + if (loader_) + loader_->SetMarginSize(start_margin_, end_margin_); + if (instant_tab_) + instant_tab_->SetMarginSize(start_margin_, end_margin_); +} + void InstantController::HandleAutocompleteResults( const std::vector<AutocompleteProvider*>& providers) { if (!extended_enabled_) @@ -869,6 +883,7 @@ bool InstantController::ResetLoader(const TemplateURL* template_url, loader_->SetDisplayInstantResults(instant_enabled_); loader_->SearchModeChanged(search_mode_); loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); + loader_->SetMarginSize(start_margin_, end_margin_); } // Restart the stale loader timer. @@ -911,6 +926,7 @@ void InstantController::ResetInstantTab() { instant_tab_.reset(new InstantTab(this, active_tab)); instant_tab_->Init(); instant_tab_->SetDisplayInstantResults(instant_enabled_); + instant_tab_->SetMarginSize(start_margin_, end_margin_); } // Hide the |loader_| since we are now using |instant_tab_| instead. @@ -1027,14 +1043,14 @@ void InstantController::ShowLoader(InstantShownReason reason, CommitIfPossible(INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION); } -void InstantController::SendBoundsToPage() { - if (last_omnibox_bounds_ == omnibox_bounds_ || !loader_ || +void InstantController::SendPopupBoundsToPage() { + if (last_popup_bounds_ == popup_bounds_ || !loader_ || loader_->is_pointer_down_from_activate()) return; - last_omnibox_bounds_ = omnibox_bounds_; + last_popup_bounds_ = popup_bounds_; gfx::Rect preview_bounds = browser_->GetInstantBounds(); - gfx::Rect intersection = gfx::IntersectRects(omnibox_bounds_, preview_bounds); + gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); // Translate into window coordinates. if (!intersection.IsEmpty()) { @@ -1051,7 +1067,7 @@ void InstantController::SendBoundsToPage() { DCHECK_LE(0, intersection.width()); DCHECK_LE(0, intersection.height()); - loader_->SetOmniboxBounds(intersection); + loader_->SetPopupBounds(intersection); } bool InstantController::GetInstantURL(const TemplateURL* template_url, diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 0e93bd01..2e1940e 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -64,8 +64,11 @@ class InstantController { bool omnibox_popup_is_open, bool escape_pressed); - // Sets the bounds of the omnibox dropdown, in screen coordinates. - void SetOmniboxBounds(const gfx::Rect& bounds); + // 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); // Send autocomplete results from |providers| to the preview page. void HandleAutocompleteResults( @@ -205,8 +208,8 @@ class InstantController { int height, InstantSizeUnits units); - // Send the omnibox dropdown bounds to the page. - void SendBoundsToPage(); + // Send the omnibox popup bounds to the page. + void SendPopupBoundsToPage(); // If |template_url| is a valid TemplateURL for use with Instant, fills in // |instant_url| and returns true; returns false otherwise. @@ -262,13 +265,19 @@ class InstantController { // The search model mode for the active tab. chrome::search::Mode search_mode_; - // Current omnibox bounds. - gfx::Rect omnibox_bounds_; + // Current omnibox popup bounds. + gfx::Rect popup_bounds_; + + // Last popup bounds passed to the page. + gfx::Rect last_popup_bounds_; + + // Size of the start-edge omnibox text area margin. + int start_margin_; - // Last bounds passed to the page. - gfx::Rect last_omnibox_bounds_; + // Size of the end-edge omnibox text area margin. + int end_margin_; - // Timer used to update the bounds of the omnibox. + // Timer used to update the bounds of the omnibox popup. base::OneShotTimer<InstantController> update_bounds_timer_; // Timer used to ensure that the Instant page does not get too stale. diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 906f750..9f9a85c 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -244,8 +244,12 @@ void InstantLoader::Cancel(const string16& text) { client_.Cancel(text); } -void InstantLoader::SetOmniboxBounds(const gfx::Rect& bounds) { - client_.SetOmniboxBounds(bounds); +void InstantLoader::SetPopupBounds(const gfx::Rect& bounds) { + client_.SetPopupBounds(bounds); +} + +void InstantLoader::SetMarginSize(int start, int end) { + client_.SetMarginSize(start, end); } void InstantLoader::SendAutocompleteResults( diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index 6694cd3..618a4fc 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -93,7 +93,8 @@ class InstantLoader : public InstantClient::Delegate, bool verbatim); void Submit(const string16& text); void Cancel(const string16& text); - void SetOmniboxBounds(const gfx::Rect& bounds); + void SetPopupBounds(const gfx::Rect& bounds); + void SetMarginSize(int start, int end); void SendAutocompleteResults( const std::vector<InstantAutocompleteResult>& results); void UpOrDownKeyPressed(int count); diff --git a/chrome/browser/instant/instant_tab.cc b/chrome/browser/instant/instant_tab.cc index f9166d3..33cfe62 100644 --- a/chrome/browser/instant/instant_tab.cc +++ b/chrome/browser/instant/instant_tab.cc @@ -46,6 +46,10 @@ void InstantTab::UpOrDownKeyPressed(int count) { client_.UpOrDownKeyPressed(count); } +void InstantTab::SetMarginSize(int start, int end) { + client_.SetMarginSize(start, end); +} + void InstantTab::SetSuggestions( const std::vector<InstantSuggestion>& suggestions) { InstantSupportDetermined(true); diff --git a/chrome/browser/instant/instant_tab.h b/chrome/browser/instant/instant_tab.h index 1e9dcaf..2e0321a 100644 --- a/chrome/browser/instant/instant_tab.h +++ b/chrome/browser/instant/instant_tab.h @@ -44,6 +44,7 @@ class InstantTab : public InstantClient::Delegate { const std::vector<InstantAutocompleteResult>& results); void SetDisplayInstantResults(bool display_instant_results); void UpOrDownKeyPressed(int count); + void SetMarginSize(int start, int end); private: // Overridden from InstantClient::Delegate: diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index f5aee48..ba89cdf 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -171,6 +171,10 @@ void BrowserInstantController::OpenURLInCurrentTab( false)); } +void BrowserInstantController::SetMarginSize(int start, int end) { + instant_.SetMarginSize(start, end); +} + void BrowserInstantController::ResetInstant() { instant_.SetInstantEnabled(IsInstantEnabled(browser_->profile())); } diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h index e66ff5f..401cfbd 100644 --- a/chrome/browser/ui/browser_instant_controller.h +++ b/chrome/browser/ui/browser_instant_controller.h @@ -87,6 +87,9 @@ class BrowserInstantController : public content::NotificationObserver, // Invoked by the InstantController when it wants to open a URL. void OpenURLInCurrentTab(const GURL& url, content::PageTransition transition); + // Sets the start and end margins of the omnibox text area. + void SetMarginSize(int start, int end); + private: // Sets the value of |instant_| based on value from profile. Invoked // on pref change. diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm index 40c571e..3f7e7b9 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm @@ -930,7 +930,7 @@ void OmniboxViewMac::OnFrameChanged() { // things even cheaper by refactoring between the popup-placement // code and the matrix-population code. popup_view_->UpdatePopupAppearance(); - model()->PopupBoundsChangedTo(popup_view_->GetTargetBounds()); + model()->OnPopupBoundsChanged(popup_view_->GetTargetBounds()); // Give controller a chance to rearrange decorations. model()->OnChanged(); diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index 507cf65..b1e489d 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -1027,10 +1027,10 @@ bool OmniboxEditModel::OnAfterPossibleChange(const string16& old_text, MaybeAcceptKeywordBySpace(user_text_)); } -void OmniboxEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { +void OmniboxEditModel::OnPopupBoundsChanged(const gfx::Rect& bounds) { InstantController* instant = controller_->GetInstant(); if (instant) - instant->SetOmniboxBounds(bounds); + instant->SetPopupBounds(bounds); } void OmniboxEditModel::OnResultChanged(bool default_match_changed) { @@ -1067,14 +1067,14 @@ void OmniboxEditModel::OnResultChanged(bool default_match_changed) { } if (popup_->IsOpen()) { - PopupBoundsChangedTo(popup_->view()->GetTargetBounds()); + OnPopupBoundsChanged(popup_->view()->GetTargetBounds()); } else if (was_open) { // Accepts the temporary text as the user text, because it makes little // sense to have temporary text when the popup is closed. InternalSetUserText(UserTextFromDisplayText(view_->GetText())); has_temporary_text_ = false; is_temporary_text_set_by_instant_ = false; - PopupBoundsChangedTo(gfx::Rect()); + OnPopupBoundsChanged(gfx::Rect()); NotifySearchTabHelper(); } diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.h b/chrome/browser/ui/omnibox/omnibox_edit_model.h index 7952ef7..7524dc7 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.h +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.h @@ -318,8 +318,9 @@ class OmniboxEditModel : public AutocompleteControllerDelegate { bool just_deleted_text, bool allow_keyword_ui_change); - // Invoked when the popup is going to change its bounds to |bounds|. - void PopupBoundsChangedTo(const gfx::Rect& bounds); + // Invoked when the popup has changed its bounds to |bounds|. |bounds| here + // is in screen coordinates. + void OnPopupBoundsChanged(const gfx::Rect& bounds); private: enum PasteState { 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 860c75b..9714e3c 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -8,6 +8,7 @@ #include <map> #include "base/command_line.h" +#include "base/i18n/rtl.h" #include "base/stl_util.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" @@ -26,6 +27,7 @@ #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_instant_controller.h" #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/omnibox/location_bar_util.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" @@ -1368,6 +1370,19 @@ bool LocationBarView::HasFocus() const { return location_entry_->model()->has_focus(); } +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); + } +} + void LocationBarView::WriteDragDataForView(views::View* sender, const gfx::Point& press_pt, OSExchangeData* data) { diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index a42bbd0..abccf47 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -271,6 +271,7 @@ class LocationBarView : public LocationBar, const ui::KeyEvent& event) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual bool HasFocus() const OVERRIDE; + virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; // Overridden from views::DragController: virtual void WriteDragDataForView(View* sender, |