Merge "Keep IMM#mCurRootView synchronized with the actual window focus." into mnc-dev

This commit is contained in:
Yohei Yukawa
2015-05-19 16:52:25 +00:00
committed by Android (Google) Code Review
3 changed files with 29 additions and 17 deletions

View File

@@ -2021,8 +2021,8 @@ public final class ViewRootImpl implements ViewParent,
mLastWasImTarget = imTarget;
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null && imTarget) {
imm.startGettingWindowFocus(mView);
imm.onWindowFocus(mView, mView.findFocus(),
imm.onPreWindowFocus(mView, true /* hasWindowFocus */);
imm.onPostWindowFocus(mView, mView.findFocus(),
mWindowAttributes.softInputMode,
!mHasHadWindowFocus, mWindowAttributes.flags);
}
@@ -3327,11 +3327,10 @@ public final class ViewRootImpl implements ViewParent,
.mayUseInputMethod(mWindowAttributes.flags);
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) {
imm.onPreWindowFocus(mView, hasWindowFocus);
}
if (mView != null) {
if (hasWindowFocus && imm != null && mLastWasImTarget &&
!isInLocalFocusMode()) {
imm.startGettingWindowFocus(mView);
}
mAttachInfo.mKeyDispatchState.reset();
mView.dispatchWindowFocusChanged(hasWindowFocus);
mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus);
@@ -3341,7 +3340,7 @@ public final class ViewRootImpl implements ViewParent,
// so all of the view state is set up correctly.
if (hasWindowFocus) {
if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) {
imm.onWindowFocus(mView, mView.findFocus(),
imm.onPostWindowFocus(mView, mView.findFocus(),
mWindowAttributes.softInputMode,
!mHasHadWindowFocus, mWindowAttributes.flags);
}

View File

@@ -1289,14 +1289,14 @@ public final class InputMethodManager {
void focusInLocked(View view) {
if (DEBUG) Log.v(TAG, "focusIn: " + view);
if (mCurRootView != view.getRootView()) {
// This is a request from a window that isn't in the window with
// IME focus, so ignore it.
if (DEBUG) Log.v(TAG, "Not IME target window, ignoring");
return;
}
mNextServedView = view;
scheduleCheckFocusLocked(view);
}
@@ -1392,7 +1392,7 @@ public final class InputMethodManager {
* Called by ViewAncestor when its window gets input focus.
* @hide
*/
public void onWindowFocus(View rootView, View focusedView, int softInputMode,
public void onPostWindowFocus(View rootView, View focusedView, int softInputMode,
boolean first, int windowFlags) {
boolean forceNewFocus = false;
synchronized (mH) {
@@ -1441,14 +1441,27 @@ public final class InputMethodManager {
}
}
}
/** @hide */
public void startGettingWindowFocus(View rootView) {
public void onPreWindowFocus(View rootView, boolean hasWindowFocus) {
synchronized (mH) {
mCurRootView = rootView;
if (rootView == null) {
mCurRootView = null;
} if (hasWindowFocus) {
mCurRootView = rootView;
} else if (rootView == mCurRootView) {
// If the mCurRootView is losing window focus, release the strong reference to it
// so as not to prevent it from being garbage-collected.
mCurRootView = null;
} else {
if (DEBUG) {
Log.v(TAG, "Ignoring onPreWindowFocus()."
+ " mCurRootView=" + mCurRootView + " rootView=" + rootView);
}
}
}
}
/**
* Report the current selection range.
*

View File

@@ -154,9 +154,9 @@ public class FindActionModeCallback implements ActionMode.Callback, TextWatcher,
}
public void showSoftInput() {
mInput.startGettingWindowFocus(mEditText.getRootView());
mInput.focusIn(mEditText);
mInput.showSoftInput(mEditText, 0);
if (mEditText.requestFocus()) {
mInput.showSoftInput(mEditText, 0);
}
}
public void updateMatchCount(int matchIndex, int matchCount, boolean isEmptyFind) {