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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 225 } |
226 | 226 |
227 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) | 227 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) |
228 : CSSValue(PrimitiveClass) | 228 : CSSValue(PrimitiveClass) |
229 { | 229 { |
230 init(type); | 230 init(type); |
231 ASSERT(std::isfinite(num)); | 231 ASSERT(std::isfinite(num)); |
232 m_value.num = num; | 232 m_value.num = num; |
233 } | 233 } |
234 | 234 |
235 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) | |
236 : CSSValue(PrimitiveClass) | |
237 { | |
238 init(type); | |
239 m_value.string = str.impl(); | |
240 if (m_value.string) | |
241 m_value.string->ref(); | |
242 } | |
243 | |
244 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) | 235 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) |
245 : CSSValue(PrimitiveClass) | 236 : CSSValue(PrimitiveClass) |
246 { | 237 { |
247 init(UnitType::RGBColor); | 238 init(UnitType::RGBColor); |
248 m_value.rgbcolor = color; | 239 m_value.rgbcolor = color; |
249 } | 240 } |
250 | 241 |
251 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) | 242 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) |
252 : CSSValue(PrimitiveClass) | 243 : CSSValue(PrimitiveClass) |
253 { | 244 { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 324 } |
334 | 325 |
335 CSSPrimitiveValue::~CSSPrimitiveValue() | 326 CSSPrimitiveValue::~CSSPrimitiveValue() |
336 { | 327 { |
337 cleanup(); | 328 cleanup(); |
338 } | 329 } |
339 | 330 |
340 void CSSPrimitiveValue::cleanup() | 331 void CSSPrimitiveValue::cleanup() |
341 { | 332 { |
342 switch (type()) { | 333 switch (type()) { |
343 case UnitType::CustomIdentifier: | |
344 case UnitType::String: | |
345 case UnitType::URI: | |
346 if (m_value.string) | |
347 m_value.string->deref(); | |
348 break; | |
349 case UnitType::Calc: | 334 case UnitType::Calc: |
350 // We must not call deref() when oilpan is enabled because m_value.calc
is traced. | 335 // We must not call deref() when oilpan is enabled because m_value.calc
is traced. |
351 #if !ENABLE(OILPAN) | 336 #if !ENABLE(OILPAN) |
352 m_value.calc->deref(); | 337 m_value.calc->deref(); |
353 #endif | 338 #endif |
354 break; | 339 break; |
355 case UnitType::CalcPercentageWithNumber: | 340 case UnitType::CalcPercentageWithNumber: |
356 case UnitType::CalcPercentageWithLength: | 341 case UnitType::CalcPercentageWithLength: |
357 ASSERT_NOT_REACHED(); | 342 ASSERT_NOT_REACHED(); |
358 break; | 343 break; |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 return CSSPrimitiveValue::UnitType::ViewportMin; | 705 return CSSPrimitiveValue::UnitType::ViewportMin; |
721 case UnitTypeViewportMax: | 706 case UnitTypeViewportMax: |
722 return CSSPrimitiveValue::UnitType::ViewportMax; | 707 return CSSPrimitiveValue::UnitType::ViewportMax; |
723 case LengthUnitTypeCount: | 708 case LengthUnitTypeCount: |
724 break; | 709 break; |
725 } | 710 } |
726 ASSERT_NOT_REACHED(); | 711 ASSERT_NOT_REACHED(); |
727 return CSSPrimitiveValue::UnitType::Unknown; | 712 return CSSPrimitiveValue::UnitType::Unknown; |
728 } | 713 } |
729 | 714 |
730 String CSSPrimitiveValue::getStringValue() const | |
731 { | |
732 switch (type()) { | |
733 case UnitType::CustomIdentifier: | |
734 case UnitType::String: | |
735 case UnitType::URI: | |
736 return m_value.string; | |
737 default: | |
738 break; | |
739 } | |
740 | |
741 ASSERT_NOT_REACHED(); | |
742 return String(); | |
743 } | |
744 | |
745 static String formatNumber(double number, const char* suffix, unsigned suffixLen
gth) | 715 static String formatNumber(double number, const char* suffix, unsigned suffixLen
gth) |
746 { | 716 { |
747 #if OS(WIN) && _MSC_VER < 1900 | 717 #if OS(WIN) && _MSC_VER < 1900 |
748 unsigned oldFormat = _set_output_format(_TWO_DIGIT_EXPONENT); | 718 unsigned oldFormat = _set_output_format(_TWO_DIGIT_EXPONENT); |
749 #endif | 719 #endif |
750 String result = String::format("%.6g", number); | 720 String result = String::format("%.6g", number); |
751 #if OS(WIN) && _MSC_VER < 1900 | 721 #if OS(WIN) && _MSC_VER < 1900 |
752 _set_output_format(oldFormat); | 722 _set_output_format(oldFormat); |
753 #endif | 723 #endif |
754 result.append(suffix, suffixLength); | 724 result.append(suffix, suffixLength); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 return "fr"; | 791 return "fr"; |
822 case UnitType::ViewportWidth: | 792 case UnitType::ViewportWidth: |
823 return "vw"; | 793 return "vw"; |
824 case UnitType::ViewportHeight: | 794 case UnitType::ViewportHeight: |
825 return "vh"; | 795 return "vh"; |
826 case UnitType::ViewportMin: | 796 case UnitType::ViewportMin: |
827 return "vmin"; | 797 return "vmin"; |
828 case UnitType::ViewportMax: | 798 case UnitType::ViewportMax: |
829 return "vmax"; | 799 return "vmax"; |
830 case UnitType::Unknown: | 800 case UnitType::Unknown: |
831 case UnitType::CustomIdentifier: | |
832 case UnitType::String: | |
833 case UnitType::URI: | |
834 case UnitType::ValueID: | 801 case UnitType::ValueID: |
835 case UnitType::PropertyID: | 802 case UnitType::PropertyID: |
836 case UnitType::RGBColor: | 803 case UnitType::RGBColor: |
837 case UnitType::Calc: | 804 case UnitType::Calc: |
838 case UnitType::CalcPercentageWithNumber: | 805 case UnitType::CalcPercentageWithNumber: |
839 case UnitType::CalcPercentageWithLength: | 806 case UnitType::CalcPercentageWithLength: |
840 break; | 807 break; |
841 }; | 808 }; |
842 ASSERT_NOT_REACHED(); | 809 ASSERT_NOT_REACHED(); |
843 return ""; | 810 return ""; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 case UnitType::Hertz: | 849 case UnitType::Hertz: |
883 case UnitType::Kilohertz: | 850 case UnitType::Kilohertz: |
884 case UnitType::Turns: | 851 case UnitType::Turns: |
885 case UnitType::Fraction: | 852 case UnitType::Fraction: |
886 case UnitType::ViewportWidth: | 853 case UnitType::ViewportWidth: |
887 case UnitType::ViewportHeight: | 854 case UnitType::ViewportHeight: |
888 case UnitType::ViewportMin: | 855 case UnitType::ViewportMin: |
889 case UnitType::ViewportMax: | 856 case UnitType::ViewportMax: |
890 text = formatNumber(m_value.num, unitTypeToString(type())); | 857 text = formatNumber(m_value.num, unitTypeToString(type())); |
891 break; | 858 break; |
892 case UnitType::CustomIdentifier: | |
893 text = quoteCSSStringIfNeeded(m_value.string); | |
894 break; | |
895 case UnitType::String: { | |
896 text = serializeString(m_value.string); | |
897 break; | |
898 } | |
899 case UnitType::URI: | |
900 text = serializeURI(m_value.string); | |
901 break; | |
902 case UnitType::ValueID: | 859 case UnitType::ValueID: |
903 text = valueName(m_value.valueID); | 860 text = valueName(m_value.valueID); |
904 break; | 861 break; |
905 case UnitType::PropertyID: | 862 case UnitType::PropertyID: |
906 text = propertyName(m_value.propertyID); | 863 text = propertyName(m_value.propertyID); |
907 break; | 864 break; |
908 case UnitType::RGBColor: { | 865 case UnitType::RGBColor: { |
909 text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); | 866 text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); |
910 break; | 867 break; |
911 } | 868 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 case UnitType::ViewportWidth: | 914 case UnitType::ViewportWidth: |
958 case UnitType::ViewportHeight: | 915 case UnitType::ViewportHeight: |
959 case UnitType::ViewportMin: | 916 case UnitType::ViewportMin: |
960 case UnitType::ViewportMax: | 917 case UnitType::ViewportMax: |
961 case UnitType::Fraction: | 918 case UnitType::Fraction: |
962 return m_value.num == other.m_value.num; | 919 return m_value.num == other.m_value.num; |
963 case UnitType::PropertyID: | 920 case UnitType::PropertyID: |
964 return m_value.propertyID == other.m_value.propertyID; | 921 return m_value.propertyID == other.m_value.propertyID; |
965 case UnitType::ValueID: | 922 case UnitType::ValueID: |
966 return m_value.valueID == other.m_value.valueID; | 923 return m_value.valueID == other.m_value.valueID; |
967 case UnitType::CustomIdentifier: | |
968 case UnitType::String: | |
969 case UnitType::URI: | |
970 return equal(m_value.string, other.m_value.string); | |
971 case UnitType::RGBColor: | 924 case UnitType::RGBColor: |
972 return m_value.rgbcolor == other.m_value.rgbcolor; | 925 return m_value.rgbcolor == other.m_value.rgbcolor; |
973 case UnitType::Calc: | 926 case UnitType::Calc: |
974 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); | 927 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other
.m_value.calc); |
975 case UnitType::Integer: | 928 case UnitType::Integer: |
976 case UnitType::Chs: | 929 case UnitType::Chs: |
977 case UnitType::CalcPercentageWithNumber: | 930 case UnitType::CalcPercentageWithNumber: |
978 case UnitType::CalcPercentageWithLength: | 931 case UnitType::CalcPercentageWithLength: |
979 case UnitType::QuirkyEms: | 932 case UnitType::QuirkyEms: |
980 return false; | 933 return false; |
981 } | 934 } |
982 return false; | 935 return false; |
983 } | 936 } |
984 | 937 |
985 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue) | 938 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue) |
986 { | 939 { |
987 #if ENABLE(OILPAN) | 940 #if ENABLE(OILPAN) |
988 switch (type()) { | 941 switch (type()) { |
989 case UnitType::Calc: | 942 case UnitType::Calc: |
990 visitor->trace(m_value.calc); | 943 visitor->trace(m_value.calc); |
991 break; | 944 break; |
992 default: | 945 default: |
993 break; | 946 break; |
994 } | 947 } |
995 #endif | 948 #endif |
996 CSSValue::traceAfterDispatch(visitor); | 949 CSSValue::traceAfterDispatch(visitor); |
997 } | 950 } |
998 | 951 |
999 } // namespace blink | 952 } // namespace blink |
OLD | NEW |