| 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 "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 9 #include "chrome/renderer/searchbox/searchbox_extension.h" | 9 #include "chrome/renderer/searchbox/searchbox_extension.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } | 21 } |
| 22 | 22 |
| 23 SearchBox::SearchBox(content::RenderView* render_view) | 23 SearchBox::SearchBox(content::RenderView* render_view) |
| 24 : content::RenderViewObserver(render_view), | 24 : content::RenderViewObserver(render_view), |
| 25 content::RenderViewObserverTracker<SearchBox>(render_view), | 25 content::RenderViewObserverTracker<SearchBox>(render_view), |
| 26 verbatim_(false), | 26 verbatim_(false), |
| 27 selection_start_(0), | 27 selection_start_(0), |
| 28 selection_end_(0), | 28 selection_end_(0), |
| 29 results_base_(0), | 29 results_base_(0), |
| 30 start_margin_(0), | 30 start_margin_(0), |
| 31 end_margin_(0), | |
| 32 last_results_base_(0), | 31 last_results_base_(0), |
| 33 is_key_capture_enabled_(false), | 32 is_key_capture_enabled_(false), |
| 34 display_instant_results_(false), | 33 display_instant_results_(false), |
| 35 omnibox_font_size_(0), | 34 omnibox_font_size_(0), |
| 36 last_restricted_id_(0) { | 35 last_restricted_id_(0) { |
| 37 } | 36 } |
| 38 | 37 |
| 39 SearchBox::~SearchBox() { | 38 SearchBox::~SearchBox() { |
| 40 } | 39 } |
| 41 | 40 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 91 |
| 93 void SearchBox::UndoAllMostVisitedDeletions() { | 92 void SearchBox::UndoAllMostVisitedDeletions() { |
| 94 render_view()->Send(new ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions( | 93 render_view()->Send(new ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions( |
| 95 render_view()->GetRoutingID())); | 94 render_view()->GetRoutingID())); |
| 96 } | 95 } |
| 97 | 96 |
| 98 int SearchBox::GetStartMargin() const { | 97 int SearchBox::GetStartMargin() const { |
| 99 return static_cast<int>(start_margin_ / GetZoom()); | 98 return static_cast<int>(start_margin_ / GetZoom()); |
| 100 } | 99 } |
| 101 | 100 |
| 102 int SearchBox::GetEndMargin() const { | |
| 103 return static_cast<int>(end_margin_ / GetZoom()); | |
| 104 } | |
| 105 | |
| 106 gfx::Rect SearchBox::GetPopupBounds() const { | 101 gfx::Rect SearchBox::GetPopupBounds() const { |
| 107 double zoom = GetZoom(); | 102 double zoom = GetZoom(); |
| 108 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), | 103 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), |
| 109 static_cast<int>(popup_bounds_.y() / zoom), | 104 static_cast<int>(popup_bounds_.y() / zoom), |
| 110 static_cast<int>(popup_bounds_.width() / zoom), | 105 static_cast<int>(popup_bounds_.width() / zoom), |
| 111 static_cast<int>(popup_bounds_.height() / zoom)); | 106 static_cast<int>(popup_bounds_.height() / zoom)); |
| 112 } | 107 } |
| 113 | 108 |
| 114 const std::vector<InstantAutocompleteResult>& | 109 const std::vector<InstantAutocompleteResult>& |
| 115 SearchBox::GetAutocompleteResults() { | 110 SearchBox::GetAutocompleteResults() { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 204 |
| 210 void SearchBox::OnPopupResize(const gfx::Rect& bounds) { | 205 void SearchBox::OnPopupResize(const gfx::Rect& bounds) { |
| 211 popup_bounds_ = bounds; | 206 popup_bounds_ = bounds; |
| 212 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 207 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 213 DVLOG(1) << render_view() << " OnPopupResize"; | 208 DVLOG(1) << render_view() << " OnPopupResize"; |
| 214 extensions_v8::SearchBoxExtension::DispatchResize( | 209 extensions_v8::SearchBoxExtension::DispatchResize( |
| 215 render_view()->GetWebView()->mainFrame()); | 210 render_view()->GetWebView()->mainFrame()); |
| 216 } | 211 } |
| 217 } | 212 } |
| 218 | 213 |
| 219 void SearchBox::OnMarginChange(int start, int end) { | 214 void SearchBox::OnMarginChange(int margin, int width) { |
| 220 start_margin_ = start; | 215 start_margin_ = margin; |
| 221 end_margin_ = end; | 216 |
| 217 // Override only the width parameter of the popup bounds. |
| 218 popup_bounds_.set_width(width); |
| 219 |
| 222 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 220 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 223 extensions_v8::SearchBoxExtension::DispatchMarginChange( | 221 extensions_v8::SearchBoxExtension::DispatchMarginChange( |
| 224 render_view()->GetWebView()->mainFrame()); | 222 render_view()->GetWebView()->mainFrame()); |
| 225 } | 223 } |
| 226 } | 224 } |
| 227 | 225 |
| 228 void SearchBox::OnDetermineIfPageSupportsInstant() { | 226 void SearchBox::OnDetermineIfPageSupportsInstant() { |
| 229 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 227 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 230 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( | 228 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
| 231 render_view()->GetWebView()->mainFrame()); | 229 render_view()->GetWebView()->mainFrame()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 303 } |
| 306 | 304 |
| 307 void SearchBox::Reset() { | 305 void SearchBox::Reset() { |
| 308 query_.clear(); | 306 query_.clear(); |
| 309 verbatim_ = false; | 307 verbatim_ = false; |
| 310 selection_start_ = 0; | 308 selection_start_ = 0; |
| 311 selection_end_ = 0; | 309 selection_end_ = 0; |
| 312 results_base_ = 0; | 310 results_base_ = 0; |
| 313 popup_bounds_ = gfx::Rect(); | 311 popup_bounds_ = gfx::Rect(); |
| 314 start_margin_ = 0; | 312 start_margin_ = 0; |
| 315 end_margin_ = 0; | |
| 316 autocomplete_results_.clear(); | 313 autocomplete_results_.clear(); |
| 317 is_key_capture_enabled_ = false; | 314 is_key_capture_enabled_ = false; |
| 318 theme_info_ = ThemeBackgroundInfo(); | 315 theme_info_ = ThemeBackgroundInfo(); |
| 319 // Don't reset display_instant_results_ to prevent clearing it on committed | 316 // Don't reset display_instant_results_ to prevent clearing it on committed |
| 320 // results pages in extended mode. Otherwise resetting it is a no-op because | 317 // results pages in extended mode. Otherwise resetting it is a no-op because |
| 321 // a new loader is created when it changes; see crbug.com/164662. | 318 // a new loader is created when it changes; see crbug.com/164662. |
| 322 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never | 319 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never |
| 323 // changes. | 320 // changes. |
| 324 } | 321 } |
| 325 | 322 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 GURL url = GURL(ostr.str()); | 355 GURL url = GURL(ostr.str()); |
| 359 return UTF8ToUTF16(url.spec()); | 356 return UTF8ToUTF16(url.spec()); |
| 360 } | 357 } |
| 361 | 358 |
| 362 string16 SearchBox::GenerateFaviconUrl(int id) { | 359 string16 SearchBox::GenerateFaviconUrl(int id) { |
| 363 std::ostringstream ostr; | 360 std::ostringstream ostr; |
| 364 ostr << kFaviconUrlPrefix << id; | 361 ostr << kFaviconUrlPrefix << id; |
| 365 GURL url = GURL(ostr.str()); | 362 GURL url = GURL(ostr.str()); |
| 366 return UTF8ToUTF16(url.spec()); | 363 return UTF8ToUTF16(url.spec()); |
| 367 } | 364 } |
| OLD | NEW |