From 99ec51f8f80a3c863d476060dca3c65823760c7f Mon Sep 17 00:00:00 2001 From: Joe Drew Date: Mon, 23 Apr 2012 10:29:14 -0700 Subject: [PATCH] Bug 744439 - Reset the checkerboard colour when we start loading a new page. r=kats a=blocker --HG-- extra : rebase_source : ca294fc3dd36a0d0a299c8247aa72673e115d372 --- mobile/android/base/GeckoApp.java | 21 +++++++---- mobile/android/base/Tab.java | 37 +++++++++++++++++++ mobile/android/base/gfx/GeckoLayerClient.java | 2 + mobile/android/base/gfx/LayerController.java | 29 --------------- 4 files changed, 53 insertions(+), 36 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 85ba9fbaedd..6aa06957be6 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -670,6 +670,7 @@ abstract public class GeckoApp tab.updateSecurityMode("unknown"); tab.removeTransientDoorHangers(); tab.setHasTouchListeners(false); + tab.setCheckerboardColor(Color.WHITE); maybeCancelFaviconLoad(tab); @@ -829,14 +830,20 @@ abstract public class GeckoApp final String title = message.getString("title"); final String backgroundColor = message.getString("bgColor"); handleContentLoaded(tabId, uri, title); - if (getLayerController() != null) { - if (backgroundColor != null) { - getLayerController().setCheckerboardColor(backgroundColor); - } else { - // Default to white if no color is given - getLayerController().setCheckerboardColor(Color.WHITE); - } + Tab tab = Tabs.getInstance().getTab(tabId); + if (backgroundColor != null) { + tab.setCheckerboardColor(backgroundColor); + } else { + // Default to white if no color is given + tab.setCheckerboardColor(Color.WHITE); } + + // Sync up the LayerController and the tab if the tab's + // currently displayed. + if (getLayerController() != null && Tabs.getInstance().isSelectedTab(tab)) { + getLayerController().setCheckerboardColor(tab.getCheckerboardColor()); + } + Log.i(LOGTAG, "URI - " + uri + ", title - " + title); } else if (event.equals("DOMTitleChanged")) { final int tabId = message.getInt("tabID"); diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index d665dc66a79..75cf5f56a2c 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -40,6 +40,7 @@ package org.mozilla.gecko; import android.content.ContentResolver; import android.database.ContentObserver; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; @@ -58,6 +59,8 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.Matcher; public final class Tab { private static final String LOGTAG = "GeckoTab"; @@ -68,6 +71,7 @@ public final class Tab { private static float sDensity = 1; private static int sMinScreenshotWidth = 0; private static int sMinScreenshotHeight = 0; + private static Pattern sColorPattern; private int mId; private String mUrl; private String mTitle; @@ -89,6 +93,7 @@ public final class Tab { private HashMap mPluginLayers; private ContentResolver mContentResolver; private ContentObserver mContentObserver; + private int mCheckerboardColor = Color.WHITE; private int mState; public static final int STATE_DELAYED = 0; @@ -561,4 +566,36 @@ public final class Tab { public Layer removePluginLayer(Surface surface) { return mPluginLayers.remove(surface); } + + public int getCheckerboardColor() { + return mCheckerboardColor; + } + + /** Sets a new color for the checkerboard. */ + public void setCheckerboardColor(int color) { + mCheckerboardColor = color; + } + + /** Parses and sets a new color for the checkerboard. */ + public void setCheckerboardColor(String newColor) { + setCheckerboardColor(parseColorFromGecko(newColor)); + } + + // Parses a color from an RGB triple of the form "rgb([0-9]+, [0-9]+, [0-9]+)". If the color + // cannot be parsed, returns white. + private static int parseColorFromGecko(String string) { + if (sColorPattern == null) { + sColorPattern = Pattern.compile("rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)"); + } + + Matcher matcher = sColorPattern.matcher(string); + if (!matcher.matches()) { + return Color.WHITE; + } + + int r = Integer.parseInt(matcher.group(1)); + int g = Integer.parseInt(matcher.group(2)); + int b = Integer.parseInt(matcher.group(3)); + return Color.rgb(r, g, b); + } } diff --git a/mobile/android/base/gfx/GeckoLayerClient.java b/mobile/android/base/gfx/GeckoLayerClient.java index 9487a3f3c0a..80bd248acd8 100644 --- a/mobile/android/base/gfx/GeckoLayerClient.java +++ b/mobile/android/base/gfx/GeckoLayerClient.java @@ -58,6 +58,7 @@ import android.util.Log; import android.view.View; import java.util.Map; import java.util.HashMap; +import org.mozilla.gecko.Tabs; public class GeckoLayerClient implements GeckoEventResponder, LayerView.Listener { @@ -329,6 +330,7 @@ public class GeckoLayerClient implements GeckoEventResponder, currentMetrics.setZoomFactor(zoom); currentMetrics.setPageSize(new FloatSize(pageWidth, pageHeight), new FloatSize(cssPageWidth, cssPageHeight)); mLayerController.setViewportMetrics(currentMetrics); + mLayerController.setCheckerboardColor(Tabs.getInstance().getSelectedTab().getCheckerboardColor()); // At this point, we have just switched to displaying a different document than we // we previously displaying. This means we need to abort any panning/zooming animations // that are in progress and send an updated display port request to browser.js as soon diff --git a/mobile/android/base/gfx/LayerController.java b/mobile/android/base/gfx/LayerController.java index c1c7257273a..5b9875270bb 100644 --- a/mobile/android/base/gfx/LayerController.java +++ b/mobile/android/base/gfx/LayerController.java @@ -52,8 +52,6 @@ import android.graphics.RectF; import android.util.Log; import android.view.GestureDetector; import android.view.View.OnTouchListener; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * The layer controller manages a tile that represents the visible page. It does panning and @@ -96,8 +94,6 @@ public class LayerController { private boolean mForceRedraw; - private static Pattern sColorPattern; - public LayerController(Context context) { mContext = context; @@ -359,29 +355,4 @@ public class LayerController { mCheckerboardColor = newColor; mView.requestRender(); } - - /** Parses and sets a new color for the checkerboard. */ - public void setCheckerboardColor(String newColor) { - setCheckerboardColor(parseColorFromGecko(newColor)); - } - - // Parses a color from an RGB triple of the form "rgb([0-9]+, [0-9]+, [0-9]+)". If the color - // cannot be parsed, returns white. - private static int parseColorFromGecko(String string) { - if (sColorPattern == null) { - sColorPattern = Pattern.compile("rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)"); - } - - Matcher matcher = sColorPattern.matcher(string); - if (!matcher.matches()) { - return Color.WHITE; - } - - int r = Integer.parseInt(matcher.group(1)); - int g = Integer.parseInt(matcher.group(2)); - int b = Integer.parseInt(matcher.group(3)); - return Color.rgb(r, g, b); - } - } -