gfx/2d/BaseSize.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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     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
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef MOZILLA_GFX_BASESIZE_H_
     7 #define MOZILLA_GFX_BASESIZE_H_
     9 #include "mozilla/Attributes.h"
    11 namespace mozilla {
    12 namespace gfx {
    14 /**
    15  * Do not use this class directly. Subclass it, pass that subclass as the
    16  * Sub parameter, and only use that subclass. This allows methods to safely
    17  * cast 'this' to 'Sub*'.
    18  */
    19 template <class T, class Sub>
    20 struct BaseSize {
    21   T width, height;
    23   // Constructors
    24   MOZ_CONSTEXPR BaseSize() : width(0), height(0) {}
    25   MOZ_CONSTEXPR BaseSize(T aWidth, T aHeight) : width(aWidth), height(aHeight) {}
    27   void SizeTo(T aWidth, T aHeight) { width = aWidth; height = aHeight; }
    29   bool IsEmpty() const {
    30     return width == 0 || height == 0;
    31   }
    33   // Note that '=' isn't defined so we'll get the
    34   // compiler generated default assignment operator
    36   bool operator==(const Sub& aSize) const {
    37     return width == aSize.width && height == aSize.height;
    38   }
    39   bool operator!=(const Sub& aSize) const {
    40     return width != aSize.width || height != aSize.height;
    41   }
    42   bool operator<=(const Sub& aSize) const {
    43     return width <= aSize.width && height <= aSize.height;
    44   }
    45   bool operator<(const Sub& aSize) const {
    46     return *this <= aSize && *this != aSize;
    47   }
    49   Sub operator+(const Sub& aSize) const {
    50     return Sub(width + aSize.width, height + aSize.height);
    51   }
    52   Sub operator-(const Sub& aSize) const {
    53     return Sub(width - aSize.width, height - aSize.height);
    54   }
    55   Sub& operator+=(const Sub& aSize) {
    56     width += aSize.width;
    57     height += aSize.height;
    58     return *static_cast<Sub*>(this);
    59   }
    60   Sub& operator-=(const Sub& aSize) {
    61     width -= aSize.width;
    62     height -= aSize.height;
    63     return *static_cast<Sub*>(this);
    64   }
    66   Sub operator*(T aScale) const {
    67     return Sub(width * aScale, height * aScale);
    68   }
    69   Sub operator/(T aScale) const {
    70     return Sub(width / aScale, height / aScale);
    71   }
    72   void Scale(T aXScale, T aYScale) {
    73     width *= aXScale;
    74     height *= aYScale;
    75   }
    77   Sub operator*(const Sub& aSize) const {
    78     return Sub(width * aSize.width, height * aSize.height);
    79   }
    80   Sub operator/(const Sub& aSize) const {
    81     return Sub(width / aSize.width, height / aSize.height);
    82   }
    83 };
    85 }
    86 }
    88 #endif /* MOZILLA_GFX_BASESIZE_H_ */

mercurial