Skip to content

Commit 2dd2e5b

Browse files
jreckAndroid (Google) Code Review
authored andcommitted
Merge changes I2df047b6,I791eeb3c into ics-mr0
* changes: Fix rebuildWebTextView issues DO NOT MERGE Fixed spell check failing to change word.
2 parents 943da7b + e20bfd9 commit 2dd2e5b

File tree

2 files changed

+52
-31
lines changed

2 files changed

+52
-31
lines changed

core/java/android/webkit/WebTextView.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -607,23 +607,31 @@ protected void onTextChanged(CharSequence s,int start,int before,int count){
607607
// character or the existing selection, so it will not get cleared
608608
// above.
609609
mGotDelete = false;
610+
// Prefer sending javascript events, so when adding one character,
611+
// don't replace the unchanged text.
612+
if (count > 1 && before == count - 1) {
613+
String replaceButOne = s.subSequence(start,
614+
start + before).toString();
615+
String replacedString = getText().subSequence(start,
616+
start + before).toString();
617+
if (replaceButOne.equals(replacedString)) {
618+
// we're just adding one character
619+
start += before;
620+
before = 0;
621+
count = 1;
622+
}
623+
}
610624
// Find the last character being replaced. If it can be represented by
611-
// events, we will pass them to native (after replacing the beginning
612-
// of the changed text), so we can see javascript events.
613-
// Otherwise, replace the text being changed (including the last
614-
// character) in the textfield.
615-
TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0);
616-
KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
617-
KeyEvent[] events = kmap.getEvents(mCharacter);
618-
boolean cannotUseKeyEvents = null == events;
619-
int charactersFromKeyEvents = cannotUseKeyEvents ? 0 : 1;
620-
if (count > 1 || cannotUseKeyEvents) {
621-
String replace = s.subSequence(start,
622-
start + count - charactersFromKeyEvents).toString();
623-
mWebView.replaceTextfieldText(start, start + before, replace,
624-
start + count - charactersFromKeyEvents,
625-
start + count - charactersFromKeyEvents);
626-
} else {
625+
// events, we will pass them to native so we can see javascript events.
626+
// Otherwise, replace the text being changed in the textfield.
627+
KeyEvent[] events = null;
628+
if (count == 1) {
629+
TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0);
630+
KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
631+
events = kmap.getEvents(mCharacter);
632+
}
633+
boolean useKeyEvents = (events != null);
634+
if (useKeyEvents) {
627635
// This corrects the selection which may have been affected by the
628636
// trackball or auto-correct.
629637
if (DebugFlags.WEB_TEXT_VIEW) {
@@ -633,8 +641,6 @@ protected void onTextChanged(CharSequence s,int start,int before,int count){
633641
if (!mInSetTextAndKeepSelection) {
634642
mWebView.setSelection(start, start + before);
635643
}
636-
}
637-
if (!cannotUseKeyEvents) {
638644
int length = events.length;
639645
for (int i = 0; i < length; i++) {
640646
// We never send modifier keys to native code so don't send them
@@ -643,6 +649,12 @@ protected void onTextChanged(CharSequence s,int start,int before,int count){
643649
sendDomEvent(events[i]);
644650
}
645651
}
652+
} else {
653+
String replace = s.subSequence(start,
654+
start + count).toString();
655+
mWebView.replaceTextfieldText(start, start + before, replace,
656+
start + count,
657+
start + count);
646658
}
647659
updateCachedTextfield();
648660
}
@@ -966,8 +978,11 @@ private void setMaxLength(int maxLength) {
966978
* @param text The new text to place in the textfield.
967979
*/
968980
/* package */ void setTextAndKeepSelection(String text) {
969-
mPreChange = text.toString();
970981
Editable edit = getText();
982+
mPreChange = text;
983+
if (edit.toString().equals(text)) {
984+
return;
985+
}
971986
int selStart = Selection.getSelectionStart(edit);
972987
int selEnd = Selection.getSelectionEnd(edit);
973988
mInSetTextAndKeepSelection = true;
@@ -1075,6 +1090,7 @@ private void setMaxLength(int maxLength) {
10751090
setMaxLength(maxLength);
10761091
setHorizontallyScrolling(single);
10771092
setInputType(inputType);
1093+
clearComposingText();
10781094
setImeOptions(imeOptions);
10791095
setVisibility(VISIBLE);
10801096
if (!autoComplete) {

core/java/android/webkit/WebView.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4798,16 +4798,7 @@ private void hideSoftKeyboard() {
47984798
mTextGeneration = 0;
47994799
}
48004800
mWebTextView.updateTextSize();
4801-
Rect visibleRect = new Rect();
4802-
calcOurContentVisibleRect(visibleRect);
4803-
// Note that sendOurVisibleRect calls viewToContent, so the coordinates
4804-
// should be in content coordinates.
4805-
Rect bounds = nativeFocusCandidateNodeBounds();
4806-
Rect vBox = contentToViewRect(bounds);
4807-
mWebTextView.setRect(vBox.left, vBox.top, vBox.width(), vBox.height());
4808-
if (!Rect.intersects(bounds, visibleRect)) {
4809-
revealSelection();
4810-
}
4801+
updateWebTextViewPosition();
48114802
String text = nativeFocusCandidateText();
48124803
int nodePointer = nativeFocusCandidatePointer();
48134804
// This needs to be called before setType, which may call
@@ -4816,7 +4807,6 @@ private void hideSoftKeyboard() {
48164807
mWebTextView.setType(nativeFocusCandidateType());
48174808
// Gravity needs to be set after setType
48184809
mWebTextView.setGravityForRtl(nativeFocusCandidateIsRtlText());
4819-
updateWebTextViewPadding();
48204810
if (null == text) {
48214811
if (DebugFlags.WEB_VIEW) {
48224812
Log.v(LOGTAG, "rebuildWebTextView null == text");
@@ -4827,12 +4817,27 @@ private void hideSoftKeyboard() {
48274817
InputMethodManager imm = InputMethodManager.peekInstance();
48284818
if (imm != null && imm.isActive(mWebTextView)) {
48294819
imm.restartInput(mWebTextView);
4820+
mWebTextView.clearComposingText();
48304821
}
48314822
if (isFocused()) {
48324823
mWebTextView.requestFocus();
48334824
}
48344825
}
48354826

4827+
public void updateWebTextViewPosition() {
4828+
Rect visibleRect = new Rect();
4829+
calcOurContentVisibleRect(visibleRect);
4830+
// Note that sendOurVisibleRect calls viewToContent, so the coordinates
4831+
// should be in content coordinates.
4832+
Rect bounds = nativeFocusCandidateNodeBounds();
4833+
Rect vBox = contentToViewRect(bounds);
4834+
mWebTextView.setRect(vBox.left, vBox.top, vBox.width(), vBox.height());
4835+
if (!Rect.intersects(bounds, visibleRect)) {
4836+
revealSelection();
4837+
}
4838+
updateWebTextViewPadding();
4839+
}
4840+
48364841
/**
48374842
* Update the padding of mWebTextView based on the native textfield/textarea
48384843
*/
@@ -8433,7 +8438,7 @@ public void handleMessage(Message msg) {
84338438
// this is sent after finishing resize in WebViewCore. Make
84348439
// sure the text edit box is still on the screen.
84358440
if (inEditingMode() && nativeCursorIsTextInput()) {
8436-
rebuildWebTextView();
8441+
updateWebTextViewPosition();
84378442
}
84388443
break;
84398444
case CLEAR_TEXT_ENTRY:

0 commit comments

Comments
 (0)