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 <android/input.h> | 7 #include <android/input.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // as a key press of character \r. | 33 // as a key press of character \r. |
34 NativeWebKeyboardEvent NativeWebKeyboardEventFromKeyEvent( | 34 NativeWebKeyboardEvent NativeWebKeyboardEventFromKeyEvent( |
35 JNIEnv* env, | 35 JNIEnv* env, |
36 jobject java_key_event, | 36 jobject java_key_event, |
37 int action, | 37 int action, |
38 int modifiers, | 38 int modifiers, |
39 long time_ms, | 39 long time_ms, |
40 int key_code, | 40 int key_code, |
41 bool is_system_key, | 41 bool is_system_key, |
42 int unicode_char) { | 42 int unicode_char) { |
43 WebKit::WebInputEvent::Type type = WebKit::WebInputEvent::Undefined; | 43 blink::WebInputEvent::Type type = blink::WebInputEvent::Undefined; |
44 if (action == AKEY_EVENT_ACTION_DOWN) | 44 if (action == AKEY_EVENT_ACTION_DOWN) |
45 type = WebKit::WebInputEvent::RawKeyDown; | 45 type = blink::WebInputEvent::RawKeyDown; |
46 else if (action == AKEY_EVENT_ACTION_UP) | 46 else if (action == AKEY_EVENT_ACTION_UP) |
47 type = WebKit::WebInputEvent::KeyUp; | 47 type = blink::WebInputEvent::KeyUp; |
48 return NativeWebKeyboardEvent(java_key_event, type, modifiers, | 48 return NativeWebKeyboardEvent(java_key_event, type, modifiers, |
49 time_ms, key_code, unicode_char, is_system_key); | 49 time_ms, key_code, unicode_char, is_system_key); |
50 } | 50 } |
51 | 51 |
52 } // anonymous namespace | 52 } // anonymous namespace |
53 | 53 |
54 bool RegisterImeAdapter(JNIEnv* env) { | 54 bool RegisterImeAdapter(JNIEnv* env) { |
55 if (!RegisterNativesImpl(env)) | 55 if (!RegisterNativesImpl(env)) |
56 return false; | 56 return false; |
57 | 57 |
58 Java_ImeAdapter_initializeWebInputEvents(env, | 58 Java_ImeAdapter_initializeWebInputEvents(env, |
59 WebKit::WebInputEvent::RawKeyDown, | 59 blink::WebInputEvent::RawKeyDown, |
60 WebKit::WebInputEvent::KeyUp, | 60 blink::WebInputEvent::KeyUp, |
61 WebKit::WebInputEvent::Char, | 61 blink::WebInputEvent::Char, |
62 WebKit::WebInputEvent::ShiftKey, | 62 blink::WebInputEvent::ShiftKey, |
63 WebKit::WebInputEvent::AltKey, | 63 blink::WebInputEvent::AltKey, |
64 WebKit::WebInputEvent::ControlKey, | 64 blink::WebInputEvent::ControlKey, |
65 WebKit::WebInputEvent::CapsLockOn, | 65 blink::WebInputEvent::CapsLockOn, |
66 WebKit::WebInputEvent::NumLockOn); | 66 blink::WebInputEvent::NumLockOn); |
67 Java_ImeAdapter_initializeTextInputTypes( | 67 Java_ImeAdapter_initializeTextInputTypes( |
68 env, | 68 env, |
69 ui::TEXT_INPUT_TYPE_NONE, | 69 ui::TEXT_INPUT_TYPE_NONE, |
70 ui::TEXT_INPUT_TYPE_TEXT, | 70 ui::TEXT_INPUT_TYPE_TEXT, |
71 ui::TEXT_INPUT_TYPE_TEXT_AREA, | 71 ui::TEXT_INPUT_TYPE_TEXT_AREA, |
72 ui::TEXT_INPUT_TYPE_PASSWORD, | 72 ui::TEXT_INPUT_TYPE_PASSWORD, |
73 ui::TEXT_INPUT_TYPE_SEARCH, | 73 ui::TEXT_INPUT_TYPE_SEARCH, |
74 ui::TEXT_INPUT_TYPE_URL, | 74 ui::TEXT_INPUT_TYPE_URL, |
75 ui::TEXT_INPUT_TYPE_EMAIL, | 75 ui::TEXT_INPUT_TYPE_EMAIL, |
76 ui::TEXT_INPUT_TYPE_TELEPHONE, | 76 ui::TEXT_INPUT_TYPE_TELEPHONE, |
(...skipping 12 matching lines...) Expand all Loading... |
89 if (!obj.is_null()) | 89 if (!obj.is_null()) |
90 Java_ImeAdapter_detach(env, obj.obj()); | 90 Java_ImeAdapter_detach(env, obj.obj()); |
91 } | 91 } |
92 | 92 |
93 bool ImeAdapterAndroid::SendSyntheticKeyEvent(JNIEnv*, | 93 bool ImeAdapterAndroid::SendSyntheticKeyEvent(JNIEnv*, |
94 jobject, | 94 jobject, |
95 int type, | 95 int type, |
96 long time_ms, | 96 long time_ms, |
97 int key_code, | 97 int key_code, |
98 int text) { | 98 int text) { |
99 NativeWebKeyboardEvent event(static_cast<WebKit::WebInputEvent::Type>(type), | 99 NativeWebKeyboardEvent event(static_cast<blink::WebInputEvent::Type>(type), |
100 0 /* modifiers */, time_ms / 1000.0, key_code, | 100 0 /* modifiers */, time_ms / 1000.0, key_code, |
101 text, false /* is_system_key */); | 101 text, false /* is_system_key */); |
102 rwhva_->SendKeyEvent(event); | 102 rwhva_->SendKeyEvent(event); |
103 return true; | 103 return true; |
104 } | 104 } |
105 | 105 |
106 bool ImeAdapterAndroid::SendKeyEvent(JNIEnv* env, jobject, | 106 bool ImeAdapterAndroid::SendKeyEvent(JNIEnv* env, jobject, |
107 jobject original_key_event, | 107 jobject original_key_event, |
108 int action, int modifiers, | 108 int action, int modifiers, |
109 long time_ms, int key_code, | 109 long time_ms, int key_code, |
110 bool is_system_key, int unicode_char) { | 110 bool is_system_key, int unicode_char) { |
111 NativeWebKeyboardEvent event = NativeWebKeyboardEventFromKeyEvent( | 111 NativeWebKeyboardEvent event = NativeWebKeyboardEventFromKeyEvent( |
112 env, original_key_event, action, modifiers, | 112 env, original_key_event, action, modifiers, |
113 time_ms, key_code, is_system_key, unicode_char); | 113 time_ms, key_code, is_system_key, unicode_char); |
114 bool key_down_text_insertion = | 114 bool key_down_text_insertion = |
115 event.type == WebKit::WebInputEvent::RawKeyDown && event.text[0]; | 115 event.type == blink::WebInputEvent::RawKeyDown && event.text[0]; |
116 // If we are going to follow up with a synthetic Char event, then that's the | 116 // If we are going to follow up with a synthetic Char event, then that's the |
117 // one we expect to test if it's handled or unhandled, so skip handling the | 117 // one we expect to test if it's handled or unhandled, so skip handling the |
118 // "real" event in the browser. | 118 // "real" event in the browser. |
119 event.skip_in_browser = key_down_text_insertion; | 119 event.skip_in_browser = key_down_text_insertion; |
120 rwhva_->SendKeyEvent(event); | 120 rwhva_->SendKeyEvent(event); |
121 if (key_down_text_insertion) { | 121 if (key_down_text_insertion) { |
122 // Send a Char event, but without an os_event since we don't want to | 122 // Send a Char event, but without an os_event since we don't want to |
123 // roundtrip back to java such synthetic event. | 123 // roundtrip back to java such synthetic event. |
124 NativeWebKeyboardEvent char_event(WebKit::WebInputEvent::Char, modifiers, | 124 NativeWebKeyboardEvent char_event(blink::WebInputEvent::Char, modifiers, |
125 time_ms, key_code, unicode_char, | 125 time_ms, key_code, unicode_char, |
126 is_system_key); | 126 is_system_key); |
127 char_event.skip_in_browser = key_down_text_insertion; | 127 char_event.skip_in_browser = key_down_text_insertion; |
128 rwhva_->SendKeyEvent(char_event); | 128 rwhva_->SendKeyEvent(char_event); |
129 } | 129 } |
130 return true; | 130 return true; |
131 } | 131 } |
132 | 132 |
133 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, jobject, jstring text, | 133 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, jobject, jstring text, |
134 int new_cursor_pos) { | 134 int new_cursor_pos) { |
135 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); | 135 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
136 if (!rwhi) | 136 if (!rwhi) |
137 return; | 137 return; |
138 | 138 |
139 string16 text16 = ConvertJavaStringToUTF16(env, text); | 139 string16 text16 = ConvertJavaStringToUTF16(env, text); |
140 std::vector<WebKit::WebCompositionUnderline> underlines; | 140 std::vector<blink::WebCompositionUnderline> underlines; |
141 underlines.push_back( | 141 underlines.push_back( |
142 WebKit::WebCompositionUnderline(0, text16.length(), SK_ColorBLACK, | 142 blink::WebCompositionUnderline(0, text16.length(), SK_ColorBLACK, |
143 false)); | 143 false)); |
144 // new_cursor_position is as described in the Android API for | 144 // new_cursor_position is as described in the Android API for |
145 // InputConnection#setComposingText, whereas the parameters for | 145 // InputConnection#setComposingText, whereas the parameters for |
146 // ImeSetComposition are relative to the start of the composition. | 146 // ImeSetComposition are relative to the start of the composition. |
147 if (new_cursor_pos > 0) | 147 if (new_cursor_pos > 0) |
148 new_cursor_pos = text16.length() + new_cursor_pos - 1; | 148 new_cursor_pos = text16.length() + new_cursor_pos - 1; |
149 | 149 |
150 rwhi->ImeSetComposition(text16, underlines, new_cursor_pos, new_cursor_pos); | 150 rwhi->ImeSetComposition(text16, underlines, new_cursor_pos, new_cursor_pos); |
151 } | 151 } |
152 | 152 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 rwhi->Send(new ViewMsg_SetEditableSelectionOffsets(rwhi->GetRoutingID(), | 187 rwhi->Send(new ViewMsg_SetEditableSelectionOffsets(rwhi->GetRoutingID(), |
188 start, end)); | 188 start, end)); |
189 } | 189 } |
190 | 190 |
191 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, jobject, | 191 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, jobject, |
192 int start, int end) { | 192 int start, int end) { |
193 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); | 193 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
194 if (!rwhi) | 194 if (!rwhi) |
195 return; | 195 return; |
196 | 196 |
197 std::vector<WebKit::WebCompositionUnderline> underlines; | 197 std::vector<blink::WebCompositionUnderline> underlines; |
198 underlines.push_back( | 198 underlines.push_back( |
199 WebKit::WebCompositionUnderline(0, end - start, SK_ColorBLACK, false)); | 199 blink::WebCompositionUnderline(0, end - start, SK_ColorBLACK, false)); |
200 | 200 |
201 rwhi->Send(new ViewMsg_SetCompositionFromExistingText( | 201 rwhi->Send(new ViewMsg_SetCompositionFromExistingText( |
202 rwhi->GetRoutingID(), start, end, underlines)); | 202 rwhi->GetRoutingID(), start, end, underlines)); |
203 } | 203 } |
204 | 204 |
205 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, jobject, | 205 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, jobject, |
206 int before, int after) { | 206 int before, int after) { |
207 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); | 207 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
208 if (!rwhi) | 208 if (!rwhi) |
209 return; | 209 return; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 RenderWidgetHostImpl* ImeAdapterAndroid::GetRenderWidgetHostImpl() { | 259 RenderWidgetHostImpl* ImeAdapterAndroid::GetRenderWidgetHostImpl() { |
260 DCHECK(rwhva_); | 260 DCHECK(rwhva_); |
261 RenderWidgetHost* rwh = rwhva_->GetRenderWidgetHost(); | 261 RenderWidgetHost* rwh = rwhva_->GetRenderWidgetHost(); |
262 if (!rwh) | 262 if (!rwh) |
263 return NULL; | 263 return NULL; |
264 | 264 |
265 return RenderWidgetHostImpl::From(rwh); | 265 return RenderWidgetHostImpl::From(rwh); |
266 } | 266 } |
267 | 267 |
268 } // namespace content | 268 } // namespace content |
OLD | NEW |