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

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

Issue 11413018: alternate ntp: implement searchbox api for instant overlay to adopt themes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed sreeram's comments, fixed to not set theme fields if no theme Created 8 years, 1 month 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.h » ('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 (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 last_results_base_(0), 19 last_results_base_(0),
20 active_tab_is_ntp_(false) { 20 active_tab_is_ntp_(false),
21 theme_area_height_(0) {
21 } 22 }
22 23
23 SearchBox::~SearchBox() { 24 SearchBox::~SearchBox() {
24 } 25 }
25 26
26 void SearchBox::SetSuggestions( 27 void SearchBox::SetSuggestions(
27 const std::vector<InstantSuggestion>& suggestions) { 28 const std::vector<InstantSuggestion>& suggestions) {
28 if (!suggestions.empty() && 29 if (!suggestions.empty() &&
29 suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) { 30 suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) {
30 query_ = suggestions[0].text; 31 query_ = suggestions[0].text;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 72 }
72 73
73 const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId( 74 const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId(
74 size_t restricted_id) const { 75 size_t restricted_id) const {
75 if (restricted_id < last_results_base_ || 76 if (restricted_id < last_results_base_ ||
76 restricted_id >= last_results_base_ + last_autocomplete_results_.size()) 77 restricted_id >= last_results_base_ + last_autocomplete_results_.size())
77 return NULL; 78 return NULL;
78 return &last_autocomplete_results_[restricted_id - last_results_base_]; 79 return &last_autocomplete_results_[restricted_id - last_results_base_];
79 } 80 }
80 81
82 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
83 return theme_info_;
84 }
85
86 int SearchBox::GetThemeAreaHeight() {
87 return theme_area_height_;
88 }
89
81 bool SearchBox::OnMessageReceived(const IPC::Message& message) { 90 bool SearchBox::OnMessageReceived(const IPC::Message& message) {
82 bool handled = true; 91 bool handled = true;
83 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) 92 IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
84 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) 93 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
85 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) 94 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit)
86 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) 95 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel)
87 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) 96 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize)
88 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, 97 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
89 OnDetermineIfPageSupportsInstant) 98 OnDetermineIfPageSupportsInstant)
90 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, 99 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults,
91 OnAutocompleteResults) 100 OnAutocompleteResults)
92 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, 101 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed,
93 OnUpOrDownKeyPressed) 102 OnUpOrDownKeyPressed)
94 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxActiveTabModeChanged, 103 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxActiveTabModeChanged,
95 OnActiveTabModeChanged) 104 OnActiveTabModeChanged)
105 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged,
106 OnThemeChanged)
107 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeAreaHeightChanged,
108 OnThemeAreaHeightChanged)
96 IPC_MESSAGE_UNHANDLED(handled = false) 109 IPC_MESSAGE_UNHANDLED(handled = false)
97 IPC_END_MESSAGE_MAP() 110 IPC_END_MESSAGE_MAP()
98 return handled; 111 return handled;
99 } 112 }
100 113
101 void SearchBox::OnChange(const string16& query, 114 void SearchBox::OnChange(const string16& query,
102 bool verbatim, 115 bool verbatim,
103 size_t selection_start, 116 size_t selection_start,
104 size_t selection_end) { 117 size_t selection_end) {
105 query_ = query; 118 query_ = query;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 182 }
170 183
171 void SearchBox::OnActiveTabModeChanged(bool active_tab_is_ntp) { 184 void SearchBox::OnActiveTabModeChanged(bool active_tab_is_ntp) {
172 active_tab_is_ntp_ = active_tab_is_ntp; 185 active_tab_is_ntp_ = active_tab_is_ntp;
173 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 186 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
174 extensions_v8::SearchBoxExtension::DispatchContextChange( 187 extensions_v8::SearchBoxExtension::DispatchContextChange(
175 render_view()->GetWebView()->mainFrame()); 188 render_view()->GetWebView()->mainFrame());
176 } 189 }
177 } 190 }
178 191
192 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) {
193 theme_info_ = theme_info;
194 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
195 extensions_v8::SearchBoxExtension::DispatchThemeChange(
196 render_view()->GetWebView()->mainFrame());
197 }
198 }
199
200 void SearchBox::OnThemeAreaHeightChanged(int height) {
201 theme_area_height_ = height;
202 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
203 extensions_v8::SearchBoxExtension::DispatchThemeAreaHeightChange(
204 render_view()->GetWebView()->mainFrame());
205 }
206 }
207
179 void SearchBox::Reset() { 208 void SearchBox::Reset() {
180 query_.clear(); 209 query_.clear();
181 verbatim_ = false; 210 verbatim_ = false;
182 selection_start_ = 0; 211 selection_start_ = 0;
183 selection_end_ = 0; 212 selection_end_ = 0;
184 results_base_ = 0; 213 results_base_ = 0;
185 rect_ = gfx::Rect(); 214 rect_ = gfx::Rect();
186 autocomplete_results_.clear(); 215 autocomplete_results_.clear();
187 active_tab_is_ntp_ = false; 216 active_tab_is_ntp_ = false;
217 theme_info_ = ThemeBackgroundInfo();
218 theme_area_height_ = 0;
188 } 219 }
OLDNEW
« no previous file with comments | « chrome/renderer/searchbox/searchbox.h ('k') | chrome/renderer/searchbox/searchbox_extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698