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_BASESIZE_H_ |
michael@0 | 7 | #define MOZILLA_GFX_BASESIZE_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.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. This allows methods to safely |
michael@0 | 17 | * cast 'this' to 'Sub*'. |
michael@0 | 18 | */ |
michael@0 | 19 | template <class T, class Sub> |
michael@0 | 20 | struct BaseSize { |
michael@0 | 21 | T width, height; |
michael@0 | 22 | |
michael@0 | 23 | // Constructors |
michael@0 | 24 | MOZ_CONSTEXPR BaseSize() : width(0), height(0) {} |
michael@0 | 25 | MOZ_CONSTEXPR BaseSize(T aWidth, T aHeight) : width(aWidth), height(aHeight) {} |
michael@0 | 26 | |
michael@0 | 27 | void SizeTo(T aWidth, T aHeight) { width = aWidth; height = aHeight; } |
michael@0 | 28 | |
michael@0 | 29 | bool IsEmpty() const { |
michael@0 | 30 | return width == 0 || height == 0; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | // Note that '=' isn't defined so we'll get the |
michael@0 | 34 | // compiler generated default assignment operator |
michael@0 | 35 | |
michael@0 | 36 | bool operator==(const Sub& aSize) const { |
michael@0 | 37 | return width == aSize.width && height == aSize.height; |
michael@0 | 38 | } |
michael@0 | 39 | bool operator!=(const Sub& aSize) const { |
michael@0 | 40 | return width != aSize.width || height != aSize.height; |
michael@0 | 41 | } |
michael@0 | 42 | bool operator<=(const Sub& aSize) const { |
michael@0 | 43 | return width <= aSize.width && height <= aSize.height; |
michael@0 | 44 | } |
michael@0 | 45 | bool operator<(const Sub& aSize) const { |
michael@0 | 46 | return *this <= aSize && *this != aSize; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | Sub operator+(const Sub& aSize) const { |
michael@0 | 50 | return Sub(width + aSize.width, height + aSize.height); |
michael@0 | 51 | } |
michael@0 | 52 | Sub operator-(const Sub& aSize) const { |
michael@0 | 53 | return Sub(width - aSize.width, height - aSize.height); |
michael@0 | 54 | } |
michael@0 | 55 | Sub& operator+=(const Sub& aSize) { |
michael@0 | 56 | width += aSize.width; |
michael@0 | 57 | height += aSize.height; |
michael@0 | 58 | return *static_cast<Sub*>(this); |
michael@0 | 59 | } |
michael@0 | 60 | Sub& operator-=(const Sub& aSize) { |
michael@0 | 61 | width -= aSize.width; |
michael@0 | 62 | height -= aSize.height; |
michael@0 | 63 | return *static_cast<Sub*>(this); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | Sub operator*(T aScale) const { |
michael@0 | 67 | return Sub(width * aScale, height * aScale); |
michael@0 | 68 | } |
michael@0 | 69 | Sub operator/(T aScale) const { |
michael@0 | 70 | return Sub(width / aScale, height / aScale); |
michael@0 | 71 | } |
michael@0 | 72 | void Scale(T aXScale, T aYScale) { |
michael@0 | 73 | width *= aXScale; |
michael@0 | 74 | height *= aYScale; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | Sub operator*(const Sub& aSize) const { |
michael@0 | 78 | return Sub(width * aSize.width, height * aSize.height); |
michael@0 | 79 | } |
michael@0 | 80 | Sub operator/(const Sub& aSize) const { |
michael@0 | 81 | return Sub(width / aSize.width, height / aSize.height); |
michael@0 | 82 | } |
michael@0 | 83 | }; |
michael@0 | 84 | |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | #endif /* MOZILLA_GFX_BASESIZE_H_ */ |