mobile/android/base/gfx/DisplayPortMetrics.java

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:14942c5e46c5
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/. */
5
6 package org.mozilla.gecko.gfx;
7
8 import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
9 import org.mozilla.gecko.util.FloatUtils;
10
11 import android.graphics.RectF;
12
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;
26
27 public DisplayPortMetrics() {
28 this(0, 0, 0, 0, 1);
29 }
30
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 }
36
37 public float getLeft() {
38 return mPosition.left;
39 }
40
41 public float getTop() {
42 return mPosition.top;
43 }
44
45 public float getRight() {
46 return mPosition.right;
47 }
48
49 public float getBottom() {
50 return mPosition.bottom;
51 }
52
53 public boolean contains(RectF rect) {
54 return mPosition.contains(rect);
55 }
56
57 public boolean fuzzyEquals(DisplayPortMetrics metrics) {
58 return RectUtils.fuzzyEquals(mPosition, metrics.mPosition)
59 && FloatUtils.fuzzyEquals(resolution, metrics.resolution);
60 }
61
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 }
72
73 @Override
74 public String toString() {
75 return "DisplayPortMetrics v=(" + mPosition.left + "," + mPosition.top + "," + mPosition.right + ","
76 + mPosition.bottom + ") z=" + resolution;
77 }
78 }

mercurial