OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_extension.h" | 5 #include "chrome/renderer/searchbox/searchbox_extension.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 static const char kDispatchUpOrDownKeyPressEventScript[] = | 135 static const char kDispatchUpOrDownKeyPressEventScript[] = |
136 "if (window.chrome &&" | 136 "if (window.chrome &&" |
137 " window.chrome.searchBox &&" | 137 " window.chrome.searchBox &&" |
138 " window.chrome.searchBox.onkeypress &&" | 138 " window.chrome.searchBox.onkeypress &&" |
139 " typeof window.chrome.searchBox.onkeypress == 'function') {" | 139 " typeof window.chrome.searchBox.onkeypress == 'function') {" |
140 " for (var i = 0; i < %d; ++i)" | 140 " for (var i = 0; i < %d; ++i)" |
141 " window.chrome.searchBox.onkeypress({keyCode: %d});" | 141 " window.chrome.searchBox.onkeypress({keyCode: %d});" |
142 " true;" | 142 " true;" |
143 "}"; | 143 "}"; |
144 | 144 |
145 // Takes one printf-style replaceable values: key_code. | |
sreeram
2013/02/12 20:52:59
values -> value
beaudoin
2013/02/12 21:34:41
Done.
| |
146 static const char kDispatchEscKeyPressEventScript[] = | |
147 "if (window.chrome &&" | |
148 " window.chrome.searchBox &&" | |
149 " window.chrome.searchBox.onkeypress &&" | |
150 " typeof window.chrome.searchBox.onkeypress == 'function') {" | |
151 " window.chrome.searchBox.onkeypress({keyCode: %d});" | |
152 " true;" | |
153 "}"; | |
154 | |
145 static const char kDispatchKeyCaptureChangeScript[] = | 155 static const char kDispatchKeyCaptureChangeScript[] = |
146 "if (window.chrome &&" | 156 "if (window.chrome &&" |
147 " window.chrome.searchBox &&" | 157 " window.chrome.searchBox &&" |
148 " window.chrome.searchBox.onkeycapturechange &&" | 158 " window.chrome.searchBox.onkeycapturechange &&" |
149 " typeof window.chrome.searchBox.onkeycapturechange == 'function') {" | 159 " typeof window.chrome.searchBox.onkeycapturechange == 'function') {" |
150 " window.chrome.searchBox.onkeycapturechange();" | 160 " window.chrome.searchBox.onkeycapturechange();" |
151 " true;" | 161 " true;" |
152 "}"; | 162 "}"; |
153 | 163 |
154 static const char kDispatchContextChangeEventScript[] = | 164 static const char kDispatchContextChangeEventScript[] = |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
926 | 936 |
927 // static | 937 // static |
928 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, | 938 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, |
929 int count) { | 939 int count) { |
930 Dispatch(frame, WebKit::WebString::fromUTF8( | 940 Dispatch(frame, WebKit::WebString::fromUTF8( |
931 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), | 941 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), |
932 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); | 942 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); |
933 } | 943 } |
934 | 944 |
935 // static | 945 // static |
946 void SearchBoxExtension::DispatchEscKeyPress(WebKit::WebFrame* frame) { | |
947 Dispatch(frame, WebKit::WebString::fromUTF8( | |
948 base::StringPrintf(kDispatchEscKeyPressEventScript, ui::VKEY_ESCAPE))); | |
949 } | |
950 | |
951 // static | |
936 void SearchBoxExtension::DispatchKeyCaptureChange(WebKit::WebFrame* frame) { | 952 void SearchBoxExtension::DispatchKeyCaptureChange(WebKit::WebFrame* frame) { |
937 Dispatch(frame, kDispatchKeyCaptureChangeScript); | 953 Dispatch(frame, kDispatchKeyCaptureChangeScript); |
938 } | 954 } |
939 | 955 |
940 // static | 956 // static |
941 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) { | 957 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) { |
942 Dispatch(frame, kDispatchContextChangeEventScript); | 958 Dispatch(frame, kDispatchContextChangeEventScript); |
943 } | 959 } |
944 | 960 |
945 // static | 961 // static |
(...skipping 12 matching lines...) Expand all Loading... | |
958 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); | 974 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); |
959 } | 975 } |
960 | 976 |
961 // static | 977 // static |
962 v8::Extension* SearchBoxExtension::Get() { | 978 v8::Extension* SearchBoxExtension::Get() { |
963 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 979 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
964 GetRawDataResource(IDR_SEARCHBOX_API)); | 980 GetRawDataResource(IDR_SEARCHBOX_API)); |
965 } | 981 } |
966 | 982 |
967 } // namespace extensions_v8 | 983 } // namespace extensions_v8 |
OLD | NEW |