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.h" | 5 #include "chrome/renderer/searchbox.h" |
6 | 6 |
| 7 #include "base/string16.h" |
7 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
8 #include "chrome/renderer/searchbox_extension.h" | 9 #include "chrome/renderer/searchbox_extension.h" |
9 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
11 | 12 |
12 using WebKit::WebView; | 13 using WebKit::WebView; |
13 | 14 |
14 SearchBox::SearchBox(content::RenderView* render_view) | 15 SearchBox::SearchBox(content::RenderView* render_view) |
15 : content::RenderViewObserver(render_view), | 16 : content::RenderViewObserver(render_view), |
16 content::RenderViewObserverTracker<SearchBox>(render_view), | 17 content::RenderViewObserverTracker<SearchBox>(render_view), |
17 verbatim_(false), | 18 verbatim_(false), |
18 selection_start_(0), | 19 selection_start_(0), |
19 selection_end_(0) { | 20 selection_end_(0) { |
20 } | 21 } |
21 | 22 |
22 SearchBox::~SearchBox() { | 23 SearchBox::~SearchBox() { |
23 } | 24 } |
24 | 25 |
25 void SearchBox::SetSuggestions(const std::vector<std::string>& suggestions, | 26 void SearchBox::SetSuggestions(const std::vector<string16>& suggestions, |
26 InstantCompleteBehavior behavior) { | 27 InstantCompleteBehavior behavior) { |
27 // Explicitly allow empty vector to be sent to the browser. | 28 // Explicitly allow empty vector to be sent to the browser. |
28 render_view()->Send(new ChromeViewHostMsg_SetSuggestions( | 29 render_view()->Send(new ChromeViewHostMsg_SetSuggestions( |
29 render_view()->GetRoutingID(), render_view()->GetPageId(), suggestions, | 30 render_view()->GetRoutingID(), render_view()->GetPageId(), suggestions, |
30 behavior)); | 31 behavior)); |
31 } | 32 } |
32 | 33 |
33 gfx::Rect SearchBox::GetRect() { | 34 gfx::Rect SearchBox::GetRect() { |
34 // Need to adjust for scale. | 35 // Need to adjust for scale. |
35 if (rect_.IsEmpty()) | 36 if (rect_.IsEmpty()) |
(...skipping 19 matching lines...) Expand all Loading... |
55 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) | 56 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) |
56 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, | 57 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, |
57 OnDetermineIfPageSupportsInstant) | 58 OnDetermineIfPageSupportsInstant) |
58 IPC_MESSAGE_UNHANDLED(handled = false) | 59 IPC_MESSAGE_UNHANDLED(handled = false) |
59 IPC_END_MESSAGE_MAP() | 60 IPC_END_MESSAGE_MAP() |
60 return handled; | 61 return handled; |
61 } | 62 } |
62 | 63 |
63 void SearchBox::OnChange(const string16& value, | 64 void SearchBox::OnChange(const string16& value, |
64 bool verbatim, | 65 bool verbatim, |
65 int selection_start, | 66 size_t selection_start, |
66 int selection_end) { | 67 size_t selection_end) { |
67 value_ = value; | 68 value_ = value; |
68 verbatim_ = verbatim; | 69 verbatim_ = verbatim; |
69 selection_start_ = selection_start; | 70 selection_start_ = selection_start; |
70 selection_end_ = selection_end; | 71 selection_end_ = selection_end; |
71 if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame()) | 72 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
72 return; | 73 extensions_v8::SearchBoxExtension::DispatchChange( |
73 extensions_v8::SearchBoxExtension::DispatchChange( | 74 render_view()->GetWebView()->mainFrame()); |
74 render_view()->GetWebView()->mainFrame()); | 75 } |
75 } | 76 } |
76 | 77 |
77 void SearchBox::OnSubmit(const string16& value, bool verbatim) { | 78 void SearchBox::OnSubmit(const string16& value) { |
78 value_ = value; | 79 value_ = value; |
79 verbatim_ = verbatim; | 80 verbatim_ = true; |
| 81 selection_start_ = selection_end_ = value_.length(); |
80 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 82 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
81 extensions_v8::SearchBoxExtension::DispatchSubmit( | 83 extensions_v8::SearchBoxExtension::DispatchSubmit( |
82 render_view()->GetWebView()->mainFrame()); | 84 render_view()->GetWebView()->mainFrame()); |
83 } | 85 } |
84 Reset(); | 86 Reset(); |
85 } | 87 } |
86 | 88 |
87 void SearchBox::OnCancel() { | 89 void SearchBox::OnCancel(const string16& value) { |
88 verbatim_ = false; | 90 value_ = value; |
| 91 verbatim_ = true; |
| 92 selection_start_ = selection_end_ = value_.length(); |
89 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 93 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
90 extensions_v8::SearchBoxExtension::DispatchCancel( | 94 extensions_v8::SearchBoxExtension::DispatchCancel( |
91 render_view()->GetWebView()->mainFrame()); | 95 render_view()->GetWebView()->mainFrame()); |
92 } | 96 } |
93 Reset(); | 97 Reset(); |
94 } | 98 } |
95 | 99 |
96 void SearchBox::OnResize(const gfx::Rect& bounds) { | 100 void SearchBox::OnResize(const gfx::Rect& bounds) { |
97 rect_ = bounds; | 101 rect_ = bounds; |
98 if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame()) | 102 if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame()) |
99 return; | 103 return; |
100 extensions_v8::SearchBoxExtension::DispatchResize( | 104 extensions_v8::SearchBoxExtension::DispatchResize( |
101 render_view()->GetWebView()->mainFrame()); | 105 render_view()->GetWebView()->mainFrame()); |
102 } | 106 } |
103 | 107 |
104 void SearchBox::OnDetermineIfPageSupportsInstant(const string16& value, | 108 void SearchBox::OnDetermineIfPageSupportsInstant() { |
105 bool verbatim, | 109 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
106 int selection_start, | 110 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
107 int selection_end) { | 111 render_view()->GetWebView()->mainFrame()); |
108 value_ = value; | 112 render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined( |
109 verbatim_ = verbatim; | 113 render_view()->GetRoutingID(), render_view()->GetPageId(), result)); |
110 selection_start_ = selection_start; | 114 } |
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)); | |
116 } | 115 } |
117 | 116 |
118 void SearchBox::Reset() { | 117 void SearchBox::Reset() { |
119 verbatim_ = false; | 118 verbatim_ = false; |
120 value_ = string16(); | 119 value_ = string16(); |
121 selection_start_ = selection_end_ = 0; | 120 selection_start_ = selection_end_ = 0; |
122 rect_ = gfx::Rect(); | 121 rect_ = gfx::Rect(); |
123 } | 122 } |
OLD | NEW |