mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-27 10:50:35 +00:00
Bug 998398 - Don't reset keyboard to change input type. r=wesj
This commit is contained in:
parent
c35907ddd4
commit
17614d6413
@ -63,19 +63,6 @@ final public class InputMethods {
|
||||
return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
|
||||
}
|
||||
|
||||
@RobocopTarget
|
||||
public static boolean shouldDisableUrlBarUpdate(Context context) {
|
||||
String inputMethod = getCurrentInputMethod(context);
|
||||
// HTC Touch Input does not react well to restarting during input (bug 909940)
|
||||
return METHOD_HTC_TOUCH_INPUT.equals(inputMethod);
|
||||
}
|
||||
|
||||
public static boolean shouldDelayUrlBarUpdate(Context context) {
|
||||
String inputMethod = getCurrentInputMethod(context);
|
||||
return METHOD_SAMSUNG.equals(inputMethod) ||
|
||||
METHOD_SWIFTKEY.equals(inputMethod);
|
||||
}
|
||||
|
||||
public static boolean isGestureKeyboard(Context context) {
|
||||
// SwiftKey is a gesture keyboard, but it doesn't seem to need any special-casing
|
||||
// to do AwesomeBar auto-spacing.
|
||||
|
@ -58,8 +58,6 @@ public class ToolbarEditText extends CustomEditText
|
||||
|
||||
// Type of the URL bar go/search button
|
||||
private TextType mToolbarTextType;
|
||||
// Type of the keyboard go/search button (cannot be EMPTY)
|
||||
private TextType mKeyboardTextType;
|
||||
|
||||
private OnCommitListener mCommitListener;
|
||||
private OnDismissListener mDismissListener;
|
||||
@ -72,14 +70,11 @@ public class ToolbarEditText extends CustomEditText
|
||||
// The user typed part of the autocomplete result
|
||||
private String mAutoCompletePrefix = null;
|
||||
|
||||
private boolean mDelayRestartInput;
|
||||
|
||||
public ToolbarEditText(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
|
||||
mToolbarTextType = TextType.EMPTY;
|
||||
mKeyboardTextType = TextType.URL;
|
||||
}
|
||||
|
||||
void setOnCommitListener(OnCommitListener listener) {
|
||||
@ -158,23 +153,6 @@ public class ToolbarEditText extends CustomEditText
|
||||
mAutoCompletePrefix = null;
|
||||
}
|
||||
|
||||
private void updateKeyboardInputType() {
|
||||
// If the user enters a space, then we know they are entering
|
||||
// search terms, not a URL. We can then switch to text mode so,
|
||||
// 1) the IME auto-inserts spaces between words
|
||||
// 2) the IME doesn't reset input keyboard to Latin keyboard.
|
||||
final String text = getText().toString();
|
||||
final int currentInputType = getInputType();
|
||||
|
||||
final int newInputType = StringUtils.isSearchQuery(text, false)
|
||||
? (currentInputType & ~InputType.TYPE_TEXT_VARIATION_URI) // Text mode
|
||||
: (currentInputType | InputType.TYPE_TEXT_VARIATION_URI); // URL mode
|
||||
|
||||
if (newInputType != currentInputType) {
|
||||
setRawInputType(newInputType);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasCompositionString(Editable content) {
|
||||
Object[] spans = content.getSpans(0, content.length(), Object.class);
|
||||
|
||||
@ -193,9 +171,6 @@ public class ToolbarEditText extends CustomEditText
|
||||
private void setTextType(TextType textType) {
|
||||
mToolbarTextType = textType;
|
||||
|
||||
if (textType != TextType.EMPTY) {
|
||||
mKeyboardTextType = textType;
|
||||
}
|
||||
if (mTextTypeListener != null) {
|
||||
mTextTypeListener.onTextTypeChange(this, textType);
|
||||
}
|
||||
@ -207,58 +182,13 @@ public class ToolbarEditText extends CustomEditText
|
||||
return;
|
||||
}
|
||||
|
||||
if (InputMethods.shouldDisableUrlBarUpdate(mContext)) {
|
||||
// Set button type to match the previous keyboard type
|
||||
setTextType(mKeyboardTextType);
|
||||
return;
|
||||
}
|
||||
|
||||
final int actionBits = getImeOptions() & EditorInfo.IME_MASK_ACTION;
|
||||
|
||||
final int imeAction;
|
||||
if (StringUtils.isSearchQuery(text, actionBits == EditorInfo.IME_ACTION_SEARCH)) {
|
||||
imeAction = EditorInfo.IME_ACTION_SEARCH;
|
||||
final TextType newType;
|
||||
if (StringUtils.isSearchQuery(text, mToolbarTextType == TextType.SEARCH_QUERY)) {
|
||||
newType = TextType.SEARCH_QUERY;
|
||||
} else {
|
||||
imeAction = EditorInfo.IME_ACTION_GO;
|
||||
newType = TextType.URL;
|
||||
}
|
||||
|
||||
InputMethodManager imm = InputMethods.getInputMethodManager(mContext);
|
||||
if (imm == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean restartInput = false;
|
||||
if (actionBits != imeAction) {
|
||||
int optionBits = getImeOptions() & ~EditorInfo.IME_MASK_ACTION;
|
||||
setImeOptions(optionBits | imeAction);
|
||||
|
||||
mDelayRestartInput = (imeAction == EditorInfo.IME_ACTION_GO) &&
|
||||
(InputMethods.shouldDelayUrlBarUpdate(mContext));
|
||||
|
||||
if (!mDelayRestartInput) {
|
||||
restartInput = true;
|
||||
}
|
||||
} else if (mDelayRestartInput) {
|
||||
// Only call delayed restartInput when actionBits == imeAction
|
||||
// so if there are two restarts in a row, the first restarts will
|
||||
// be discarded and the second restart will be properly delayed
|
||||
mDelayRestartInput = false;
|
||||
restartInput = true;
|
||||
}
|
||||
|
||||
if (!restartInput) {
|
||||
// If the text content was previously empty, the toolbar text type
|
||||
// is empty as well. Since the keyboard text type cannot be empty,
|
||||
// the two text types are now inconsistent. Reset the toolbar text
|
||||
// type here to the keyboard text type to ensure consistency.
|
||||
setTextType(mKeyboardTextType);
|
||||
return;
|
||||
}
|
||||
updateKeyboardInputType();
|
||||
imm.restartInput(ToolbarEditText.this);
|
||||
|
||||
setTextType(imeAction == EditorInfo.IME_ACTION_GO ?
|
||||
TextType.URL : TextType.SEARCH_QUERY);
|
||||
setTextType(newType);
|
||||
}
|
||||
|
||||
private class TextChangeListener implements TextWatcher {
|
||||
@ -301,11 +231,7 @@ public class ToolbarEditText extends CustomEditText
|
||||
}
|
||||
}
|
||||
|
||||
// If the edit text has a composition string, don't call updateGoButton().
|
||||
// That method resets IME and composition state will be broken.
|
||||
if (!hasCompositionString(s) || InputMethods.isGestureKeyboard(mContext)) {
|
||||
updateTextTypeFromText(text);
|
||||
}
|
||||
updateTextTypeFromText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user