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 "content/browser/renderer_host/ime_adapter_android.h" | 5 #include "content/browser/renderer_host/ime_adapter_android.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <android/input.h> | 8 #include <android/input.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 // type, |modifiers|, |time_ms|, |key_code|, |unicode_char| is used to create | 43 // type, |modifiers|, |time_ms|, |key_code|, |unicode_char| is used to create |
44 // WebKeyboardEvent. |key_code| is also needed ad need to treat the enter key | 44 // WebKeyboardEvent. |key_code| is also needed ad need to treat the enter key |
45 // as a key press of character \r. | 45 // as a key press of character \r. |
46 NativeWebKeyboardEvent NativeWebKeyboardEventFromKeyEvent( | 46 NativeWebKeyboardEvent NativeWebKeyboardEventFromKeyEvent( |
47 JNIEnv* env, | 47 JNIEnv* env, |
48 jobject java_key_event, | 48 jobject java_key_event, |
49 int action, | 49 int action, |
50 int modifiers, | 50 int modifiers, |
51 long time_ms, | 51 long time_ms, |
52 int key_code, | 52 int key_code, |
53 int scan_code, | |
53 bool is_system_key, | 54 bool is_system_key, |
54 int unicode_char) { | 55 int unicode_char) { |
55 blink::WebInputEvent::Type type = blink::WebInputEvent::Undefined; | 56 blink::WebInputEvent::Type type = blink::WebInputEvent::Undefined; |
56 if (action == AKEY_EVENT_ACTION_DOWN) | 57 if (action == AKEY_EVENT_ACTION_DOWN) |
57 type = blink::WebInputEvent::RawKeyDown; | 58 type = blink::WebInputEvent::RawKeyDown; |
58 else if (action == AKEY_EVENT_ACTION_UP) | 59 else if (action == AKEY_EVENT_ACTION_UP) |
59 type = blink::WebInputEvent::KeyUp; | 60 type = blink::WebInputEvent::KeyUp; |
60 else | 61 else |
61 NOTREACHED() << "Invalid Android key event action: " << action; | 62 NOTREACHED() << "Invalid Android key event action: " << action; |
62 return NativeWebKeyboardEvent(java_key_event, type, modifiers, | 63 return NativeWebKeyboardEvent(java_key_event, type, modifiers, |
63 time_ms / 1000.0, key_code, unicode_char, is_system_key); | 64 time_ms / 1000.0, key_code, scan_code, unicode_char, is_system_key); |
64 } | 65 } |
65 | 66 |
66 } // anonymous namespace | 67 } // anonymous namespace |
67 | 68 |
68 bool RegisterImeAdapter(JNIEnv* env) { | 69 bool RegisterImeAdapter(JNIEnv* env) { |
69 return RegisterNativesImpl(env); | 70 return RegisterNativesImpl(env); |
70 } | 71 } |
71 | 72 |
72 // Callback from Java to convert BackgroundColorSpan data to a | 73 // Callback from Java to convert BackgroundColorSpan data to a |
73 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. | 74 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 } | 124 } |
124 | 125 |
125 bool ImeAdapterAndroid::SendSyntheticKeyEvent(JNIEnv*, | 126 bool ImeAdapterAndroid::SendSyntheticKeyEvent(JNIEnv*, |
126 jobject, | 127 jobject, |
127 int type, | 128 int type, |
128 long time_ms, | 129 long time_ms, |
129 int key_code, | 130 int key_code, |
130 int modifiers, | 131 int modifiers, |
131 int text) { | 132 int text) { |
132 NativeWebKeyboardEvent event(static_cast<blink::WebInputEvent::Type>(type), | 133 NativeWebKeyboardEvent event(static_cast<blink::WebInputEvent::Type>(type), |
133 modifiers, time_ms / 1000.0, key_code, | 134 modifiers, time_ms / 1000.0, key_code, 0, |
134 text, false /* is_system_key */); | 135 text, false /* is_system_key */); |
135 rwhva_->SendKeyEvent(event); | 136 rwhva_->SendKeyEvent(event); |
136 return true; | 137 return true; |
137 } | 138 } |
138 | 139 |
139 bool ImeAdapterAndroid::SendKeyEvent(JNIEnv* env, jobject, | 140 bool ImeAdapterAndroid::SendKeyEvent(JNIEnv* env, jobject, |
140 jobject original_key_event, | 141 jobject original_key_event, |
141 int action, int modifiers, | 142 int action, int modifiers, |
142 long time_ms, int key_code, | 143 long time_ms, int key_code, |
143 bool is_system_key, int unicode_char) { | 144 int scan_code, bool is_system_key, |
145 int unicode_char) { | |
144 NativeWebKeyboardEvent event = NativeWebKeyboardEventFromKeyEvent( | 146 NativeWebKeyboardEvent event = NativeWebKeyboardEventFromKeyEvent( |
145 env, original_key_event, action, modifiers, | 147 env, original_key_event, action, modifiers, |
146 time_ms, key_code, is_system_key, unicode_char); | 148 time_ms, key_code, scan_code, is_system_key, unicode_char); |
147 bool key_down_text_insertion = | 149 bool key_down_text_insertion = |
148 event.type == blink::WebInputEvent::RawKeyDown && event.text[0]; | 150 event.type == blink::WebInputEvent::RawKeyDown && event.text[0]; |
149 // If we are going to follow up with a synthetic Char event, then that's the | 151 // If we are going to follow up with a synthetic Char event, then that's the |
150 // one we expect to test if it's handled or unhandled, so skip handling the | 152 // one we expect to test if it's handled or unhandled, so skip handling the |
151 // "real" event in the browser. | 153 // "real" event in the browser. |
152 event.skip_in_browser = key_down_text_insertion; | 154 event.skip_in_browser = key_down_text_insertion; |
153 rwhva_->SendKeyEvent(event); | 155 rwhva_->SendKeyEvent(event); |
154 if (key_down_text_insertion) { | 156 if (key_down_text_insertion) { |
155 // Send a Char event, but without an os_event since we don't want to | 157 // Send a Char event, but without an os_event since we don't want to |
156 // roundtrip back to java such synthetic event. | 158 // roundtrip back to java such synthetic event. |
157 NativeWebKeyboardEvent char_event(blink::WebInputEvent::Char, modifiers, | 159 NativeWebKeyboardEvent char_event(blink::WebInputEvent::Char, modifiers, |
158 time_ms / 1000.0, key_code, unicode_char, | 160 time_ms / 1000.0, key_code, scan_code, |
161 unicode_char, | |
159 is_system_key); | 162 is_system_key); |
Wez
2015/09/14 22:03:50
nit: unnecessary line-wrap at the end here?
| |
160 char_event.skip_in_browser = key_down_text_insertion; | 163 char_event.skip_in_browser = key_down_text_insertion; |
161 rwhva_->SendKeyEvent(char_event); | 164 rwhva_->SendKeyEvent(char_event); |
162 } | 165 } |
163 return true; | 166 return true; |
164 } | 167 } |
165 | 168 |
166 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, | 169 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, |
167 jobject obj, | 170 jobject obj, |
168 jobject text, | 171 jobject text, |
169 jstring text_str, | 172 jstring text_str, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 WebContents* ImeAdapterAndroid::GetWebContents() { | 304 WebContents* ImeAdapterAndroid::GetWebContents() { |
302 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); | 305 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); |
303 if (!rwh) | 306 if (!rwh) |
304 return NULL; | 307 return NULL; |
305 if (!rwh->IsRenderView()) | 308 if (!rwh->IsRenderView()) |
306 return NULL; | 309 return NULL; |
307 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); | 310 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
308 } | 311 } |
309 | 312 |
310 } // namespace content | 313 } // namespace content |
OLD | NEW |