diff --git a/layout/base/ShapeUtils.cpp b/layout/base/ShapeUtils.cpp deleted file mode 100644 index e671d1bbbd60..000000000000 --- a/layout/base/ShapeUtils.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "mozilla/ShapeUtils.h" - -#include - -namespace mozilla { - -nscoord -ShapeUtils::ComputeShapeRadius(const StyleShapeRadius aType, - const nscoord aCenter, - const nscoord aPosMin, - const nscoord aPosMax) -{ - nscoord dist1 = std::abs(aPosMin - aCenter); - nscoord dist2 = std::abs(aPosMax - aCenter); - nscoord length = 0; - switch (aType) { - case StyleShapeRadius::FarthestSide: - length = dist1 > dist2 ? dist1 : dist2; - break; - case StyleShapeRadius::ClosestSide: - length = dist1 > dist2 ? dist2 : dist1; - break; - } - return length; -} - -} // namespace mozilla diff --git a/layout/base/ShapeUtils.h b/layout/base/ShapeUtils.h deleted file mode 100644 index 3f051c2d0ff6..000000000000 --- a/layout/base/ShapeUtils.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_ShapeUtils_h -#define mozilla_ShapeUtils_h - -#include "nsCoord.h" -#include "nsStyleConsts.h" - -namespace mozilla { - -// ShapeUtils is a namespace class containing utility functions related to -// processing basic shapes in the CSS Shapes Module. -// https://drafts.csswg.org/css-shapes/#basic-shape-functions -// -struct ShapeUtils final -{ - // Compute the length of a keyword , i.e. closest-side or - // farthest-side, for a circle or an ellipse on a single dimension. The - // caller needs to call for both dimensions and combine the result. - // https://drafts.csswg.org/css-shapes/#typedef-shape-radius. - // - // @return The length of the radius in app units. - static nscoord ComputeShapeRadius(const StyleShapeRadius aType, - const nscoord aCenter, - const nscoord aPosMin, - const nscoord aPosMax); -}; - -} // namespace mozilla - -#endif // mozilla_ShapeUtils_h diff --git a/layout/base/moz.build b/layout/base/moz.build index 92f8388c2dfa..331a63cbab90 100644 --- a/layout/base/moz.build +++ b/layout/base/moz.build @@ -80,7 +80,6 @@ EXPORTS.mozilla += [ 'RestyleManagerHandleInlines.h', 'ServoRestyleManager.h', 'ServoRestyleManagerInlines.h', - 'ShapeUtils.h', 'StaticPresData.h', ] @@ -115,7 +114,6 @@ UNIFIED_SOURCES += [ 'RestyleTracker.cpp', 'ScrollbarStyles.cpp', 'ServoRestyleManager.cpp', - 'ShapeUtils.cpp', 'StackArena.cpp', 'StaticPresData.cpp', 'TouchManager.cpp', diff --git a/layout/svg/nsCSSClipPathInstance.cpp b/layout/svg/nsCSSClipPathInstance.cpp index d51d074c26d9..080101746b7a 100644 --- a/layout/svg/nsCSSClipPathInstance.cpp +++ b/layout/svg/nsCSSClipPathInstance.cpp @@ -11,7 +11,6 @@ #include "mozilla/dom/SVGSVGElement.h" #include "mozilla/gfx/2D.h" #include "mozilla/gfx/PathHelpers.h" -#include "mozilla/ShapeUtils.h" #include "nsCSSRendering.h" #include "nsIFrame.h" #include "nsRenderingContext.h" @@ -105,6 +104,22 @@ nsCSSClipPathInstance::CreateClipPath(DrawTarget* aDrawTarget) return builder->Finish(); } +static void +EnumerationToLength(nscoord& aCoord, StyleShapeRadius aType, + nscoord aCenter, nscoord aPosMin, nscoord aPosMax) +{ + nscoord dist1 = abs(aPosMin - aCenter); + nscoord dist2 = abs(aPosMax - aCenter); + switch (aType) { + case StyleShapeRadius::FarthestSide: + aCoord = dist1 > dist2 ? dist1 : dist2; + break; + case StyleShapeRadius::ClosestSide: + aCoord = dist1 > dist2 ? dist2 : dist1; + break; + } +} + already_AddRefed nsCSSClipPathInstance::CreateClipPathCircle(DrawTarget* aDrawTarget, const nsRect& aRefBox) @@ -125,12 +140,11 @@ nsCSSClipPathInstance::CreateClipPathCircle(DrawTarget* aDrawTarget, nscoord r = 0; if (coords[0].GetUnit() == eStyleUnit_Enumerated) { const auto styleShapeRadius = coords[0].GetEnumValue(); - nscoord horizontal = - ShapeUtils::ComputeShapeRadius(styleShapeRadius, center.x, aRefBox.x, - aRefBox.x + aRefBox.width); - nscoord vertical = - ShapeUtils::ComputeShapeRadius(styleShapeRadius, center.y, aRefBox.y, - aRefBox.y + aRefBox.height); + nscoord horizontal, vertical; + EnumerationToLength(horizontal, styleShapeRadius, + center.x, aRefBox.x, aRefBox.x + aRefBox.width); + EnumerationToLength(vertical, styleShapeRadius, + center.y, aRefBox.y, aRefBox.y + aRefBox.height); if (styleShapeRadius == StyleShapeRadius::FarthestSide) { r = horizontal > vertical ? horizontal : vertical; } else { @@ -174,18 +188,14 @@ nsCSSClipPathInstance::CreateClipPathEllipse(DrawTarget* aDrawTarget, MOZ_ASSERT(coords.Length() == 2, "wrong number of arguments"); nscoord rx = 0, ry = 0; if (coords[0].GetUnit() == eStyleUnit_Enumerated) { - rx = ShapeUtils::ComputeShapeRadius(coords[0].GetEnumValue(), - center.x, - aRefBox.x, - aRefBox.x + aRefBox.width); + EnumerationToLength(rx, coords[0].GetEnumValue(), + center.x, aRefBox.x, aRefBox.x + aRefBox.width); } else { rx = nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.width); } if (coords[1].GetUnit() == eStyleUnit_Enumerated) { - ry = ShapeUtils::ComputeShapeRadius(coords[1].GetEnumValue(), - center.y, - aRefBox.y, - aRefBox.y + aRefBox.height); + EnumerationToLength(ry, coords[1].GetEnumValue(), + center.y, aRefBox.y, aRefBox.y + aRefBox.height); } else { ry = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height); }