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

mercurial