Merge changes I2df047b6,I791eeb3c into ics-mr0

* changes:
  Fix rebuildWebTextView issues
  DO NOT MERGE Fixed spell check failing to change word.
This commit is contained in:
John Reck
2011-10-21 13:01:48 -07:00
committed by Android (Google) Code Review
2 changed files with 52 additions and 31 deletions

View File

@@ -607,23 +607,31 @@ import junit.framework.Assert;
// character or the existing selection, so it will not get cleared // character or the existing selection, so it will not get cleared
// above. // above.
mGotDelete = false; mGotDelete = false;
// Prefer sending javascript events, so when adding one character,
// don't replace the unchanged text.
if (count > 1 && before == count - 1) {
String replaceButOne = s.subSequence(start,
start + before).toString();
String replacedString = getText().subSequence(start,
start + before).toString();
if (replaceButOne.equals(replacedString)) {
// we're just adding one character
start += before;
before = 0;
count = 1;
}
}
// Find the last character being replaced. If it can be represented by // Find the last character being replaced. If it can be represented by
// events, we will pass them to native (after replacing the beginning // events, we will pass them to native so we can see javascript events.
// of the changed text), so we can see javascript events. // Otherwise, replace the text being changed in the textfield.
// Otherwise, replace the text being changed (including the last KeyEvent[] events = null;
// character) in the textfield. if (count == 1) {
TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0); TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0);
KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
KeyEvent[] events = kmap.getEvents(mCharacter); events = kmap.getEvents(mCharacter);
boolean cannotUseKeyEvents = null == events; }
int charactersFromKeyEvents = cannotUseKeyEvents ? 0 : 1; boolean useKeyEvents = (events != null);
if (count > 1 || cannotUseKeyEvents) { if (useKeyEvents) {
String replace = s.subSequence(start,
start + count - charactersFromKeyEvents).toString();
mWebView.replaceTextfieldText(start, start + before, replace,
start + count - charactersFromKeyEvents,
start + count - charactersFromKeyEvents);
} else {
// This corrects the selection which may have been affected by the // This corrects the selection which may have been affected by the
// trackball or auto-correct. // trackball or auto-correct.
if (DebugFlags.WEB_TEXT_VIEW) { if (DebugFlags.WEB_TEXT_VIEW) {
@@ -633,8 +641,6 @@ import junit.framework.Assert;
if (!mInSetTextAndKeepSelection) { if (!mInSetTextAndKeepSelection) {
mWebView.setSelection(start, start + before); mWebView.setSelection(start, start + before);
} }
}
if (!cannotUseKeyEvents) {
int length = events.length; int length = events.length;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
// We never send modifier keys to native code so don't send them // We never send modifier keys to native code so don't send them
@@ -643,6 +649,12 @@ import junit.framework.Assert;
sendDomEvent(events[i]); sendDomEvent(events[i]);
} }
} }
} else {
String replace = s.subSequence(start,
start + count).toString();
mWebView.replaceTextfieldText(start, start + before, replace,
start + count,
start + count);
} }
updateCachedTextfield(); updateCachedTextfield();
} }
@@ -966,8 +978,11 @@ import junit.framework.Assert;
* @param text The new text to place in the textfield. * @param text The new text to place in the textfield.
*/ */
/* package */ void setTextAndKeepSelection(String text) { /* package */ void setTextAndKeepSelection(String text) {
mPreChange = text.toString();
Editable edit = getText(); Editable edit = getText();
mPreChange = text;
if (edit.toString().equals(text)) {
return;
}
int selStart = Selection.getSelectionStart(edit); int selStart = Selection.getSelectionStart(edit);
int selEnd = Selection.getSelectionEnd(edit); int selEnd = Selection.getSelectionEnd(edit);
mInSetTextAndKeepSelection = true; mInSetTextAndKeepSelection = true;
@@ -1075,6 +1090,7 @@ import junit.framework.Assert;
setMaxLength(maxLength); setMaxLength(maxLength);
setHorizontallyScrolling(single); setHorizontallyScrolling(single);
setInputType(inputType); setInputType(inputType);
clearComposingText();
setImeOptions(imeOptions); setImeOptions(imeOptions);
setVisibility(VISIBLE); setVisibility(VISIBLE);
if (!autoComplete) { if (!autoComplete) {

View File

@@ -4798,16 +4798,7 @@ public class WebView extends AbsoluteLayout
mTextGeneration = 0; mTextGeneration = 0;
} }
mWebTextView.updateTextSize(); mWebTextView.updateTextSize();
Rect visibleRect = new Rect(); updateWebTextViewPosition();
calcOurContentVisibleRect(visibleRect);
// Note that sendOurVisibleRect calls viewToContent, so the coordinates
// should be in content coordinates.
Rect bounds = nativeFocusCandidateNodeBounds();
Rect vBox = contentToViewRect(bounds);
mWebTextView.setRect(vBox.left, vBox.top, vBox.width(), vBox.height());
if (!Rect.intersects(bounds, visibleRect)) {
revealSelection();
}
String text = nativeFocusCandidateText(); String text = nativeFocusCandidateText();
int nodePointer = nativeFocusCandidatePointer(); int nodePointer = nativeFocusCandidatePointer();
// This needs to be called before setType, which may call // This needs to be called before setType, which may call
@@ -4816,7 +4807,6 @@ public class WebView extends AbsoluteLayout
mWebTextView.setType(nativeFocusCandidateType()); mWebTextView.setType(nativeFocusCandidateType());
// Gravity needs to be set after setType // Gravity needs to be set after setType
mWebTextView.setGravityForRtl(nativeFocusCandidateIsRtlText()); mWebTextView.setGravityForRtl(nativeFocusCandidateIsRtlText());
updateWebTextViewPadding();
if (null == text) { if (null == text) {
if (DebugFlags.WEB_VIEW) { if (DebugFlags.WEB_VIEW) {
Log.v(LOGTAG, "rebuildWebTextView null == text"); Log.v(LOGTAG, "rebuildWebTextView null == text");
@@ -4827,12 +4817,27 @@ public class WebView extends AbsoluteLayout
InputMethodManager imm = InputMethodManager.peekInstance(); InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null && imm.isActive(mWebTextView)) { if (imm != null && imm.isActive(mWebTextView)) {
imm.restartInput(mWebTextView); imm.restartInput(mWebTextView);
mWebTextView.clearComposingText();
} }
if (isFocused()) { if (isFocused()) {
mWebTextView.requestFocus(); mWebTextView.requestFocus();
} }
} }
public void updateWebTextViewPosition() {
Rect visibleRect = new Rect();
calcOurContentVisibleRect(visibleRect);
// Note that sendOurVisibleRect calls viewToContent, so the coordinates
// should be in content coordinates.
Rect bounds = nativeFocusCandidateNodeBounds();
Rect vBox = contentToViewRect(bounds);
mWebTextView.setRect(vBox.left, vBox.top, vBox.width(), vBox.height());
if (!Rect.intersects(bounds, visibleRect)) {
revealSelection();
}
updateWebTextViewPadding();
}
/** /**
* Update the padding of mWebTextView based on the native textfield/textarea * Update the padding of mWebTextView based on the native textfield/textarea
*/ */
@@ -8433,7 +8438,7 @@ public class WebView extends AbsoluteLayout
// this is sent after finishing resize in WebViewCore. Make // this is sent after finishing resize in WebViewCore. Make
// sure the text edit box is still on the screen. // sure the text edit box is still on the screen.
if (inEditingMode() && nativeCursorIsTextInput()) { if (inEditingMode() && nativeCursorIsTextInput()) {
rebuildWebTextView(); updateWebTextViewPosition();
} }
break; break;
case CLEAR_TEXT_ENTRY: case CLEAR_TEXT_ENTRY: