| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/searchbox/searchbox.h" | 5 #include "chrome/renderer/searchbox/searchbox.h" |
| 6 | 6 |
| 7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
| 8 #include "chrome/renderer/searchbox/searchbox_extension.h" | 8 #include "chrome/renderer/searchbox/searchbox_extension.h" |
| 9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 11 | 11 |
| 12 SearchBox::SearchBox(content::RenderView* render_view) | 12 SearchBox::SearchBox(content::RenderView* render_view) |
| 13 : content::RenderViewObserver(render_view), | 13 : content::RenderViewObserver(render_view), |
| 14 content::RenderViewObserverTracker<SearchBox>(render_view), | 14 content::RenderViewObserverTracker<SearchBox>(render_view), |
| 15 verbatim_(false), | 15 verbatim_(false), |
| 16 selection_start_(0), | 16 selection_start_(0), |
| 17 selection_end_(0), | 17 selection_end_(0), |
| 18 results_base_(0), | 18 results_base_(0), |
| 19 start_margin_(0), | 19 start_margin_(0), |
| 20 end_margin_(0), | |
| 21 last_results_base_(0), | 20 last_results_base_(0), |
| 22 is_key_capture_enabled_(false), | 21 is_key_capture_enabled_(false), |
| 23 theme_area_height_(0), | 22 theme_area_height_(0), |
| 24 display_instant_results_(false), | 23 display_instant_results_(false), |
| 25 omnibox_font_size_(0) { | 24 omnibox_font_size_(0) { |
| 26 } | 25 } |
| 27 | 26 |
| 28 SearchBox::~SearchBox() { | 27 SearchBox::~SearchBox() { |
| 29 } | 28 } |
| 30 | 29 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 content::PageTransition transition) { | 62 content::PageTransition transition) { |
| 64 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( | 63 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( |
| 65 render_view()->GetRoutingID(), render_view()->GetPageId(), | 64 render_view()->GetRoutingID(), render_view()->GetPageId(), |
| 66 url, transition)); | 65 url, transition)); |
| 67 } | 66 } |
| 68 | 67 |
| 69 int SearchBox::GetStartMargin() const { | 68 int SearchBox::GetStartMargin() const { |
| 70 return static_cast<int>(start_margin_ / GetZoom()); | 69 return static_cast<int>(start_margin_ / GetZoom()); |
| 71 } | 70 } |
| 72 | 71 |
| 73 int SearchBox::GetEndMargin() const { | |
| 74 return static_cast<int>(end_margin_ / GetZoom()); | |
| 75 } | |
| 76 | |
| 77 gfx::Rect SearchBox::GetPopupBounds() const { | 72 gfx::Rect SearchBox::GetPopupBounds() const { |
| 78 double zoom = GetZoom(); | 73 double zoom = GetZoom(); |
| 79 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), | 74 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), |
| 80 static_cast<int>(popup_bounds_.y() / zoom), | 75 static_cast<int>(popup_bounds_.y() / zoom), |
| 81 static_cast<int>(popup_bounds_.width() / zoom), | 76 static_cast<int>(popup_bounds_.width() / zoom), |
| 82 static_cast<int>(popup_bounds_.height() / zoom)); | 77 static_cast<int>(popup_bounds_.height() / zoom)); |
| 83 } | 78 } |
| 84 | 79 |
| 85 const std::vector<InstantAutocompleteResult>& | 80 const std::vector<InstantAutocompleteResult>& |
| 86 SearchBox::GetAutocompleteResults() { | 81 SearchBox::GetAutocompleteResults() { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 179 |
| 185 void SearchBox::OnPopupResize(const gfx::Rect& bounds) { | 180 void SearchBox::OnPopupResize(const gfx::Rect& bounds) { |
| 186 popup_bounds_ = bounds; | 181 popup_bounds_ = bounds; |
| 187 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 182 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 188 DVLOG(1) << render_view() << " OnPopupResize"; | 183 DVLOG(1) << render_view() << " OnPopupResize"; |
| 189 extensions_v8::SearchBoxExtension::DispatchResize( | 184 extensions_v8::SearchBoxExtension::DispatchResize( |
| 190 render_view()->GetWebView()->mainFrame()); | 185 render_view()->GetWebView()->mainFrame()); |
| 191 } | 186 } |
| 192 } | 187 } |
| 193 | 188 |
| 194 void SearchBox::OnMarginChange(int start, int end) { | 189 void SearchBox::OnMarginChange(int margin, int width) { |
| 195 start_margin_ = start; | 190 start_margin_ = margin; |
| 196 end_margin_ = end; | 191 |
| 192 // Override only the width parameter of the popup bounds. |
| 193 popup_bounds_.set_width(width); |
| 194 |
| 197 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 195 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 198 extensions_v8::SearchBoxExtension::DispatchMarginChange( | 196 extensions_v8::SearchBoxExtension::DispatchMarginChange( |
| 199 render_view()->GetWebView()->mainFrame()); | 197 render_view()->GetWebView()->mainFrame()); |
| 200 } | 198 } |
| 201 } | 199 } |
| 202 | 200 |
| 203 void SearchBox::OnDetermineIfPageSupportsInstant() { | 201 void SearchBox::OnDetermineIfPageSupportsInstant() { |
| 204 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 202 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 205 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( | 203 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
| 206 render_view()->GetWebView()->mainFrame()); | 204 render_view()->GetWebView()->mainFrame()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 283 } |
| 286 | 284 |
| 287 void SearchBox::Reset() { | 285 void SearchBox::Reset() { |
| 288 query_.clear(); | 286 query_.clear(); |
| 289 verbatim_ = false; | 287 verbatim_ = false; |
| 290 selection_start_ = 0; | 288 selection_start_ = 0; |
| 291 selection_end_ = 0; | 289 selection_end_ = 0; |
| 292 results_base_ = 0; | 290 results_base_ = 0; |
| 293 popup_bounds_ = gfx::Rect(); | 291 popup_bounds_ = gfx::Rect(); |
| 294 start_margin_ = 0; | 292 start_margin_ = 0; |
| 295 end_margin_ = 0; | |
| 296 autocomplete_results_.clear(); | 293 autocomplete_results_.clear(); |
| 297 is_key_capture_enabled_ = false; | 294 is_key_capture_enabled_ = false; |
| 298 mode_ = chrome::search::Mode(); | 295 mode_ = chrome::search::Mode(); |
| 299 theme_info_ = ThemeBackgroundInfo(); | 296 theme_info_ = ThemeBackgroundInfo(); |
| 300 theme_area_height_ = 0; | 297 theme_area_height_ = 0; |
| 301 // Don't reset display_instant_results_ to prevent clearing it on committed | 298 // Don't reset display_instant_results_ to prevent clearing it on committed |
| 302 // results pages in extended mode. Otherwise resetting it is a no-op because | 299 // results pages in extended mode. Otherwise resetting it is a no-op because |
| 303 // a new loader is created when it changes; see crbug.com/164662. | 300 // a new loader is created when it changes; see crbug.com/164662. |
| 304 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never | 301 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never |
| 305 // changes. | 302 // changes. |
| 306 } | 303 } |
| OLD | NEW |