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

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: Changing early-exit in populateUnderlinesFromSpans() to if{}. 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(blink::WebCompositionUnderline(
104 start, end, SK_ColorTRANSPARENT, false, background_color));
Ted C 2014/06/10 20:47:33 indented 4 too much same for the underlines push_
huangs 2014/06/11 02:41:01 Done.
105 }
106
107 // Callback from Java to convert UnderlineSpan data to a
108 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|.
109 void AppendUnderlineSpan(JNIEnv*,
110 jclass,
111 jlong underlines_ptr,
112 jint start,
113 jint end) {
114 std::vector<blink::WebCompositionUnderline>* underlines =
115 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>(
116 underlines_ptr);
117 underlines->push_back(blink::WebCompositionUnderline(
118 start, end, SK_ColorBLACK, false, SK_ColorTRANSPARENT));
119 }
120
90 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) 121 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva)
91 : rwhva_(rwhva) { 122 : rwhva_(rwhva) {
92 } 123 }
93 124
94 ImeAdapterAndroid::~ImeAdapterAndroid() { 125 ImeAdapterAndroid::~ImeAdapterAndroid() {
95 JNIEnv* env = AttachCurrentThread(); 126 JNIEnv* env = AttachCurrentThread();
96 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); 127 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env);
97 if (!obj.is_null()) 128 if (!obj.is_null())
98 Java_ImeAdapter_detach(env, obj.obj()); 129 Java_ImeAdapter_detach(env, obj.obj());
99 } 130 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // roundtrip back to java such synthetic event. 162 // roundtrip back to java such synthetic event.
132 NativeWebKeyboardEvent char_event(blink::WebInputEvent::Char, modifiers, 163 NativeWebKeyboardEvent char_event(blink::WebInputEvent::Char, modifiers,
133 time_ms / 1000.0, key_code, unicode_char, 164 time_ms / 1000.0, key_code, unicode_char,
134 is_system_key); 165 is_system_key);
135 char_event.skip_in_browser = key_down_text_insertion; 166 char_event.skip_in_browser = key_down_text_insertion;
136 rwhva_->SendKeyEvent(char_event); 167 rwhva_->SendKeyEvent(char_event);
137 } 168 }
138 return true; 169 return true;
139 } 170 }
140 171
141 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, jobject, jstring text, 172 void ImeAdapterAndroid::SetComposingText(JNIEnv* env,
173 jobject obj,
174 jobject text,
175 jstring text_str,
142 int new_cursor_pos) { 176 int new_cursor_pos) {
143 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 177 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
144 if (!rwhi) 178 if (!rwhi)
145 return; 179 return;
146 180
147 base::string16 text16 = ConvertJavaStringToUTF16(env, text); 181 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str);
182
148 std::vector<blink::WebCompositionUnderline> underlines; 183 std::vector<blink::WebCompositionUnderline> underlines;
149 underlines.push_back( 184 // Iterate over spans in |text|, dispatch those that we care about (e.g.,
150 blink::WebCompositionUnderline(0, text16.length(), SK_ColorBLACK, 185 // BackgroundColorSpan) to a matching callback (e.g.,
151 false)); 186 // AppendBackgroundColorSpan()), and populate |underlines|.
187 Java_ImeAdapter_populateUnderlinesFromSpans(env, obj, text,
188 reinterpret_cast<jlong>(&underlines));
189
190 // Default to plain underline if we didn't find any span that we care about.
191 if (underlines.empty()) {
192 underlines.push_back(
193 blink::WebCompositionUnderline(0, text16.length(), SK_ColorBLACK, false,
194 SK_ColorTRANSPARENT));
195 }
196 // Sort spans by |.startOffset|.
197 std::sort(underlines.begin(), underlines.end());
198
152 // new_cursor_position is as described in the Android API for 199 // new_cursor_position is as described in the Android API for
153 // InputConnection#setComposingText, whereas the parameters for 200 // InputConnection#setComposingText, whereas the parameters for
154 // ImeSetComposition are relative to the start of the composition. 201 // ImeSetComposition are relative to the start of the composition.
155 if (new_cursor_pos > 0) 202 if (new_cursor_pos > 0)
156 new_cursor_pos = text16.length() + new_cursor_pos - 1; 203 new_cursor_pos = text16.length() + new_cursor_pos - 1;
157 204
158 rwhi->ImeSetComposition(text16, underlines, new_cursor_pos, new_cursor_pos); 205 rwhi->ImeSetComposition(text16, underlines, new_cursor_pos, new_cursor_pos);
159 } 206 }
160 207
161 void ImeAdapterAndroid::CommitText(JNIEnv* env, jobject, jstring text) { 208 void ImeAdapterAndroid::CommitText(JNIEnv* env, jobject, jstring text_str) {
162 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 209 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
163 if (!rwhi) 210 if (!rwhi)
164 return; 211 return;
165 212
166 base::string16 text16 = ConvertJavaStringToUTF16(env, text); 213 base::string16 text16 = ConvertJavaStringToUTF16(env, text_str);
167 rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false); 214 rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false);
168 } 215 }
169 216
170 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, jobject) { 217 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, jobject) {
171 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); 218 RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl();
172 if (!rwhi) 219 if (!rwhi)
173 return; 220 return;
174 221
175 rwhi->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), 222 rwhi->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
176 true); 223 true);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 255 }
209 256
210 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, jobject, 257 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, jobject,
211 int start, int end) { 258 int start, int end) {
212 RenderFrameHost* rfh = GetFocusedFrame(); 259 RenderFrameHost* rfh = GetFocusedFrame();
213 if (!rfh) 260 if (!rfh)
214 return; 261 return;
215 262
216 std::vector<blink::WebCompositionUnderline> underlines; 263 std::vector<blink::WebCompositionUnderline> underlines;
217 underlines.push_back( 264 underlines.push_back(
218 blink::WebCompositionUnderline(0, end - start, SK_ColorBLACK, false)); 265 blink::WebCompositionUnderline(0, end - start, SK_ColorBLACK, false,
266 SK_ColorTRANSPARENT));
219 267
220 rfh->Send(new FrameMsg_SetCompositionFromExistingText( 268 rfh->Send(new FrameMsg_SetCompositionFromExistingText(
221 rfh->GetRoutingID(), start, end, underlines)); 269 rfh->GetRoutingID(), start, end, underlines));
222 } 270 }
223 271
224 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, jobject, 272 void ImeAdapterAndroid::DeleteSurroundingText(JNIEnv*, jobject,
225 int before, int after) { 273 int before, int after) {
226 RenderFrameHostImpl* rfh = 274 RenderFrameHostImpl* rfh =
227 static_cast<RenderFrameHostImpl*>(GetFocusedFrame()); 275 static_cast<RenderFrameHostImpl*>(GetFocusedFrame());
228 if (rfh) 276 if (rfh)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 WebContents* ImeAdapterAndroid::GetWebContents() { 339 WebContents* ImeAdapterAndroid::GetWebContents() {
292 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); 340 RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl();
293 if (!rwh) 341 if (!rwh)
294 return NULL; 342 return NULL;
295 if (!rwh->IsRenderView()) 343 if (!rwh->IsRenderView())
296 return NULL; 344 return NULL;
297 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); 345 return WebContents::FromRenderViewHost(RenderViewHost::From(rwh));
298 } 346 }
299 347
300 } // namespace content 348 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698