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

Unified Diff: ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java

Issue 1144333004: Make WebView work for external displays (over Presentations). Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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: ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
diff --git a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
index da8e0262a1f9e202086b5d4095cc61b47555dd48..15ff695a5c1e72b06f5f2205ea6d78bcc245f595 100644
--- a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
+++ b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
@@ -16,6 +16,9 @@ import android.view.WindowManager;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
+import org.chromium.ui.base.WindowAndroid;
+
+import java.lang.ref.WeakReference;
/**
* This class facilitates access to android information typically only
@@ -27,14 +30,17 @@ import org.chromium.base.JNINamespace;
@JNINamespace("gfx")
public class DeviceDisplayInfo {
- private final Context mAppContext;
+ private final WeakReference<Context> mContextRef;
private final WindowManager mWinManager;
private Point mTempPoint = new Point();
private DisplayMetrics mTempMetrics = new DisplayMetrics();
- private DeviceDisplayInfo(Context context) {
- mAppContext = context.getApplicationContext();
- mWinManager = (WindowManager) mAppContext.getSystemService(Context.WINDOW_SERVICE);
+ private DeviceDisplayInfo(WeakReference<Context> contextRef) {
+ mContextRef = contextRef;
+ Context context = mContextRef.get();
+ if (context == null)
+ throw new RuntimeException("got null Context in DeviceDisplayInfo constructor");
+ mWinManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}
/**
@@ -154,7 +160,10 @@ public class DeviceDisplayInfo {
*/
@CalledByNative
private int getSmallestDIPWidth() {
- return mAppContext.getResources().getConfiguration().smallestScreenWidthDp;
+ Context context = mContextRef.get();
+ if (context == null)
+ throw new RuntimeException("null context in getSmallestDIPWidth!!!");
+ return context.getResources().getConfiguration().smallestScreenWidthDp;
}
/**
@@ -181,18 +190,6 @@ public class DeviceDisplayInfo {
return 0;
}
- /**
- * Inform the native implementation to update its cached representation of
- * the DeviceDisplayInfo values.
- */
- public void updateNativeSharedDisplayInfo() {
- nativeUpdateSharedDeviceDisplayInfo(
- getDisplayHeight(), getDisplayWidth(),
- getPhysicalDisplayHeight(), getPhysicalDisplayWidth(),
- getBitsPerPixel(), getBitsPerComponent(),
- getDIPScale(), getSmallestDIPWidth(), getRotationDegrees());
- }
-
private Display getDisplay() {
return mWinManager.getDefaultDisplay();
}
@@ -204,14 +201,15 @@ public class DeviceDisplayInfo {
* @return DeviceDisplayInfo associated with a given Context.
*/
@CalledByNative
- public static DeviceDisplayInfo create(Context context) {
- return new DeviceDisplayInfo(context);
+ public static DeviceDisplayInfo createFromWindow(WindowAndroid windowAndroid) {
+ if (windowAndroid == null)
+ throw new RuntimeException("passed null windowAndroid to DeviceDisplayInfo.create");
+ return new DeviceDisplayInfo(windowAndroid.getCurrentContext());
}
- private native void nativeUpdateSharedDeviceDisplayInfo(
- int displayHeight, int displayWidth,
- int physicalDisplayHeight, int physicalDisplayWidth,
- int bitsPerPixel, int bitsPerComponent, double dipScale,
- int smallestDIPWidth, int rotationDegrees);
+ @CalledByNative
+ public static DeviceDisplayInfo create(Context context) { // TODO createFromContext
+ return new DeviceDisplayInfo(new WeakReference<Context>(context));
+ }
}

Powered by Google App Engine
This is Rietveld 408576698