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

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

Issue 2300463002: Add observers for DIP scale change. (Closed)
Patch Set: Do not force layout during initialization. Created 4 years, 2 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 0a5293ba55910c06f9f875e7fbe0115e5489ad2b..03cb36b9f8ffd4012c249b9738ae46e8a4d5c4b1 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
@@ -86,6 +86,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;
import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver;
import org.chromium.ui.touch_selection.SelectionEventType;
@@ -659,7 +660,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
setContainerViewInternals(internalDispatcher);
mRenderCoordinates.reset();
- mRenderCoordinates.updateDeviceScaleFactorFromWindow(windowAndroid);
+ updateDeviceScaleFactorFromWindow(windowAndroid);
initPopupZoomer(mContext);
mImeAdapter = createImeAdapter();
@@ -694,9 +695,10 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
if (!mAttachedToWindow) return;
WindowAndroid windowAndroid = getWindowAndroid();
if (windowAndroid != null) {
- mRenderCoordinates.updateDeviceScaleFactorFromWindow(windowAndroid);
- windowAndroid.getDisplay().addObserver(this);
- onRotationChanged(windowAndroid.getDisplay().getRotation());
+ DisplayAndroid display = windowAndroid.getDisplay();
+ display.addObserver(this);
+ onRotationChanged(display.getRotation());
+ onDIPScaleChanged(display.getDIPScale());
}
}
@@ -3234,6 +3236,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
updateGestureStateListener(GestureEventType.FLING_END);
}
+ // DisplayAndroidObserver method.
@Override
public void onRotationChanged(int rotation) {
// ActionMode#invalidate() won't be able to re-layout the floating
@@ -3266,6 +3269,26 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
sendOrientationChangeEvent(rotationDegrees);
}
+ // DisplayAndroidObserver method.
+ @Override
+ public void onDIPScaleChanged(float dipScale) {
+ Context displayContext =
+ getWindowAndroid() == null ? null : getWindowAndroid().getContext().get();
boliu 2016/10/18 00:26:25 should this be an assert?
Tima Vaisburd 2016/10/19 01:15:54 This method might be called directly by DisplayAnd
+ mRenderCoordinates.setDeviceScaleFactor(dipScale, displayContext);
+
+ if (mNativeContentViewCore == 0) return;
+ nativeSetDIPScale(mNativeContentViewCore, dipScale, true); // force layout
boliu 2016/10/18 00:26:25 format it like (..., true /* force layout */);
Tima Vaisburd 2016/10/19 01:15:54 Done.
+ }
+
+ private void updateDeviceScaleFactorFromWindow(WindowAndroid window) {
boliu 2016/10/18 00:26:25 there is only one caller, just inline it?
Tima Vaisburd 2016/10/19 01:15:54 Done.
+ float dipScale = window.getDisplay().getDIPScale();
+ Context displayContext = window.getContext().get();
+ mRenderCoordinates.setDeviceScaleFactor(dipScale, displayContext);
+
+ if (mNativeContentViewCore == 0) return;
+ nativeSetDIPScale(mNativeContentViewCore, dipScale, false); // do not force layout
boliu 2016/10/18 00:26:25 ditto about formatting
Tima Vaisburd 2016/10/19 01:15:54 Done.
+ }
+
/**
* Set whether the ContentViewCore requires the WebContents to be fullscreen in order to lock
* the screen orientation.
@@ -3330,6 +3353,9 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa
private native void nativeSetFocus(long nativeContentViewCoreImpl, boolean focused);
+ private native void nativeSetDIPScale(
+ long nativeContentViewCoreImpl, float dipScale, boolean forceLayout);
+
private native void nativeSendOrientationChangeEvent(
long nativeContentViewCoreImpl, int orientation);

Powered by Google App Engine
This is Rietveld 408576698