| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv
ed. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv
ed. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "config.h" | 21 #include "config.h" |
| 22 #include "core/css/CSSPrimitiveValue.h" | 22 #include "core/css/CSSPrimitiveValue.h" |
| 23 | 23 |
| 24 #include "CSSPropertyNames.h" | 24 #include "CSSPropertyNames.h" |
| 25 #include "CSSValueKeywords.h" | 25 #include "CSSValueKeywords.h" |
| 26 #include "bindings/v8/ExceptionState.h" | 26 #include "bindings/v8/ExceptionState.h" |
| 27 #include "core/css/CSSBasicShapes.h" | 27 #include "core/css/CSSBasicShapes.h" |
| 28 #include "core/css/CSSCalculationValue.h" | 28 #include "core/css/CSSCalculationValue.h" |
| 29 #include "core/css/CSSHelper.h" | 29 #include "core/css/CSSHelper.h" |
| 30 #include "core/css/CSSParser.h" | 30 #include "core/css/CSSParser.h" |
| 31 #include "core/css/CSSToLengthConversionData.h" |
| 31 #include "core/css/Counter.h" | 32 #include "core/css/Counter.h" |
| 32 #include "core/css/Pair.h" | 33 #include "core/css/Pair.h" |
| 33 #include "core/css/RGBColor.h" | 34 #include "core/css/RGBColor.h" |
| 34 #include "core/css/Rect.h" | 35 #include "core/css/Rect.h" |
| 35 #include "core/css/StyleSheetContents.h" | 36 #include "core/css/StyleSheetContents.h" |
| 36 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
| 37 #include "core/dom/Node.h" | 38 #include "core/dom/Node.h" |
| 38 #include "core/rendering/style/RenderStyle.h" | 39 #include "core/rendering/style/RenderStyle.h" |
| 39 #include "platform/LayoutUnit.h" | 40 #include "platform/LayoutUnit.h" |
| 40 #include "platform/graphics/Color.h" | 41 #include "platform/graphics/Color.h" |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 case CSS_GRAD: | 513 case CSS_GRAD: |
| 513 return grad2deg(getDoubleValue()); | 514 return grad2deg(getDoubleValue()); |
| 514 case CSS_TURN: | 515 case CSS_TURN: |
| 515 return turn2deg(getDoubleValue()); | 516 return turn2deg(getDoubleValue()); |
| 516 default: | 517 default: |
| 517 ASSERT_NOT_REACHED(); | 518 ASSERT_NOT_REACHED(); |
| 518 return 0; | 519 return 0; |
| 519 } | 520 } |
| 520 } | 521 } |
| 521 | 522 |
| 522 template<> int CSSPrimitiveValue::computeLength(const RenderStyle* style, const
RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 523 template<> int CSSPrimitiveValue::computeLength(const CSSToLengthConversionData&
conversionData) |
| 523 { | 524 { |
| 524 return roundForImpreciseConversion<int>(computeLengthDouble(style, rootStyle
, multiplier, computingFontSize)); | 525 return roundForImpreciseConversion<int>(computeLengthDouble(conversionData))
; |
| 525 } | 526 } |
| 526 | 527 |
| 527 template<> unsigned CSSPrimitiveValue::computeLength(const RenderStyle* style, c
onst RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 528 template<> unsigned CSSPrimitiveValue::computeLength(const CSSToLengthConversion
Data& conversionData) |
| 528 { | 529 { |
| 529 return roundForImpreciseConversion<unsigned>(computeLengthDouble(style, root
Style, multiplier, computingFontSize)); | 530 return roundForImpreciseConversion<unsigned>(computeLengthDouble(conversionD
ata)); |
| 530 } | 531 } |
| 531 | 532 |
| 532 template<> Length CSSPrimitiveValue::computeLength(const RenderStyle* style, con
st RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 533 template<> Length CSSPrimitiveValue::computeLength(const CSSToLengthConversionDa
ta& conversionData) |
| 533 { | 534 { |
| 534 return Length(clampTo<float>(computeLengthDouble(style, rootStyle, multiplie
r, computingFontSize), minValueForCssLength, maxValueForCssLength), Fixed); | 535 return Length(clampTo<float>(computeLengthDouble(conversionData), minValueFo
rCssLength, maxValueForCssLength), Fixed); |
| 535 } | 536 } |
| 536 | 537 |
| 537 template<> short CSSPrimitiveValue::computeLength(const RenderStyle* style, cons
t RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 538 template<> short CSSPrimitiveValue::computeLength(const CSSToLengthConversionDat
a& conversionData) |
| 538 { | 539 { |
| 539 return roundForImpreciseConversion<short>(computeLengthDouble(style, rootSty
le, multiplier, computingFontSize)); | 540 return roundForImpreciseConversion<short>(computeLengthDouble(conversionData
)); |
| 540 } | 541 } |
| 541 | 542 |
| 542 template<> unsigned short CSSPrimitiveValue::computeLength(const RenderStyle* st
yle, const RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 543 template<> unsigned short CSSPrimitiveValue::computeLength(const CSSToLengthConv
ersionData& conversionData) |
| 543 { | 544 { |
| 544 return roundForImpreciseConversion<unsigned short>(computeLengthDouble(style
, rootStyle, multiplier, computingFontSize)); | 545 return roundForImpreciseConversion<unsigned short>(computeLengthDouble(conve
rsionData)); |
| 545 } | 546 } |
| 546 | 547 |
| 547 template<> float CSSPrimitiveValue::computeLength(const RenderStyle* style, cons
t RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 548 template<> float CSSPrimitiveValue::computeLength(const CSSToLengthConversionDat
a& conversionData) |
| 548 { | 549 { |
| 549 return static_cast<float>(computeLengthDouble(style, rootStyle, multiplier,
computingFontSize)); | 550 return static_cast<float>(computeLengthDouble(conversionData)); |
| 550 } | 551 } |
| 551 | 552 |
| 552 template<> double CSSPrimitiveValue::computeLength(const RenderStyle* style, con
st RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 553 template<> double CSSPrimitiveValue::computeLength(const CSSToLengthConversionDa
ta& conversionData) |
| 553 { | 554 { |
| 554 return computeLengthDouble(style, rootStyle, multiplier, computingFontSize); | 555 return computeLengthDouble(conversionData); |
| 555 } | 556 } |
| 556 | 557 |
| 557 double CSSPrimitiveValue::computeLengthDouble(const RenderStyle* style, const Re
nderStyle* rootStyle, float multiplier, bool computingFontSize) | 558 double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& c
onversionData) |
| 558 { | 559 { |
| 559 if (m_primitiveUnitType == CSS_CALC) | 560 if (m_primitiveUnitType == CSS_CALC) |
| 560 // The multiplier and factor is applied to each value in the calc expres
sion individually | 561 return m_value.calc->computeLengthPx(conversionData); |
| 561 return m_value.calc->computeLengthPx(style, rootStyle, multiplier, compu
tingFontSize); | 562 |
| 563 const RenderStyle& style = conversionData.style(); |
| 564 const RenderStyle& rootStyle = conversionData.rootStyle(); |
| 565 bool computingFontSize = conversionData.computingFontSize(); |
| 562 | 566 |
| 563 double factor; | 567 double factor; |
| 564 | 568 |
| 565 switch (primitiveType()) { | 569 switch (primitiveType()) { |
| 566 case CSS_EMS: | 570 case CSS_EMS: |
| 567 factor = computingFontSize ? style->fontDescription().specifiedSize(
) : style->fontDescription().computedSize(); | 571 factor = computingFontSize ? style.fontDescription().specifiedSize()
: style.fontDescription().computedSize(); |
| 568 break; | 572 break; |
| 569 case CSS_EXS: | 573 case CSS_EXS: |
| 570 // FIXME: We have a bug right now where the zoom will be applied twi
ce to EX units. | 574 // FIXME: We have a bug right now where the zoom will be applied twi
ce to EX units. |
| 571 // We really need to compute EX using fontMetrics for the original s
pecifiedSize and not use | 575 // We really need to compute EX using fontMetrics for the original s
pecifiedSize and not use |
| 572 // our actual constructed rendering font. | 576 // our actual constructed rendering font. |
| 573 if (style->fontMetrics().hasXHeight()) | 577 if (style.fontMetrics().hasXHeight()) |
| 574 factor = style->fontMetrics().xHeight(); | 578 factor = style.fontMetrics().xHeight(); |
| 575 else | 579 else |
| 576 factor = (computingFontSize ? style->fontDescription().specified
Size() : style->fontDescription().computedSize()) / 2.0; | 580 factor = (computingFontSize ? style.fontDescription().specifiedS
ize() : style.fontDescription().computedSize()) / 2.0; |
| 577 break; | 581 break; |
| 578 case CSS_REMS: | 582 case CSS_REMS: |
| 579 if (rootStyle) | 583 factor = computingFontSize ? rootStyle.fontDescription().specifiedSi
ze() : rootStyle.fontDescription().computedSize(); |
| 580 factor = computingFontSize ? rootStyle->fontDescription().specif
iedSize() : rootStyle->fontDescription().computedSize(); | |
| 581 else | |
| 582 factor = 1.0; | |
| 583 break; | 584 break; |
| 584 case CSS_CHS: | 585 case CSS_CHS: |
| 585 factor = style->fontMetrics().zeroWidth(); | 586 factor = style.fontMetrics().zeroWidth(); |
| 586 break; | 587 break; |
| 587 case CSS_PX: | 588 case CSS_PX: |
| 588 factor = 1.0; | 589 factor = 1.0; |
| 589 break; | 590 break; |
| 590 case CSS_CM: | 591 case CSS_CM: |
| 591 factor = cssPixelsPerInch / 2.54; // (2.54 cm/in) | 592 factor = cssPixelsPerInch / 2.54; // (2.54 cm/in) |
| 592 break; | 593 break; |
| 593 case CSS_MM: | 594 case CSS_MM: |
| 594 factor = cssPixelsPerInch / 25.4; | 595 factor = cssPixelsPerInch / 25.4; |
| 595 break; | 596 break; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 612 return -1.0; | 613 return -1.0; |
| 613 } | 614 } |
| 614 | 615 |
| 615 // We do not apply the zoom factor when we are computing the value of the fo
nt-size property. The zooming | 616 // We do not apply the zoom factor when we are computing the value of the fo
nt-size property. The zooming |
| 616 // for font sizes is much more complicated, since we have to worry about enf
orcing the minimum font size preference | 617 // for font sizes is much more complicated, since we have to worry about enf
orcing the minimum font size preference |
| 617 // as well as enforcing the implicit "smart minimum." | 618 // as well as enforcing the implicit "smart minimum." |
| 618 double result = getDoubleValue() * factor; | 619 double result = getDoubleValue() * factor; |
| 619 if (computingFontSize || isFontRelativeLength()) | 620 if (computingFontSize || isFontRelativeLength()) |
| 620 return result; | 621 return result; |
| 621 | 622 |
| 622 return result * multiplier; | 623 return result * conversionData.zoom(); |
| 623 } | 624 } |
| 624 | 625 |
| 625 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex
ceptionState) | 626 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex
ceptionState) |
| 626 { | 627 { |
| 627 // Keeping values immutable makes optimizations easier and allows sharing of
the primitive value objects. | 628 // Keeping values immutable makes optimizations easier and allows sharing of
the primitive value objects. |
| 628 // No other engine supports mutating style through this API. Computed style
is always read-only anyway. | 629 // No other engine supports mutating style through this API. Computed style
is always read-only anyway. |
| 629 // Supporting setter would require making primitive value copy-on-write and
taking care of style invalidation. | 630 // Supporting setter would require making primitive value copy-on-write and
taking care of style invalidation. |
| 630 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowe
dError); | 631 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowe
dError); |
| 631 } | 632 } |
| 632 | 633 |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 return m_value.parserOperator == other.m_value.parserOperator; | 1332 return m_value.parserOperator == other.m_value.parserOperator; |
| 1332 case CSS_CALC: | 1333 case CSS_CALC: |
| 1333 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); | 1334 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); |
| 1334 case CSS_SHAPE: | 1335 case CSS_SHAPE: |
| 1335 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot
her.m_value.shape); | 1336 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot
her.m_value.shape); |
| 1336 } | 1337 } |
| 1337 return false; | 1338 return false; |
| 1338 } | 1339 } |
| 1339 | 1340 |
| 1340 } // namespace WebCore | 1341 } // namespace WebCore |
| OLD | NEW |