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

Side by Side Diff: Source/core/css/CSSToStyleMap.cpp

Issue 64293008: Wrap CSS length conversion arguments in an object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: erm.. use DEFINE_STATIC_REF Created 7 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 29 matching lines...) Expand all
40 #include "core/rendering/style/BorderImageLengthBox.h" 40 #include "core/rendering/style/BorderImageLengthBox.h"
41 #include "core/rendering/style/FillLayer.h" 41 #include "core/rendering/style/FillLayer.h"
42 42
43 namespace WebCore { 43 namespace WebCore {
44 44
45 const RenderStyle* CSSToStyleMap::style() const 45 const RenderStyle* CSSToStyleMap::style() const
46 { 46 {
47 return m_state.style(); 47 return m_state.style();
48 } 48 }
49 49
50 const RenderStyle* CSSToStyleMap::rootElementStyle() const 50 const CSSToLengthConversionData& CSSToStyleMap::cssToLengthConversionData() cons t
51 { 51 {
52 return m_state.rootElementStyle(); 52 return m_state.cssToLengthConversionData();
53 } 53 }
54 54
55 bool CSSToStyleMap::useSVGZoomRules() const 55 bool CSSToStyleMap::useSVGZoomRules() const
56 { 56 {
57 return m_state.useSVGZoomRules(); 57 return m_state.useSVGZoomRules();
58 } 58 }
59 59
60 PassRefPtr<StyleImage> CSSToStyleMap::styleImage(CSSPropertyID propertyId, CSSVa lue* value) 60 PassRefPtr<StyleImage> CSSToStyleMap::styleImage(CSSPropertyID propertyId, CSSVa lue* value)
61 { 61 {
62 return m_elementStyleResources.styleImage(m_state.document().textLinkColors( ), m_state.style()->visitedDependentColor(CSSPropertyColor), propertyId, value); 62 return m_elementStyleResources.styleImage(m_state.document().textLinkColors( ), m_state.style()->visitedDependentColor(CSSPropertyColor), propertyId, value);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 else 198 else
199 layer->setSizeType(SizeLength); 199 layer->setSizeType(SizeLength);
200 200
201 LengthSize b = FillLayer::initialFillSizeLength(layer->type()); 201 LengthSize b = FillLayer::initialFillSizeLength(layer->type());
202 202
203 if (value->isInitialValue() || primitiveValue->getValueID() == CSSValueConta in || primitiveValue->getValueID() == CSSValueCover) { 203 if (value->isInitialValue() || primitiveValue->getValueID() == CSSValueConta in || primitiveValue->getValueID() == CSSValueCover) {
204 layer->setSizeLength(b); 204 layer->setSizeLength(b);
205 return; 205 return;
206 } 206 }
207 207
208 float zoomFactor = style()->effectiveZoom();
209
210 Length firstLength; 208 Length firstLength;
211 Length secondLength; 209 Length secondLength;
212 210
213 if (Pair* pair = primitiveValue->getPairValue()) { 211 if (Pair* pair = primitiveValue->getPairValue()) {
214 firstLength = pair->first()->convertToLength<AnyConversion>(style(), roo tElementStyle(), zoomFactor); 212 firstLength = pair->first()->convertToLength<AnyConversion>(cssToLengthC onversionData());
215 secondLength = pair->second()->convertToLength<AnyConversion>(style(), r ootElementStyle(), zoomFactor); 213 secondLength = pair->second()->convertToLength<AnyConversion>(cssToLengt hConversionData());
216 } else { 214 } else {
217 firstLength = primitiveValue->convertToLength<AnyConversion>(style(), ro otElementStyle(), zoomFactor); 215 firstLength = primitiveValue->convertToLength<AnyConversion>(cssToLength ConversionData());
218 secondLength = Length(); 216 secondLength = Length();
219 } 217 }
220 218
221 if (firstLength.isUndefined() || secondLength.isUndefined()) 219 if (firstLength.isUndefined() || secondLength.isUndefined())
222 return; 220 return;
223 221
224 b.setWidth(firstLength); 222 b.setWidth(firstLength);
225 b.setHeight(secondLength); 223 b.setHeight(secondLength);
226 layer->setSizeLength(b); 224 layer->setSizeLength(b);
227 } 225 }
228 226
229 void CSSToStyleMap::mapFillXPosition(CSSPropertyID propertyID, FillLayer* layer, CSSValue* value) const 227 void CSSToStyleMap::mapFillXPosition(CSSPropertyID propertyID, FillLayer* layer, CSSValue* value) const
230 { 228 {
231 if (!value->isPrimitiveValue()) 229 if (!value->isPrimitiveValue())
232 return; 230 return;
233 231
234 float zoomFactor = style()->effectiveZoom();
235
236 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 232 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
237 Pair* pair = primitiveValue->getPairValue(); 233 Pair* pair = primitiveValue->getPairValue();
238 if (pair) { 234 if (pair) {
239 ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionX | | propertyID == CSSPropertyWebkitMaskPositionX); 235 ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionX | | propertyID == CSSPropertyWebkitMaskPositionX);
240 primitiveValue = pair->second(); 236 primitiveValue = pair->second();
241 } 237 }
242 238
243 Length length; 239 Length length;
244 if (primitiveValue->isLength()) 240 if (primitiveValue->isLength())
245 length = primitiveValue->computeLength<Length>(style(), rootElementStyle (), zoomFactor); 241 length = primitiveValue->computeLength<Length>(cssToLengthConversionData ());
246 else if (primitiveValue->isPercentage()) 242 else if (primitiveValue->isPercentage())
247 length = Length(primitiveValue->getDoubleValue(), Percent); 243 length = Length(primitiveValue->getDoubleValue(), Percent);
248 else if (primitiveValue->isCalculatedPercentageWithLength()) 244 else if (primitiveValue->isCalculatedPercentageWithLength())
249 length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), roo tElementStyle(), zoomFactor)); 245 length = Length(primitiveValue->cssCalcValue()->toCalcValue(cssToLengthC onversionData()));
250 else if (primitiveValue->isViewportPercentageLength()) 246 else if (primitiveValue->isViewportPercentageLength())
251 length = primitiveValue->viewportPercentageLength(); 247 length = primitiveValue->viewportPercentageLength();
252 else 248 else
253 return; 249 return;
254 250
255 layer->setXPosition(length); 251 layer->setXPosition(length);
256 if (pair) 252 if (pair)
257 layer->setBackgroundXOrigin(*(pair->first())); 253 layer->setBackgroundXOrigin(*(pair->first()));
258 } 254 }
259 255
260 void CSSToStyleMap::mapFillYPosition(CSSPropertyID propertyID, FillLayer* layer, CSSValue* value) const 256 void CSSToStyleMap::mapFillYPosition(CSSPropertyID propertyID, FillLayer* layer, CSSValue* value) const
261 { 257 {
262 if (!value->isPrimitiveValue()) 258 if (!value->isPrimitiveValue())
263 return; 259 return;
264 260
265 float zoomFactor = style()->effectiveZoom();
266
267 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 261 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
268 Pair* pair = primitiveValue->getPairValue(); 262 Pair* pair = primitiveValue->getPairValue();
269 if (pair) { 263 if (pair) {
270 ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionY | | propertyID == CSSPropertyWebkitMaskPositionY); 264 ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionY | | propertyID == CSSPropertyWebkitMaskPositionY);
271 primitiveValue = pair->second(); 265 primitiveValue = pair->second();
272 } 266 }
273 267
274 Length length; 268 Length length;
275 if (primitiveValue->isLength()) 269 if (primitiveValue->isLength())
276 length = primitiveValue->computeLength<Length>(style(), rootElementStyle (), zoomFactor); 270 length = primitiveValue->computeLength<Length>(cssToLengthConversionData ());
277 else if (primitiveValue->isPercentage()) 271 else if (primitiveValue->isPercentage())
278 length = Length(primitiveValue->getDoubleValue(), Percent); 272 length = Length(primitiveValue->getDoubleValue(), Percent);
279 else if (primitiveValue->isCalculatedPercentageWithLength()) 273 else if (primitiveValue->isCalculatedPercentageWithLength())
280 length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), roo tElementStyle(), zoomFactor)); 274 length = Length(primitiveValue->cssCalcValue()->toCalcValue(cssToLengthC onversionData()));
281 else if (primitiveValue->isViewportPercentageLength()) 275 else if (primitiveValue->isViewportPercentageLength())
282 length = primitiveValue->viewportPercentageLength(); 276 length = primitiveValue->viewportPercentageLength();
283 else 277 else
284 return; 278 return;
285 279
286 layer->setYPosition(length); 280 layer->setYPosition(length);
287 if (pair) 281 if (pair)
288 layer->setBackgroundYOrigin(*(pair->first())); 282 layer->setBackgroundYOrigin(*(pair->first()));
289 } 283 }
290 284
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 602
609 // Set our fill mode. 603 // Set our fill mode.
610 image.setFill(borderImageSlice->m_fill); 604 image.setFill(borderImageSlice->m_fill);
611 } 605 }
612 606
613 BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) const 607 BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) const
614 { 608 {
615 if (!value || !value->isPrimitiveValue()) 609 if (!value || !value->isPrimitiveValue())
616 return BorderImageLengthBox(); 610 return BorderImageLengthBox();
617 611
618 // Get our zoom value.
619 float zoom = useSVGZoomRules() ? 1.0f : style()->effectiveZoom(); 612 float zoom = useSVGZoomRules() ? 1.0f : style()->effectiveZoom();
613 const CSSToLengthConversionData& conversionData = cssToLengthConversionData( ).copyWithAdjustedZoom(zoom);
620 614
621 // Retrieve the primitive value. 615 // Retrieve the primitive value.
622 CSSPrimitiveValue* borderWidths = toCSSPrimitiveValue(value); 616 CSSPrimitiveValue* borderWidths = toCSSPrimitiveValue(value);
623 617
624 // Set up a length box to represent our image slices. 618 // Set up a length box to represent our image slices.
625 BorderImageLengthBox box; // Defaults to 'auto' so we don't have to handle t hat explicitly below. 619 BorderImageLengthBox box; // Defaults to 'auto' so we don't have to handle t hat explicitly below.
626 Quad* slices = borderWidths->getQuadValue(); 620 Quad* slices = borderWidths->getQuadValue();
627 if (slices->top()->isNumber()) 621 if (slices->top()->isNumber())
628 box.setTop(slices->top()->getDoubleValue()); 622 box.setTop(slices->top()->getDoubleValue());
629 else if (slices->top()->isPercentage()) 623 else if (slices->top()->isPercentage())
630 box.setTop(Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_P ERCENTAGE), Percent)); 624 box.setTop(Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_P ERCENTAGE), Percent));
631 else if (slices->top()->getValueID() != CSSValueAuto) 625 else if (slices->top()->getValueID() != CSSValueAuto)
632 box.setTop(slices->top()->computeLength<Length>(style(), rootElementStyl e(), zoom)); 626 box.setTop(slices->top()->computeLength<Length>(conversionData));
633 627
634 if (slices->right()->isNumber()) 628 if (slices->right()->isNumber())
635 box.setRight(slices->right()->getDoubleValue()); 629 box.setRight(slices->right()->getDoubleValue());
636 else if (slices->right()->isPercentage()) 630 else if (slices->right()->isPercentage())
637 box.setRight(Length(slices->right()->getDoubleValue(CSSPrimitiveValue::C SS_PERCENTAGE), Percent)); 631 box.setRight(Length(slices->right()->getDoubleValue(CSSPrimitiveValue::C SS_PERCENTAGE), Percent));
638 else if (slices->right()->getValueID() != CSSValueAuto) 632 else if (slices->right()->getValueID() != CSSValueAuto)
639 box.setRight(slices->right()->computeLength<Length>(style(), rootElement Style(), zoom)); 633 box.setRight(slices->right()->computeLength<Length>(conversionData));
640 634
641 if (slices->bottom()->isNumber()) 635 if (slices->bottom()->isNumber())
642 box.setBottom(slices->bottom()->getDoubleValue()); 636 box.setBottom(slices->bottom()->getDoubleValue());
643 else if (slices->bottom()->isPercentage()) 637 else if (slices->bottom()->isPercentage())
644 box.setBottom(Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue: :CSS_PERCENTAGE), Percent)); 638 box.setBottom(Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue: :CSS_PERCENTAGE), Percent));
645 else if (slices->bottom()->getValueID() != CSSValueAuto) 639 else if (slices->bottom()->getValueID() != CSSValueAuto)
646 box.setBottom(slices->bottom()->computeLength<Length>(style(), rootEleme ntStyle(), zoom)); 640 box.setBottom(slices->bottom()->computeLength<Length>(conversionData));
647 641
648 if (slices->left()->isNumber()) 642 if (slices->left()->isNumber())
649 box.setLeft(slices->left()->getDoubleValue()); 643 box.setLeft(slices->left()->getDoubleValue());
650 else if (slices->left()->isPercentage()) 644 else if (slices->left()->isPercentage())
651 box.setLeft(Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS _PERCENTAGE), Percent)); 645 box.setLeft(Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS _PERCENTAGE), Percent));
652 else if (slices->left()->getValueID() != CSSValueAuto) 646 else if (slices->left()->getValueID() != CSSValueAuto)
653 box.setLeft(slices->left()->computeLength<Length>(style(), rootElementSt yle(), zoom)); 647 box.setLeft(slices->left()->computeLength<Length>(conversionData));
654 648
655 return box; 649 return box;
656 } 650 }
657 651
658 void CSSToStyleMap::mapNinePieceImageRepeat(CSSValue* value, NinePieceImage& ima ge) const 652 void CSSToStyleMap::mapNinePieceImageRepeat(CSSValue* value, NinePieceImage& ima ge) const
659 { 653 {
660 if (!value || !value->isPrimitiveValue()) 654 if (!value || !value->isPrimitiveValue())
661 return; 655 return;
662 656
663 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 657 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 verticalRule = SpaceImageRule; 691 verticalRule = SpaceImageRule;
698 break; 692 break;
699 default: // CSSValueRepeat 693 default: // CSSValueRepeat
700 verticalRule = RepeatImageRule; 694 verticalRule = RepeatImageRule;
701 break; 695 break;
702 } 696 }
703 image.setVerticalRule(verticalRule); 697 image.setVerticalRule(verticalRule);
704 } 698 }
705 699
706 }; 700 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698