Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Unified Diff: Source/core/css/CSSToStyleMap.cpp

Issue 81123002: Factor out common BorderImageLength code in CSSToStyleMap (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address review comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/css/CSSToStyleMap.cpp
diff --git a/Source/core/css/CSSToStyleMap.cpp b/Source/core/css/CSSToStyleMap.cpp
index 10530f487d080f296c199bb96fe74af669677dbe..eecea918e21133161adb170cd8abbf9f00bbc6c5 100644
--- a/Source/core/css/CSSToStyleMap.cpp
+++ b/Source/core/css/CSSToStyleMap.cpp
@@ -610,49 +610,31 @@ void CSSToStyleMap::mapNinePieceImageSlice(CSSValue* value, NinePieceImage& imag
image.setFill(borderImageSlice->m_fill);
}
+static BorderImageLength toBorderImageLength(CSSPrimitiveValue& value, const RenderStyle* currentStyle, const RenderStyle* rootStyle, float multiplier)
+{
+ if (value.isNumber())
+ return value.getDoubleValue();
+ if (value.isPercentage())
+ return Length(value.getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
+ if (value.getValueID() != CSSValueAuto)
+ return value.computeLength<Length>(currentStyle, rootStyle, multiplier);
+ return Length(Auto);
+}
+
BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) const
{
if (!value || !value->isPrimitiveValue())
- return BorderImageLengthBox();
+ return BorderImageLengthBox(Length(Auto));
- // Get our zoom value.
float zoom = useSVGZoomRules() ? 1.0f : style()->effectiveZoom();
-
- // Retrieve the primitive value.
- CSSPrimitiveValue* borderWidths = toCSSPrimitiveValue(value);
-
- // Set up a length box to represent our image slices.
- BorderImageLengthBox box; // Defaults to 'auto' so we don't have to handle that explicitly below.
- Quad* slices = borderWidths->getQuadValue();
- if (slices->top()->isNumber())
- box.setTop(slices->top()->getDoubleValue());
- else if (slices->top()->isPercentage())
- box.setTop(Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent));
- else if (slices->top()->getValueID() != CSSValueAuto)
- box.setTop(slices->top()->computeLength<Length>(style(), rootElementStyle(), zoom));
-
- if (slices->right()->isNumber())
- box.setRight(slices->right()->getDoubleValue());
- else if (slices->right()->isPercentage())
- box.setRight(Length(slices->right()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent));
- else if (slices->right()->getValueID() != CSSValueAuto)
- box.setRight(slices->right()->computeLength<Length>(style(), rootElementStyle(), zoom));
-
- if (slices->bottom()->isNumber())
- box.setBottom(slices->bottom()->getDoubleValue());
- else if (slices->bottom()->isPercentage())
- box.setBottom(Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent));
- else if (slices->bottom()->getValueID() != CSSValueAuto)
- box.setBottom(slices->bottom()->computeLength<Length>(style(), rootElementStyle(), zoom));
-
- if (slices->left()->isNumber())
- box.setLeft(slices->left()->getDoubleValue());
- else if (slices->left()->isPercentage())
- box.setLeft(Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent));
- else if (slices->left()->getValueID() != CSSValueAuto)
- box.setLeft(slices->left()->computeLength<Length>(style(), rootElementStyle(), zoom));
-
- return box;
+ Quad* slices = toCSSPrimitiveValue(value)->getQuadValue();
+
+ // Set up a border image length box to represent our image slices.
+ return BorderImageLengthBox(
+ toBorderImageLength(*slices->top(), style(), rootElementStyle(), zoom),
+ toBorderImageLength(*slices->right(), style(), rootElementStyle(), zoom),
+ toBorderImageLength(*slices->bottom(), style(), rootElementStyle(), zoom),
+ toBorderImageLength(*slices->left(), style(), rootElementStyle(), zoom));
}
void CSSToStyleMap::mapNinePieceImageRepeat(CSSValue* value, NinePieceImage& image) const
« no previous file with comments | « Source/build/scripts/templates/StyleBuilderFunctions.cpp.tmpl ('k') | Source/core/rendering/style/BorderImageLength.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698