 Chromium Code Reviews
 Chromium Code Reviews Issue 11359198:
  Implement the Instant extended API startMargin, endMargin, and rtl properties and the onmarginchang…  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 11359198:
  Implement the Instant extended API startMargin, endMargin, and rtl properties and the onmarginchang…  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: chrome/renderer/searchbox/searchbox.cc | 
| diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc | 
| index 1aba77a77a1516e98dd3e117469eb727ef7ca26f..3e019a932b708b83f44366fdcb4adbeb3e1f65ce 100644 | 
| --- a/chrome/renderer/searchbox/searchbox.cc | 
| +++ b/chrome/renderer/searchbox/searchbox.cc | 
| @@ -16,6 +16,8 @@ SearchBox::SearchBox(content::RenderView* render_view) | 
| selection_start_(0), | 
| selection_end_(0), | 
| results_base_(0), | 
| + start_margin_(0), | 
| + end_margin_(0), | 
| last_results_base_(0), | 
| theme_area_height_(0) { | 
| } | 
| @@ -44,20 +46,20 @@ 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)); | 
| +int SearchBox::GetStartMargin() const { | 
| + return static_cast<int>(start_margin_ / GetZoom()); | 
| +} | 
| + | 
| +int SearchBox::GetEndMargin() const { | 
| + return static_cast<int>(end_margin_ / GetZoom()); | 
| +} | 
| + | 
| +gfx::Rect SearchBox::GetPopupBounds() const { | 
| + double zoom = GetZoom(); | 
| + return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), | 
| + static_cast<int>(popup_bounds_.y() / zoom), | 
| + static_cast<int>(popup_bounds_.width() / zoom), | 
| + static_cast<int>(popup_bounds_.height() / zoom)); | 
| } | 
| const std::vector<InstantAutocompleteResult>& | 
| @@ -92,7 +94,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_SearchBoxMarginChange, OnMarginChange) | 
| IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, | 
| OnDetermineIfPageSupportsInstant) | 
| IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, | 
| @@ -146,14 +149,23 @@ 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::OnMarginChange(int start, int end) { | 
| + start_margin_ = start; | 
| + end_margin_ = end; | 
| + 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( | 
| @@ -210,9 +222,21 @@ void SearchBox::Reset() { | 
| selection_start_ = 0; | 
| selection_end_ = 0; | 
| results_base_ = 0; | 
| - rect_ = gfx::Rect(); | 
| + popup_bounds_ = gfx::Rect(); | 
| + start_margin_ = 0; | 
| + end_margin_ = 0; | 
| autocomplete_results_.clear(); | 
| mode_ = chrome::search::Mode(); | 
| theme_info_ = ThemeBackgroundInfo(); | 
| theme_area_height_ = 0; | 
| } | 
| + | 
| +double SearchBox::GetZoom() const { | 
| + WebKit::WebView* web_view = render_view()->GetWebView(); | 
| + if (web_view) { | 
| + double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel()); | 
| + if (zoom != 0) | 
| + return zoom; | 
| + } | 
| + return 1.0; | 
| +} | 
| 
sreeram
2012/11/29 19:22:49
Move this above Reset() to match the .h order.
 
melevin
2012/11/30 23:37:09
Done.
 |