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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 jlong underlines_ptr, | 73 jlong underlines_ptr, |
74 jint start, | 74 jint start, |
75 jint end, | 75 jint end, |
76 jint background_color) { | 76 jint background_color) { |
77 DCHECK_GE(start, 0); | 77 DCHECK_GE(start, 0); |
78 DCHECK_GE(end, 0); | 78 DCHECK_GE(end, 0); |
79 // Do not check |background_color|. | 79 // Do not check |background_color|. |
80 std::vector<blink::WebCompositionUnderline>* underlines = | 80 std::vector<blink::WebCompositionUnderline>* underlines = |
81 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( | 81 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( |
82 underlines_ptr); | 82 underlines_ptr); |
83 underlines->push_back( | 83 underlines->push_back(blink::WebCompositionUnderline( |
84 blink::WebCompositionUnderline(static_cast<unsigned>(start), | 84 static_cast<unsigned>(start), static_cast<unsigned>(end), |
85 static_cast<unsigned>(end), | 85 SK_ColorTRANSPARENT, false, static_cast<unsigned>(background_color), |
86 SK_ColorTRANSPARENT, | 86 false)); |
87 false, | |
88 static_cast<unsigned>(background_color))); | |
89 } | 87 } |
90 | 88 |
91 // Callback from Java to convert UnderlineSpan data to a | 89 // Callback from Java to convert UnderlineSpan data to a |
92 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. | 90 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. |
93 void AppendUnderlineSpan(JNIEnv*, | 91 void AppendUnderlineSpan(JNIEnv*, |
94 const JavaParamRef<jclass>&, | 92 const JavaParamRef<jclass>&, |
95 jlong underlines_ptr, | 93 jlong underlines_ptr, |
96 jint start, | 94 jint start, |
97 jint end) { | 95 jint end) { |
98 DCHECK_GE(start, 0); | 96 DCHECK_GE(start, 0); |
99 DCHECK_GE(end, 0); | 97 DCHECK_GE(end, 0); |
100 std::vector<blink::WebCompositionUnderline>* underlines = | 98 std::vector<blink::WebCompositionUnderline>* underlines = |
101 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( | 99 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( |
102 underlines_ptr); | 100 underlines_ptr); |
103 underlines->push_back( | 101 underlines->push_back(blink::WebCompositionUnderline( |
104 blink::WebCompositionUnderline(static_cast<unsigned>(start), | 102 static_cast<unsigned>(start), static_cast<unsigned>(end), SK_ColorBLACK, |
105 static_cast<unsigned>(end), | 103 false, SK_ColorTRANSPARENT, false)); |
106 SK_ColorBLACK, | |
107 false, | |
108 SK_ColorTRANSPARENT)); | |
109 } | 104 } |
110 | 105 |
111 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) | 106 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) |
112 : rwhva_(rwhva) { | 107 : rwhva_(rwhva) { |
113 } | 108 } |
114 | 109 |
115 ImeAdapterAndroid::~ImeAdapterAndroid() { | 110 ImeAdapterAndroid::~ImeAdapterAndroid() { |
116 JNIEnv* env = AttachCurrentThread(); | 111 JNIEnv* env = AttachCurrentThread(); |
117 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | 112 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
118 if (!obj.is_null()) | 113 if (!obj.is_null()) |
(...skipping 28 matching lines...) Expand all Loading... |
147 return; | 142 return; |
148 | 143 |
149 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str); | 144 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str); |
150 | 145 |
151 std::vector<blink::WebCompositionUnderline> underlines = | 146 std::vector<blink::WebCompositionUnderline> underlines = |
152 GetUnderlinesFromSpans(env, obj, text, text16); | 147 GetUnderlinesFromSpans(env, obj, text, text16); |
153 | 148 |
154 // Default to plain underline if we didn't find any span that we care about. | 149 // Default to plain underline if we didn't find any span that we care about. |
155 if (underlines.empty()) { | 150 if (underlines.empty()) { |
156 underlines.push_back(blink::WebCompositionUnderline( | 151 underlines.push_back(blink::WebCompositionUnderline( |
157 0, text16.length(), SK_ColorBLACK, false, SK_ColorTRANSPARENT)); | 152 0, text16.length(), SK_ColorBLACK, false, SK_ColorTRANSPARENT, false)); |
158 } | 153 } |
159 | 154 |
160 // relative_cursor_pos is as described in the Android API for | 155 // relative_cursor_pos is as described in the Android API for |
161 // InputConnection#setComposingText, whereas the parameters for | 156 // InputConnection#setComposingText, whereas the parameters for |
162 // ImeSetComposition are relative to the start of the composition. | 157 // ImeSetComposition are relative to the start of the composition. |
163 if (relative_cursor_pos > 0) | 158 if (relative_cursor_pos > 0) |
164 relative_cursor_pos = text16.length() + relative_cursor_pos - 1; | 159 relative_cursor_pos = text16.length() + relative_cursor_pos - 1; |
165 | 160 |
166 rwhi->ImeSetComposition(text16, underlines, gfx::Range::InvalidRange(), | 161 rwhi->ImeSetComposition(text16, underlines, gfx::Range::InvalidRange(), |
167 relative_cursor_pos, relative_cursor_pos); | 162 relative_cursor_pos, relative_cursor_pos); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, | 257 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, |
263 const JavaParamRef<jobject>&, | 258 const JavaParamRef<jobject>&, |
264 int start, | 259 int start, |
265 int end) { | 260 int end) { |
266 RenderFrameHost* rfh = GetFocusedFrame(); | 261 RenderFrameHost* rfh = GetFocusedFrame(); |
267 if (!rfh) | 262 if (!rfh) |
268 return; | 263 return; |
269 | 264 |
270 std::vector<blink::WebCompositionUnderline> underlines; | 265 std::vector<blink::WebCompositionUnderline> underlines; |
271 underlines.push_back(blink::WebCompositionUnderline( | 266 underlines.push_back(blink::WebCompositionUnderline( |
272 0, end - start, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); | 267 0, end - start, SK_ColorBLACK, false, SK_ColorTRANSPARENT, false)); |
273 | 268 |
274 rfh->Send(new InputMsg_SetCompositionFromExistingText( | 269 rfh->Send(new InputMsg_SetCompositionFromExistingText( |
275 rfh->GetRoutingID(), start, end, underlines)); | 270 rfh->GetRoutingID(), start, end, underlines)); |
276 } | 271 } |
277 | 272 |
278 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, | 273 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, |
279 const JavaParamRef<jobject>&, | 274 const JavaParamRef<jobject>&, |
280 int before, | 275 int before, |
281 int after) { | 276 int after) { |
282 RenderFrameHostImpl* rfh = | 277 RenderFrameHostImpl* rfh = |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 Java_ImeAdapter_populateUnderlinesFromSpans( | 352 Java_ImeAdapter_populateUnderlinesFromSpans( |
358 env, obj, text, reinterpret_cast<jlong>(&underlines)); | 353 env, obj, text, reinterpret_cast<jlong>(&underlines)); |
359 | 354 |
360 // Sort spans by |.startOffset|. | 355 // Sort spans by |.startOffset|. |
361 std::sort(underlines.begin(), underlines.end()); | 356 std::sort(underlines.begin(), underlines.end()); |
362 | 357 |
363 return underlines; | 358 return underlines; |
364 } | 359 } |
365 | 360 |
366 } // namespace content | 361 } // namespace content |
OLD | NEW |