| 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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 return result; | 608 return result; |
| 609 | 609 |
| 610 return result * conversionData.zoom(); | 610 return result * conversionData.zoom(); |
| 611 } | 611 } |
| 612 | 612 |
| 613 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex
ceptionState) | 613 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex
ceptionState) |
| 614 { | 614 { |
| 615 // Keeping values immutable makes optimizations easier and allows sharing of
the primitive value objects. | 615 // Keeping values immutable makes optimizations easier and allows sharing of
the primitive value objects. |
| 616 // No other engine supports mutating style through this API. Computed style
is always read-only anyway. | 616 // No other engine supports mutating style through this API. Computed style
is always read-only anyway. |
| 617 // Supporting setter would require making primitive value copy-on-write and
taking care of style invalidation. | 617 // Supporting setter would require making primitive value copy-on-write and
taking care of style invalidation. |
| 618 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowe
dError); | 618 exceptionState.throwDOMException(NoModificationAllowedError, "CSSPrimitiveVa
lue objects are read-only."); |
| 619 } | 619 } |
| 620 | 620 |
| 621 double CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(unsigned short u
nitType) | 621 double CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(unsigned short u
nitType) |
| 622 { | 622 { |
| 623 double factor = 1.0; | 623 double factor = 1.0; |
| 624 // FIXME: the switch can be replaced by an array of scale factors. | 624 // FIXME: the switch can be replaced by an array of scale factors. |
| 625 switch (unitType) { | 625 switch (unitType) { |
| 626 // These are "canonical" units in their respective categories. | 626 // These are "canonical" units in their respective categories. |
| 627 case CSS_PX: | 627 case CSS_PX: |
| 628 case CSS_DEG: | 628 case CSS_DEG: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 } | 668 } |
| 669 | 669 |
| 670 return factor; | 670 return factor; |
| 671 } | 671 } |
| 672 | 672 |
| 673 double CSSPrimitiveValue::getDoubleValue(unsigned short unitType, ExceptionState
& exceptionState) const | 673 double CSSPrimitiveValue::getDoubleValue(unsigned short unitType, ExceptionState
& exceptionState) const |
| 674 { | 674 { |
| 675 double result = 0; | 675 double result = 0; |
| 676 bool success = getDoubleValueInternal(static_cast<UnitTypes>(unitType), &res
ult); | 676 bool success = getDoubleValueInternal(static_cast<UnitTypes>(unitType), &res
ult); |
| 677 if (!success) { | 677 if (!success) { |
| 678 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr
or); | 678 exceptionState.throwDOMException(InvalidAccessError, "Failed to obtain a
double value."); |
| 679 return 0.0; | 679 return 0.0; |
| 680 } | 680 } |
| 681 | 681 |
| 682 return result; | 682 return result; |
| 683 } | 683 } |
| 684 | 684 |
| 685 double CSSPrimitiveValue::getDoubleValue(unsigned short unitType) const | 685 double CSSPrimitiveValue::getDoubleValue(unsigned short unitType) const |
| 686 { | 686 { |
| 687 double result = 0; | 687 double result = 0; |
| 688 getDoubleValueInternal(static_cast<UnitTypes>(unitType), &result); | 688 getDoubleValueInternal(static_cast<UnitTypes>(unitType), &result); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 | 766 |
| 767 *result = convertedValue; | 767 *result = convertedValue; |
| 768 return true; | 768 return true; |
| 769 } | 769 } |
| 770 | 770 |
| 771 void CSSPrimitiveValue::setStringValue(unsigned short, const String&, ExceptionS
tate& exceptionState) | 771 void CSSPrimitiveValue::setStringValue(unsigned short, const String&, ExceptionS
tate& exceptionState) |
| 772 { | 772 { |
| 773 // Keeping values immutable makes optimizations easier and allows sharing of
the primitive value objects. | 773 // Keeping values immutable makes optimizations easier and allows sharing of
the primitive value objects. |
| 774 // No other engine supports mutating style through this API. Computed style
is always read-only anyway. | 774 // No other engine supports mutating style through this API. Computed style
is always read-only anyway. |
| 775 // Supporting setter would require making primitive value copy-on-write and
taking care of style invalidation. | 775 // Supporting setter would require making primitive value copy-on-write and
taking care of style invalidation. |
| 776 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowe
dError); | 776 exceptionState.throwDOMException(NoModificationAllowedError, "CSSPrimitiveVa
lue objects are read-only."); |
| 777 } | 777 } |
| 778 | 778 |
| 779 String CSSPrimitiveValue::getStringValue(ExceptionState& exceptionState) const | 779 String CSSPrimitiveValue::getStringValue(ExceptionState& exceptionState) const |
| 780 { | 780 { |
| 781 switch (m_primitiveUnitType) { | 781 switch (m_primitiveUnitType) { |
| 782 case CSS_STRING: | 782 case CSS_STRING: |
| 783 case CSS_ATTR: | 783 case CSS_ATTR: |
| 784 case CSS_URI: | 784 case CSS_URI: |
| 785 case CSS_VARIABLE_NAME: | 785 case CSS_VARIABLE_NAME: |
| 786 return m_value.string; | 786 return m_value.string; |
| 787 case CSS_VALUE_ID: | 787 case CSS_VALUE_ID: |
| 788 return valueName(m_value.valueID); | 788 return valueName(m_value.valueID); |
| 789 case CSS_PROPERTY_ID: | 789 case CSS_PROPERTY_ID: |
| 790 return propertyName(m_value.propertyID); | 790 return propertyName(m_value.propertyID); |
| 791 default: | 791 default: |
| 792 exceptionState.throwUninformativeAndGenericDOMException(InvalidAcces
sError); | 792 exceptionState.throwDOMException(InvalidAccessError, "This object's
value cannot be represented as a string."); |
| 793 break; | 793 break; |
| 794 } | 794 } |
| 795 | 795 |
| 796 return String(); | 796 return String(); |
| 797 } | 797 } |
| 798 | 798 |
| 799 String CSSPrimitiveValue::getStringValue() const | 799 String CSSPrimitiveValue::getStringValue() const |
| 800 { | 800 { |
| 801 switch (m_primitiveUnitType) { | 801 switch (m_primitiveUnitType) { |
| 802 case CSS_STRING: | 802 case CSS_STRING: |
| 803 case CSS_ATTR: | 803 case CSS_ATTR: |
| 804 case CSS_URI: | 804 case CSS_URI: |
| 805 case CSS_VARIABLE_NAME: | 805 case CSS_VARIABLE_NAME: |
| 806 return m_value.string; | 806 return m_value.string; |
| 807 case CSS_VALUE_ID: | 807 case CSS_VALUE_ID: |
| 808 return valueName(m_value.valueID); | 808 return valueName(m_value.valueID); |
| 809 case CSS_PROPERTY_ID: | 809 case CSS_PROPERTY_ID: |
| 810 return propertyName(m_value.propertyID); | 810 return propertyName(m_value.propertyID); |
| 811 default: | 811 default: |
| 812 break; | 812 break; |
| 813 } | 813 } |
| 814 | 814 |
| 815 return String(); | 815 return String(); |
| 816 } | 816 } |
| 817 | 817 |
| 818 Counter* CSSPrimitiveValue::getCounterValue(ExceptionState& exceptionState) cons
t | 818 Counter* CSSPrimitiveValue::getCounterValue(ExceptionState& exceptionState) cons
t |
| 819 { | 819 { |
| 820 if (m_primitiveUnitType != CSS_COUNTER) { | 820 if (m_primitiveUnitType != CSS_COUNTER) { |
| 821 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr
or); | 821 exceptionState.throwDOMException(InvalidAccessError, "This object is not
a counter value."); |
| 822 return 0; | 822 return 0; |
| 823 } | 823 } |
| 824 | 824 |
| 825 return m_value.counter; | 825 return m_value.counter; |
| 826 } | 826 } |
| 827 | 827 |
| 828 Rect* CSSPrimitiveValue::getRectValue(ExceptionState& exceptionState) const | 828 Rect* CSSPrimitiveValue::getRectValue(ExceptionState& exceptionState) const |
| 829 { | 829 { |
| 830 if (m_primitiveUnitType != CSS_RECT) { | 830 if (m_primitiveUnitType != CSS_RECT) { |
| 831 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr
or); | 831 exceptionState.throwDOMException(InvalidAccessError, "This object is not
a rect value."); |
| 832 return 0; | 832 return 0; |
| 833 } | 833 } |
| 834 | 834 |
| 835 return m_value.rect; | 835 return m_value.rect; |
| 836 } | 836 } |
| 837 | 837 |
| 838 Quad* CSSPrimitiveValue::getQuadValue(ExceptionState& exceptionState) const | 838 Quad* CSSPrimitiveValue::getQuadValue(ExceptionState& exceptionState) const |
| 839 { | 839 { |
| 840 if (m_primitiveUnitType != CSS_QUAD) { | 840 if (m_primitiveUnitType != CSS_QUAD) { |
| 841 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr
or); | 841 exceptionState.throwDOMException(InvalidAccessError, "This object is not
a quad value."); |
| 842 return 0; | 842 return 0; |
| 843 } | 843 } |
| 844 | 844 |
| 845 return m_value.quad; | 845 return m_value.quad; |
| 846 } | 846 } |
| 847 | 847 |
| 848 PassRefPtr<RGBColor> CSSPrimitiveValue::getRGBColorValue(ExceptionState& excepti
onState) const | 848 PassRefPtr<RGBColor> CSSPrimitiveValue::getRGBColorValue(ExceptionState& excepti
onState) const |
| 849 { | 849 { |
| 850 if (m_primitiveUnitType != CSS_RGBCOLOR) { | 850 if (m_primitiveUnitType != CSS_RGBCOLOR) { |
| 851 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr
or); | 851 exceptionState.throwDOMException(InvalidAccessError, "This object is not
an RGB color value."); |
| 852 return 0; | 852 return 0; |
| 853 } | 853 } |
| 854 | 854 |
| 855 // FIMXE: This should not return a new object for each invocation. | 855 // FIMXE: This should not return a new object for each invocation. |
| 856 return RGBColor::create(m_value.rgbcolor); | 856 return RGBColor::create(m_value.rgbcolor); |
| 857 } | 857 } |
| 858 | 858 |
| 859 Pair* CSSPrimitiveValue::getPairValue(ExceptionState& exceptionState) const | 859 Pair* CSSPrimitiveValue::getPairValue(ExceptionState& exceptionState) const |
| 860 { | 860 { |
| 861 if (m_primitiveUnitType != CSS_PAIR) { | 861 if (m_primitiveUnitType != CSS_PAIR) { |
| 862 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr
or); | 862 exceptionState.throwDOMException(InvalidAccessError, "This object is not
a pair value."); |
| 863 return 0; | 863 return 0; |
| 864 } | 864 } |
| 865 | 865 |
| 866 return m_value.pair; | 866 return m_value.pair; |
| 867 } | 867 } |
| 868 | 868 |
| 869 static String formatNumber(double number, const char* suffix, unsigned suffixLen
gth) | 869 static String formatNumber(double number, const char* suffix, unsigned suffixLen
gth) |
| 870 { | 870 { |
| 871 DecimalNumber decimal(number); | 871 DecimalNumber decimal(number); |
| 872 | 872 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 return m_value.parserOperator == other.m_value.parserOperator; | 1266 return m_value.parserOperator == other.m_value.parserOperator; |
| 1267 case CSS_CALC: | 1267 case CSS_CALC: |
| 1268 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); | 1268 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); |
| 1269 case CSS_SHAPE: | 1269 case CSS_SHAPE: |
| 1270 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot
her.m_value.shape); | 1270 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot
her.m_value.shape); |
| 1271 } | 1271 } |
| 1272 return false; | 1272 return false; |
| 1273 } | 1273 } |
| 1274 | 1274 |
| 1275 } // namespace WebCore | 1275 } // namespace WebCore |
| OLD | NEW |