Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1767)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 2300463002: Add observers for DIP scale change. (Closed)
Patch Set: An attempt to fix tests compilation Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d0c951da7c477f2ad72424b826e488c551975a40..02cad9896e5a30e7b24ad2a6ffe2f4721a0fd116 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
@@ -81,6 +81,7 @@ import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.device.gamepad.GamepadList;
+import org.chromium.ui.base.DIPScaleListener;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid;
@@ -101,9 +102,9 @@ import java.util.Map;
* being tied to the view system.
*/
@JNINamespace("content")
-public class ContentViewCore implements AccessibilityStateChangeListener, ScreenOrientationObserver,
- SystemCaptioningBridge.SystemCaptioningBridgeListener,
- WindowAndroidProvider {
+public class ContentViewCore
+ implements AccessibilityStateChangeListener, ScreenOrientationObserver, DIPScaleListener,
+ SystemCaptioningBridge.SystemCaptioningBridgeListener, WindowAndroidProvider {
private static final String TAG = "cr_ContentViewCore";
// Used to avoid enabling zooming in / out if resulting zooming will
@@ -659,7 +660,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
setContainerViewInternals(internalDispatcher);
mRenderCoordinates.reset();
- mRenderCoordinates.setDeviceScaleFactor(getDisplayContext(windowAndroid));
+ onDIPScaleChanged(windowAndroid.getDIPScale());
initPopupZoomer(mContext);
mImeAdapter = createImeAdapter();
@@ -674,6 +675,11 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
* @param windowAndroid The new {@link WindowAndroid} for this {@link ContentViewCore}.
*/
public void updateWindowAndroid(WindowAndroid windowAndroid) {
+ if (windowAndroid == null) {
boliu 2016/09/14 04:35:32 this check seems wrong
Tima Vaisburd 2016/09/15 00:05:03 Thank you, I see now. Removed this check.
+ WindowAndroid oldWindowAndroid = getWindowAndroid();
+ if (oldWindowAndroid != null) oldWindowAndroid.removeDIPScaleListener(this);
+ }
+
long windowNativePointer = windowAndroid == null ? 0 : windowAndroid.getNativePointer();
nativeUpdateWindowAndroid(mNativeContentViewCore, windowNativePointer);
@@ -682,11 +688,11 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
mSelectPopup = null;
mPastePopupMenu = null;
- mRenderCoordinates.setDeviceScaleFactor(getDisplayContext(windowAndroid));
-
for (WindowAndroidChangedObserver observer : mWindowAndroidChangedObservers) {
observer.onWindowAndroidChanged(windowAndroid);
}
+
+ if (windowAndroid != null) windowAndroid.addDIPScaleListener(this);
boliu 2016/09/14 04:35:32 do this above the observer call
Tima Vaisburd 2016/09/15 00:05:03 Done.
}
/**
@@ -1361,6 +1367,11 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
mAccessibilityManager.addAccessibilityStateChangeListener(this);
mSystemCaptioningBridge.addListener(this);
mImeAdapter.onViewAttachedToWindow();
+
+ WindowAndroid windowAndroid = getWindowAndroid();
+ if (windowAndroid != null) {
+ windowAndroid.addDIPScaleListener(this);
+ }
}
/**
@@ -1386,6 +1397,11 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
@SuppressWarnings("javadoc")
@SuppressLint("MissingSuperCall")
public void onDetachedFromWindow() {
+ WindowAndroid windowAndroid = getWindowAndroid();
+ if (windowAndroid != null) {
+ windowAndroid.removeDIPScaleListener(this);
+ }
+
mImeAdapter.onViewDetachedFromWindow();
mZoomControlsDelegate.dismissZoomPicker();
@@ -3246,6 +3262,23 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
sendOrientationChangeEvent(orientation);
}
+ // DIPScaleObserver method implementation.
+ @Override
+ public void onDIPScaleChanged(float dipScale) {
+ if (mNativeContentViewCore == 0) return;
+ nativeSetDIPScale(mNativeContentViewCore, dipScale);
+
+ mRenderCoordinates.setDeviceScaleFactor(dipScale);
+
+ // The wheel scroll factor might depend on device scale factor.
+ mRenderCoordinates.setWheelScrollFactor(getDisplayContext(getWindowAndroid()));
+
+ // Force re-layout.
+ if (mViewportWidthPix > 0 && mViewportHeightPix > 0) {
+ nativeWasResized(mNativeContentViewCore);
boliu 2016/09/14 04:35:32 why? if that's needed, then it should just be hand
Tima Vaisburd 2016/09/15 00:05:03 I thought we need to force the new layout without
+ }
+ }
+
/**
* Set whether the ContentViewCore requires the WebContents to be fullscreen in order to lock
* the screen orientation.
@@ -3310,6 +3343,8 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
private native void nativeSetFocus(long nativeContentViewCoreImpl, boolean focused);
+ private native void nativeSetDIPScale(long nativeContentViewCoreImpl, float dipScale);
+
private native void nativeSendOrientationChangeEvent(
long nativeContentViewCoreImpl, int orientation);

Powered by Google App Engine
This is Rietveld 408576698