1/*
2 * Copyright (C) 2016 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "CSSPrimitiveValue.h"
29#include "DeprecatedCSSOMValue.h"
30
31namespace WebCore {
32
33class DeprecatedCSSOMCounter;
34class DeprecatedCSSOMRGBColor;
35class DeprecatedCSSOMRect;
36
37class DeprecatedCSSOMPrimitiveValue : public DeprecatedCSSOMValue {
38public:
39 // Only expose what's in the IDL file.
40 enum UnitType {
41 CSS_UNKNOWN = 0,
42 CSS_NUMBER = 1,
43 CSS_PERCENTAGE = 2,
44 CSS_EMS = 3,
45 CSS_EXS = 4,
46 CSS_PX = 5,
47 CSS_CM = 6,
48 CSS_MM = 7,
49 CSS_IN = 8,
50 CSS_PT = 9,
51 CSS_PC = 10,
52 CSS_DEG = 11,
53 CSS_RAD = 12,
54 CSS_GRAD = 13,
55 CSS_MS = 14,
56 CSS_S = 15,
57 CSS_HZ = 16,
58 CSS_KHZ = 17,
59 CSS_DIMENSION = 18,
60 CSS_STRING = 19,
61 CSS_URI = 20,
62 CSS_IDENT = 21,
63 CSS_ATTR = 22,
64 CSS_COUNTER = 23,
65 CSS_RECT = 24,
66 CSS_RGBCOLOR = 25,
67 CSS_VW = 26,
68 CSS_VH = 27,
69 CSS_VMIN = 28,
70 CSS_VMAX = 29
71 };
72
73 static Ref<DeprecatedCSSOMPrimitiveValue> create(const CSSPrimitiveValue& value, CSSStyleDeclaration& owner)
74 {
75 return adoptRef(*new DeprecatedCSSOMPrimitiveValue(value, owner));
76 }
77
78 bool equals(const DeprecatedCSSOMPrimitiveValue& other) const { return m_value->equals(other.m_value); }
79 unsigned cssValueType() const { return m_value->cssValueType(); }
80 String cssText() const { return m_value->cssText(); }
81
82 // FIXME: Eventually these will contain more code and not just call through to
83 // CSSPrimitiveValue.
84 WEBCORE_EXPORT unsigned short primitiveType() const;
85 WEBCORE_EXPORT ExceptionOr<void> setFloatValue(unsigned short unitType, double);
86 WEBCORE_EXPORT ExceptionOr<float> getFloatValue(unsigned short unitType) const;
87 WEBCORE_EXPORT ExceptionOr<void> setStringValue(unsigned short stringType, const String&);
88 WEBCORE_EXPORT ExceptionOr<String> getStringValue() const;
89 WEBCORE_EXPORT ExceptionOr<Ref<DeprecatedCSSOMCounter>> getCounterValue() const;
90 WEBCORE_EXPORT ExceptionOr<Ref<DeprecatedCSSOMRect>> getRectValue() const;
91 WEBCORE_EXPORT ExceptionOr<Ref<DeprecatedCSSOMRGBColor>> getRGBColorValue() const;
92
93 String stringValue() const { return m_value->stringValue(); }
94
95protected:
96 DeprecatedCSSOMPrimitiveValue(const CSSPrimitiveValue& value, CSSStyleDeclaration& owner)
97 : DeprecatedCSSOMValue(DeprecatedPrimitiveValueClass, owner)
98 , m_value(const_cast<CSSPrimitiveValue&>(value))
99 {
100 }
101
102private:
103 Ref<CSSPrimitiveValue> m_value;
104};
105
106} // namespace WebCore
107
108SPECIALIZE_TYPE_TRAITS_CSSOM_VALUE(DeprecatedCSSOMPrimitiveValue, isPrimitiveValue())
109