summaryrefslogtreecommitdiffstats
path: root/android_webview/java
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-23 23:03:35 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-23 23:03:35 +0000
commit25645efa60be6f6392f321c66ced61c53c3f0865 (patch)
tree47ea46a585a609628f9b32b2841ea73cb0c0df33 /android_webview/java
parent049dd99c2271b818e2e3e2ae23187c60cb4e6f38 (diff)
downloadchromium_src-25645efa60be6f6392f321c66ced61c53c3f0865.zip
chromium_src-25645efa60be6f6392f321c66ced61c53c3f0865.tar.gz
chromium_src-25645efa60be6f6392f321c66ced61c53c3f0865.tar.bz2
Hooking up setBackgroundColor from AwContents to renderer
Final call into WebKit API ommitted as it depends on blink change https://codereview.chromium.org/19883002/ BUG=263263 Review URL: https://chromiumcodereview.appspot.com/19693016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213255 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/java')
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContents.java29
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContentsClient.java21
2 files changed, 46 insertions, 4 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index 40075d7..c94c1ab 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -156,12 +156,15 @@ public class AwContents {
// TODO(boliu): This should be in a global context, not per webview.
private final double mDIPScale;
+ // The base background color, i.e. not accounting for any CSS body from the current page.
+ private int mBaseBackgroundColor = Color.WHITE;
+
// Must call nativeUpdateLastHitTestData first to update this before use.
private final HitTestData mPossiblyStaleHitTestData = new HitTestData();
private DefaultVideoPosterRequestHandler mDefaultVideoPosterRequestHandler;
- // Bound method for suppling Picture instances to the AwContentClient. Will be null if the
+ // Bound method for suppling Picture instances to the AwContentsClient. Will be null if the
// picture listener API has not yet been enabled, or if it is using invalidation-only mode.
private Callable<Picture> mPictureListenerContentProvider;
@@ -641,7 +644,10 @@ public class AwContents {
private final Rect mClipBoundsTemporary = new Rect();
public void onDraw(Canvas canvas) {
- if (mNativeAwContents == 0) return;
+ if (mNativeAwContents == 0) {
+ canvas.drawColor(getEffectiveBackgroundColor());
+ return;
+ }
mScrollOffsetManager.syncScrollOffsetFromOnDraw();
@@ -651,8 +657,7 @@ public class AwContents {
mClipBoundsTemporary.left, mClipBoundsTemporary.top,
mClipBoundsTemporary.right, mClipBoundsTemporary.bottom )) {
Log.w(TAG, "nativeOnDraw failed; clearing to background color.");
- int c = mContentViewCore.getBackgroundColor();
- canvas.drawRGB(Color.red(c), Color.green(c), Color.blue(c));
+ canvas.drawColor(getEffectiveBackgroundColor());
}
}
@@ -818,6 +823,21 @@ public class AwContents {
}
}
+ public void setBackgroundColor(int color) {
+ mBaseBackgroundColor = color;
+ if (mNativeAwContents != 0) nativeSetBackgroundColor(mNativeAwContents, color);
+ }
+
+ private int getEffectiveBackgroundColor() {
+ // Do not ask the ContentViewCore for the background color, as it will always
+ // report white prior to initial navigation or post destruction, whereas we want
+ // to use the client supplied base value in those cases.
+ if (mNativeAwContents == 0 || !mContentsClient.isCachedRendererBackgroundColorValid()) {
+ return mBaseBackgroundColor;
+ }
+ return mContentsClient.getCachedRendererBackgroundColor();
+ }
+
public boolean isMultiTouchZoomSupported() {
return mSettings.supportsMultiTouchZoom();
}
@@ -1718,6 +1738,7 @@ public class AwContents {
private native int nativeReleasePopupAwContents(int nativeAwContents);
private native void nativeFocusFirstNode(int nativeAwContents);
+ private native void nativeSetBackgroundColor(int nativeAwContents, int color);
private native int nativeGetAwDrawGLViewContext(int nativeAwContents);
private native Picture nativeCapturePicture(int nativeAwContents);
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java
index 7de19e5..fe42ad3 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java
@@ -52,6 +52,12 @@ public abstract class AwContentsClient {
private double mDIPScale;
+ // Last background color reported from the renderer. Holds the sentinal value INVALID_COLOR
+ // if not valid.
+ private int mCachedRendererBackgroundColor = INVALID_COLOR;
+
+ private static final int INVALID_COLOR = 0;
+
class AwWebContentsObserver extends WebContentsObserverAndroid {
public AwWebContentsObserver(ContentViewCore contentViewCore) {
super(contentViewCore);
@@ -90,6 +96,12 @@ public abstract class AwContentsClient {
}
private class AwContentViewClient extends ContentViewClient {
+ @Override
+ public void onBackgroundColorChanged(int color) {
+ // Avoid storing the sentinal INVALID_COLOR (note that both 0 and 1 are both
+ // fully transparent so this transpose makes no visible difference).
+ mCachedRendererBackgroundColor = color == INVALID_COLOR ? 1 : color;
+ }
@Override
public void onScaleChanged(float oldScale, float newScale) {
@@ -174,6 +186,15 @@ public abstract class AwContentsClient {
return mContentViewClient;
}
+ final int getCachedRendererBackgroundColor() {
+ assert isCachedRendererBackgroundColorValid();
+ return mCachedRendererBackgroundColor;
+ }
+
+ final boolean isCachedRendererBackgroundColorValid() {
+ return mCachedRendererBackgroundColor != INVALID_COLOR;
+ }
+
//--------------------------------------------------------------------------------------------
// WebView specific methods that map directly to WebViewClient / WebChromeClient
//--------------------------------------------------------------------------------------------