gfx/src/nsPoint.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef NSPOINT_H
michael@0 7 #define NSPOINT_H
michael@0 8
michael@0 9 #include "nsCoord.h"
michael@0 10 #include "mozilla/gfx/BaseSize.h"
michael@0 11 #include "mozilla/gfx/BasePoint.h"
michael@0 12 #include "nsSize.h"
michael@0 13
michael@0 14 struct nsIntPoint;
michael@0 15
michael@0 16 // nsPoint represents a point in app units.
michael@0 17
michael@0 18 struct nsPoint : public mozilla::gfx::BasePoint<nscoord, nsPoint> {
michael@0 19 typedef mozilla::gfx::BasePoint<nscoord, nsPoint> Super;
michael@0 20
michael@0 21 nsPoint() : Super() {}
michael@0 22 nsPoint(const nsPoint& aPoint) : Super(aPoint) {}
michael@0 23 nsPoint(nscoord aX, nscoord aY) : Super(aX, aY) {}
michael@0 24
michael@0 25 inline nsIntPoint ScaleToNearestPixels(float aXScale, float aYScale,
michael@0 26 nscoord aAppUnitsPerPixel) const;
michael@0 27 inline nsIntPoint ToNearestPixels(nscoord aAppUnitsPerPixel) const;
michael@0 28
michael@0 29 // Converts this point from aFromAPP, an appunits per pixel ratio, to aToAPP.
michael@0 30 inline nsPoint ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const;
michael@0 31 };
michael@0 32
michael@0 33 // nsIntPoint represents a point in one of the types of pixels.
michael@0 34 // Uses of nsIntPoint should eventually be converted to CSSIntPoint,
michael@0 35 // LayoutDeviceIntPoint, etc. (see layout/base/Units.h).
michael@0 36
michael@0 37 struct nsIntPoint : public mozilla::gfx::BasePoint<int32_t, nsIntPoint> {
michael@0 38 typedef mozilla::gfx::BasePoint<int32_t, nsIntPoint> Super;
michael@0 39
michael@0 40 nsIntPoint() : Super() {}
michael@0 41 nsIntPoint(const nsIntPoint& aPoint) : Super(aPoint) {}
michael@0 42 nsIntPoint(int32_t aX, int32_t aY) : Super(aX, aY) {}
michael@0 43
michael@0 44 inline nsPoint ToAppUnits(nscoord aAppUnitsPerPixel) const;
michael@0 45 };
michael@0 46
michael@0 47 inline nsIntPoint
michael@0 48 nsPoint::ScaleToNearestPixels(float aXScale, float aYScale,
michael@0 49 nscoord aAppUnitsPerPixel) const
michael@0 50 {
michael@0 51 return nsIntPoint(
michael@0 52 NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel) * aXScale),
michael@0 53 NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel) * aYScale));
michael@0 54 }
michael@0 55
michael@0 56 inline nsIntPoint
michael@0 57 nsPoint::ToNearestPixels(nscoord aAppUnitsPerPixel) const
michael@0 58 {
michael@0 59 return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel);
michael@0 60 }
michael@0 61
michael@0 62 inline nsPoint
michael@0 63 nsPoint::ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const
michael@0 64 {
michael@0 65 if (aFromAPP != aToAPP) {
michael@0 66 nsPoint point;
michael@0 67 point.x = NSToCoordRound(NSCoordScale(x, aFromAPP, aToAPP));
michael@0 68 point.y = NSToCoordRound(NSCoordScale(y, aFromAPP, aToAPP));
michael@0 69 return point;
michael@0 70 }
michael@0 71 return *this;
michael@0 72 }
michael@0 73
michael@0 74 // app units are integer multiples of pixels, so no rounding needed
michael@0 75 inline nsPoint
michael@0 76 nsIntPoint::ToAppUnits(nscoord aAppUnitsPerPixel) const
michael@0 77 {
michael@0 78 return nsPoint(NSIntPixelsToAppUnits(x, aAppUnitsPerPixel),
michael@0 79 NSIntPixelsToAppUnits(y, aAppUnitsPerPixel));
michael@0 80 }
michael@0 81
michael@0 82 #endif /* NSPOINT_H */

mercurial