Bug 781713 - Inline getEditable() and remove unnecessary null checks. r=blassey

--HG--
extra : rebase_source : 62522e83d95c1dc309c1b286dc48ddfa69f6f560
This commit is contained in:
Chris Peterson 2012-08-09 17:49:59 -07:00
Родитель b1c08c934c
Коммит c976b8651f
1 изменённых файлов: 25 добавлений и 50 удалений

Просмотреть файл

@ -162,12 +162,9 @@ class GeckoInputConnection
endComposition();
}
final Editable content = getEditable();
if (content != null) {
beginBatchEdit();
removeComposingSpans(content);
endBatchEdit();
}
beginBatchEdit();
removeComposingSpans(mEditable);
endBatchEdit();
return true;
}
@ -178,11 +175,7 @@ class GeckoInputConnection
@Override
public boolean performContextMenuAction(int id) {
final Editable content = getEditable();
if (content == null)
return false;
String text = content.toString();
String text = mEditable.toString();
Span selection = getSelection();
switch (id) {
@ -218,10 +211,6 @@ class GeckoInputConnection
if (req == null)
return null;
final Editable content = getEditable();
if (content == null)
return null;
if ((flags & GET_EXTRACTED_TEXT_MONITOR) != 0)
mUpdateRequest = req;
@ -234,7 +223,7 @@ class GeckoInputConnection
extract.selectionStart = selection.start;
extract.selectionEnd = selection.end;
extract.startOffset = 0;
extract.text = content.toString();
extract.text = mEditable.toString();
return extract;
}
@ -242,7 +231,7 @@ class GeckoInputConnection
@Override
public boolean setSelection(int start, int end) {
// Some IMEs call setSelection() with negative or stale indexes, so clamp them.
Span newSelection = Span.clamp(start, end, getEditable());
Span newSelection = Span.clamp(start, end, mEditable);
GeckoAppShell.sendEventToGecko(GeckoEvent.createIMEEvent(GeckoEvent.IME_SET_SELECTION,
newSelection.start,
newSelection.length));
@ -268,7 +257,7 @@ class GeckoInputConnection
public CharSequence getTextAfterCursor(int length, int flags) {
// Avoid overrunning text buffer.
Span selection = getSelection();
int contentLength = getEditable().length();
int contentLength = mEditable.length();
if (selection.end + length > contentLength) {
length = contentLength - selection.end;
}
@ -294,10 +283,9 @@ class GeckoInputConnection
}
private Span getSelection() {
Editable content = getEditable();
int start = Selection.getSelectionStart(content);
int end = Selection.getSelectionEnd(content);
return Span.clamp(start, end, content);
int start = Selection.getSelectionStart(mEditable);
int end = Selection.getSelectionEnd(mEditable);
return Span.clamp(start, end, mEditable);
}
private void replaceText(CharSequence text, int newCursorPosition, boolean composing) {
@ -310,11 +298,6 @@ class GeckoInputConnection
if (text == null)
text = "";
final Editable content = getEditable();
if (content == null) {
return;
}
beginBatchEdit();
// delete composing text set previously.
@ -323,7 +306,7 @@ class GeckoInputConnection
Span composingSpan = getComposingSpan();
if (composingSpan != null) {
removeComposingSpans(content);
removeComposingSpans(mEditable);
a = composingSpan.start;
b = composingSpan.end;
composingSpan = null;
@ -354,7 +337,7 @@ class GeckoInputConnection
if (DEBUG) {
LogPrinter lp = new LogPrinter(Log.VERBOSE, LOGTAG);
lp.println("Current text:");
TextUtils.dumpSpans(content, lp, " ");
TextUtils.dumpSpans(mEditable, lp, " ");
lp.println("Composing text:");
TextUtils.dumpSpans(text, lp, " ");
}
@ -369,16 +352,16 @@ class GeckoInputConnection
newCursorPosition += a;
}
if (newCursorPosition < 0) newCursorPosition = 0;
if (newCursorPosition > content.length())
newCursorPosition = content.length();
Selection.setSelection(content, newCursorPosition);
if (newCursorPosition > mEditable.length())
newCursorPosition = mEditable.length();
Selection.setSelection(mEditable, newCursorPosition);
content.replace(a, b, text);
mEditable.replace(a, b, text);
if (DEBUG) {
LogPrinter lp = new LogPrinter(Log.VERBOSE, LOGTAG);
lp.println("Final text:");
TextUtils.dumpSpans(content, lp, " ");
TextUtils.dumpSpans(mEditable, lp, " ");
}
endBatchEdit();
@ -391,22 +374,17 @@ class GeckoInputConnection
endComposition();
}
Span newComposingRegion = Span.clamp(start, end, getEditable());
Span newComposingRegion = Span.clamp(start, end, mEditable);
return super.setComposingRegion(newComposingRegion.start, newComposingRegion.end);
}
public String getComposingText() {
final Editable content = getEditable();
if (content == null) {
return null;
}
Span composingSpan = getComposingSpan();
if (composingSpan == null || composingSpan.length == 0) {
return "";
}
return TextUtils.substring(content, composingSpan.start, composingSpan.end);
return TextUtils.substring(mEditable, composingSpan.start, composingSpan.end);
}
public boolean onKeyDel() {
@ -484,9 +462,7 @@ class GeckoInputConnection
protected void notifySelectionChange(InputMethodManager imm, int start, int end) {
if (mBatchEditCount == 0) {
final Editable content = getEditable();
Span newSelection = Span.clamp(start, end, content);
Span newSelection = Span.clamp(start, end, mEditable);
start = newSelection.start;
end = newSelection.end;
@ -510,7 +486,7 @@ class GeckoInputConnection
int cb = composingSpan.end;
if (start < ca || start > cb || end < ca || end > cb) {
if (DEBUG) Log.d(LOGTAG, ". . . notifySelectionChange: removeComposingSpans");
removeComposingSpans(content);
removeComposingSpans(mEditable);
}
}
}
@ -1167,20 +1143,19 @@ class GeckoInputConnection
}
private Span getComposingSpan() {
Editable content = getEditable();
int start = getComposingSpanStart(content);
int end = getComposingSpanEnd(content);
int start = getComposingSpanStart(mEditable);
int end = getComposingSpanEnd(mEditable);
// Does the editable have a composing span?
if (start < 0 || end < 0) {
if (start != -1 || end != -1) {
throw new IndexOutOfBoundsException("Bad composing span [" + start + "," + end
+ "), contentLength=" + content.length());
+ "), contentLength=" + mEditable.length());
}
return null;
}
return new Span(start, end, content);
return new Span(start, end, mEditable);
}
private static String prettyPrintString(CharSequence s) {