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

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

Issue 2268103002: Use WindowAndroid to get display metrics in ContentViewCore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved DisplayMetrics logic and wheel scroll factor to RenderCoordinates Created 4 years, 4 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
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/RenderCoordinates.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/RenderCoordinates.java b/content/public/android/java/src/org/chromium/content/browser/RenderCoordinates.java
index a971c681ec145ef91c1fa6ef92aeb96a5fb4a90a..2df4f974938fc00b0ed8930b8fab2d0c6fdca053 100644
--- a/content/public/android/java/src/org/chromium/content/browser/RenderCoordinates.java
+++ b/content/public/android/java/src/org/chromium/content/browser/RenderCoordinates.java
@@ -4,7 +4,12 @@
package org.chromium.content.browser;
+import android.content.Context;
+import android.util.TypedValue;
+
+import org.chromium.base.CommandLine;
import org.chromium.base.VisibleForTesting;
+import org.chromium.content.common.ContentSwitches;
/**
* Cached copy of all positions and scales (CSS-to-DIP-to-physical pixels)
@@ -36,6 +41,10 @@ public class RenderCoordinates {
// Cached device density.
private float mDeviceScaleFactor;
+ // Multiplier that determines how many (device) pixels to scroll per mouse
+ // wheel tick. Defaults to the preferred list item height.
+ private float mWheelScrollFactor;
+
private float mTopContentOffsetYPix;
private float mBottomContentOffsetYPix;
@@ -53,8 +62,27 @@ public class RenderCoordinates {
mContentHeightCss = contentHeightCss;
}
- void setDeviceScaleFactor(float deviceScaleFactor) {
- mDeviceScaleFactor = deviceScaleFactor;
+ void setDeviceScaleFactor(Context context) {
+ String forceScaleFactor =
+ CommandLine.getInstance().getSwitchValue(ContentSwitches.FORCE_DEVICE_SCALE_FACTOR);
+ mDeviceScaleFactor = forceScaleFactor != null
+ ? Float.valueOf(forceScaleFactor)
+ : context.getResources().getDisplayMetrics().density;
+
+ // The wheel scroll factor depends on the theme in the context.
+ // This code assumes that the theme won't change between this call and
+ // getWheelScrollScale().
+
+ TypedValue outValue = new TypedValue();
+ // This is the same attribute used by Android Views to scale wheel
+ // event motion into scroll deltas.
+ if (context.getTheme().resolveAttribute(
+ android.R.attr.listPreferredItemHeight, outValue, true)) {
+ mWheelScrollFactor = outValue.getDimension(context.getResources().getDisplayMetrics());
+ } else {
+ // If attribute retrieval fails, just use a sensible default.
+ mWheelScrollFactor = 64 * mDeviceScaleFactor;
+ }
}
void updateFrameInfo(
@@ -343,6 +371,13 @@ public class RenderCoordinates {
}
/**
+ * @return Current wheel scroll factor (physical pixels per mouse scroll click).
+ */
+ public float getWheelScrollFactor() {
+ return mWheelScrollFactor;
+ }
+
+ /**
* @return Maximum possible horizontal scroll in physical pixels.
*/
public float getMaxHorizontalScrollPix() {
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698