| 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), | 20 width_(0), |
| 21 last_results_base_(0), | 21 last_results_base_(0), |
| 22 is_key_capture_enabled_(false), | 22 is_key_capture_enabled_(false), |
| 23 theme_area_height_(0), | 23 theme_area_height_(0), |
| 24 display_instant_results_(false), | 24 display_instant_results_(false), |
| 25 omnibox_font_size_(0) { | 25 omnibox_font_size_(0) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 SearchBox::~SearchBox() { | 28 SearchBox::~SearchBox() { |
| 29 } | 29 } |
| 30 | 30 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 content::PageTransition transition) { | 63 content::PageTransition transition) { |
| 64 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( | 64 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( |
| 65 render_view()->GetRoutingID(), render_view()->GetPageId(), | 65 render_view()->GetRoutingID(), render_view()->GetPageId(), |
| 66 url, transition)); | 66 url, transition)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 int SearchBox::GetStartMargin() const { | 69 int SearchBox::GetStartMargin() const { |
| 70 return static_cast<int>(start_margin_ / GetZoom()); | 70 return static_cast<int>(start_margin_ / GetZoom()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 int SearchBox::GetEndMargin() const { | 73 int SearchBox::GetWidth() const { |
| 74 return static_cast<int>(end_margin_ / GetZoom()); | 74 // Width set by a margin-change event takes precedence over the popup width. |
| 75 return static_cast<int>( |
| 76 (width_ ? width_ : popup_bounds_.width()) / GetZoom()); |
| 75 } | 77 } |
| 76 | 78 |
| 77 gfx::Rect SearchBox::GetPopupBounds() const { | 79 gfx::Rect SearchBox::GetPopupBounds() const { |
| 78 double zoom = GetZoom(); | 80 double zoom = GetZoom(); |
| 79 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), | 81 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), |
| 80 static_cast<int>(popup_bounds_.y() / zoom), | 82 static_cast<int>(popup_bounds_.y() / zoom), |
| 81 static_cast<int>(popup_bounds_.width() / zoom), | 83 static_cast<int>(popup_bounds_.width() / zoom), |
| 82 static_cast<int>(popup_bounds_.height() / zoom)); | 84 static_cast<int>(popup_bounds_.height() / zoom)); |
| 83 } | 85 } |
| 84 | 86 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 186 |
| 185 void SearchBox::OnPopupResize(const gfx::Rect& bounds) { | 187 void SearchBox::OnPopupResize(const gfx::Rect& bounds) { |
| 186 popup_bounds_ = bounds; | 188 popup_bounds_ = bounds; |
| 187 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 189 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 188 DVLOG(1) << render_view() << " OnPopupResize"; | 190 DVLOG(1) << render_view() << " OnPopupResize"; |
| 189 extensions_v8::SearchBoxExtension::DispatchResize( | 191 extensions_v8::SearchBoxExtension::DispatchResize( |
| 190 render_view()->GetWebView()->mainFrame()); | 192 render_view()->GetWebView()->mainFrame()); |
| 191 } | 193 } |
| 192 } | 194 } |
| 193 | 195 |
| 194 void SearchBox::OnMarginChange(int start, int end) { | 196 void SearchBox::OnMarginChange(int margin, int width) { |
| 195 start_margin_ = start; | 197 start_margin_ = margin; |
| 196 end_margin_ = end; | 198 width_ = width; |
| 197 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 199 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 198 extensions_v8::SearchBoxExtension::DispatchMarginChange( | 200 extensions_v8::SearchBoxExtension::DispatchMarginChange( |
| 199 render_view()->GetWebView()->mainFrame()); | 201 render_view()->GetWebView()->mainFrame()); |
| 200 } | 202 } |
| 201 } | 203 } |
| 202 | 204 |
| 203 void SearchBox::OnDetermineIfPageSupportsInstant() { | 205 void SearchBox::OnDetermineIfPageSupportsInstant() { |
| 204 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 206 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 205 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( | 207 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
| 206 render_view()->GetWebView()->mainFrame()); | 208 render_view()->GetWebView()->mainFrame()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 287 } |
| 286 | 288 |
| 287 void SearchBox::Reset() { | 289 void SearchBox::Reset() { |
| 288 query_.clear(); | 290 query_.clear(); |
| 289 verbatim_ = false; | 291 verbatim_ = false; |
| 290 selection_start_ = 0; | 292 selection_start_ = 0; |
| 291 selection_end_ = 0; | 293 selection_end_ = 0; |
| 292 results_base_ = 0; | 294 results_base_ = 0; |
| 293 popup_bounds_ = gfx::Rect(); | 295 popup_bounds_ = gfx::Rect(); |
| 294 start_margin_ = 0; | 296 start_margin_ = 0; |
| 295 end_margin_ = 0; | 297 width_ = 0; |
| 296 autocomplete_results_.clear(); | 298 autocomplete_results_.clear(); |
| 297 is_key_capture_enabled_ = false; | 299 is_key_capture_enabled_ = false; |
| 298 mode_ = chrome::search::Mode(); | 300 mode_ = chrome::search::Mode(); |
| 299 theme_info_ = ThemeBackgroundInfo(); | 301 theme_info_ = ThemeBackgroundInfo(); |
| 300 theme_area_height_ = 0; | 302 theme_area_height_ = 0; |
| 301 // Don't reset display_instant_results_ to prevent clearing it on committed | 303 // 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 | 304 // 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. | 305 // 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 | 306 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never |
| 305 // changes. | 307 // changes. |
| 306 } | 308 } |
| OLD | NEW |