Fixed service side implementation of glTexStorage2DEXT to only initialize the number of
[chromium-blink-merge.git] / chrome / renderer / searchbox.cc
blobc58b1a6e362fa1513f5e5795b25717396e21b9ea
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/searchbox.h"
7 #include "chrome/common/render_messages.h"
8 #include "chrome/renderer/searchbox_extension.h"
9 #include "content/public/renderer/render_view.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
12 using WebKit::WebView;
14 SearchBox::SearchBox(content::RenderView* render_view)
15 : content::RenderViewObserver(render_view),
16 content::RenderViewObserverTracker<SearchBox>(render_view),
17 verbatim_(false),
18 selection_start_(0),
19 selection_end_(0) {
22 SearchBox::~SearchBox() {
25 void SearchBox::SetSuggestions(const std::vector<std::string>& suggestions,
26 InstantCompleteBehavior behavior) {
27 // Explicitly allow empty vector to be sent to the browser.
28 render_view()->Send(new ChromeViewHostMsg_SetSuggestions(
29 render_view()->GetRoutingId(), render_view()->GetPageId(), suggestions,
30 behavior));
33 gfx::Rect SearchBox::GetRect() {
34 // Need to adjust for scale.
35 if (rect_.IsEmpty())
36 return rect_;
37 WebView* web_view = render_view()->GetWebView();
38 if (!web_view)
39 return rect_;
40 double zoom = WebView::zoomLevelToZoomFactor(web_view->zoomLevel());
41 if (zoom == 0)
42 return rect_;
43 return gfx::Rect(static_cast<int>(static_cast<float>(rect_.x()) / zoom),
44 static_cast<int>(static_cast<float>(rect_.y()) / zoom),
45 static_cast<int>(static_cast<float>(rect_.width()) / zoom),
46 static_cast<int>(static_cast<float>(rect_.height()) / zoom));
49 bool SearchBox::OnMessageReceived(const IPC::Message& message) {
50 bool handled = true;
51 IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
52 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
53 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit)
54 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel)
55 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize)
56 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
57 OnDetermineIfPageSupportsInstant)
58 IPC_MESSAGE_UNHANDLED(handled = false)
59 IPC_END_MESSAGE_MAP()
60 return handled;
63 void SearchBox::OnChange(const string16& value,
64 bool verbatim,
65 int selection_start,
66 int selection_end) {
67 value_ = value;
68 verbatim_ = verbatim;
69 selection_start_ = selection_start;
70 selection_end_ = selection_end;
71 if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame())
72 return;
73 extensions_v8::SearchBoxExtension::DispatchChange(
74 render_view()->GetWebView()->mainFrame());
77 void SearchBox::OnSubmit(const string16& value, bool verbatim) {
78 value_ = value;
79 verbatim_ = verbatim;
80 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
81 extensions_v8::SearchBoxExtension::DispatchSubmit(
82 render_view()->GetWebView()->mainFrame());
84 Reset();
87 void SearchBox::OnCancel() {
88 verbatim_ = false;
89 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
90 extensions_v8::SearchBoxExtension::DispatchCancel(
91 render_view()->GetWebView()->mainFrame());
93 Reset();
96 void SearchBox::OnResize(const gfx::Rect& bounds) {
97 rect_ = bounds;
98 if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame())
99 return;
100 extensions_v8::SearchBoxExtension::DispatchResize(
101 render_view()->GetWebView()->mainFrame());
104 void SearchBox::OnDetermineIfPageSupportsInstant(const string16& value,
105 bool verbatim,
106 int selection_start,
107 int selection_end) {
108 value_ = value;
109 verbatim_ = verbatim;
110 selection_start_ = selection_start;
111 selection_end_ = selection_end;
112 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
113 render_view()->GetWebView()->mainFrame());
114 render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined(
115 render_view()->GetRoutingId(), render_view()->GetPageId(), result));
118 void SearchBox::Reset() {
119 verbatim_ = false;
120 value_ = string16();
121 selection_start_ = selection_end_ = 0;
122 rect_ = gfx::Rect();