| OLD | NEW |
| 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" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId( | 74 const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId( |
| 75 size_t restricted_id) const { | 75 size_t restricted_id) const { |
| 76 if (restricted_id < last_results_base_ || | 76 if (restricted_id < last_results_base_ || |
| 77 restricted_id >= last_results_base_ + last_autocomplete_results_.size()) | 77 restricted_id >= last_results_base_ + last_autocomplete_results_.size()) |
| 78 return NULL; | 78 return NULL; |
| 79 return &last_autocomplete_results_[restricted_id - last_results_base_]; | 79 return &last_autocomplete_results_[restricted_id - last_results_base_]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() { |
| 83 return theme_info_; |
| 84 } |
| 85 |
| 86 int SearchBox::GetThemeAreaHeight() { |
| 87 return theme_area_height_; |
| 88 } |
| 89 |
| 82 bool SearchBox::OnMessageReceived(const IPC::Message& message) { | 90 bool SearchBox::OnMessageReceived(const IPC::Message& message) { |
| 83 bool handled = true; | 91 bool handled = true; |
| 84 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) | 92 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) |
| 85 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) | 93 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) |
| 86 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) | 94 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) |
| 87 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) | 95 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) |
| 88 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) | 96 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) |
| 89 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, | 97 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, |
| 90 OnDetermineIfPageSupportsInstant) | 98 OnDetermineIfPageSupportsInstant) |
| 91 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, | 99 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, |
| 92 OnAutocompleteResults) | 100 OnAutocompleteResults) |
| 93 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, | 101 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, |
| 94 OnUpOrDownKeyPressed) | 102 OnUpOrDownKeyPressed) |
| 95 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocus, OnFocus) | 103 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocus, OnFocus) |
| 96 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBlur, OnBlur) | 104 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBlur, OnBlur) |
| 97 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxActiveTabModeChanged, | 105 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxActiveTabModeChanged, |
| 98 OnActiveTabModeChanged) | 106 OnActiveTabModeChanged) |
| 107 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, |
| 108 OnThemeChanged) |
| 109 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeAreaHeightChanged, |
| 110 OnThemeAreaHeightChanged) |
| 99 IPC_MESSAGE_UNHANDLED(handled = false) | 111 IPC_MESSAGE_UNHANDLED(handled = false) |
| 100 IPC_END_MESSAGE_MAP() | 112 IPC_END_MESSAGE_MAP() |
| 101 return handled; | 113 return handled; |
| 102 } | 114 } |
| 103 | 115 |
| 104 void SearchBox::OnChange(const string16& query, | 116 void SearchBox::OnChange(const string16& query, |
| 105 bool verbatim, | 117 bool verbatim, |
| 106 size_t selection_start, | 118 size_t selection_start, |
| 107 size_t selection_end) { | 119 size_t selection_end) { |
| 108 query_ = query; | 120 query_ = query; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 200 } |
| 189 | 201 |
| 190 void SearchBox::OnActiveTabModeChanged(bool active_tab_is_ntp) { | 202 void SearchBox::OnActiveTabModeChanged(bool active_tab_is_ntp) { |
| 191 active_tab_is_ntp_ = active_tab_is_ntp; | 203 active_tab_is_ntp_ = active_tab_is_ntp; |
| 192 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 204 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 193 extensions_v8::SearchBoxExtension::DispatchContextChange( | 205 extensions_v8::SearchBoxExtension::DispatchContextChange( |
| 194 render_view()->GetWebView()->mainFrame()); | 206 render_view()->GetWebView()->mainFrame()); |
| 195 } | 207 } |
| 196 } | 208 } |
| 197 | 209 |
| 210 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { |
| 211 theme_info_ = theme_info; |
| 212 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 213 extensions_v8::SearchBoxExtension::DispatchThemeChange( |
| 214 render_view()->GetWebView()->mainFrame()); |
| 215 } |
| 216 } |
| 217 |
| 218 void SearchBox::OnThemeAreaHeightChanged(int height) { |
| 219 theme_area_height_ = height; |
| 220 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 221 extensions_v8::SearchBoxExtension::DispatchThemeAreaHeightChange( |
| 222 render_view()->GetWebView()->mainFrame()); |
| 223 } |
| 224 } |
| 225 |
| 198 void SearchBox::Reset() { | 226 void SearchBox::Reset() { |
| 199 query_.clear(); | 227 query_.clear(); |
| 200 verbatim_ = false; | 228 verbatim_ = false; |
| 201 selection_start_ = 0; | 229 selection_start_ = 0; |
| 202 selection_end_ = 0; | 230 selection_end_ = 0; |
| 203 results_base_ = 0; | 231 results_base_ = 0; |
| 204 rect_ = gfx::Rect(); | 232 rect_ = gfx::Rect(); |
| 205 autocomplete_results_.clear(); | 233 autocomplete_results_.clear(); |
| 206 is_focused_ = false; | 234 is_focused_ = false; |
| 207 active_tab_is_ntp_ = false; | 235 active_tab_is_ntp_ = false; |
| 208 } | 236 } |
| OLD | NEW |