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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 226 } |
227 | 227 |
228 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) | 228 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) |
229 : CSSValue(PrimitiveClass) | 229 : CSSValue(PrimitiveClass) |
230 { | 230 { |
231 init(type); | 231 init(type); |
232 ASSERT(std::isfinite(num)); | 232 ASSERT(std::isfinite(num)); |
233 m_value.num = num; | 233 m_value.num = num; |
234 } | 234 } |
235 | 235 |
236 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) | |
237 : CSSValue(PrimitiveClass) | |
238 { | |
239 init(type); | |
240 m_value.string = str.impl(); | |
241 if (m_value.string) | |
242 m_value.string->ref(); | |
243 } | |
244 | |
245 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) | 236 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) |
246 : CSSValue(PrimitiveClass) | 237 : CSSValue(PrimitiveClass) |
247 { | 238 { |
248 init(UnitType::RGBColor); | 239 init(UnitType::RGBColor); |
249 m_value.rgbcolor = color; | 240 m_value.rgbcolor = color; |
250 } | 241 } |
251 | 242 |
252 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) | 243 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) |
253 : CSSValue(PrimitiveClass) | 244 : CSSValue(PrimitiveClass) |
254 { | 245 { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 332 } |
342 | 333 |
343 CSSPrimitiveValue::~CSSPrimitiveValue() | 334 CSSPrimitiveValue::~CSSPrimitiveValue() |
344 { | 335 { |
345 cleanup(); | 336 cleanup(); |
346 } | 337 } |
347 | 338 |
348 void CSSPrimitiveValue::cleanup() | 339 void CSSPrimitiveValue::cleanup() |
349 { | 340 { |
350 switch (type()) { | 341 switch (type()) { |
351 case UnitType::CustomIdentifier: | |
352 case UnitType::String: | |
353 case UnitType::URI: | |
354 if (m_value.string) | |
355 m_value.string->deref(); | |
356 break; | |
357 case UnitType::Calc: | 342 case UnitType::Calc: |
358 // We must not call deref() when oilpan is enabled because m_value.calc
is traced. | 343 // We must not call deref() when oilpan is enabled because m_value.calc
is traced. |
359 #if !ENABLE(OILPAN) | 344 #if !ENABLE(OILPAN) |
360 m_value.calc->deref(); | 345 m_value.calc->deref(); |
361 #endif | 346 #endif |
362 break; | 347 break; |
363 case UnitType::CalcPercentageWithNumber: | 348 case UnitType::CalcPercentageWithNumber: |
364 case UnitType::CalcPercentageWithLength: | 349 case UnitType::CalcPercentageWithLength: |
365 ASSERT_NOT_REACHED(); | 350 ASSERT_NOT_REACHED(); |
366 break; | 351 break; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 return CSSPrimitiveValue::UnitType::ViewportMin; | 719 return CSSPrimitiveValue::UnitType::ViewportMin; |
735 case UnitTypeViewportMax: | 720 case UnitTypeViewportMax: |
736 return CSSPrimitiveValue::UnitType::ViewportMax; | 721 return CSSPrimitiveValue::UnitType::ViewportMax; |
737 case LengthUnitTypeCount: | 722 case LengthUnitTypeCount: |
738 break; | 723 break; |
739 } | 724 } |
740 ASSERT_NOT_REACHED(); | 725 ASSERT_NOT_REACHED(); |
741 return CSSPrimitiveValue::UnitType::Unknown; | 726 return CSSPrimitiveValue::UnitType::Unknown; |
742 } | 727 } |
743 | 728 |
744 String CSSPrimitiveValue::getStringValue() const | |
745 { | |
746 switch (type()) { | |
747 case UnitType::CustomIdentifier: | |
748 case UnitType::String: | |
749 case UnitType::URI: | |
750 return m_value.string; | |
751 default: | |
752 break; | |
753 } | |
754 | |
755 ASSERT_NOT_REACHED(); | |
756 return String(); | |
757 } | |
758 | |
759 static String formatNumber(double number, const char* suffix, unsigned suffixLen
gth) | 729 static String formatNumber(double number, const char* suffix, unsigned suffixLen
gth) |
760 { | 730 { |
761 #if OS(WIN) && _MSC_VER < 1900 | 731 #if OS(WIN) && _MSC_VER < 1900 |
762 unsigned oldFormat = _set_output_format(_TWO_DIGIT_EXPONENT); | 732 unsigned oldFormat = _set_output_format(_TWO_DIGIT_EXPONENT); |
763 #endif | 733 #endif |
764 String result = String::format("%.6g", number); | 734 String result = String::format("%.6g", number); |
765 #if OS(WIN) && _MSC_VER < 1900 | 735 #if OS(WIN) && _MSC_VER < 1900 |
766 _set_output_format(oldFormat); | 736 _set_output_format(oldFormat); |
767 #endif | 737 #endif |
768 result.append(suffix, suffixLength); | 738 result.append(suffix, suffixLength); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 return "fr"; | 805 return "fr"; |
836 case UnitType::ViewportWidth: | 806 case UnitType::ViewportWidth: |
837 return "vw"; | 807 return "vw"; |
838 case UnitType::ViewportHeight: | 808 case UnitType::ViewportHeight: |
839 return "vh"; | 809 return "vh"; |
840 case UnitType::ViewportMin: | 810 case UnitType::ViewportMin: |
841 return "vmin"; | 811 return "vmin"; |
842 case UnitType::ViewportMax: | 812 case UnitType::ViewportMax: |
843 return "vmax"; | 813 return "vmax"; |
844 case UnitType::Unknown: | 814 case UnitType::Unknown: |
845 case UnitType::CustomIdentifier: | |
846 case UnitType::String: | |
847 case UnitType::URI: | |
848 case UnitType::ValueID: | 815 case UnitType::ValueID: |
849 case UnitType::PropertyID: | 816 case UnitType::PropertyID: |
850 case UnitType::RGBColor: | 817 case UnitType::RGBColor: |
851 case UnitType::Calc: | 818 case UnitType::Calc: |
852 case UnitType::Shape: | 819 case UnitType::Shape: |
853 case UnitType::CalcPercentageWithNumber: | 820 case UnitType::CalcPercentageWithNumber: |
854 case UnitType::CalcPercentageWithLength: | 821 case UnitType::CalcPercentageWithLength: |
855 break; | 822 break; |
856 }; | 823 }; |
857 ASSERT_NOT_REACHED(); | 824 ASSERT_NOT_REACHED(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 case UnitType::Hertz: | 864 case UnitType::Hertz: |
898 case UnitType::Kilohertz: | 865 case UnitType::Kilohertz: |
899 case UnitType::Turns: | 866 case UnitType::Turns: |
900 case UnitType::Fraction: | 867 case UnitType::Fraction: |
901 case UnitType::ViewportWidth: | 868 case UnitType::ViewportWidth: |
902 case UnitType::ViewportHeight: | 869 case UnitType::ViewportHeight: |
903 case UnitType::ViewportMin: | 870 case UnitType::ViewportMin: |
904 case UnitType::ViewportMax: | 871 case UnitType::ViewportMax: |
905 text = formatNumber(m_value.num, unitTypeToString(type())); | 872 text = formatNumber(m_value.num, unitTypeToString(type())); |
906 break; | 873 break; |
907 case UnitType::CustomIdentifier: | |
908 text = quoteCSSStringIfNeeded(m_value.string); | |
909 break; | |
910 case UnitType::String: { | |
911 text = serializeString(m_value.string); | |
912 break; | |
913 } | |
914 case UnitType::URI: | |
915 text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; | |
916 break; | |
917 case UnitType::ValueID: | 874 case UnitType::ValueID: |
918 text = valueName(m_value.valueID); | 875 text = valueName(m_value.valueID); |
919 break; | 876 break; |
920 case UnitType::PropertyID: | 877 case UnitType::PropertyID: |
921 text = propertyName(m_value.propertyID); | 878 text = propertyName(m_value.propertyID); |
922 break; | 879 break; |
923 case UnitType::RGBColor: { | 880 case UnitType::RGBColor: { |
924 text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); | 881 text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); |
925 break; | 882 break; |
926 } | 883 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 case UnitType::ViewportWidth: | 932 case UnitType::ViewportWidth: |
976 case UnitType::ViewportHeight: | 933 case UnitType::ViewportHeight: |
977 case UnitType::ViewportMin: | 934 case UnitType::ViewportMin: |
978 case UnitType::ViewportMax: | 935 case UnitType::ViewportMax: |
979 case UnitType::Fraction: | 936 case UnitType::Fraction: |
980 return m_value.num == other.m_value.num; | 937 return m_value.num == other.m_value.num; |
981 case UnitType::PropertyID: | 938 case UnitType::PropertyID: |
982 return m_value.propertyID == other.m_value.propertyID; | 939 return m_value.propertyID == other.m_value.propertyID; |
983 case UnitType::ValueID: | 940 case UnitType::ValueID: |
984 return m_value.valueID == other.m_value.valueID; | 941 return m_value.valueID == other.m_value.valueID; |
985 case UnitType::CustomIdentifier: | |
986 case UnitType::String: | |
987 case UnitType::URI: | |
988 return equal(m_value.string, other.m_value.string); | |
989 case UnitType::RGBColor: | 942 case UnitType::RGBColor: |
990 return m_value.rgbcolor == other.m_value.rgbcolor; | 943 return m_value.rgbcolor == other.m_value.rgbcolor; |
991 case UnitType::Calc: | 944 case UnitType::Calc: |
992 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); | 945 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); |
993 case UnitType::Shape: | 946 case UnitType::Shape: |
994 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot
her.m_value.shape); | 947 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot
her.m_value.shape); |
995 case UnitType::Integer: | 948 case UnitType::Integer: |
996 case UnitType::Chs: | 949 case UnitType::Chs: |
997 case UnitType::CalcPercentageWithNumber: | 950 case UnitType::CalcPercentageWithNumber: |
998 case UnitType::CalcPercentageWithLength: | 951 case UnitType::CalcPercentageWithLength: |
(...skipping 14 matching lines...) Expand all Loading... |
1013 visitor->trace(m_value.shape); | 966 visitor->trace(m_value.shape); |
1014 break; | 967 break; |
1015 default: | 968 default: |
1016 break; | 969 break; |
1017 } | 970 } |
1018 #endif | 971 #endif |
1019 CSSValue::traceAfterDispatch(visitor); | 972 CSSValue::traceAfterDispatch(visitor); |
1020 } | 973 } |
1021 | 974 |
1022 } // namespace blink | 975 } // namespace blink |
OLD | NEW |