Merge "Add javascript key events for special characters."
This commit is contained in:
@@ -556,17 +556,13 @@ public class WebView extends AbsoluteLayout
|
||||
&& TextUtils.regionMatches(text, 0, original, 0,
|
||||
textLength);
|
||||
}
|
||||
boolean sendChange = false;
|
||||
if (isCharacterAdd) {
|
||||
sendChange = !sendCharacter(text.charAt(textLength - 1));
|
||||
sendCharacter(text.charAt(textLength - 1));
|
||||
} else if (isCharacterDelete) {
|
||||
sendDeleteKey();
|
||||
} else {
|
||||
sendChange = (textLength != originalLength) ||
|
||||
!TextUtils.regionMatches(text, 0, original, 0,
|
||||
textLength);
|
||||
}
|
||||
if (sendChange) {
|
||||
} else if ((textLength != originalLength) ||
|
||||
!TextUtils.regionMatches(text, 0, original, 0,
|
||||
textLength)) {
|
||||
// Send a message so that key strokes and text replacement
|
||||
// do not come out of order.
|
||||
Message replaceMessage = mPrivateHandler.obtainMessage(
|
||||
@@ -580,20 +576,21 @@ public class WebView extends AbsoluteLayout
|
||||
* Send a single character to the WebView as a key down and up event.
|
||||
* @param c The character to be sent.
|
||||
*/
|
||||
private boolean sendCharacter(char c) {
|
||||
private void sendCharacter(char c) {
|
||||
if (mKeyCharacterMap == null) {
|
||||
mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
||||
}
|
||||
char[] chars = new char[1];
|
||||
chars[0] = c;
|
||||
KeyEvent[] events = mKeyCharacterMap.getEvents(chars);
|
||||
boolean mapsToKeyEvent = (events != null);
|
||||
if (mapsToKeyEvent) {
|
||||
if (events != null) {
|
||||
for (KeyEvent event : events) {
|
||||
sendKeyEvent(event);
|
||||
}
|
||||
} else {
|
||||
Message msg = mPrivateHandler.obtainMessage(KEY_PRESS, (int) c, 0);
|
||||
mPrivateHandler.sendMessage(msg);
|
||||
}
|
||||
return mapsToKeyEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1031,6 +1028,7 @@ public class WebView extends AbsoluteLayout
|
||||
static final int INIT_EDIT_FIELD = 142;
|
||||
static final int REPLACE_TEXT = 143;
|
||||
static final int CLEAR_CARET_HANDLE = 144;
|
||||
static final int KEY_PRESS = 145;
|
||||
|
||||
private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID;
|
||||
private static final int LAST_PACKAGE_MSG_ID = HIT_TEST_RESULT;
|
||||
@@ -9229,6 +9227,10 @@ public class WebView extends AbsoluteLayout
|
||||
selectionDone();
|
||||
break;
|
||||
|
||||
case KEY_PRESS:
|
||||
mWebViewCore.sendMessage(EventHub.KEY_PRESS, msg.arg1);
|
||||
break;
|
||||
|
||||
default:
|
||||
super.handleMessage(msg);
|
||||
break;
|
||||
|
||||
@@ -1173,8 +1173,11 @@ public final class WebViewCore {
|
||||
static final int TRUST_STORAGE_UPDATED = 220;
|
||||
|
||||
// find-on-page controls
|
||||
static final int FIND_ALL = 220;
|
||||
static final int FIND_NEXT = 221;
|
||||
static final int FIND_ALL = 221;
|
||||
static final int FIND_NEXT = 222;
|
||||
|
||||
// key was pressed (down and up)
|
||||
static final int KEY_PRESS = 223;
|
||||
|
||||
// Private handler for WebCore messages.
|
||||
private Handler mHandler;
|
||||
@@ -1355,6 +1358,10 @@ public final class WebViewCore {
|
||||
key((KeyEvent) msg.obj, false);
|
||||
break;
|
||||
|
||||
case KEY_PRESS:
|
||||
keyPress(msg.arg1);
|
||||
break;
|
||||
|
||||
case FAKE_CLICK:
|
||||
nativeClick(mNativeClass, msg.arg1, msg.arg2, true);
|
||||
break;
|
||||
@@ -2061,6 +2068,11 @@ public final class WebViewCore {
|
||||
}
|
||||
}
|
||||
|
||||
private void keyPress(int unicodeChar) {
|
||||
nativeKey(mNativeClass, 0, unicodeChar, 0, false, false, false, true);
|
||||
nativeKey(mNativeClass, 0, unicodeChar, 0, false, false, false, false);
|
||||
}
|
||||
|
||||
// These values are used to avoid requesting a layout based on old values
|
||||
private int mCurrentViewWidth = 0;
|
||||
private int mCurrentViewHeight = 0;
|
||||
|
||||
Reference in New Issue
Block a user