mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1274835 - Refactor code to process basic shape from clip-path. r=heycam
This can be used in the implementation of shape-outside. MozReview-Commit-ID: C7bd4D2Kwpm --HG-- extra : rebase_source : fefdd869b1ede3c518e496d8b25ffa5953a7145d
This commit is contained in:
parent
3afaab9b67
commit
d06693b2f0
@ -5887,11 +5887,11 @@ nsComputedDOMStyle::BasicShapeRadiiToString(nsAString& aCssText,
|
||||
}
|
||||
|
||||
already_AddRefed<CSSValue>
|
||||
nsComputedDOMStyle::CreatePrimitiveValueForClipPath(
|
||||
const nsStyleBasicShape* aStyleBasicShape, uint8_t aSizingBox)
|
||||
nsComputedDOMStyle::CreatePrimitiveValueForBasicShape(
|
||||
const nsStyleBasicShape* aStyleBasicShape)
|
||||
{
|
||||
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
|
||||
if (aStyleBasicShape) {
|
||||
MOZ_ASSERT(aStyleBasicShape, "Expect a valid basic shape pointer!");
|
||||
|
||||
nsStyleBasicShape::Type type = aStyleBasicShape->GetShapeType();
|
||||
// Shape function name and opening parenthesis.
|
||||
nsAutoString shapeFunctionString;
|
||||
@ -5963,7 +5963,17 @@ nsComputedDOMStyle::CreatePrimitiveValueForClipPath(
|
||||
shapeFunctionString.Append(')');
|
||||
RefPtr<nsROCSSPrimitiveValue> functionValue = new nsROCSSPrimitiveValue;
|
||||
functionValue->SetString(shapeFunctionString);
|
||||
valueList->AppendCSSValue(functionValue.forget());
|
||||
return functionValue.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<CSSValue>
|
||||
nsComputedDOMStyle::CreatePrimitiveValueForClipPath(
|
||||
const nsStyleBasicShape* aStyleBasicShape, uint8_t aSizingBox)
|
||||
{
|
||||
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
|
||||
if (aStyleBasicShape) {
|
||||
valueList->AppendCSSValue(
|
||||
CreatePrimitiveValueForBasicShape(aStyleBasicShape));
|
||||
}
|
||||
|
||||
if (aSizingBox == NS_STYLE_CLIP_SHAPE_SIZING_NOBOX) {
|
||||
|
@ -643,9 +643,12 @@ private:
|
||||
already_AddRefed<CSSValue> CreatePrimitiveValueForStyleFilter(
|
||||
const nsStyleFilter& aStyleFilter);
|
||||
|
||||
// Helper function for computing basic shape styles.
|
||||
already_AddRefed<CSSValue> CreatePrimitiveValueForClipPath(
|
||||
const nsStyleBasicShape* aStyleBasicShape, uint8_t aSizingBox);
|
||||
|
||||
// Helper function for computing basic shape styles.
|
||||
already_AddRefed<CSSValue> CreatePrimitiveValueForBasicShape(
|
||||
const nsStyleBasicShape* aStyleBasicShape);
|
||||
void BoxValuesToString(nsAString& aString,
|
||||
const nsTArray<nsStyleCoord>& aBoxValues);
|
||||
void BasicShapeRadiiToString(nsAString& aCssText,
|
||||
|
@ -9522,35 +9522,18 @@ nsRuleNode::ComputeSVGData(void* aStartStruct,
|
||||
COMPUTE_END_INHERITED(SVG, svg)
|
||||
}
|
||||
|
||||
void
|
||||
nsRuleNode::SetStyleClipPathToCSSValue(nsStyleClipPath* aStyleClipPath,
|
||||
const nsCSSValue* aValue,
|
||||
already_AddRefed<nsStyleBasicShape>
|
||||
nsRuleNode::GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
|
||||
nsStyleContext* aStyleContext,
|
||||
nsPresContext* aPresContext,
|
||||
RuleNodeCacheConditions& aConditions)
|
||||
{
|
||||
MOZ_ASSERT(aValue->GetUnit() == eCSSUnit_Array,
|
||||
"expected a basic shape or reference box");
|
||||
|
||||
const nsCSSValue::Array* array = aValue->GetArrayValue();
|
||||
MOZ_ASSERT(array->Count() == 1 || array->Count() == 2,
|
||||
"Expect one or both of a shape function and geometry-box");
|
||||
|
||||
uint8_t sizingBox = NS_STYLE_CLIP_SHAPE_SIZING_NOBOX;
|
||||
RefPtr<nsStyleBasicShape> basicShape;
|
||||
for (size_t i = 0; i < array->Count(); ++i) {
|
||||
if (array->Item(i).GetUnit() == eCSSUnit_Enumerated) {
|
||||
int32_t type = array->Item(i).GetIntValue();
|
||||
if (type > NS_STYLE_CLIP_SHAPE_SIZING_VIEW ||
|
||||
type < NS_STYLE_CLIP_SHAPE_SIZING_NOBOX) {
|
||||
NS_NOTREACHED("unexpected reference box");
|
||||
return;
|
||||
}
|
||||
sizingBox = (uint8_t)type;
|
||||
} else if (array->Item(i).GetUnit() == eCSSUnit_Function) {
|
||||
nsCSSValue::Array* shapeFunction = array->Item(i).GetArrayValue();
|
||||
|
||||
nsCSSValue::Array* shapeFunction = aValue.GetArrayValue();
|
||||
nsCSSKeyword functionName =
|
||||
(nsCSSKeyword)shapeFunction->Item(0).GetIntValue();
|
||||
|
||||
if (functionName == eCSSKeyword_polygon) {
|
||||
MOZ_ASSERT(!basicShape, "did not expect value");
|
||||
basicShape = new nsStyleBasicShape(nsStyleBasicShape::ePolygon);
|
||||
@ -9683,8 +9666,39 @@ nsRuleNode::SetStyleClipPathToCSSValue(nsStyleClipPath* aStyleClipPath,
|
||||
}
|
||||
} else {
|
||||
NS_NOTREACHED("unexpected basic shape function");
|
||||
}
|
||||
|
||||
return basicShape.forget();
|
||||
}
|
||||
|
||||
void
|
||||
nsRuleNode::SetStyleClipPathToCSSValue(nsStyleClipPath* aStyleClipPath,
|
||||
const nsCSSValue* aValue,
|
||||
nsStyleContext* aStyleContext,
|
||||
nsPresContext* aPresContext,
|
||||
RuleNodeCacheConditions& aConditions)
|
||||
{
|
||||
MOZ_ASSERT(aValue->GetUnit() == eCSSUnit_Array,
|
||||
"expected a basic shape or reference box");
|
||||
|
||||
const nsCSSValue::Array* array = aValue->GetArrayValue();
|
||||
MOZ_ASSERT(array->Count() == 1 || array->Count() == 2,
|
||||
"Expect one or both of a shape function and geometry-box");
|
||||
|
||||
uint8_t sizingBox = NS_STYLE_CLIP_SHAPE_SIZING_NOBOX;
|
||||
RefPtr<nsStyleBasicShape> basicShape;
|
||||
for (size_t i = 0; i < array->Count(); ++i) {
|
||||
if (array->Item(i).GetUnit() == eCSSUnit_Enumerated) {
|
||||
int32_t type = array->Item(i).GetIntValue();
|
||||
if (type > NS_STYLE_CLIP_SHAPE_SIZING_VIEW ||
|
||||
type < NS_STYLE_CLIP_SHAPE_SIZING_NOBOX) {
|
||||
NS_NOTREACHED("unexpected reference box");
|
||||
return;
|
||||
}
|
||||
sizingBox = (uint8_t)type;
|
||||
} else if (array->Item(i).GetUnit() == eCSSUnit_Function) {
|
||||
basicShape = GetStyleBasicShapeFromCSSValue(array->Item(i), aStyleContext,
|
||||
aPresContext, aConditions);
|
||||
} else {
|
||||
NS_NOTREACHED("unexpected value");
|
||||
return;
|
||||
|
@ -788,6 +788,11 @@ protected:
|
||||
nsStyleContext* aContext,
|
||||
bool aIsBoxShadow,
|
||||
mozilla::RuleNodeCacheConditions& aConditions);
|
||||
already_AddRefed<nsStyleBasicShape>
|
||||
GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
|
||||
nsStyleContext* aStyleContext,
|
||||
nsPresContext* aPresContext,
|
||||
mozilla::RuleNodeCacheConditions& aConditions);
|
||||
bool SetStyleFilterToCSSValue(nsStyleFilter* aStyleFilter,
|
||||
const nsCSSValue& aValue,
|
||||
nsStyleContext* aStyleContext,
|
||||
|
Loading…
Reference in New Issue
Block a user