michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxRect.h" michael@0: michael@0: namespace mozilla { michael@0: /* A rounded rectangle abstraction. michael@0: * michael@0: * This can represent a rectangle with a different pair of radii on each corner. michael@0: * michael@0: * Note: CoreGraphics and Direct2D only support rounded rectangle with the same michael@0: * radii on all corners. However, supporting CSS's border-radius requires the extra flexibility. */ michael@0: struct RoundedRect { michael@0: RoundedRect(gfxRect &aRect, gfxCornerSizes &aCorners) : rect(aRect), corners(aCorners) { } michael@0: void Deflate(gfxFloat aTopWidth, gfxFloat aBottomWidth, gfxFloat aLeftWidth, gfxFloat aRightWidth) { michael@0: // deflate the internal rect michael@0: rect.x += aLeftWidth; michael@0: rect.y += aTopWidth; michael@0: rect.width = std::max(0., rect.width - aLeftWidth - aRightWidth); michael@0: rect.height = std::max(0., rect.height - aTopWidth - aBottomWidth); michael@0: michael@0: corners.sizes[NS_CORNER_TOP_LEFT].width = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].width - aLeftWidth); michael@0: corners.sizes[NS_CORNER_TOP_LEFT].height = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].height - aTopWidth); michael@0: michael@0: corners.sizes[NS_CORNER_TOP_RIGHT].width = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].width - aRightWidth); michael@0: corners.sizes[NS_CORNER_TOP_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].height - aTopWidth); michael@0: michael@0: corners.sizes[NS_CORNER_BOTTOM_LEFT].width = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].width - aLeftWidth); michael@0: corners.sizes[NS_CORNER_BOTTOM_LEFT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].height - aBottomWidth); michael@0: michael@0: corners.sizes[NS_CORNER_BOTTOM_RIGHT].width = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].width - aRightWidth); michael@0: corners.sizes[NS_CORNER_BOTTOM_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].height - aBottomWidth); michael@0: } michael@0: gfxRect rect; michael@0: gfxCornerSizes corners; michael@0: }; michael@0: michael@0: } // namespace mozilla