| Index: chrome/renderer/searchbox/searchbox.cc
|
| diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
|
| index a41e4a9d865b710e8767937cbfbc20f4a620cc32..b052433290035d9386417aed887bbebf5189fd66 100644
|
| --- a/chrome/renderer/searchbox/searchbox.cc
|
| +++ b/chrome/renderer/searchbox/searchbox.cc
|
| @@ -45,20 +45,12 @@ void SearchBox::ShowInstantPreview(InstantShownReason reason,
|
| height, units));
|
| }
|
|
|
| -gfx::Rect SearchBox::GetRect() {
|
| - // Need to adjust for scale.
|
| - if (rect_.IsEmpty())
|
| - return rect_;
|
| - WebKit::WebView* web_view = render_view()->GetWebView();
|
| - if (!web_view)
|
| - return rect_;
|
| - double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel());
|
| - if (zoom == 0)
|
| - return rect_;
|
| - return gfx::Rect(static_cast<int>(static_cast<float>(rect_.x()) / zoom),
|
| - static_cast<int>(static_cast<float>(rect_.y()) / zoom),
|
| - static_cast<int>(static_cast<float>(rect_.width()) / zoom),
|
| - static_cast<int>(static_cast<float>(rect_.height()) / zoom));
|
| +gfx::Rect SearchBox::GetOmniboxBounds() {
|
| + return GetZoomedBounds(omnibox_bounds_);
|
| +}
|
| +
|
| +gfx::Rect SearchBox::GetPopupBounds() {
|
| + return GetZoomedBounds(popup_bounds_);
|
| }
|
|
|
| const std::vector<InstantAutocompleteResult>&
|
| @@ -85,7 +77,8 @@ bool SearchBox::OnMessageReceived(const IPC::Message& message) {
|
| IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
|
| IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit)
|
| IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel)
|
| - IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize)
|
| + IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPopupResize, OnPopupResize)
|
| + IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxOmniboxResize, OnOmniboxResize)
|
| IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
|
| OnDetermineIfPageSupportsInstant)
|
| IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults,
|
| @@ -137,14 +130,24 @@ void SearchBox::OnCancel(const string16& query) {
|
| Reset();
|
| }
|
|
|
| -void SearchBox::OnResize(const gfx::Rect& bounds) {
|
| - rect_ = bounds;
|
| +void SearchBox::OnPopupResize(const gfx::Rect& bounds) {
|
| + popup_bounds_ = bounds;
|
| if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
|
| extensions_v8::SearchBoxExtension::DispatchResize(
|
| render_view()->GetWebView()->mainFrame());
|
| }
|
| }
|
|
|
| +void SearchBox::OnOmniboxResize(const gfx::Rect& bounds) {
|
| + omnibox_bounds_ = bounds;
|
| +
|
| + // The omnibox bounds are used to compute the Instant page side margins.
|
| + if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
|
| + extensions_v8::SearchBoxExtension::DispatchMarginChange(
|
| + render_view()->GetWebView()->mainFrame());
|
| + }
|
| +}
|
| +
|
| void SearchBox::OnDetermineIfPageSupportsInstant() {
|
| if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
|
| bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
|
| @@ -200,7 +203,26 @@ void SearchBox::Reset() {
|
| verbatim_ = false;
|
| selection_start_ = selection_end_ = 0;
|
| results_base_ = 0;
|
| - rect_ = gfx::Rect();
|
| + popup_bounds_ = gfx::Rect();
|
| + omnibox_bounds_ = gfx::Rect();
|
| autocomplete_results_.clear();
|
| is_focused_ = false;
|
| }
|
| +
|
| +// Returns the input |bounds| rect scaled by the current zoom level.
|
| +gfx::Rect SearchBox::GetZoomedBounds(const gfx::Rect bounds) {
|
| + if (!bounds.IsEmpty()) {
|
| + WebKit::WebView* web_view = render_view()->GetWebView();
|
| + if (web_view) {
|
| + double zoom =
|
| + WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel());
|
| + if (zoom != 0) {
|
| + return gfx::Rect(static_cast<int>(bounds.x() / zoom),
|
| + static_cast<int>(bounds.y() / zoom),
|
| + static_cast<int>(bounds.width() / zoom),
|
| + static_cast<int>(bounds.height() / zoom));
|
| + }
|
| + }
|
| + }
|
| + return bounds;
|
| +}
|
|
|