| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 " window.chrome.embeddedSearch &&" | 148 " window.chrome.embeddedSearch &&" |
| 149 " window.chrome.embeddedSearch.searchBox &&" | 149 " window.chrome.embeddedSearch.searchBox &&" |
| 150 " window.chrome.embeddedSearch.searchBox.onkeypress &&" | 150 " window.chrome.embeddedSearch.searchBox.onkeypress &&" |
| 151 " typeof window.chrome.embeddedSearch.searchBox.onkeypress ==" | 151 " typeof window.chrome.embeddedSearch.searchBox.onkeypress ==" |
| 152 " 'function') {" | 152 " 'function') {" |
| 153 " for (var i = 0; i < %d; ++i)" | 153 " for (var i = 0; i < %d; ++i)" |
| 154 " window.chrome.embeddedSearch.searchBox.onkeypress({keyCode: %d});" | 154 " window.chrome.embeddedSearch.searchBox.onkeypress({keyCode: %d});" |
| 155 " true;" | 155 " true;" |
| 156 "}"; | 156 "}"; |
| 157 | 157 |
| 158 // Takes one printf-style replaceable value: key_code. |
| 159 static const char kDispatchEscKeyPressEventScript[] = |
| 160 "if (window.chrome &&" |
| 161 " window.chrome.searchBox &&" |
| 162 " window.chrome.searchBox.onkeypress &&" |
| 163 " typeof window.chrome.searchBox.onkeypress == 'function') {" |
| 164 " window.chrome.searchBox.onkeypress({keyCode: %d});" |
| 165 " true;" |
| 166 "}"; |
| 167 |
| 158 static const char kDispatchKeyCaptureChangeScript[] = | 168 static const char kDispatchKeyCaptureChangeScript[] = |
| 159 "if (window.chrome &&" | 169 "if (window.chrome &&" |
| 160 " window.chrome.embeddedSearch &&" | 170 " window.chrome.embeddedSearch &&" |
| 161 " window.chrome.embeddedSearch.searchBox &&" | 171 " window.chrome.embeddedSearch.searchBox &&" |
| 162 " window.chrome.embeddedSearch.searchBox.onkeycapturechange &&" | 172 " window.chrome.embeddedSearch.searchBox.onkeycapturechange &&" |
| 163 " typeof window.chrome.embeddedSearch.searchBox.onkeycapturechange ==" | 173 " typeof window.chrome.embeddedSearch.searchBox.onkeycapturechange ==" |
| 164 " 'function') {" | 174 " 'function') {" |
| 165 " window.chrome.embeddedSearch.searchBox.onkeycapturechange();" | 175 " window.chrome.embeddedSearch.searchBox.onkeycapturechange();" |
| 166 " true;" | 176 " true;" |
| 167 "}"; | 177 "}"; |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 | 933 |
| 924 // static | 934 // static |
| 925 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, | 935 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, |
| 926 int count) { | 936 int count) { |
| 927 Dispatch(frame, WebKit::WebString::fromUTF8( | 937 Dispatch(frame, WebKit::WebString::fromUTF8( |
| 928 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), | 938 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), |
| 929 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); | 939 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); |
| 930 } | 940 } |
| 931 | 941 |
| 932 // static | 942 // static |
| 943 void SearchBoxExtension::DispatchEscKeyPress(WebKit::WebFrame* frame) { |
| 944 Dispatch(frame, WebKit::WebString::fromUTF8( |
| 945 base::StringPrintf(kDispatchEscKeyPressEventScript, ui::VKEY_ESCAPE))); |
| 946 } |
| 947 |
| 948 // static |
| 933 void SearchBoxExtension::DispatchKeyCaptureChange(WebKit::WebFrame* frame) { | 949 void SearchBoxExtension::DispatchKeyCaptureChange(WebKit::WebFrame* frame) { |
| 934 Dispatch(frame, kDispatchKeyCaptureChangeScript); | 950 Dispatch(frame, kDispatchKeyCaptureChangeScript); |
| 935 } | 951 } |
| 936 | 952 |
| 937 // static | 953 // static |
| 938 void SearchBoxExtension::DispatchMarginChange(WebKit::WebFrame* frame) { | 954 void SearchBoxExtension::DispatchMarginChange(WebKit::WebFrame* frame) { |
| 939 Dispatch(frame, kDispatchMarginChangeEventScript); | 955 Dispatch(frame, kDispatchMarginChangeEventScript); |
| 940 } | 956 } |
| 941 | 957 |
| 942 // static | 958 // static |
| 943 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { | 959 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { |
| 944 Dispatch(frame, kDispatchThemeChangeEventScript); | 960 Dispatch(frame, kDispatchThemeChangeEventScript); |
| 945 } | 961 } |
| 946 | 962 |
| 947 // static | 963 // static |
| 948 void SearchBoxExtension::DispatchThemeAreaHeightChange( | 964 void SearchBoxExtension::DispatchThemeAreaHeightChange( |
| 949 WebKit::WebFrame* frame) { | 965 WebKit::WebFrame* frame) { |
| 950 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); | 966 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); |
| 951 } | 967 } |
| 952 | 968 |
| 953 } // namespace extensions_v8 | 969 } // namespace extensions_v8 |
| OLD | NEW |