author | Ting-Yu Lin <tlin@mozilla.com> |
Thu, 16 Feb 2017 10:51:47 +0800 | |
changeset 343235 | ecc715f72d6112bd6a57a5b52603c3ca2683a003 |
parent 343234 | ea8bf524e3c8a7bdb26a329b8effa3ba0d9e822e |
child 343236 | 2b9a5fad30b78c77860a5418b8db96b56edab11b |
push id | 31372 |
push user | cbook@mozilla.com |
push date | Thu, 16 Feb 2017 12:16:10 +0000 |
treeherder | mozilla-central@2737f66ad6ac [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | dbaron |
bugs | 1326407 |
milestone | 54.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/layout/base/ShapeUtils.cpp +++ b/layout/base/ShapeUtils.cpp @@ -4,16 +4,17 @@ * 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 <cstdlib> #include "nsCSSRendering.h" +#include "nsMargin.h" #include "nsRuleNode.h" #include "nsStyleCoord.h" #include "nsStyleStruct.h" #include "SVGContentUtils.h" namespace mozilla { nscoord @@ -110,9 +111,30 @@ ShapeUtils::ComputeEllipseRadii(StyleBas aRefBox.YMost()); } else { radii.height = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height); } return radii; } +/* static */ nsRect +ShapeUtils::ComputeInsetRect(StyleBasicShape* const aBasicShape, + const nsRect& aRefBox) +{ + MOZ_ASSERT(aBasicShape->GetShapeType() == StyleBasicShapeType::Inset, + "The basic shape must be inset()!"); + + const nsTArray<nsStyleCoord>& coords = aBasicShape->Coordinates(); + MOZ_ASSERT(coords.Length() == 4, "wrong number of arguments"); + + nsMargin inset(nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.height), + nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.width), + nsRuleNode::ComputeCoordPercentCalc(coords[2], aRefBox.height), + nsRuleNode::ComputeCoordPercentCalc(coords[3], aRefBox.width)); + + nsRect insetRect(aRefBox); + insetRect.Deflate(inset); + + return insetRect; +} + } // namespace mozilla
--- a/layout/base/ShapeUtils.h +++ b/layout/base/ShapeUtils.h @@ -21,25 +21,23 @@ class StyleBasicShape; // https://drafts.csswg.org/css-shapes/#basic-shape-functions // struct ShapeUtils final { // Compute the length of a keyword <shape-radius>, 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); // Compute the center of a circle or an ellipse. - // // @param aRefBox The reference box of the basic shape. // @return The point of the center. static nsPoint ComputeCircleOrEllipseCenter( StyleBasicShape* const aBasicShape, const nsRect& aRefBox); // Compute the radius for a circle. // @param aCenter the center of the circle. @@ -52,13 +50,20 @@ struct ShapeUtils final // Compute the radii for an ellipse. // @param aCenter the center of the ellipse. // @param aRefBox the reference box of the ellipse. // @return The radii of the ellipse in app units. The width and height // represent the x-axis and y-axis radii of the ellipse. static nsSize ComputeEllipseRadii( mozilla::StyleBasicShape* const aBasicShape, const nsPoint& aCenter, const nsRect& aRefBox); + + // Compute the rect for an inset. + // @param aRefBox the reference box of the inset. + // @return The inset rect in app units. + static nsRect ComputeInsetRect( + mozilla::StyleBasicShape* const aBasicShape, + const nsRect& aRefBox); }; } // namespace mozilla #endif // mozilla_ShapeUtils_h
--- a/layout/svg/nsCSSClipPathInstance.cpp +++ b/layout/svg/nsCSSClipPathInstance.cpp @@ -172,31 +172,23 @@ nsCSSClipPathInstance::CreateClipPathPol return builder->Finish(); } already_AddRefed<Path> nsCSSClipPathInstance::CreateClipPathInset(DrawTarget* aDrawTarget, const nsRect& aRefBox) { StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape(); - const nsTArray<nsStyleCoord>& coords = basicShape->Coordinates(); - MOZ_ASSERT(coords.Length() == 4, "wrong number of arguments"); RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder(); nscoord appUnitsPerDevPixel = mTargetFrame->PresContext()->AppUnitsPerDevPixel(); - nsMargin inset(nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.height), - nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.width), - nsRuleNode::ComputeCoordPercentCalc(coords[2], aRefBox.height), - nsRuleNode::ComputeCoordPercentCalc(coords[3], aRefBox.width)); - - nsRect insetRect(aRefBox); - insetRect.Deflate(inset); + nsRect insetRect = ShapeUtils::ComputeInsetRect(basicShape, aRefBox); const Rect insetRectPixels = NSRectToRect(insetRect, appUnitsPerDevPixel); const nsStyleCorners& radius = basicShape->GetRadius(); nscoord appUnitsRadii[8]; if (nsIFrame::ComputeBorderRadii(radius, insetRect.Size(), aRefBox.Size(), Sides(), appUnitsRadii)) { RectCornerRadii corners;