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

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: bool for useEffectiveZoom instead of -1 magic number 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 if (slices->right()->isPercentage()) 597 if (slices->right()->isPercentage())
604 box.m_right = Length(slices->right()->getDoubleValue(), Percent); 598 box.m_right = Length(slices->right()->getDoubleValue(), Percent);
605 else 599 else
606 box.m_right = Length(slices->right()->getIntValue(CSSPrimitiveValue::CSS _NUMBER), Fixed); 600 box.m_right = Length(slices->right()->getIntValue(CSSPrimitiveValue::CSS _NUMBER), Fixed);
607 image.setImageSlices(box); 601 image.setImageSlices(box);
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 static BorderImageLength toBorderImageLength(CSSPrimitiveValue& value, const Ren derStyle* currentStyle, const RenderStyle* rootStyle, float multiplier) 607 static BorderImageLength toBorderImageLength(CSSPrimitiveValue& value, const CSS ToLengthConversionData& conversionData)
614 { 608 {
615 if (value.isNumber()) 609 if (value.isNumber())
616 return value.getDoubleValue(); 610 return value.getDoubleValue();
617 if (value.isPercentage()) 611 if (value.isPercentage())
618 return Length(value.getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), P ercent); 612 return Length(value.getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), P ercent);
619 if (value.getValueID() != CSSValueAuto) 613 if (value.getValueID() != CSSValueAuto)
620 return value.computeLength<Length>(currentStyle, rootStyle, multiplier); 614 return value.computeLength<Length>(conversionData);
621 return Length(Auto); 615 return Length(Auto);
622 } 616 }
623 617
624 BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) const 618 BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) const
625 { 619 {
626 if (!value || !value->isPrimitiveValue()) 620 if (!value || !value->isPrimitiveValue())
627 return BorderImageLengthBox(Length(Auto)); 621 return BorderImageLengthBox(Length(Auto));
628 622
629 float zoom = useSVGZoomRules() ? 1.0f : style()->effectiveZoom(); 623 float zoom = useSVGZoomRules() ? 1.0f : style()->effectiveZoom();
630 Quad* slices = toCSSPrimitiveValue(value)->getQuadValue(); 624 Quad* slices = toCSSPrimitiveValue(value)->getQuadValue();
631 625
632 // Set up a border image length box to represent our image slices. 626 // Set up a border image length box to represent our image slices.
627 const CSSToLengthConversionData& conversionData = cssToLengthConversionData( ).copyWithAdjustedZoom(zoom);
633 return BorderImageLengthBox( 628 return BorderImageLengthBox(
634 toBorderImageLength(*slices->top(), style(), rootElementStyle(), zoom), 629 toBorderImageLength(*slices->top(), conversionData),
635 toBorderImageLength(*slices->right(), style(), rootElementStyle(), zoom) , 630 toBorderImageLength(*slices->right(), conversionData),
636 toBorderImageLength(*slices->bottom(), style(), rootElementStyle(), zoom ), 631 toBorderImageLength(*slices->bottom(), conversionData),
637 toBorderImageLength(*slices->left(), style(), rootElementStyle(), zoom)) ; 632 toBorderImageLength(*slices->left(), conversionData));
638 } 633 }
639 634
640 void CSSToStyleMap::mapNinePieceImageRepeat(CSSValue* value, NinePieceImage& ima ge) const 635 void CSSToStyleMap::mapNinePieceImageRepeat(CSSValue* value, NinePieceImage& ima ge) const
641 { 636 {
642 if (!value || !value->isPrimitiveValue()) 637 if (!value || !value->isPrimitiveValue())
643 return; 638 return;
644 639
645 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 640 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
646 Pair* pair = primitiveValue->getPairValue(); 641 Pair* pair = primitiveValue->getPairValue();
647 if (!pair || !pair->first() || !pair->second()) 642 if (!pair || !pair->first() || !pair->second())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 verticalRule = SpaceImageRule; 674 verticalRule = SpaceImageRule;
680 break; 675 break;
681 default: // CSSValueRepeat 676 default: // CSSValueRepeat
682 verticalRule = RepeatImageRule; 677 verticalRule = RepeatImageRule;
683 break; 678 break;
684 } 679 }
685 image.setVerticalRule(verticalRule); 680 image.setVerticalRule(verticalRule);
686 } 681 }
687 682
688 }; 683 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698