Chromium Code Reviews| 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 5bcebc28c86b732dac67dbb830cd7e9c03ab5c00..cbdadf9fdb90ccb1746232779b4d460a7adc8f3c 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 |
| @@ -8,7 +8,8 @@ import android.content.Context; |
| import android.util.TypedValue; |
| import org.chromium.base.VisibleForTesting; |
| -import org.chromium.ui.base.WindowAndroid; |
| + |
| +import java.lang.ref.WeakReference; |
| /** |
| * Cached copy of all positions and scales (CSS-to-DIP-to-physical pixels) |
| @@ -38,7 +39,7 @@ public class RenderCoordinates { |
| private float mMaxPageScaleFactor = 1.0f; |
| // Cached device density. |
| - private float mDeviceScaleFactor; |
| + private float mDeviceScaleFactor = 1.0f; |
| // Multiplier that determines how many (device) pixels to scroll per mouse |
| // wheel tick. Defaults to the preferred list item height. |
| @@ -61,20 +62,20 @@ public class RenderCoordinates { |
| mContentHeightCss = contentHeightCss; |
| } |
| - void updateDeviceScaleFactorFromWindow(WindowAndroid windowAndroid) { |
| - mDeviceScaleFactor = windowAndroid.getDisplay().getDIPScale(); |
| + void setDeviceScaleFactor(float dipScale, WeakReference<Context> context) { |
| + mDeviceScaleFactor = dipScale; |
| // The wheel scroll factor depends on the theme in the context. |
| // This code assumes that the theme won't change between this call and |
| // getWheelScrollFactor(). |
| - Context context = windowAndroid.getContext().get(); |
| TypedValue outValue = new TypedValue(); |
| // This is the same attribute used by Android Views to scale wheel |
| // event motion into scroll deltas. |
| - if (context != null && context.getTheme().resolveAttribute( |
| + if (context.get() != null && context.get().getTheme().resolveAttribute( |
|
boliu
2016/10/19 04:19:19
you need to call get() first and save it in a loca
Tima Vaisburd
2016/10/19 20:25:11
Thank you! Done.
|
| android.R.attr.listPreferredItemHeight, outValue, true)) { |
| - mWheelScrollFactor = outValue.getDimension(context.getResources().getDisplayMetrics()); |
| + mWheelScrollFactor = outValue.getDimension( |
| + context.get().getResources().getDisplayMetrics()); |
| } else { |
| // If attribute retrieval fails, just use a sensible default. |
| mWheelScrollFactor = 64 * mDeviceScaleFactor; |