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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 base::string16 text16 = ConvertJavaStringToUTF16(env, text); |
140 std::vector<blink::WebCompositionUnderline> underlines; | 140 std::vector<blink::WebCompositionUnderline> underlines; |
141 underlines.push_back( | 141 underlines.push_back( |
142 blink::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 |
153 void ImeAdapterAndroid::CommitText(JNIEnv* env, jobject, jstring text) { | 153 void ImeAdapterAndroid::CommitText(JNIEnv* env, jobject, jstring text) { |
154 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); | 154 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
155 if (!rwhi) | 155 if (!rwhi) |
156 return; | 156 return; |
157 | 157 |
158 string16 text16 = ConvertJavaStringToUTF16(env, text); | 158 base::string16 text16 = ConvertJavaStringToUTF16(env, text); |
159 rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false); | 159 rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false); |
160 } | 160 } |
161 | 161 |
162 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, jobject) { | 162 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, jobject) { |
163 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); | 163 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
164 if (!rwhi) | 164 if (!rwhi) |
165 return; | 165 return; |
166 | 166 |
167 rwhi->ImeConfirmComposition(string16(), gfx::Range::InvalidRange(), true); | 167 rwhi->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), |
| 168 true); |
168 } | 169 } |
169 | 170 |
170 void ImeAdapterAndroid::AttachImeAdapter(JNIEnv* env, jobject java_object) { | 171 void ImeAdapterAndroid::AttachImeAdapter(JNIEnv* env, jobject java_object) { |
171 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, java_object); | 172 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, java_object); |
172 } | 173 } |
173 | 174 |
174 void ImeAdapterAndroid::CancelComposition() { | 175 void ImeAdapterAndroid::CancelComposition() { |
175 base::android::ScopedJavaLocalRef<jobject> obj = | 176 base::android::ScopedJavaLocalRef<jobject> obj = |
176 java_ime_adapter_.get(AttachCurrentThread()); | 177 java_ime_adapter_.get(AttachCurrentThread()); |
177 if (!obj.is_null()) | 178 if (!obj.is_null()) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 RenderWidgetHostImpl* ImeAdapterAndroid::GetRenderWidgetHostImpl() { | 260 RenderWidgetHostImpl* ImeAdapterAndroid::GetRenderWidgetHostImpl() { |
260 DCHECK(rwhva_); | 261 DCHECK(rwhva_); |
261 RenderWidgetHost* rwh = rwhva_->GetRenderWidgetHost(); | 262 RenderWidgetHost* rwh = rwhva_->GetRenderWidgetHost(); |
262 if (!rwh) | 263 if (!rwh) |
263 return NULL; | 264 return NULL; |
264 | 265 |
265 return RenderWidgetHostImpl::From(rwh); | 266 return RenderWidgetHostImpl::From(rwh); |
266 } | 267 } |
267 | 268 |
268 } // namespace content | 269 } // namespace content |
OLD | NEW |