gfx/thebes/RoundedRect.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: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     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 #include "gfxRect.h"
     8 namespace mozilla {
     9 /* A rounded rectangle abstraction.
    10  *
    11  * This can represent a rectangle with a different pair of radii on each corner.
    12  *
    13  * Note: CoreGraphics and Direct2D only support rounded rectangle with the same
    14  * radii on all corners. However, supporting CSS's border-radius requires the extra flexibility. */
    15 struct RoundedRect {
    16     RoundedRect(gfxRect &aRect, gfxCornerSizes &aCorners) : rect(aRect), corners(aCorners) { }
    17     void Deflate(gfxFloat aTopWidth, gfxFloat aBottomWidth, gfxFloat aLeftWidth, gfxFloat aRightWidth) {
    18         // deflate the internal rect
    19         rect.x += aLeftWidth;
    20         rect.y += aTopWidth;
    21         rect.width = std::max(0., rect.width - aLeftWidth - aRightWidth);
    22         rect.height = std::max(0., rect.height - aTopWidth - aBottomWidth);
    24         corners.sizes[NS_CORNER_TOP_LEFT].width  = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].width - aLeftWidth);
    25         corners.sizes[NS_CORNER_TOP_LEFT].height = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].height - aTopWidth);
    27         corners.sizes[NS_CORNER_TOP_RIGHT].width  = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].width - aRightWidth);
    28         corners.sizes[NS_CORNER_TOP_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].height - aTopWidth);
    30         corners.sizes[NS_CORNER_BOTTOM_LEFT].width  = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].width - aLeftWidth);
    31         corners.sizes[NS_CORNER_BOTTOM_LEFT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].height - aBottomWidth);
    33         corners.sizes[NS_CORNER_BOTTOM_RIGHT].width  = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].width - aRightWidth);
    34         corners.sizes[NS_CORNER_BOTTOM_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].height - aBottomWidth);
    35     }
    36     gfxRect rect;
    37     gfxCornerSizes corners;
    38 };
    40 } // namespace mozilla

mercurial