| 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 44a559d9272a39c959bc7627c140541af8144d49..0f07c0a5d125e304e7cb1758e80d0338f0a9da34 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
|
| @@ -33,6 +33,7 @@ import android.view.HapticFeedbackConstants;
|
| import android.view.InputDevice;
|
| import android.view.KeyEvent;
|
| import android.view.MotionEvent;
|
| +import android.view.Surface;
|
| import android.view.View;
|
| import android.view.ViewGroup;
|
| import android.view.ViewStructure;
|
| @@ -56,7 +57,6 @@ import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| import org.chromium.base.metrics.RecordUserAction;
|
| import org.chromium.content.R;
|
| -import org.chromium.content.browser.ScreenOrientationListener.ScreenOrientationObserver;
|
| import org.chromium.content.browser.accessibility.BrowserAccessibilityManager;
|
| import org.chromium.content.browser.accessibility.captioning.CaptioningBridgeFactory;
|
| import org.chromium.content.browser.accessibility.captioning.SystemCaptioningBridge;
|
| @@ -85,6 +85,7 @@ import org.chromium.ui.base.DeviceFormFactor;
|
| import org.chromium.ui.base.ViewAndroidDelegate;
|
| import org.chromium.ui.base.WindowAndroid;
|
| import org.chromium.ui.base.ime.TextInputType;
|
| +import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver;
|
| import org.chromium.ui.touch_selection.SelectionEventType;
|
|
|
| import java.lang.annotation.Annotation;
|
| @@ -101,7 +102,7 @@ import java.util.Map;
|
| * being tied to the view system.
|
| */
|
| @JNINamespace("content")
|
| -public class ContentViewCore implements AccessibilityStateChangeListener, ScreenOrientationObserver,
|
| +public class ContentViewCore implements AccessibilityStateChangeListener, DisplayAndroidObserver,
|
| SystemCaptioningBridge.SystemCaptioningBridgeListener,
|
| WindowAndroidProvider {
|
| private static final String TAG = "cr_ContentViewCore";
|
| @@ -327,6 +328,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| // Native pointer to C++ ContentViewCoreImpl object which will be set by nativeInit().
|
| private long mNativeContentViewCore = 0;
|
|
|
| + private boolean mAttachedToWindow;
|
| private final ObserverList<GestureStateListener> mGestureStateListeners;
|
| private final RewindableIterator<GestureStateListener> mGestureStateListenersIterator;
|
| private ZoomControlsDelegate mZoomControlsDelegate;
|
| @@ -680,6 +682,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| * @param windowAndroid The new {@link WindowAndroid} for this {@link ContentViewCore}.
|
| */
|
| public void updateWindowAndroid(WindowAndroid windowAndroid) {
|
| + removeDisplayAndroidObserver();
|
| long windowNativePointer = windowAndroid == null ? 0 : windowAndroid.getNativePointer();
|
| nativeUpdateWindowAndroid(mNativeContentViewCore, windowNativePointer);
|
|
|
| @@ -689,12 +692,29 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| mPastePopupMenu = null;
|
|
|
| mRenderCoordinates.setDeviceScaleFactor(getDisplayContext(windowAndroid));
|
| + addDisplayAndroidObserverIfNeeded();
|
|
|
| for (WindowAndroidChangedObserver observer : mWindowAndroidChangedObservers) {
|
| observer.onWindowAndroidChanged(windowAndroid);
|
| }
|
| }
|
|
|
| + private void addDisplayAndroidObserverIfNeeded() {
|
| + if (!mAttachedToWindow) return;
|
| + WindowAndroid windowAndroid = getWindowAndroid();
|
| + if (windowAndroid != null) {
|
| + windowAndroid.getDisplay().addObserver(this);
|
| + onRotationChanged(windowAndroid.getDisplay().getRotation());
|
| + }
|
| + }
|
| +
|
| + private void removeDisplayAndroidObserver() {
|
| + WindowAndroid windowAndroid = getWindowAndroid();
|
| + if (windowAndroid != null) {
|
| + windowAndroid.getDisplay().removeObserver(this);
|
| + }
|
| + }
|
| +
|
| /**
|
| * Sets a new container view for this {@link ContentViewCore}.
|
| *
|
| @@ -820,6 +840,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| * onDetachedFromWindow() which is guaranteed to be called in Android WebView.
|
| */
|
| public void destroy() {
|
| + removeDisplayAndroidObserver();
|
| if (mNativeContentViewCore != 0) {
|
| nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore);
|
| }
|
| @@ -843,7 +864,6 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| mGestureStateListenersIterator.next().onDestroyed();
|
| }
|
| mGestureStateListeners.clear();
|
| - ScreenOrientationListener.getInstance().removeObserver(this);
|
| hidePopupsAndPreserveSelection();
|
| mPastePopupMenu = null;
|
|
|
| @@ -1348,9 +1368,10 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| */
|
| @SuppressWarnings("javadoc")
|
| public void onAttachedToWindow() {
|
| + mAttachedToWindow = true;
|
| + addDisplayAndroidObserverIfNeeded();
|
| setAccessibilityState(mAccessibilityManager.isEnabled());
|
| updateTextSelectionUI(true);
|
| - ScreenOrientationListener.getInstance().addObserver(this, mContext);
|
| GamepadList.onAttachedToWindow(mContext);
|
| mAccessibilityManager.addAccessibilityStateChangeListener(this);
|
| mSystemCaptioningBridge.addListener(this);
|
| @@ -1380,10 +1401,10 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| @SuppressWarnings("javadoc")
|
| @SuppressLint("MissingSuperCall")
|
| public void onDetachedFromWindow() {
|
| + mAttachedToWindow = false;
|
| mImeAdapter.onViewDetachedFromWindow();
|
| mZoomControlsDelegate.dismissZoomPicker();
|
| -
|
| - ScreenOrientationListener.getInstance().removeObserver(this);
|
| + removeDisplayAndroidObserver();
|
| GamepadList.onDetachedFromWindow();
|
| mAccessibilityManager.removeAccessibilityStateChangeListener(this);
|
|
|
| @@ -3217,16 +3238,35 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| }
|
|
|
| @Override
|
| - public void onScreenOrientationChanged(int orientation) {
|
| + public void onRotationChanged(int rotation) {
|
| // ActionMode#invalidate() won't be able to re-layout the floating
|
| - // action mode menu items according to the new orientation. So Chrome
|
| + // action mode menu items according to the new rotation. So Chrome
|
| // has to re-create the action mode.
|
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && mActionMode != null) {
|
| hidePopupsAndPreserveSelection();
|
| showSelectActionMode(true);
|
| }
|
|
|
| - sendOrientationChangeEvent(orientation);
|
| + int rotationDegrees = 0;
|
| + switch (rotation) {
|
| + case Surface.ROTATION_0:
|
| + rotationDegrees = 0;
|
| + break;
|
| + case Surface.ROTATION_90:
|
| + rotationDegrees = 90;
|
| + break;
|
| + case Surface.ROTATION_180:
|
| + rotationDegrees = 180;
|
| + break;
|
| + case Surface.ROTATION_270:
|
| + rotationDegrees = -90;
|
| + break;
|
| + default:
|
| + throw new IllegalStateException(
|
| + "Display.getRotation() shouldn't return that value");
|
| + }
|
| +
|
| + sendOrientationChangeEvent(rotationDegrees);
|
| }
|
|
|
| /**
|
|
|