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

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

Issue 10918289: Instant extended API: Make arrow up/down work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Hackiness noted Created 8 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 key_code_(0) {
20 } 19 }
21 20
22 SearchBox::~SearchBox() { 21 SearchBox::~SearchBox() {
23 } 22 }
24 23
25 void SearchBox::SetSuggestions( 24 void SearchBox::SetSuggestions(
26 const std::vector<InstantSuggestion>& suggestions) { 25 const std::vector<InstantSuggestion>& suggestions) {
27 if (!suggestions.empty() && 26 if (!suggestions.empty() &&
28 suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) { 27 suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) {
29 query_ = suggestions[0].text; 28 query_ = suggestions[0].text;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 bool handled = true; 60 bool handled = true;
62 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) 61 IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
63 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) 62 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
64 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) 63 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit)
65 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) 64 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel)
66 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) 65 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize)
67 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, 66 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
68 OnDetermineIfPageSupportsInstant) 67 OnDetermineIfPageSupportsInstant)
69 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, 68 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults,
70 OnAutocompleteResults) 69 OnAutocompleteResults)
71 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyPress, OnKeyPress) 70 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed,
71 OnUpOrDownKeyPressed)
72 IPC_MESSAGE_UNHANDLED(handled = false) 72 IPC_MESSAGE_UNHANDLED(handled = false)
73 IPC_END_MESSAGE_MAP() 73 IPC_END_MESSAGE_MAP()
74 return handled; 74 return handled;
75 } 75 }
76 76
77 void SearchBox::OnChange(const string16& query, 77 void SearchBox::OnChange(const string16& query,
78 bool verbatim, 78 bool verbatim,
79 size_t selection_start, 79 size_t selection_start,
80 size_t selection_end) { 80 size_t selection_end) {
81 query_ = query; 81 query_ = query;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void SearchBox::OnAutocompleteResults( 130 void SearchBox::OnAutocompleteResults(
131 const std::vector<InstantAutocompleteResult>& results) { 131 const std::vector<InstantAutocompleteResult>& results) {
132 results_base_ += autocomplete_results_.size(); 132 results_base_ += autocomplete_results_.size();
133 autocomplete_results_ = results; 133 autocomplete_results_ = results;
134 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 134 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
135 extensions_v8::SearchBoxExtension::DispatchAutocompleteResults( 135 extensions_v8::SearchBoxExtension::DispatchAutocompleteResults(
136 render_view()->GetWebView()->mainFrame()); 136 render_view()->GetWebView()->mainFrame());
137 } 137 }
138 } 138 }
139 139
140 void SearchBox::OnKeyPress(int key_code) { 140 void SearchBox::OnUpOrDownKeyPressed(int count) {
141 key_code_ = key_code;
142 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 141 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
143 extensions_v8::SearchBoxExtension::DispatchKeyPress( 142 extensions_v8::SearchBoxExtension::DispatchUpOrDownKeyPress(
144 render_view()->GetWebView()->mainFrame()); 143 render_view()->GetWebView()->mainFrame(), count);
145 } 144 }
146 } 145 }
147 146
148 void SearchBox::Reset() { 147 void SearchBox::Reset() {
149 query_.clear(); 148 query_.clear();
150 verbatim_ = false; 149 verbatim_ = false;
151 selection_start_ = selection_end_ = 0; 150 selection_start_ = selection_end_ = 0;
152 results_base_ = 0; 151 results_base_ = 0;
153 rect_ = gfx::Rect(); 152 rect_ = gfx::Rect();
154 autocomplete_results_.clear(); 153 autocomplete_results_.clear();
155 key_code_ = 0;
156 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698