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 "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "chrome/renderer/searchbox_extension.h" | 8 #include "chrome/renderer/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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) | 53 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) |
54 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) | 54 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) |
55 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) | 55 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) |
56 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, | 56 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, |
57 OnDetermineIfPageSupportsInstant) | 57 OnDetermineIfPageSupportsInstant) |
58 IPC_MESSAGE_UNHANDLED(handled = false) | 58 IPC_MESSAGE_UNHANDLED(handled = false) |
59 IPC_END_MESSAGE_MAP() | 59 IPC_END_MESSAGE_MAP() |
60 return handled; | 60 return handled; |
61 } | 61 } |
62 | 62 |
63 void SearchBox::OnChange(const string16& value, | 63 void SearchBox::OnChange(const std::string& value, |
64 bool verbatim, | 64 bool verbatim, |
65 int selection_start, | 65 size_t selection_start, |
66 int selection_end) { | 66 size_t selection_end) { |
67 value_ = value; | 67 value_ = value; |
68 verbatim_ = verbatim; | 68 verbatim_ = verbatim; |
69 selection_start_ = selection_start; | 69 selection_start_ = selection_start; |
70 selection_end_ = selection_end; | 70 selection_end_ = selection_end; |
71 if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame()) | 71 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
72 return; | 72 extensions_v8::SearchBoxExtension::DispatchChange( |
73 extensions_v8::SearchBoxExtension::DispatchChange( | 73 render_view()->GetWebView()->mainFrame()); |
74 render_view()->GetWebView()->mainFrame()); | 74 } |
75 } | 75 } |
76 | 76 |
77 void SearchBox::OnSubmit(const string16& value, bool verbatim) { | 77 void SearchBox::OnSubmit(const std::string& value) { |
78 value_ = value; | 78 value_ = value; |
79 verbatim_ = verbatim; | 79 verbatim_ = true; |
| 80 selection_start_ = selection_end_ = value_.size(); |
80 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 81 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
81 extensions_v8::SearchBoxExtension::DispatchSubmit( | 82 extensions_v8::SearchBoxExtension::DispatchSubmit( |
82 render_view()->GetWebView()->mainFrame()); | 83 render_view()->GetWebView()->mainFrame()); |
83 } | 84 } |
84 Reset(); | 85 Reset(); |
85 } | 86 } |
86 | 87 |
87 void SearchBox::OnCancel() { | 88 void SearchBox::OnCancel(const std::string& value) { |
88 verbatim_ = false; | 89 value_ = value; |
| 90 verbatim_ = true; |
| 91 selection_start_ = selection_end_ = value_.size(); |
89 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 92 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
90 extensions_v8::SearchBoxExtension::DispatchCancel( | 93 extensions_v8::SearchBoxExtension::DispatchCancel( |
91 render_view()->GetWebView()->mainFrame()); | 94 render_view()->GetWebView()->mainFrame()); |
92 } | 95 } |
93 Reset(); | 96 Reset(); |
94 } | 97 } |
95 | 98 |
96 void SearchBox::OnResize(const gfx::Rect& bounds) { | 99 void SearchBox::OnResize(const gfx::Rect& bounds) { |
97 rect_ = bounds; | 100 rect_ = bounds; |
98 if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame()) | 101 if (!render_view()->GetWebView() || !render_view()->GetWebView()->mainFrame()) |
99 return; | 102 return; |
100 extensions_v8::SearchBoxExtension::DispatchResize( | 103 extensions_v8::SearchBoxExtension::DispatchResize( |
101 render_view()->GetWebView()->mainFrame()); | 104 render_view()->GetWebView()->mainFrame()); |
102 } | 105 } |
103 | 106 |
104 void SearchBox::OnDetermineIfPageSupportsInstant(const string16& value, | 107 void SearchBox::OnDetermineIfPageSupportsInstant() { |
105 bool verbatim, | 108 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
106 int selection_start, | 109 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( |
107 int selection_end) { | 110 render_view()->GetWebView()->mainFrame()); |
108 value_ = value; | 111 render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined( |
109 verbatim_ = verbatim; | 112 render_view()->GetRoutingID(), render_view()->GetPageId(), result)); |
110 selection_start_ = selection_start; | 113 } |
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 } | 114 } |
117 | 115 |
118 void SearchBox::Reset() { | 116 void SearchBox::Reset() { |
119 verbatim_ = false; | 117 verbatim_ = false; |
120 value_ = string16(); | 118 value_.clear(); |
121 selection_start_ = selection_end_ = 0; | 119 selection_start_ = selection_end_ = 0; |
122 rect_ = gfx::Rect(); | 120 rect_ = gfx::Rect(); |
123 } | 121 } |
OLD | NEW |