Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: chrome/renderer/searchbox/searchbox.cc

Issue 12771013: Instant: Make clicks on Most Visited items work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cancel Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/searchbox/searchbox.h ('k') | chrome/renderer/searchbox/searchbox_extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 #include "chrome/renderer/searchbox/searchbox_extension.h" 10 #include "chrome/renderer/searchbox/searchbox_extension.h"
(...skipping 16 matching lines...) Expand all
27 content::RenderViewObserverTracker<SearchBox>(render_view), 27 content::RenderViewObserverTracker<SearchBox>(render_view),
28 verbatim_(false), 28 verbatim_(false),
29 selection_start_(0), 29 selection_start_(0),
30 selection_end_(0), 30 selection_end_(0),
31 results_base_(0), 31 results_base_(0),
32 start_margin_(0), 32 start_margin_(0),
33 last_results_base_(0), 33 last_results_base_(0),
34 is_key_capture_enabled_(false), 34 is_key_capture_enabled_(false),
35 display_instant_results_(false), 35 display_instant_results_(false),
36 omnibox_font_size_(0), 36 omnibox_font_size_(0),
37 last_restricted_id_(0) { 37 last_most_visited_item_id_(0) {
38 } 38 }
39 39
40 SearchBox::~SearchBox() { 40 SearchBox::~SearchBox() {
41 } 41 }
42 42
43 void SearchBox::SetSuggestions( 43 void SearchBox::SetSuggestions(
44 const std::vector<InstantSuggestion>& suggestions) { 44 const std::vector<InstantSuggestion>& suggestions) {
45 if (!suggestions.empty() && 45 if (!suggestions.empty() &&
46 suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) { 46 suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) {
47 query_ = suggestions[0].text; 47 query_ = suggestions[0].text;
(...skipping 29 matching lines...) Expand all
77 } 77 }
78 78
79 void SearchBox::NavigateToURL(const GURL& url, 79 void SearchBox::NavigateToURL(const GURL& url,
80 content::PageTransition transition, 80 content::PageTransition transition,
81 WindowOpenDisposition disposition) { 81 WindowOpenDisposition disposition) {
82 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate( 82 render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate(
83 render_view()->GetRoutingID(), render_view()->GetPageId(), 83 render_view()->GetRoutingID(), render_view()->GetPageId(),
84 url, transition, disposition)); 84 url, transition, disposition));
85 } 85 }
86 86
87 void SearchBox::DeleteMostVisitedItem(int restrict_id) { 87 void SearchBox::DeleteMostVisitedItem(int most_visited_item_id) {
88 string16 url = RestrictedIdToURL(restrict_id); 88 string16 url = MostVisitedItemIDToURL(most_visited_item_id);
89 render_view()->Send(new ChromeViewHostMsg_InstantDeleteMostVisitedItem( 89 render_view()->Send(new ChromeViewHostMsg_InstantDeleteMostVisitedItem(
90 render_view()->GetRoutingID(), GURL(url))); 90 render_view()->GetRoutingID(), GURL(url)));
91 } 91 }
92 92
93 void SearchBox::UndoMostVisitedDeletion(int restrict_id) { 93 void SearchBox::UndoMostVisitedDeletion(int most_visited_item_id) {
94 string16 url = RestrictedIdToURL(restrict_id); 94 string16 url = MostVisitedItemIDToURL(most_visited_item_id);
95 render_view()->Send(new ChromeViewHostMsg_InstantUndoMostVisitedDeletion( 95 render_view()->Send(new ChromeViewHostMsg_InstantUndoMostVisitedDeletion(
96 render_view()->GetRoutingID(), GURL(url))); 96 render_view()->GetRoutingID(), GURL(url)));
97 } 97 }
98 98
99 void SearchBox::UndoAllMostVisitedDeletions() { 99 void SearchBox::UndoAllMostVisitedDeletions() {
100 render_view()->Send(new ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions( 100 render_view()->Send(new ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions(
101 render_view()->GetRoutingID())); 101 render_view()->GetRoutingID()));
102 } 102 }
103 103
104 int SearchBox::GetStartMargin() const { 104 int SearchBox::GetStartMargin() const {
(...skipping 12 matching lines...) Expand all
117 SearchBox::GetAutocompleteResults() { 117 SearchBox::GetAutocompleteResults() {
118 // Remember the last requested autocomplete_results to account for race 118 // Remember the last requested autocomplete_results to account for race
119 // conditions between autocomplete providers returning new data and the user 119 // conditions between autocomplete providers returning new data and the user
120 // clicking on a suggestion. 120 // clicking on a suggestion.
121 last_autocomplete_results_ = autocomplete_results_; 121 last_autocomplete_results_ = autocomplete_results_;
122 last_results_base_ = results_base_; 122 last_results_base_ = results_base_;
123 return autocomplete_results_; 123 return autocomplete_results_;
124 } 124 }
125 125
126 const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId( 126 const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId(
127 size_t restricted_id) const { 127 size_t autocomplete_result_id) const {
128 if (restricted_id < last_results_base_ || 128 if (autocomplete_result_id < last_results_base_ ||
129 restricted_id >= last_results_base_ + last_autocomplete_results_.size()) 129 autocomplete_result_id >=
130 last_results_base_ + last_autocomplete_results_.size())
130 return NULL; 131 return NULL;
131 return &last_autocomplete_results_[restricted_id - last_results_base_]; 132 return &last_autocomplete_results_[
133 autocomplete_result_id - last_results_base_];
132 } 134 }
133 135
134 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() { 136 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
135 return theme_info_; 137 return theme_info_;
136 } 138 }
137 139
138 bool SearchBox::OnMessageReceived(const IPC::Message& message) { 140 bool SearchBox::OnMessageReceived(const IPC::Message& message) {
139 bool handled = true; 141 bool handled = true;
140 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) 142 IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
141 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) 143 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 358 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
357 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( 359 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged(
358 render_view()->GetWebView()->mainFrame()); 360 render_view()->GetWebView()->mainFrame());
359 } 361 }
360 } 362 }
361 363
362 const std::vector<MostVisitedItem>& SearchBox::GetMostVisitedItems() { 364 const std::vector<MostVisitedItem>& SearchBox::GetMostVisitedItems() {
363 return most_visited_items_; 365 return most_visited_items_;
364 } 366 }
365 367
366 int SearchBox::UrlToRestrictedId(string16 url) { 368 int SearchBox::URLToMostVisitedItemID(string16 url) {
367 if (url_to_restricted_id_map_[url]) 369 if (url_to_most_visited_item_id_map_[url])
368 return url_to_restricted_id_map_[url]; 370 return url_to_most_visited_item_id_map_[url];
369 371
370 last_restricted_id_++; 372 last_most_visited_item_id_++;
371 url_to_restricted_id_map_[url] = last_restricted_id_; 373 url_to_most_visited_item_id_map_[url] = last_most_visited_item_id_;
372 restricted_id_to_url_map_[last_restricted_id_] = url; 374 most_visited_item_id_to_url_map_[last_most_visited_item_id_] = url;
373 375
374 return last_restricted_id_; 376 return last_most_visited_item_id_;
375 } 377 }
376 378
377 string16 SearchBox::RestrictedIdToURL(int id) { 379 string16 SearchBox::MostVisitedItemIDToURL(int most_visited_item_id) {
378 return restricted_id_to_url_map_[id]; 380 return most_visited_item_id_to_url_map_[most_visited_item_id];
379 } 381 }
380 382
381 string16 SearchBox::GenerateThumbnailUrl(int id) { 383 string16 SearchBox::GenerateThumbnailUrl(int most_visited_item_id) {
382 std::ostringstream ostr; 384 std::ostringstream ostr;
383 ostr << kThumbnailUrlPrefix << id; 385 ostr << kThumbnailUrlPrefix << most_visited_item_id;
384 GURL url = GURL(ostr.str()); 386 GURL url = GURL(ostr.str());
385 return UTF8ToUTF16(url.spec()); 387 return UTF8ToUTF16(url.spec());
386 } 388 }
387 389
388 string16 SearchBox::GenerateFaviconUrl(int id) { 390 string16 SearchBox::GenerateFaviconUrl(int most_visited_item_id) {
389 std::ostringstream ostr; 391 std::ostringstream ostr;
390 ostr << kFaviconUrlPrefix << id; 392 ostr << kFaviconUrlPrefix << most_visited_item_id;
391 GURL url = GURL(ostr.str()); 393 GURL url = GURL(ostr.str());
392 return UTF8ToUTF16(url.spec()); 394 return UTF8ToUTF16(url.spec());
393 } 395 }
OLDNEW
« no previous file with comments | « chrome/renderer/searchbox/searchbox.h ('k') | chrome/renderer/searchbox/searchbox_extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698