1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/RoundedRect.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,40 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "gfxRect.h" 1.10 + 1.11 +namespace mozilla { 1.12 +/* A rounded rectangle abstraction. 1.13 + * 1.14 + * This can represent a rectangle with a different pair of radii on each corner. 1.15 + * 1.16 + * Note: CoreGraphics and Direct2D only support rounded rectangle with the same 1.17 + * radii on all corners. However, supporting CSS's border-radius requires the extra flexibility. */ 1.18 +struct RoundedRect { 1.19 + RoundedRect(gfxRect &aRect, gfxCornerSizes &aCorners) : rect(aRect), corners(aCorners) { } 1.20 + void Deflate(gfxFloat aTopWidth, gfxFloat aBottomWidth, gfxFloat aLeftWidth, gfxFloat aRightWidth) { 1.21 + // deflate the internal rect 1.22 + rect.x += aLeftWidth; 1.23 + rect.y += aTopWidth; 1.24 + rect.width = std::max(0., rect.width - aLeftWidth - aRightWidth); 1.25 + rect.height = std::max(0., rect.height - aTopWidth - aBottomWidth); 1.26 + 1.27 + corners.sizes[NS_CORNER_TOP_LEFT].width = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].width - aLeftWidth); 1.28 + corners.sizes[NS_CORNER_TOP_LEFT].height = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].height - aTopWidth); 1.29 + 1.30 + corners.sizes[NS_CORNER_TOP_RIGHT].width = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].width - aRightWidth); 1.31 + corners.sizes[NS_CORNER_TOP_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].height - aTopWidth); 1.32 + 1.33 + corners.sizes[NS_CORNER_BOTTOM_LEFT].width = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].width - aLeftWidth); 1.34 + corners.sizes[NS_CORNER_BOTTOM_LEFT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].height - aBottomWidth); 1.35 + 1.36 + corners.sizes[NS_CORNER_BOTTOM_RIGHT].width = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].width - aRightWidth); 1.37 + corners.sizes[NS_CORNER_BOTTOM_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].height - aBottomWidth); 1.38 + } 1.39 + gfxRect rect; 1.40 + gfxCornerSizes corners; 1.41 +}; 1.42 + 1.43 +} // namespace mozilla