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" |
11 #include "base/android/scoped_java_ref.h" | |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
14 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 15 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
15 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
16 #include "content/public/browser/native_web_keyboard_event.h" | 17 #include "content/public/browser/native_web_keyboard_event.h" |
17 #include "jni/ImeAdapter_jni.h" | 18 #include "jni/ImeAdapter_jni.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
20 | 21 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 ui::TEXT_INPUT_TYPE_DATE_TIME, | 81 ui::TEXT_INPUT_TYPE_DATE_TIME, |
81 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, | 82 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, |
82 ui::TEXT_INPUT_TYPE_MONTH, | 83 ui::TEXT_INPUT_TYPE_MONTH, |
83 ui::TEXT_INPUT_TYPE_TIME, | 84 ui::TEXT_INPUT_TYPE_TIME, |
84 ui::TEXT_INPUT_TYPE_WEEK, | 85 ui::TEXT_INPUT_TYPE_WEEK, |
85 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE); | 86 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE); |
86 return true; | 87 return true; |
87 } | 88 } |
88 | 89 |
89 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) | 90 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) |
90 : rwhva_(rwhva), | 91 : rwhva_(rwhva) { |
91 java_ime_adapter_(NULL) { | |
92 } | 92 } |
93 | 93 |
94 ImeAdapterAndroid::~ImeAdapterAndroid() { | 94 ImeAdapterAndroid::~ImeAdapterAndroid() { |
95 if (java_ime_adapter_) { | 95 JNIEnv* env = AttachCurrentThread(); |
96 JNIEnv* env = base::android::AttachCurrentThread(); | 96 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
97 Java_ImeAdapter_detach(env, java_ime_adapter_); | 97 if (!obj.is_null()) |
98 env->DeleteGlobalRef(java_ime_adapter_); | 98 Java_ImeAdapter_detach(env, obj.obj()); |
99 } | |
100 } | 99 } |
101 | 100 |
102 bool ImeAdapterAndroid::SendSyntheticKeyEvent(JNIEnv*, | 101 bool ImeAdapterAndroid::SendSyntheticKeyEvent(JNIEnv*, |
103 jobject, | 102 jobject, |
104 int type, | 103 int type, |
105 long time_ms, | 104 long time_ms, |
106 int key_code, | 105 int key_code, |
107 int text) { | 106 int text) { |
108 NativeWebKeyboardEvent event(static_cast<WebKit::WebInputEvent::Type>(type), | 107 NativeWebKeyboardEvent event(static_cast<WebKit::WebInputEvent::Type>(type), |
109 0 /* modifiers */, time_ms / 1000.0, key_code, | 108 0 /* modifiers */, time_ms / 1000.0, key_code, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( | 167 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( |
169 rwhva_->GetRenderWidgetHost()); | 168 rwhva_->GetRenderWidgetHost()); |
170 if (!rwhi) | 169 if (!rwhi) |
171 return; | 170 return; |
172 | 171 |
173 string16 text16 = ConvertJavaStringToUTF16(env, text); | 172 string16 text16 = ConvertJavaStringToUTF16(env, text); |
174 rwhi->ImeConfirmComposition(text16); | 173 rwhi->ImeConfirmComposition(text16); |
175 } | 174 } |
176 | 175 |
177 void ImeAdapterAndroid::AttachImeAdapter(JNIEnv* env, jobject java_object) { | 176 void ImeAdapterAndroid::AttachImeAdapter(JNIEnv* env, jobject java_object) { |
178 java_ime_adapter_ = AttachCurrentThread()->NewGlobalRef(java_object); | 177 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, java_object); |
179 } | 178 } |
180 | 179 |
181 void ImeAdapterAndroid::CancelComposition() { | 180 void ImeAdapterAndroid::CancelComposition() { |
182 Java_ImeAdapter_cancelComposition(AttachCurrentThread(), java_ime_adapter_); | 181 base::android::ScopedJavaLocalRef<jobject> obj = |
Kristian Monsen
2013/03/14 22:42:38
maybe slightly more expressive name than obj? Also
joth
2013/03/15 02:39:45
yeah.. obj seems to be a fairly common name for "t
| |
182 java_ime_adapter_.get(AttachCurrentThread()); | |
183 if (!obj.is_null()) | |
184 Java_ImeAdapter_cancelComposition(AttachCurrentThread(), obj.obj()); | |
183 } | 185 } |
184 | 186 |
185 void ImeAdapterAndroid::SetEditableSelectionOffsets(JNIEnv*, jobject, | 187 void ImeAdapterAndroid::SetEditableSelectionOffsets(JNIEnv*, jobject, |
186 int start, int end) { | 188 int start, int end) { |
187 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( | 189 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( |
188 rwhva_->GetRenderWidgetHost()); | 190 rwhva_->GetRenderWidgetHost()); |
189 if (!rwhi) | 191 if (!rwhi) |
190 return; | 192 return; |
191 | 193 |
192 rwhi->Send(new ViewMsg_SetEditableSelectionOffsets(rwhi->GetRoutingID(), | 194 rwhi->Send(new ViewMsg_SetEditableSelectionOffsets(rwhi->GetRoutingID(), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 void ImeAdapterAndroid::Paste(JNIEnv* env, jobject) { | 260 void ImeAdapterAndroid::Paste(JNIEnv* env, jobject) { |
259 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( | 261 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( |
260 rwhva_->GetRenderWidgetHost()); | 262 rwhva_->GetRenderWidgetHost()); |
261 if (!rwhi) | 263 if (!rwhi) |
262 return; | 264 return; |
263 | 265 |
264 rwhi->Send(new ViewMsg_Paste(rwhi->GetRoutingID())); | 266 rwhi->Send(new ViewMsg_Paste(rwhi->GetRoutingID())); |
265 } | 267 } |
266 | 268 |
267 } // namespace content | 269 } // namespace content |
OLD | NEW |