Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Side by Side Diff: content/browser/renderer_host/ime_adapter_android.cc

Issue 313053007: Passing BackgroundColorSpan and UnderlineSpan from Clank to Blink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <android/input.h> 8 #include <android/input.h>
9 #include <vector>
8 10
9 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h" 13 #include "base/android/scoped_java_ref.h"
12 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "content/browser/frame_host/frame_tree.h" 16 #include "content/browser/frame_host/frame_tree.h"
15 #include "content/browser/frame_host/frame_tree_node.h" 17 #include "content/browser/frame_host/frame_tree_node.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h" 18 #include "content/browser/frame_host/render_frame_host_impl.h"
17 #include "content/browser/renderer_host/render_view_host_delegate.h" 19 #include "content/browser/renderer_host/render_view_host_delegate.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 ui::TEXT_INPUT_TYPE_PASSWORD, 82 ui::TEXT_INPUT_TYPE_PASSWORD,
81 ui::TEXT_INPUT_TYPE_SEARCH, 83 ui::TEXT_INPUT_TYPE_SEARCH,
82 ui::TEXT_INPUT_TYPE_URL, 84 ui::TEXT_INPUT_TYPE_URL,
83 ui::TEXT_INPUT_TYPE_EMAIL, 85 ui::TEXT_INPUT_TYPE_EMAIL,
84 ui::TEXT_INPUT_TYPE_TELEPHONE, 86 ui::TEXT_INPUT_TYPE_TELEPHONE,
85 ui::TEXT_INPUT_TYPE_NUMBER, 87 ui::TEXT_INPUT_TYPE_NUMBER,
86 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE); 88 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
87 return true; 89 return true;
88 } 90 }
89 91
92 // Callback from Java to convert BackgroundColorSpan data to a
93 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|.
94 void AppendBackgroundColorSpan(JNIEnv*,
95 jclass,
96 jlong underlines_ptr,
97 jint start,
98 jint end,
99 jint background_color) {
100 std::vector<blink::WebCompositionUnderline>* underlines =
101 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>(
102 underlines_ptr);
103 underlines->push_back(
104 blink::WebCompositionUnderline(static_cast<unsigned>(start),
105 static_cast<unsigned>(end),
106 SK_ColorTRANSPARENT,
107 false,
108 static_cast<unsigned>(background_color)));
109 }
110
111 // Callback from Java to convert UnderlineSpan data to a
112 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|.
113 void AppendUnderlineSpan(JNIEnv*,
114 jclass,
115 jlong underlines_ptr,
116 jint start,
117 jint end) {
118 std::vector<blink::WebCompositionUnderline>* underlines =
119 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>(
120 underlines_ptr);
121 underlines->push_back(
122 blink::WebCompositionUnderline(static_cast<unsigned>(start),
123 static_cast<unsigned>(end),
124 SK_ColorBLACK,
125 false,
126 SK_ColorTRANSPARENT));
127 }
128
90 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) 129 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva)
91 : rwhva_(rwhva) { 130 : rwhva_(rwhva) {
92 } 131 }
93 132
94 ImeAdapterAndroid::~ImeAdapterAndroid() { 133 ImeAdapterAndroid::~ImeAdapterAndroid() {
95 JNIEnv* env = AttachCurrentThread(); 134 JNIEnv* env = AttachCurrentThread();
96 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); 135 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env);
97 if (!obj.is_null()) 136 if (!obj.is_null())
98 Java_ImeAdapter_detach(env, obj.obj()); 137 Java_ImeAdapter_detach(env, obj.obj());
99 } 138 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // roundtrip back to java such synthetic event. 170 // roundtrip back to java such synthetic event.
132 NativeWebKeyboardEvent char_event(blink::WebInputEvent::Char, modifiers, 171 NativeWebKeyboardEvent char_event(blink::WebInputEvent::Char, modifiers,
133 time_ms / 1000.0, key_code, unicode_char, 172 time_ms / 1000.0, key_code, unicode_char,
134 is_system_key); 173 is_system_key);
135 char_event.skip_in_browser = key_down_text_insertion; 174 char_event.skip_in_browser = key_down_text_insertion;
136 rwhva_->SendKeyEvent(char_event); 175 rwhva_->SendKeyEvent(char_event);
137 } 176 }
138 return true; 177 return true;
139 } 178 }
140 179
141 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, jobject, jstring text, 180 void ImeAdapterAndroid::SetComposingText(JNIEnv* env,
181 jobject obj,
182 jobject text,
183 jstring text_str,
142 int new_cursor_pos) { 184 int new_cursor_pos) {
143 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 185 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
144 if (!rwhi) 186 if (!rwhi)
145 return; 187 return;
146 188
147 base::string16 text16 = ConvertJavaStringToUTF16(env, text); 189 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str);
190
148 std::vector<blink::WebCompositionUnderline> underlines; 191 std::vector<blink::WebCompositionUnderline> underlines;
149 underlines.push_back( 192 // Iterate over spans in |text|, dispatch those that we care about (e.g.,
150 blink::WebCompositionUnderline(0, text16.length(), SK_ColorBLACK, 193 // BackgroundColorSpan) to a matching callback (e.g.,
151 false)); 194 // AppendBackgroundColorSpan()), and populate |underlines|.
195 Java_ImeAdapter_populateUnderlinesFromSpans(
196 env, obj, text, reinterpret_cast<jlong>(&underlines));
197
198 // Default to plain underline if we didn't find any span that we care about.
199 if (underlines.empty()) {
200 underlines.push_back(blink::WebCompositionUnderline(
201 0, text16.length(), SK_ColorBLACK, false, SK_ColorTRANSPARENT));
202 }
203 // Sort spans by |.startOffset|.
204 std::sort(underlines.begin(), underlines.end());
205
152 // new_cursor_position is as described in the Android API for 206 // new_cursor_position is as described in the Android API for
153 // InputConnection#setComposingText, whereas the parameters for 207 // InputConnection#setComposingText, whereas the parameters for
154 // ImeSetComposition are relative to the start of the composition. 208 // ImeSetComposition are relative to the start of the composition.
155 if (new_cursor_pos > 0) 209 if (new_cursor_pos > 0)
156 new_cursor_pos = text16.length() + new_cursor_pos - 1; 210 new_cursor_pos = text16.length() + new_cursor_pos - 1;
157 211
158 rwhi->ImeSetComposition(text16, underlines, new_cursor_pos, new_cursor_pos); 212 rwhi->ImeSetComposition(text16, underlines, new_cursor_pos, new_cursor_pos);
159 } 213 }
160 214
161 void ImeAdapterAndroid::CommitText(JNIEnv* env, jobject, jstring text) { 215 void ImeAdapterAndroid::CommitText(JNIEnv* env, jobject, jstring text_str) {
162 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 216 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
163 if (!rwhi) 217 if (!rwhi)
164 return; 218 return;
165 219
166 base::string16 text16 = ConvertJavaStringToUTF16(env, text); 220 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str);
167 rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false); 221 rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false);
168 } 222 }
169 223
170 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, jobject) { 224 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, jobject) {
171 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 225 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
172 if (!rwhi) 226 if (!rwhi)
173 return; 227 return;
174 228
175 rwhi->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), 229 rwhi->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
176 true); 230 true);
(...skipping 30 matching lines...) Expand all
207 start, end)); 261 start, end));
208 } 262 }
209 263
210 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, jobject, 264 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, jobject,
211 int start, int end) { 265 int start, int end) {
212 RenderFrameHost* rfh = GetFocusedFrame(); 266 RenderFrameHost* rfh = GetFocusedFrame();
213 if (!rfh) 267 if (!rfh)
214 return; 268 return;
215 269
216 std::vector<blink::WebCompositionUnderline> underlines; 270 std::vector<blink::WebCompositionUnderline> underlines;
217 underlines.push_back( 271 underlines.push_back(blink::WebCompositionUnderline(
218 blink::WebCompositionUnderline(0, end - start, SK_ColorBLACK, false)); 272 0, end - start, SK_ColorBLACK, false, SK_ColorTRANSPARENT));
219 273
220 rfh->Send(new FrameMsg_SetCompositionFromExistingText( 274 rfh->Send(new FrameMsg_SetCompositionFromExistingText(
221 rfh->GetRoutingID(), start, end, underlines)); 275 rfh->GetRoutingID(), start, end, underlines));
222 } 276 }
223 277
224 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, jobject, 278 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, jobject,
225 int before, int after) { 279 int before, int after) {
226 RenderFrameHostImpl* rfh = 280 RenderFrameHostImpl* rfh =
227 static_cast<RenderFrameHostImpl*>(GetFocusedFrame()); 281 static_cast<RenderFrameHostImpl*>(GetFocusedFrame());
228 if (rfh) 282 if (rfh)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 WebContents* ImeAdapterAndroid::GetWebContents() { 345 WebContents* ImeAdapterAndroid::GetWebContents() {
292 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); 346 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl();
293 if (!rwh) 347 if (!rwh)
294 return NULL; 348 return NULL;
295 if (!rwh->IsRenderView()) 349 if (!rwh->IsRenderView())
296 return NULL; 350 return NULL;
297 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); 351 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh));
298 } 352 }
299 353
300 } // namespace content 354 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698