| Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
|
| index 4f54ff25e4455c47fa5d73073115f644e5a12b0f..b5672225e65d390ba7d134c9d0f2cd25811ec75c 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
|
| @@ -371,6 +371,11 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
|
| // ResultReceiver in the InputMethodService (IME app) gets gc'ed.
|
| private ShowKeyboardResultReceiver mShowKeyboardResultReceiver;
|
|
|
| + // Whether this ContentViewCore has view focus.
|
| + private boolean mHasViewFocus;
|
| + // Whether this ContentViewCore has window focus.
|
| + private boolean mHasWindowFocus;
|
| +
|
| // The list of observers that are notified when ContentViewCore changes its WindowAndroid.
|
| private final ObserverList<WindowAndroidChangedObserver> mWindowAndroidChangedObservers;
|
|
|
| @@ -676,6 +681,8 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
|
| }
|
|
|
| mContainerView = containerView;
|
| + onFocusChangedInternal(getRealWindowFocusedState(), containerView.hasFocus(),
|
| + false /* hideKeyboardOnBlur */);
|
| mContainerView.setClickable(true);
|
| if (mSelectionPopupController != null) {
|
| mSelectionPopupController.setContainerView(containerView);
|
| @@ -685,6 +692,19 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
|
| }
|
| }
|
|
|
| + /**
|
| + * Note: We don't use View#hasWindowFocus() because it returns incorrect values when the View
|
| + * doesn't have View focus.
|
| + * @return Whether the containerView actually has Window focus.
|
| + */
|
| + private boolean getRealWindowFocusedState() {
|
| + int[] states = mContainerView.getDrawableState();
|
| + for (int state : states) {
|
| + if ((state & android.R.attr.state_window_focused) != 0) return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| @CalledByNative
|
| private void onNativeContentViewCoreDestroyed(long nativeContentViewCore) {
|
| assert nativeContentViewCore == mNativeContentViewCore;
|
| @@ -1334,23 +1354,36 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
|
| * @see View#onWindowFocusChanged(boolean)
|
| */
|
| public void onWindowFocusChanged(boolean hasWindowFocus) {
|
| + if (mHasWindowFocus == hasWindowFocus) return;
|
| mImeAdapter.onWindowFocusChanged(hasWindowFocus);
|
| if (!hasWindowFocus) resetGestureDetection();
|
| mSelectionPopupController.onWindowFocusChanged(hasWindowFocus);
|
| for (mGestureStateListenersIterator.rewind(); mGestureStateListenersIterator.hasNext();) {
|
| mGestureStateListenersIterator.next().onWindowFocusChanged(hasWindowFocus);
|
| }
|
| + onFocusChangedInternal(hasWindowFocus, mHasViewFocus, true /* hideKeyboardOnBlur */);
|
| + }
|
| +
|
| + public void onFocusChanged(boolean hasViewFocus, boolean hideKeyboardOnBlur) {
|
| + if (mHasViewFocus == hasViewFocus) return;
|
| + onFocusChangedInternal(mHasWindowFocus, hasViewFocus, hideKeyboardOnBlur);
|
| }
|
|
|
| - public void onFocusChanged(boolean gainFocus, boolean hideKeyboardOnBlur) {
|
| - mImeAdapter.onViewFocusChanged(gainFocus, hideKeyboardOnBlur);
|
| + private void onFocusChangedInternal(
|
| + boolean hasWindowFocus, boolean hasViewFocus, boolean hideKeyboardOnBlur) {
|
| + boolean hadInputFocus = mHasWindowFocus && mHasViewFocus;
|
| + boolean hasInputFocus = hasWindowFocus && hasViewFocus;
|
| + mHasWindowFocus = hasWindowFocus;
|
| + mHasViewFocus = hasViewFocus;
|
| + if (hasInputFocus == hadInputFocus) return;
|
| + mImeAdapter.onViewFocusChanged(hasInputFocus, hideKeyboardOnBlur);
|
|
|
| // Used in test that bypasses initialize().
|
| if (mJoystickScrollProvider != null) {
|
| - mJoystickScrollProvider.setEnabled(gainFocus && !isFocusedNodeEditable());
|
| + mJoystickScrollProvider.setEnabled(hasInputFocus && !isFocusedNodeEditable());
|
| }
|
|
|
| - if (gainFocus) {
|
| + if (hasInputFocus) {
|
| restoreSelectionPopupsIfNecessary();
|
| } else {
|
| cancelRequestToScrollFocusedEditableNodeIntoView();
|
| @@ -1365,7 +1398,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
|
| clearSelection();
|
| }
|
| }
|
| - if (mNativeContentViewCore != 0) nativeSetFocus(mNativeContentViewCore, gainFocus);
|
| + if (mNativeContentViewCore != 0) nativeSetFocus(mNativeContentViewCore, hasInputFocus);
|
| }
|
|
|
| /**
|
|
|