diff options
Diffstat (limited to 'android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ViewportMetrics.java')
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ViewportMetrics.java | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ViewportMetrics.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ViewportMetrics.java index 8c3004eebf83..f21f499077e8 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ViewportMetrics.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ViewportMetrics.java @@ -1,40 +1,7 @@ /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Android code. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2009-2010 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Patrick Walton <pcwalton@mozilla.com> - * Chris Lord <chrislord.net@gmail.com> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.mozilla.gecko.gfx; @@ -55,6 +22,7 @@ public class ViewportMetrics { private static final String LOGTAG = "GeckoViewportMetrics"; private FloatSize mPageSize; + private FloatSize mCssPageSize; private RectF mViewportRect; private float mZoomFactor; @@ -63,18 +31,21 @@ public class ViewportMetrics { LibreOfficeMainActivity.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics); mPageSize = new FloatSize(metrics.widthPixels, metrics.heightPixels); + mCssPageSize = new FloatSize(metrics.widthPixels, metrics.heightPixels); mViewportRect = new RectF(0, 0, metrics.widthPixels, metrics.heightPixels); mZoomFactor = 1.0f; } public ViewportMetrics(ViewportMetrics viewport) { mPageSize = new FloatSize(viewport.getPageSize()); + mCssPageSize = new FloatSize(viewport.getCssPageSize()); mViewportRect = new RectF(viewport.getViewport()); mZoomFactor = viewport.getZoomFactor(); } public ViewportMetrics(ImmutableViewportMetrics viewport) { mPageSize = new FloatSize(viewport.pageSizeWidth, viewport.pageSizeHeight); + mCssPageSize = new FloatSize(viewport.cssPageSizeWidth, viewport.cssPageSizeHeight); mViewportRect = new RectF(viewport.viewportRectLeft, viewport.viewportRectTop, viewport.viewportRectRight, @@ -90,9 +61,12 @@ public class ViewportMetrics { float height = (float)json.getDouble("height"); float pageWidth = (float)json.getDouble("pageWidth"); float pageHeight = (float)json.getDouble("pageHeight"); + float cssPageWidth = (float)json.getDouble("cssPageWidth"); + float cssPageHeight = (float)json.getDouble("cssPageHeight"); float zoom = (float)json.getDouble("zoom"); mPageSize = new FloatSize(pageWidth, pageHeight); + mCssPageSize = new FloatSize(cssPageWidth, cssPageHeight); mViewportRect = new RectF(x, y, x + width, y + height); mZoomFactor = zoom; } @@ -109,6 +83,10 @@ public class ViewportMetrics { return mViewportRect; } + public RectF getCssViewport() { + return RectUtils.scale(mViewportRect, 1/mZoomFactor); + } + /** Returns the viewport rectangle, clamped within the page-size. */ public RectF getClampedViewport() { RectF clampedViewport = new RectF(mViewportRect); @@ -133,12 +111,18 @@ public class ViewportMetrics { return mPageSize; } + public FloatSize getCssPageSize() { + return mCssPageSize; + } + + public float getZoomFactor() { return mZoomFactor; } - public void setPageSize(FloatSize pageSize) { + public void setPageSize(FloatSize pageSize, FloatSize cssPageSize) { mPageSize = pageSize; + mCssPageSize = cssPageSize; } public void setViewport(RectF viewport) { @@ -165,14 +149,17 @@ public class ViewportMetrics { * after scaling. */ public void scaleTo(float newZoomFactor, PointF focus) { - float scaleFactor = newZoomFactor / mZoomFactor; - - mPageSize = mPageSize.scale(scaleFactor); + // mCssPageSize is invariant, since we're setting the scale factor + // here. The page size is based on the CSS page size. + mPageSize = mCssPageSize.scale(newZoomFactor); + float scaleFactor = newZoomFactor / mZoomFactor; PointF origin = getOrigin(); + origin.offset(focus.x, focus.y); origin = PointUtils.scale(origin, scaleFactor); origin.offset(-focus.x, -focus.y); + setOrigin(origin); mZoomFactor = newZoomFactor; @@ -186,6 +173,7 @@ public class ViewportMetrics { public ViewportMetrics interpolate(ViewportMetrics to, float t) { ViewportMetrics result = new ViewportMetrics(); result.mPageSize = mPageSize.interpolate(to.mPageSize, t); + result.mCssPageSize = mCssPageSize.interpolate(to.mCssPageSize, t); result.mZoomFactor = FloatUtils.interpolate(mZoomFactor, to.mZoomFactor, t); result.mViewportRect = RectUtils.interpolate(mViewportRect, to.mViewportRect, t); return result; @@ -193,6 +181,7 @@ public class ViewportMetrics { public boolean fuzzyEquals(ViewportMetrics other) { return mPageSize.fuzzyEquals(other.mPageSize) + && mCssPageSize.fuzzyEquals(other.mCssPageSize) && RectUtils.fuzzyEquals(mViewportRect, other.mViewportRect) && FloatUtils.fuzzyEquals(mZoomFactor, other.mZoomFactor); } @@ -210,6 +199,8 @@ public class ViewportMetrics { .append(", \"height\" : ").append(height) .append(", \"pageWidth\" : ").append(mPageSize.width) .append(", \"pageHeight\" : ").append(mPageSize.height) + .append(", \"cssPageWidth\" : ").append(mCssPageSize.width) + .append(", \"cssPageHeight\" : ").append(mCssPageSize.height) .append(", \"zoom\" : ").append(mZoomFactor) .append(" }"); return sb.toString(); @@ -220,6 +211,7 @@ public class ViewportMetrics { StringBuffer buff = new StringBuffer(128); buff.append("v=").append(mViewportRect.toString()) .append(" p=").append(mPageSize.toString()) + .append(" c=").append(mCssPageSize.toString()) .append(" z=").append(mZoomFactor); return buff.toString(); } |