gfx/thebes/RoundedRect.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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