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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ImeAdapter.java

Issue 11914003: Start sending synthetic keyevents for enter and tab in Android IME (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.Handler; 8 import android.os.Handler;
9 import android.os.ResultReceiver; 9 import android.os.ResultReceiver;
10 import android.text.Editable; 10 import android.text.Editable;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 sTextInputTypeTel = textInputTypeTel; 110 sTextInputTypeTel = textInputTypeTel;
111 sTextInputTypeNumber = textInputTypeNumber; 111 sTextInputTypeNumber = textInputTypeNumber;
112 sTextInputTypeWeek = textInputTypeWeek; 112 sTextInputTypeWeek = textInputTypeWeek;
113 sTextInputTypeContentEditable = textInputTypeContentEditable; 113 sTextInputTypeContentEditable = textInputTypeContentEditable;
114 InputDialogContainer.initializeInputTypes(textInputTypeDate, textInputTy peDateTime, 114 InputDialogContainer.initializeInputTypes(textInputTypeDate, textInputTy peDateTime,
115 textInputTypeDateTimeLocal, textInputTypeMonth, textInputTypeTim e); 115 textInputTypeDateTimeLocal, textInputTypeMonth, textInputTypeTim e);
116 } 116 }
117 117
118 private int mNativeImeAdapterAndroid; 118 private int mNativeImeAdapterAndroid;
119 private int mTextInputType; 119 private int mTextInputType;
120 private int mPreImeEventCount;
121 120
122 private Context mContext; 121 private Context mContext;
123 private SelectionHandleController mSelectionHandleController; 122 private SelectionHandleController mSelectionHandleController;
124 private InsertionHandleController mInsertionHandleController; 123 private InsertionHandleController mInsertionHandleController;
125 private AdapterInputConnection mInputConnection; 124 private AdapterInputConnection mInputConnection;
126 private ViewEmbedder mViewEmbedder; 125 private ViewEmbedder mViewEmbedder;
127 private Handler mHandler; 126 private Handler mHandler;
128 private InputDialogContainer mInputDialogContainer; 127 private InputDialogContainer mInputDialogContainer;
129 128
130 private class DelayedDismissInput implements Runnable { 129 private class DelayedDismissInput implements Runnable {
(...skipping 14 matching lines...) Expand all
145 144
146 // Delay introduced to avoid hiding the keyboard if new show requests are re ceived. 145 // Delay introduced to avoid hiding the keyboard if new show requests are re ceived.
147 // The time required by the unfocus-focus events triggered by tab has been m easured in soju: 146 // The time required by the unfocus-focus events triggered by tab has been m easured in soju:
148 // Mean: 18.633 ms, Standard deviation: 7.9837 ms. 147 // Mean: 18.633 ms, Standard deviation: 7.9837 ms.
149 // The value here should be higher enough to cover these cases, but not too high to avoid 148 // The value here should be higher enough to cover these cases, but not too high to avoid
150 // letting the user perceiving important delays. 149 // letting the user perceiving important delays.
151 private static final int INPUT_DISMISS_DELAY = 150; 150 private static final int INPUT_DISMISS_DELAY = 150;
152 151
153 ImeAdapter(Context context, SelectionHandleController selectionHandleControl ler, 152 ImeAdapter(Context context, SelectionHandleController selectionHandleControl ler,
154 InsertionHandleController insertionHandleController, ViewEmbedder em bedder) { 153 InsertionHandleController insertionHandleController, ViewEmbedder em bedder) {
155 mPreImeEventCount = 0;
156 mContext = context; 154 mContext = context;
157 mSelectionHandleController = selectionHandleController; 155 mSelectionHandleController = selectionHandleController;
158 mInsertionHandleController = insertionHandleController; 156 mInsertionHandleController = insertionHandleController;
159 mViewEmbedder = embedder; 157 mViewEmbedder = embedder;
160 mHandler = new Handler(); 158 mHandler = new Handler();
161 mInputDialogContainer = new InputDialogContainer(context, 159 mInputDialogContainer = new InputDialogContainer(context,
162 new InputDialogContainer.InputActionDelegate() { 160 new InputDialogContainer.InputActionDelegate() {
163 161
164 @Override 162 @Override
165 public void replaceDateTime(String text) { 163 public void replaceDateTime(String text) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 293 }
296 294
297 boolean hasTextInputType() { 295 boolean hasTextInputType() {
298 return isTextInputType(mTextInputType); 296 return isTextInputType(mTextInputType);
299 } 297 }
300 298
301 boolean hasDialogInputType() { 299 boolean hasDialogInputType() {
302 return InputDialogContainer.isDialogInputType(mTextInputType); 300 return InputDialogContainer.isDialogInputType(mTextInputType);
303 } 301 }
304 302
305 void dispatchKeyEventPreIme(KeyEvent event) {
306 // We only register that a key was pressed, but we don't actually interc ept
307 // it.
308 ++mPreImeEventCount;
309 }
310
311 boolean dispatchKeyEvent(KeyEvent event) { 303 boolean dispatchKeyEvent(KeyEvent event) {
312 mPreImeEventCount = 0;
313 return translateAndSendNativeEvents(event); 304 return translateAndSendNativeEvents(event);
314 } 305 }
315 306
316 void commitText() { 307 void commitText() {
317 cancelComposition(); 308 cancelComposition();
318 if (mNativeImeAdapterAndroid != 0) { 309 if (mNativeImeAdapterAndroid != 0) {
319 nativeCommitText(mNativeImeAdapterAndroid, ""); 310 nativeCommitText(mNativeImeAdapterAndroid, "");
320 } 311 }
321 } 312 }
322 313
(...skipping 11 matching lines...) Expand all
334 return false; 325 return false;
335 } 326 }
336 327
337 // Committing an empty string finishes the current composition. 328 // Committing an empty string finishes the current composition.
338 boolean isFinish = text.isEmpty(); 329 boolean isFinish = text.isEmpty();
339 if (!isFinish) { 330 if (!isFinish) {
340 mSelectionHandleController.hideAndDisallowAutomaticShowing(); 331 mSelectionHandleController.hideAndDisallowAutomaticShowing();
341 mInsertionHandleController.hideAndDisallowAutomaticShowing(); 332 mInsertionHandleController.hideAndDisallowAutomaticShowing();
342 } 333 }
343 mViewEmbedder.onImeEvent(isFinish); 334 mViewEmbedder.onImeEvent(isFinish);
344 boolean hasSingleChar = mPreImeEventCount == 1 && text.length() == 1; 335 boolean hasSingleChar = text.length() == 1;
aurimas (slooooooooow) 2013/01/16 00:39:57 This is not needed anymore since shouldSendKeyEven
Yusuf 2013/01/16 08:07:57 Done.
345 int keyCode = hasSingleChar ? text.codePointAt(0) : COMPOSITION_KEY_CODE ; 336 int keyCode = shouldSendKeyEventWithKeyCode(text);
346 int keyChar = hasSingleChar ? text.codePointAt(0) : 0; 337 int keyChar = keyCode == COMPOSITION_KEY_CODE ? 0 : text.codePointAt(0);
347 long timeStampMs = System.currentTimeMillis(); 338 long timeStampMs = System.currentTimeMillis();
339
348 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeRawKeyDo wn, 340 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeRawKeyDo wn,
349 timeStampMs, keyCode, keyChar); 341 timeStampMs, keyCode, keyChar);
350 if (hasSingleChar) { 342 if (hasSingleChar && keyCode != COMPOSITION_KEY_CODE) {
351 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeChar , 343 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeChar ,
352 timeStampMs, text.codePointAt(0), text.codePointAt(0)); 344 timeStampMs, keyCode, keyChar);
Ted C 2013/01/16 02:13:30 previously this sent the same two values...now you
Yusuf 2013/01/16 08:07:57 Sadly this part of the code never really worked fo
353 } else { 345 } else {
354 if (isCommit) { 346 if (isCommit) {
355 nativeCommitText(mNativeImeAdapterAndroid, text); 347 nativeCommitText(mNativeImeAdapterAndroid, text);
356 } else { 348 } else {
357 nativeSetComposingText(mNativeImeAdapterAndroid, text, newCursor Position); 349 nativeSetComposingText(mNativeImeAdapterAndroid, text, newCursor Position);
358 } 350 }
359 } 351 }
360 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeKeyUp, 352 nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeKeyUp,
361 timeStampMs, keyCode, keyChar); 353 timeStampMs, keyCode, keyChar);
362 mPreImeEventCount = 0;
363 return true; 354 return true;
364 } 355 }
365 356
357 private int shouldSendKeyEventWithKeyCode(String singleChar) {
aurimas (slooooooooow) 2013/01/16 00:39:57 Might not be a single char, should call it some ot
Yusuf 2013/01/16 08:07:57 Done.
358 if (singleChar.equals("\n")) return KeyEvent.KEYCODE_ENTER;
359 else if (singleChar.equals("\t")) return KeyEvent.KEYCODE_TAB;
360 else return COMPOSITION_KEY_CODE;
361 }
362
366 private boolean translateAndSendNativeEvents(KeyEvent event) { 363 private boolean translateAndSendNativeEvents(KeyEvent event) {
367 if (mNativeImeAdapterAndroid == 0) { 364 if (mNativeImeAdapterAndroid == 0) {
368 return false; 365 return false;
369 } 366 }
370 int action = event.getAction(); 367 int action = event.getAction();
371 if (action != KeyEvent.ACTION_DOWN && 368 if (action != KeyEvent.ACTION_DOWN &&
372 action != KeyEvent.ACTION_UP) { 369 action != KeyEvent.ACTION_UP) {
373 // action == KeyEvent.ACTION_MULTIPLE 370 // action == KeyEvent.ACTION_MULTIPLE
374 // TODO(bulach): confirm the actual behavior. Apparently: 371 // TODO(bulach): confirm the actual behavior. Apparently:
375 // If event.getKeyCode() == KEYCODE_UNKNOWN, we can send a 372 // If event.getKeyCode() == KEYCODE_UNKNOWN, we can send a
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 786
790 private native void nativeDeleteSurroundingText(int nativeImeAdapterAndroid, 787 private native void nativeDeleteSurroundingText(int nativeImeAdapterAndroid,
791 int before, int after); 788 int before, int after);
792 789
793 private native void nativeUnselect(int nativeImeAdapterAndroid); 790 private native void nativeUnselect(int nativeImeAdapterAndroid);
794 private native void nativeSelectAll(int nativeImeAdapterAndroid); 791 private native void nativeSelectAll(int nativeImeAdapterAndroid);
795 private native void nativeCut(int nativeImeAdapterAndroid); 792 private native void nativeCut(int nativeImeAdapterAndroid);
796 private native void nativeCopy(int nativeImeAdapterAndroid); 793 private native void nativeCopy(int nativeImeAdapterAndroid);
797 private native void nativePaste(int nativeImeAdapterAndroid); 794 private native void nativePaste(int nativeImeAdapterAndroid);
798 } 795 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698