mobile/android/base/gfx/DisplayPortMetrics.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 package org.mozilla.gecko.gfx;
     8 import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
     9 import org.mozilla.gecko.util.FloatUtils;
    11 import android.graphics.RectF;
    13 /*
    14  * This class keeps track of the area we request Gecko to paint, as well
    15  * as the resolution of the paint. The area may be different from the visible
    16  * area of the page, and the resolution may be different from the resolution
    17  * used in the compositor to render the page. This is so that we can ask Gecko
    18  * to paint a much larger area without using extra memory, and then render some
    19  * subsection of that with compositor scaling.
    20  */
    21 public final class DisplayPortMetrics {
    22     @WrapElementForJNI
    23     public final float resolution;
    24     @WrapElementForJNI
    25     private final RectF mPosition;
    27     public DisplayPortMetrics() {
    28         this(0, 0, 0, 0, 1);
    29     }
    31     @WrapElementForJNI
    32     public DisplayPortMetrics(float left, float top, float right, float bottom, float resolution) {
    33         this.resolution = resolution;
    34         mPosition = new RectF(left, top, right, bottom);
    35     }
    37     public float getLeft() {
    38         return mPosition.left;
    39     }
    41     public float getTop() {
    42         return mPosition.top;
    43     }
    45     public float getRight() {
    46         return mPosition.right;
    47     }
    49     public float getBottom() {
    50         return mPosition.bottom;
    51     }
    53     public boolean contains(RectF rect) {
    54         return mPosition.contains(rect);
    55     }
    57     public boolean fuzzyEquals(DisplayPortMetrics metrics) {
    58         return RectUtils.fuzzyEquals(mPosition, metrics.mPosition)
    59             && FloatUtils.fuzzyEquals(resolution, metrics.resolution);
    60     }
    62     public String toJSON() {
    63         StringBuilder sb = new StringBuilder(256);
    64         sb.append("{ \"left\": ").append(mPosition.left)
    65           .append(", \"top\": ").append(mPosition.top)
    66           .append(", \"right\": ").append(mPosition.right)
    67           .append(", \"bottom\": ").append(mPosition.bottom)
    68           .append(", \"resolution\": ").append(resolution)
    69           .append('}');
    70         return sb.toString();
    71     }
    73     @Override
    74     public String toString() {
    75         return "DisplayPortMetrics v=(" + mPosition.left + "," + mPosition.top + "," + mPosition.right + ","
    76                 + mPosition.bottom + ") z=" + resolution;
    77     }
    78 }

mercurial