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

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

Issue 834133004: Don't initialize C++ constants in Java during JNI registration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: multi-line package name yet again Created 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.input; 5 package org.chromium.content.browser.input;
6 6
7 import android.os.SystemClock; 7 import android.os.SystemClock;
8 import android.text.Editable; 8 import android.text.Editable;
9 import android.text.InputType; 9 import android.text.InputType;
10 import android.text.Selection; 10 import android.text.Selection;
11 import android.text.TextUtils; 11 import android.text.TextUtils;
12 import android.util.Log; 12 import android.util.Log;
13 import android.view.KeyCharacterMap; 13 import android.view.KeyCharacterMap;
14 import android.view.KeyEvent; 14 import android.view.KeyEvent;
15 import android.view.View; 15 import android.view.View;
16 import android.view.inputmethod.BaseInputConnection; 16 import android.view.inputmethod.BaseInputConnection;
17 import android.view.inputmethod.EditorInfo; 17 import android.view.inputmethod.EditorInfo;
18 import android.view.inputmethod.ExtractedText; 18 import android.view.inputmethod.ExtractedText;
19 import android.view.inputmethod.ExtractedTextRequest; 19 import android.view.inputmethod.ExtractedTextRequest;
20 20
21 import org.chromium.base.VisibleForTesting; 21 import org.chromium.base.VisibleForTesting;
22 import org.chromium.blink_public.web.WebInputEventType;
23 import org.chromium.blink_public.web.WebTextInputFlags;
22 import org.chromium.ui.base.ime.TextInputType; 24 import org.chromium.ui.base.ime.TextInputType;
23 25
24 /** 26 /**
25 * InputConnection is created by ContentView.onCreateInputConnection. 27 * InputConnection is created by ContentView.onCreateInputConnection.
26 * It then adapts android's IME to chrome's RenderWidgetHostView using the 28 * It then adapts android's IME to chrome's RenderWidgetHostView using the
27 * native ImeAdapterAndroid via the class ImeAdapter. 29 * native ImeAdapterAndroid via the class ImeAdapter.
28 */ 30 */
29 public class AdapterInputConnection extends BaseInputConnection { 31 public class AdapterInputConnection extends BaseInputConnection {
30 private static final String TAG = "AdapterInputConnection"; 32 private static final String TAG = "AdapterInputConnection";
31 private static final boolean DEBUG = false; 33 private static final boolean DEBUG = false;
(...skipping 30 matching lines...) Expand all
62 // when taking ownership of an existing Editable. 64 // when taking ownership of an existing Editable.
63 removeComposingSpans(mEditable); 65 removeComposingSpans(mEditable);
64 mSingleLine = true; 66 mSingleLine = true;
65 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN 67 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN
66 | EditorInfo.IME_FLAG_NO_EXTRACT_UI; 68 | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
67 outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT 69 outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
68 | EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT; 70 | EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;
69 71
70 int inputType = imeAdapter.getTextInputType(); 72 int inputType = imeAdapter.getTextInputType();
71 int inputFlags = imeAdapter.getTextInputFlags(); 73 int inputFlags = imeAdapter.getTextInputFlags();
72 if ((inputFlags & ImeAdapter.sTextInputFlagAutocompleteOff) != 0) { 74 if ((inputFlags & WebTextInputFlags.AutocompleteOff) != 0) {
73 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; 75 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
74 } 76 }
75 77
76 if (inputType == TextInputType.TEXT) { 78 if (inputType == TextInputType.TEXT) {
77 // Normal text field 79 // Normal text field
78 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; 80 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
79 if ((inputFlags & ImeAdapter.sTextInputFlagAutocorrectOff) == 0) { 81 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) {
80 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; 82 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
81 } 83 }
82 } else if (inputType == TextInputType.TEXT_AREA 84 } else if (inputType == TextInputType.TEXT_AREA
83 || inputType == TextInputType.CONTENT_EDITABLE) { 85 || inputType == TextInputType.CONTENT_EDITABLE) {
84 // TextArea or contenteditable. 86 // TextArea or contenteditable.
85 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE 87 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
86 | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES; 88 | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES;
87 if ((inputFlags & ImeAdapter.sTextInputFlagAutocorrectOff) == 0) { 89 if ((inputFlags & WebTextInputFlags.AutocorrectOff) == 0) {
88 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; 90 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
89 } 91 }
90 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE; 92 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
91 mSingleLine = false; 93 mSingleLine = false;
92 } else if (inputType == TextInputType.PASSWORD) { 94 } else if (inputType == TextInputType.PASSWORD) {
93 // Password 95 // Password
94 outAttrs.inputType = InputType.TYPE_CLASS_TEXT 96 outAttrs.inputType = InputType.TYPE_CLASS_TEXT
95 | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD; 97 | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
96 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO; 98 outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
97 } else if (inputType == TextInputType.SEARCH) { 99 } else if (inputType == TextInputType.SEARCH) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 * @see BaseInputConnection#performEditorAction(int) 264 * @see BaseInputConnection#performEditorAction(int)
263 */ 265 */
264 @Override 266 @Override
265 public boolean performEditorAction(int actionCode) { 267 public boolean performEditorAction(int actionCode) {
266 if (DEBUG) Log.w(TAG, "performEditorAction [" + actionCode + "]"); 268 if (DEBUG) Log.w(TAG, "performEditorAction [" + actionCode + "]");
267 if (actionCode == EditorInfo.IME_ACTION_NEXT) { 269 if (actionCode == EditorInfo.IME_ACTION_NEXT) {
268 restartInput(); 270 restartInput();
269 // Send TAB key event 271 // Send TAB key event
270 long timeStampMs = SystemClock.uptimeMillis(); 272 long timeStampMs = SystemClock.uptimeMillis();
271 mImeAdapter.sendSyntheticKeyEvent( 273 mImeAdapter.sendSyntheticKeyEvent(
272 ImeAdapter.sEventTypeRawKeyDown, timeStampMs, KeyEvent.KEYCO DE_TAB, 0, 0); 274 WebInputEventType.RawKeyDown, timeStampMs, KeyEvent.KEYCODE_ TAB, 0, 0);
273 } else { 275 } else {
274 mImeAdapter.sendKeyEventWithKeyCode(KeyEvent.KEYCODE_ENTER, 276 mImeAdapter.sendKeyEventWithKeyCode(KeyEvent.KEYCODE_ENTER,
275 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE 277 KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE
276 | KeyEvent.FLAG_EDITOR_ACTION); 278 | KeyEvent.FLAG_EDITOR_ACTION);
277 } 279 }
278 return true; 280 return true;
279 } 281 }
280 282
281 /** 283 /**
282 * @see BaseInputConnection#performContextMenuAction(int) 284 * @see BaseInputConnection#performContextMenuAction(int)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 int keyCode = KeyEvent.KEYCODE_UNKNOWN; 361 int keyCode = KeyEvent.KEYCODE_UNKNOWN;
360 if (originalBeforeLength == 1 && originalAfterLength == 0) { 362 if (originalBeforeLength == 1 && originalAfterLength == 0) {
361 keyCode = KeyEvent.KEYCODE_DEL; 363 keyCode = KeyEvent.KEYCODE_DEL;
362 } else if (originalBeforeLength == 0 && originalAfterLength == 1) { 364 } else if (originalBeforeLength == 0 && originalAfterLength == 1) {
363 keyCode = KeyEvent.KEYCODE_FORWARD_DEL; 365 keyCode = KeyEvent.KEYCODE_FORWARD_DEL;
364 } 366 }
365 367
366 boolean result = true; 368 boolean result = true;
367 if (keyCode == KeyEvent.KEYCODE_UNKNOWN) { 369 if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
368 result = mImeAdapter.sendSyntheticKeyEvent( 370 result = mImeAdapter.sendSyntheticKeyEvent(
369 ImeAdapter.sEventTypeRawKeyDown, SystemClock.uptimeMillis(), keyCode, 0, 0); 371 WebInputEventType.RawKeyDown, SystemClock.uptimeMillis(), ke yCode, 0, 0);
370 result &= mImeAdapter.deleteSurroundingText(beforeLength, afterLengt h); 372 result &= mImeAdapter.deleteSurroundingText(beforeLength, afterLengt h);
371 result &= mImeAdapter.sendSyntheticKeyEvent( 373 result &= mImeAdapter.sendSyntheticKeyEvent(
372 ImeAdapter.sEventTypeKeyUp, SystemClock.uptimeMillis(), keyC ode, 0, 0); 374 WebInputEventType.KeyUp, SystemClock.uptimeMillis(), keyCode , 0, 0);
373 } else { 375 } else {
374 mImeAdapter.sendKeyEventWithKeyCode( 376 mImeAdapter.sendKeyEventWithKeyCode(
375 keyCode, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TO UCH_MODE); 377 keyCode, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TO UCH_MODE);
376 } 378 }
377 return result; 379 return result;
378 } 380 }
379 381
380 /** 382 /**
381 * @see BaseInputConnection#sendKeyEvent(android.view.KeyEvent) 383 * @see BaseInputConnection#sendKeyEvent(android.view.KeyEvent)
382 */ 384 */
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 @VisibleForTesting 607 @VisibleForTesting
606 ImeState getImeStateForTesting() { 608 ImeState getImeStateForTesting() {
607 String text = mEditable.toString(); 609 String text = mEditable.toString();
608 int selectionStart = Selection.getSelectionStart(mEditable); 610 int selectionStart = Selection.getSelectionStart(mEditable);
609 int selectionEnd = Selection.getSelectionEnd(mEditable); 611 int selectionEnd = Selection.getSelectionEnd(mEditable);
610 int compositionStart = getComposingSpanStart(mEditable); 612 int compositionStart = getComposingSpanStart(mEditable);
611 int compositionEnd = getComposingSpanEnd(mEditable); 613 int compositionEnd = getComposingSpanEnd(mEditable);
612 return new ImeState(text, selectionStart, selectionEnd, compositionStart , compositionEnd); 614 return new ImeState(text, selectionStart, selectionEnd, compositionStart , compositionEnd);
613 } 615 }
614 } 616 }
OLDNEW
« no previous file with comments | « content/public/android/BUILD.gn ('k') | content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698