Backed out changeset d523b9c7c0bb (bug 1311244)

This commit is contained in:
Carsten "Tomcat" Book 2017-01-12 14:19:26 +01:00
parent ee7d4daa84
commit 9ced0d536f
4 changed files with 25 additions and 85 deletions

View File

@ -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 <cstdlib>
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

View File

@ -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 <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);
};
} // namespace mozilla
#endif // mozilla_ShapeUtils_h

View File

@ -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',

View File

@ -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<Path>
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<StyleShapeRadius>();
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<StyleShapeRadius>(),
center.x,
aRefBox.x,
aRefBox.x + aRefBox.width);
EnumerationToLength(rx, coords[0].GetEnumValue<StyleShapeRadius>(),
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<StyleShapeRadius>(),
center.y,
aRefBox.y,
aRefBox.y + aRefBox.height);
EnumerationToLength(ry, coords[1].GetEnumValue<StyleShapeRadius>(),
center.y, aRefBox.y, aRefBox.y + aRefBox.height);
} else {
ry = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height);
}