| 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 display_instant_results_(false), | 22 display_instant_results_(false), |
| 24 omnibox_font_size_(0) { | 23 omnibox_font_size_(0) { |
| 25 } | 24 } |
| 26 | 25 |
| 27 SearchBox::~SearchBox() { | 26 SearchBox::~SearchBox() { |
| 28 } | 27 } |
| 29 | 28 |
| 30 void SearchBox::SetSuggestions( | 29 void SearchBox::SetSuggestions( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 content::PageTransition transition) { | 61 content::PageTransition transition) { |
| 63 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( | 62 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( |
| 64 render_view()->GetRoutingID(), render_view()->GetPageId(), | 63 render_view()->GetRoutingID(), render_view()->GetPageId(), |
| 65 url, transition)); | 64 url, transition)); |
| 66 } | 65 } |
| 67 | 66 |
| 68 int SearchBox::GetStartMargin() const { | 67 int SearchBox::GetStartMargin() const { |
| 69 return static_cast<int>(start_margin_ / GetZoom()); | 68 return static_cast<int>(start_margin_ / GetZoom()); |
| 70 } | 69 } |
| 71 | 70 |
| 72 int SearchBox::GetEndMargin() const { | |
| 73 return static_cast<int>(end_margin_ / GetZoom()); | |
| 74 } | |
| 75 | |
| 76 gfx::Rect SearchBox::GetPopupBounds() const { | 71 gfx::Rect SearchBox::GetPopupBounds() const { |
| 77 double zoom = GetZoom(); | 72 double zoom = GetZoom(); |
| 78 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), | 73 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), |
| 79 static_cast<int>(popup_bounds_.y() / zoom), | 74 static_cast<int>(popup_bounds_.y() / zoom), |
| 80 static_cast<int>(popup_bounds_.width() / zoom), | 75 static_cast<int>(popup_bounds_.width() / zoom), |
| 81 static_cast<int>(popup_bounds_.height() / zoom)); | 76 static_cast<int>(popup_bounds_.height() / zoom)); |
| 82 } | 77 } |
| 83 | 78 |
| 84 const std::vector<InstantAutocompleteResult>& | 79 const std::vector<InstantAutocompleteResult>& |
| 85 SearchBox::GetAutocompleteResults() { | 80 SearchBox::GetAutocompleteResults() { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 172 |
| 178 void SearchBox::OnPopupResize(const gfx::Rect& bounds) { | 173 void SearchBox::OnPopupResize(const gfx::Rect& bounds) { |
| 179 popup_bounds_ = bounds; | 174 popup_bounds_ = bounds; |
| 180 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 175 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 181 DVLOG(1) << render_view() << " OnPopupResize"; | 176 DVLOG(1) << render_view() << " OnPopupResize"; |
| 182 extensions_v8::SearchBoxExtension::DispatchResize( | 177 extensions_v8::SearchBoxExtension::DispatchResize( |
| 183 render_view()->GetWebView()->mainFrame()); | 178 render_view()->GetWebView()->mainFrame()); |
| 184 } | 179 } |
| 185 } | 180 } |
| 186 | 181 |
| 187 void SearchBox::OnMarginChange(int start, int end) { | 182 void SearchBox::OnMarginChange(int margin, int width) { |
| 188 start_margin_ = start; | 183 start_margin_ = margin; |
| 189 end_margin_ = end; | 184 |
| 185 // Override only the width parameter of the popup bounds. |
| 186 popup_bounds_.set_width(width); |
| 187 |
| 190 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 188 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 191 extensions_v8::SearchBoxExtension::DispatchMarginChange( | 189 extensions_v8::SearchBoxExtension::DispatchMarginChange( |
| 192 render_view()->GetWebView()->mainFrame()); | 190 render_view()->GetWebView()->mainFrame()); |
| 193 } | 191 } |
| 194 } | 192 } |
| 195 | 193 |
| 196 void SearchBox::OnDetermineIfPageSupportsInstant() { | 194 void SearchBox::OnDetermineIfPageSupportsInstant() { |
| 197 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 195 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 198 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( | 196 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
| 199 render_view()->GetWebView()->mainFrame()); | 197 render_view()->GetWebView()->mainFrame()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 271 } |
| 274 | 272 |
| 275 void SearchBox::Reset() { | 273 void SearchBox::Reset() { |
| 276 query_.clear(); | 274 query_.clear(); |
| 277 verbatim_ = false; | 275 verbatim_ = false; |
| 278 selection_start_ = 0; | 276 selection_start_ = 0; |
| 279 selection_end_ = 0; | 277 selection_end_ = 0; |
| 280 results_base_ = 0; | 278 results_base_ = 0; |
| 281 popup_bounds_ = gfx::Rect(); | 279 popup_bounds_ = gfx::Rect(); |
| 282 start_margin_ = 0; | 280 start_margin_ = 0; |
| 283 end_margin_ = 0; | |
| 284 autocomplete_results_.clear(); | 281 autocomplete_results_.clear(); |
| 285 is_key_capture_enabled_ = false; | 282 is_key_capture_enabled_ = false; |
| 286 theme_info_ = ThemeBackgroundInfo(); | 283 theme_info_ = ThemeBackgroundInfo(); |
| 287 // Don't reset display_instant_results_ to prevent clearing it on committed | 284 // Don't reset display_instant_results_ to prevent clearing it on committed |
| 288 // results pages in extended mode. Otherwise resetting it is a no-op because | 285 // results pages in extended mode. Otherwise resetting it is a no-op because |
| 289 // a new loader is created when it changes; see crbug.com/164662. | 286 // a new loader is created when it changes; see crbug.com/164662. |
| 290 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never | 287 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never |
| 291 // changes. | 288 // changes. |
| 292 } | 289 } |
| OLD | NEW |