Tue, 06 Jan 2015 21:39:09 +0100
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 MOZILLA_GFX_RECT_H_ |
michael@0 | 7 | #define MOZILLA_GFX_RECT_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "BaseRect.h" |
michael@0 | 10 | #include "BaseMargin.h" |
michael@0 | 11 | #include "Point.h" |
michael@0 | 12 | #include "Tools.h" |
michael@0 | 13 | |
michael@0 | 14 | #include <cmath> |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace gfx { |
michael@0 | 18 | |
michael@0 | 19 | template<class units> |
michael@0 | 20 | struct IntMarginTyped: |
michael@0 | 21 | public BaseMargin<int32_t, IntMarginTyped<units> >, |
michael@0 | 22 | public units { |
michael@0 | 23 | typedef BaseMargin<int32_t, IntMarginTyped<units> > Super; |
michael@0 | 24 | |
michael@0 | 25 | IntMarginTyped() : Super() {} |
michael@0 | 26 | IntMarginTyped(int32_t aTop, int32_t aRight, int32_t aBottom, int32_t aLeft) : |
michael@0 | 27 | Super(aTop, aRight, aBottom, aLeft) {} |
michael@0 | 28 | }; |
michael@0 | 29 | typedef IntMarginTyped<UnknownUnits> IntMargin; |
michael@0 | 30 | |
michael@0 | 31 | template<class units> |
michael@0 | 32 | struct MarginTyped: |
michael@0 | 33 | public BaseMargin<Float, MarginTyped<units> >, |
michael@0 | 34 | public units { |
michael@0 | 35 | typedef BaseMargin<Float, MarginTyped<units> > Super; |
michael@0 | 36 | |
michael@0 | 37 | MarginTyped() : Super() {} |
michael@0 | 38 | MarginTyped(Float aTop, Float aRight, Float aBottom, Float aLeft) : |
michael@0 | 39 | Super(aTop, aRight, aBottom, aLeft) {} |
michael@0 | 40 | explicit MarginTyped(const IntMarginTyped<units>& aMargin) : |
michael@0 | 41 | Super(float(aMargin.top), float(aMargin.right), |
michael@0 | 42 | float(aMargin.bottom), float(aMargin.left)) {} |
michael@0 | 43 | }; |
michael@0 | 44 | typedef MarginTyped<UnknownUnits> Margin; |
michael@0 | 45 | |
michael@0 | 46 | template<class units> |
michael@0 | 47 | IntMarginTyped<units> RoundedToInt(const MarginTyped<units>& aMargin) |
michael@0 | 48 | { |
michael@0 | 49 | return IntMarginTyped<units>(int32_t(floorf(aMargin.top + 0.5f)), |
michael@0 | 50 | int32_t(floorf(aMargin.right + 0.5f)), |
michael@0 | 51 | int32_t(floorf(aMargin.bottom + 0.5f)), |
michael@0 | 52 | int32_t(floorf(aMargin.left + 0.5f))); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | template<class units> |
michael@0 | 56 | struct IntRectTyped : |
michael@0 | 57 | public BaseRect<int32_t, IntRectTyped<units>, IntPointTyped<units>, IntSizeTyped<units>, IntMarginTyped<units> >, |
michael@0 | 58 | public units { |
michael@0 | 59 | typedef BaseRect<int32_t, IntRectTyped<units>, IntPointTyped<units>, IntSizeTyped<units>, IntMarginTyped<units> > Super; |
michael@0 | 60 | |
michael@0 | 61 | IntRectTyped() : Super() {} |
michael@0 | 62 | IntRectTyped(const IntPointTyped<units>& aPos, const IntSizeTyped<units>& aSize) : |
michael@0 | 63 | Super(aPos, aSize) {} |
michael@0 | 64 | IntRectTyped(int32_t _x, int32_t _y, int32_t _width, int32_t _height) : |
michael@0 | 65 | Super(_x, _y, _width, _height) {} |
michael@0 | 66 | |
michael@0 | 67 | // Rounding isn't meaningful on an integer rectangle. |
michael@0 | 68 | void Round() {} |
michael@0 | 69 | void RoundIn() {} |
michael@0 | 70 | void RoundOut() {} |
michael@0 | 71 | |
michael@0 | 72 | // XXX When all of the code is ported, the following functions to convert to and from |
michael@0 | 73 | // unknown types should be removed. |
michael@0 | 74 | |
michael@0 | 75 | static IntRectTyped<units> FromUnknownRect(const IntRectTyped<UnknownUnits>& rect) { |
michael@0 | 76 | return IntRectTyped<units>(rect.x, rect.y, rect.width, rect.height); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | IntRectTyped<UnknownUnits> ToUnknownRect() const { |
michael@0 | 80 | return IntRectTyped<UnknownUnits>(this->x, this->y, this->width, this->height); |
michael@0 | 81 | } |
michael@0 | 82 | }; |
michael@0 | 83 | typedef IntRectTyped<UnknownUnits> IntRect; |
michael@0 | 84 | |
michael@0 | 85 | template<class units> |
michael@0 | 86 | struct RectTyped : |
michael@0 | 87 | public BaseRect<Float, RectTyped<units>, PointTyped<units>, SizeTyped<units>, MarginTyped<units> >, |
michael@0 | 88 | public units { |
michael@0 | 89 | typedef BaseRect<Float, RectTyped<units>, PointTyped<units>, SizeTyped<units>, MarginTyped<units> > Super; |
michael@0 | 90 | |
michael@0 | 91 | RectTyped() : Super() {} |
michael@0 | 92 | RectTyped(const PointTyped<units>& aPos, const SizeTyped<units>& aSize) : |
michael@0 | 93 | Super(aPos, aSize) {} |
michael@0 | 94 | RectTyped(Float _x, Float _y, Float _width, Float _height) : |
michael@0 | 95 | Super(_x, _y, _width, _height) {} |
michael@0 | 96 | explicit RectTyped(const IntRectTyped<units>& rect) : |
michael@0 | 97 | Super(float(rect.x), float(rect.y), |
michael@0 | 98 | float(rect.width), float(rect.height)) {} |
michael@0 | 99 | |
michael@0 | 100 | void NudgeToIntegers() |
michael@0 | 101 | { |
michael@0 | 102 | NudgeToInteger(&(this->x)); |
michael@0 | 103 | NudgeToInteger(&(this->y)); |
michael@0 | 104 | NudgeToInteger(&(this->width)); |
michael@0 | 105 | NudgeToInteger(&(this->height)); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | bool ToIntRect(IntRectTyped<units> *aOut) const |
michael@0 | 109 | { |
michael@0 | 110 | *aOut = IntRectTyped<units>(int32_t(this->X()), int32_t(this->Y()), |
michael@0 | 111 | int32_t(this->Width()), int32_t(this->Height())); |
michael@0 | 112 | return RectTyped<units>(Float(aOut->x), Float(aOut->y), |
michael@0 | 113 | Float(aOut->width), Float(aOut->height)) |
michael@0 | 114 | .IsEqualEdges(*this); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | // XXX When all of the code is ported, the following functions to convert to and from |
michael@0 | 118 | // unknown types should be removed. |
michael@0 | 119 | |
michael@0 | 120 | static RectTyped<units> FromUnknownRect(const RectTyped<UnknownUnits>& rect) { |
michael@0 | 121 | return RectTyped<units>(rect.x, rect.y, rect.width, rect.height); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | RectTyped<UnknownUnits> ToUnknownRect() const { |
michael@0 | 125 | return RectTyped<UnknownUnits>(this->x, this->y, this->width, this->height); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | // This is here only to keep IPDL-generated code happy. DO NOT USE. |
michael@0 | 129 | bool operator==(const RectTyped<units>& aRect) const |
michael@0 | 130 | { |
michael@0 | 131 | return RectTyped<units>::IsEqualEdges(aRect); |
michael@0 | 132 | } |
michael@0 | 133 | }; |
michael@0 | 134 | typedef RectTyped<UnknownUnits> Rect; |
michael@0 | 135 | |
michael@0 | 136 | template<class units> |
michael@0 | 137 | IntRectTyped<units> RoundedToInt(const RectTyped<units>& aRect) |
michael@0 | 138 | { |
michael@0 | 139 | return IntRectTyped<units>(int32_t(floorf(aRect.x + 0.5f)), |
michael@0 | 140 | int32_t(floorf(aRect.y + 0.5f)), |
michael@0 | 141 | int32_t(floorf(aRect.width + 0.5f)), |
michael@0 | 142 | int32_t(floorf(aRect.height + 0.5f))); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | template<class units> |
michael@0 | 146 | IntRectTyped<units> RoundedIn(const RectTyped<units>& aRect) |
michael@0 | 147 | { |
michael@0 | 148 | RectTyped<units> copy(aRect); |
michael@0 | 149 | copy.RoundIn(); |
michael@0 | 150 | return IntRectTyped<units>(int32_t(copy.x), |
michael@0 | 151 | int32_t(copy.y), |
michael@0 | 152 | int32_t(copy.width), |
michael@0 | 153 | int32_t(copy.height)); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | template<class units> |
michael@0 | 157 | IntRectTyped<units> RoundedOut(const RectTyped<units>& aRect) |
michael@0 | 158 | { |
michael@0 | 159 | RectTyped<units> copy(aRect); |
michael@0 | 160 | copy.RoundOut(); |
michael@0 | 161 | return IntRectTyped<units>(int32_t(copy.x), |
michael@0 | 162 | int32_t(copy.y), |
michael@0 | 163 | int32_t(copy.width), |
michael@0 | 164 | int32_t(copy.height)); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | } |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | #endif /* MOZILLA_GFX_RECT_H_ */ |