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_BASEMARGIN_H_ |
michael@0 | 7 | #define MOZILLA_GFX_BASEMARGIN_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "Types.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace gfx { |
michael@0 | 13 | |
michael@0 | 14 | /** |
michael@0 | 15 | * Do not use this class directly. Subclass it, pass that subclass as the |
michael@0 | 16 | * Sub parameter, and only use that subclass. |
michael@0 | 17 | */ |
michael@0 | 18 | template <class T, class Sub> |
michael@0 | 19 | struct BaseMargin { |
michael@0 | 20 | typedef mozilla::css::Side SideT; |
michael@0 | 21 | |
michael@0 | 22 | // Do not change the layout of these members; the Side() methods below |
michael@0 | 23 | // depend on this order. |
michael@0 | 24 | T top, right, bottom, left; |
michael@0 | 25 | |
michael@0 | 26 | // Constructors |
michael@0 | 27 | BaseMargin() : top(0), right(0), bottom(0), left(0) {} |
michael@0 | 28 | BaseMargin(T aTop, T aRight, T aBottom, T aLeft) : |
michael@0 | 29 | top(aTop), right(aRight), bottom(aBottom), left(aLeft) {} |
michael@0 | 30 | |
michael@0 | 31 | void SizeTo(T aTop, T aRight, T aBottom, T aLeft) |
michael@0 | 32 | { |
michael@0 | 33 | top = aTop; right = aRight; bottom = aBottom; left = aLeft; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | T LeftRight() const { return left + right; } |
michael@0 | 37 | T TopBottom() const { return top + bottom; } |
michael@0 | 38 | |
michael@0 | 39 | T& Side(SideT aSide) { |
michael@0 | 40 | // This is ugly! |
michael@0 | 41 | return *(&top + T(aSide)); |
michael@0 | 42 | } |
michael@0 | 43 | T Side(SideT aSide) const { |
michael@0 | 44 | // This is ugly! |
michael@0 | 45 | return *(&top + T(aSide)); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | // Overloaded operators. Note that '=' isn't defined so we'll get the |
michael@0 | 49 | // compiler generated default assignment operator |
michael@0 | 50 | bool operator==(const Sub& aMargin) const { |
michael@0 | 51 | return top == aMargin.top && right == aMargin.right && |
michael@0 | 52 | bottom == aMargin.bottom && left == aMargin.left; |
michael@0 | 53 | } |
michael@0 | 54 | bool operator!=(const Sub& aMargin) const { |
michael@0 | 55 | return !(*this == aMargin); |
michael@0 | 56 | } |
michael@0 | 57 | Sub operator+(const Sub& aMargin) const { |
michael@0 | 58 | return Sub(top + aMargin.top, right + aMargin.right, |
michael@0 | 59 | bottom + aMargin.bottom, left + aMargin.left); |
michael@0 | 60 | } |
michael@0 | 61 | Sub operator-(const Sub& aMargin) const { |
michael@0 | 62 | return Sub(top - aMargin.top, right - aMargin.right, |
michael@0 | 63 | bottom - aMargin.bottom, left - aMargin.left); |
michael@0 | 64 | } |
michael@0 | 65 | Sub& operator+=(const Sub& aMargin) { |
michael@0 | 66 | top += aMargin.top; |
michael@0 | 67 | right += aMargin.right; |
michael@0 | 68 | bottom += aMargin.bottom; |
michael@0 | 69 | left += aMargin.left; |
michael@0 | 70 | return *static_cast<Sub*>(this); |
michael@0 | 71 | } |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | #endif /* MOZILLA_GFX_BASEMARGIN_H_ */ |