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, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "core/css/CSSPrimitiveValue.h" | 22 #include "core/css/CSSPrimitiveValue.h" |
23 | 23 |
24 #include "bindings/v8/ExceptionState.h" | 24 #include "bindings/v8/ExceptionState.h" |
25 #include "core/css/CSSBasicShapes.h" | 25 #include "core/css/CSSBasicShapes.h" |
26 #include "core/css/CSSCalculationValue.h" | 26 #include "core/css/CSSCalculationValue.h" |
27 #include "core/css/CSSHelper.h" | 27 #include "core/css/CSSHelper.h" |
28 #include "core/css/CSSParser.h" | 28 #include "core/css/CSSParser.h" |
| 29 #include "core/css/CSSToLengthConversionData.h" |
29 #include "core/css/Counter.h" | 30 #include "core/css/Counter.h" |
30 #include "core/css/Pair.h" | 31 #include "core/css/Pair.h" |
31 #include "core/css/RGBColor.h" | 32 #include "core/css/RGBColor.h" |
32 #include "core/css/Rect.h" | 33 #include "core/css/Rect.h" |
33 #include "core/css/StyleSheetContents.h" | 34 #include "core/css/StyleSheetContents.h" |
34 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
35 #include "core/dom/Node.h" | 36 #include "core/dom/Node.h" |
36 #include "core/rendering/style/RenderStyle.h" | 37 #include "core/rendering/style/RenderStyle.h" |
37 #include "platform/LayoutUnit.h" | 38 #include "platform/LayoutUnit.h" |
38 #include "wtf/DecimalNumber.h" | 39 #include "wtf/DecimalNumber.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 case CSS_GRAD: | 510 case CSS_GRAD: |
510 return grad2deg(getDoubleValue()); | 511 return grad2deg(getDoubleValue()); |
511 case CSS_TURN: | 512 case CSS_TURN: |
512 return turn2deg(getDoubleValue()); | 513 return turn2deg(getDoubleValue()); |
513 default: | 514 default: |
514 ASSERT_NOT_REACHED(); | 515 ASSERT_NOT_REACHED(); |
515 return 0; | 516 return 0; |
516 } | 517 } |
517 } | 518 } |
518 | 519 |
519 template<> int CSSPrimitiveValue::computeLength(const RenderStyle* style, const
RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 520 template<> int CSSPrimitiveValue::computeLength(const CSSToLengthConversionData&
conversionData) |
520 { | 521 { |
521 return roundForImpreciseConversion<int>(computeLengthDouble(style, rootStyle
, multiplier, computingFontSize)); | 522 return roundForImpreciseConversion<int>(computeLengthDouble(conversionData))
; |
522 } | 523 } |
523 | 524 |
524 template<> unsigned CSSPrimitiveValue::computeLength(const RenderStyle* style, c
onst RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 525 template<> unsigned CSSPrimitiveValue::computeLength(const CSSToLengthConversion
Data& conversionData) |
525 { | 526 { |
526 return roundForImpreciseConversion<unsigned>(computeLengthDouble(style, root
Style, multiplier, computingFontSize)); | 527 return roundForImpreciseConversion<unsigned>(computeLengthDouble(conversionD
ata)); |
527 } | 528 } |
528 | 529 |
529 template<> Length CSSPrimitiveValue::computeLength(const RenderStyle* style, con
st RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 530 template<> Length CSSPrimitiveValue::computeLength(const CSSToLengthConversionDa
ta& conversionData) |
530 { | 531 { |
531 return Length(clampTo<float>(computeLengthDouble(style, rootStyle, multiplie
r, computingFontSize), minValueForCssLength, maxValueForCssLength), Fixed); | 532 return Length(clampTo<float>(computeLengthDouble(conversionData), minValueFo
rCssLength, maxValueForCssLength), Fixed); |
532 } | 533 } |
533 | 534 |
534 template<> short CSSPrimitiveValue::computeLength(const RenderStyle* style, cons
t RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 535 template<> short CSSPrimitiveValue::computeLength(const CSSToLengthConversionDat
a& conversionData) |
535 { | 536 { |
536 return roundForImpreciseConversion<short>(computeLengthDouble(style, rootSty
le, multiplier, computingFontSize)); | 537 return roundForImpreciseConversion<short>(computeLengthDouble(conversionData
)); |
537 } | 538 } |
538 | 539 |
539 template<> unsigned short CSSPrimitiveValue::computeLength(const RenderStyle* st
yle, const RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 540 template<> unsigned short CSSPrimitiveValue::computeLength(const CSSToLengthConv
ersionData& conversionData) |
540 { | 541 { |
541 return roundForImpreciseConversion<unsigned short>(computeLengthDouble(style
, rootStyle, multiplier, computingFontSize)); | 542 return roundForImpreciseConversion<unsigned short>(computeLengthDouble(conve
rsionData)); |
542 } | 543 } |
543 | 544 |
544 template<> float CSSPrimitiveValue::computeLength(const RenderStyle* style, cons
t RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 545 template<> float CSSPrimitiveValue::computeLength(const CSSToLengthConversionDat
a& conversionData) |
545 { | 546 { |
546 return static_cast<float>(computeLengthDouble(style, rootStyle, multiplier,
computingFontSize)); | 547 return static_cast<float>(computeLengthDouble(conversionData)); |
547 } | 548 } |
548 | 549 |
549 template<> double CSSPrimitiveValue::computeLength(const RenderStyle* style, con
st RenderStyle* rootStyle, float multiplier, bool computingFontSize) | 550 template<> double CSSPrimitiveValue::computeLength(const CSSToLengthConversionDa
ta& conversionData) |
550 { | 551 { |
551 return computeLengthDouble(style, rootStyle, multiplier, computingFontSize); | 552 return computeLengthDouble(conversionData); |
552 } | 553 } |
553 | 554 |
554 double CSSPrimitiveValue::computeLengthDouble(const RenderStyle* style, const Re
nderStyle* rootStyle, float multiplier, bool computingFontSize) | 555 double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& c
onversionData) |
555 { | 556 { |
556 if (m_primitiveUnitType == CSS_CALC) | 557 if (m_primitiveUnitType == CSS_CALC) |
557 // The multiplier and factor is applied to each value in the calc expres
sion individually | 558 return m_value.calc->computeLengthPx(conversionData); |
558 return m_value.calc->computeLengthPx(style, rootStyle, multiplier, compu
tingFontSize); | 559 |
| 560 const RenderStyle& style = conversionData.style(); |
| 561 const RenderStyle& rootStyle = conversionData.rootStyle(); |
| 562 bool computingFontSize = conversionData.computingFontSize(); |
559 | 563 |
560 double factor; | 564 double factor; |
561 | 565 |
562 switch (primitiveType()) { | 566 switch (primitiveType()) { |
563 case CSS_EMS: | 567 case CSS_EMS: |
564 factor = computingFontSize ? style->fontDescription().specifiedSize(
) : style->fontDescription().computedSize(); | 568 factor = computingFontSize ? style.fontDescription().specifiedSize()
: style.fontDescription().computedSize(); |
565 break; | 569 break; |
566 case CSS_EXS: | 570 case CSS_EXS: |
567 // FIXME: We have a bug right now where the zoom will be applied twi
ce to EX units. | 571 // FIXME: We have a bug right now where the zoom will be applied twi
ce to EX units. |
568 // We really need to compute EX using fontMetrics for the original s
pecifiedSize and not use | 572 // We really need to compute EX using fontMetrics for the original s
pecifiedSize and not use |
569 // our actual constructed rendering font. | 573 // our actual constructed rendering font. |
570 if (style->fontMetrics().hasXHeight()) | 574 if (style.fontMetrics().hasXHeight()) |
571 factor = style->fontMetrics().xHeight(); | 575 factor = style.fontMetrics().xHeight(); |
572 else | 576 else |
573 factor = (computingFontSize ? style->fontDescription().specified
Size() : style->fontDescription().computedSize()) / 2.0; | 577 factor = (computingFontSize ? style.fontDescription().specifiedS
ize() : style.fontDescription().computedSize()) / 2.0; |
574 break; | 578 break; |
575 case CSS_REMS: | 579 case CSS_REMS: |
576 if (rootStyle) | 580 factor = computingFontSize ? rootStyle.fontDescription().specifiedSi
ze() : rootStyle.fontDescription().computedSize(); |
577 factor = computingFontSize ? rootStyle->fontDescription().specif
iedSize() : rootStyle->fontDescription().computedSize(); | |
578 else | |
579 factor = 1.0; | |
580 break; | 581 break; |
581 case CSS_CHS: | 582 case CSS_CHS: |
582 factor = style->fontMetrics().zeroWidth(); | 583 factor = style.fontMetrics().zeroWidth(); |
583 break; | 584 break; |
584 case CSS_PX: | 585 case CSS_PX: |
585 factor = 1.0; | 586 factor = 1.0; |
586 break; | 587 break; |
587 case CSS_CM: | 588 case CSS_CM: |
588 factor = cssPixelsPerCentimeter; | 589 factor = cssPixelsPerCentimeter; |
589 break; | 590 break; |
590 case CSS_MM: | 591 case CSS_MM: |
591 factor = cssPixelsPerMillimeter; | 592 factor = cssPixelsPerMillimeter; |
592 break; | 593 break; |
(...skipping 15 matching lines...) Expand all Loading... |
608 return -1.0; | 609 return -1.0; |
609 } | 610 } |
610 | 611 |
611 // We do not apply the zoom factor when we are computing the value of the fo
nt-size property. The zooming | 612 // We do not apply the zoom factor when we are computing the value of the fo
nt-size property. The zooming |
612 // for font sizes is much more complicated, since we have to worry about enf
orcing the minimum font size preference | 613 // for font sizes is much more complicated, since we have to worry about enf
orcing the minimum font size preference |
613 // as well as enforcing the implicit "smart minimum." | 614 // as well as enforcing the implicit "smart minimum." |
614 double result = getDoubleValue() * factor; | 615 double result = getDoubleValue() * factor; |
615 if (computingFontSize || isFontRelativeLength()) | 616 if (computingFontSize || isFontRelativeLength()) |
616 return result; | 617 return result; |
617 | 618 |
618 return result * multiplier; | 619 return result * conversionData.zoom(); |
619 } | 620 } |
620 | 621 |
621 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex
ceptionState) | 622 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex
ceptionState) |
622 { | 623 { |
623 // Keeping values immutable makes optimizations easier and allows sharing of
the primitive value objects. | 624 // Keeping values immutable makes optimizations easier and allows sharing of
the primitive value objects. |
624 // No other engine supports mutating style through this API. Computed style
is always read-only anyway. | 625 // No other engine supports mutating style through this API. Computed style
is always read-only anyway. |
625 // Supporting setter would require making primitive value copy-on-write and
taking care of style invalidation. | 626 // Supporting setter would require making primitive value copy-on-write and
taking care of style invalidation. |
626 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowe
dError); | 627 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowe
dError); |
627 } | 628 } |
628 | 629 |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 return m_value.parserOperator == other.m_value.parserOperator; | 1331 return m_value.parserOperator == other.m_value.parserOperator; |
1331 case CSS_CALC: | 1332 case CSS_CALC: |
1332 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); | 1333 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); |
1333 case CSS_SHAPE: | 1334 case CSS_SHAPE: |
1334 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot
her.m_value.shape); | 1335 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot
her.m_value.shape); |
1335 } | 1336 } |
1336 return false; | 1337 return false; |
1337 } | 1338 } |
1338 | 1339 |
1339 } // namespace WebCore | 1340 } // namespace WebCore |
OLD | NEW |