2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef CSSPrimitiveValue_h
23 #define CSSPrimitiveValue_h
26 #include <wtf/PassRefPtr.h>
31 class DashboardRegion
;
39 class CSSPrimitiveValue
: public CSSValue
{
68 CSS_PAIR
= 100, // We envision this being exposed as a means of getting computed style values for pairs (border-spacing/radius, background-position, etc.)
69 CSS_DASHBOARD_REGION
= 101, // FIXME: Dashboard region should not be a primitive value.
70 CSS_UNICODE_RANGE
= 102,
72 // These next types are just used internally to allow us to translate back and forth from CSSPrimitiveValues to CSSParserValues.
73 CSS_PARSER_OPERATOR
= 103,
74 CSS_PARSER_INTEGER
= 104,
75 CSS_PARSER_VARIABLE_FUNCTION_SYNTAX
= 105,
76 CSS_PARSER_HEXCOLOR
= 106,
78 // This is used internally for unknown identifiers
79 CSS_PARSER_IDENTIFIER
= 107,
81 // This unit is in CSS 3, but that isn't a finished standard yet
85 static bool isUnitTypeLength(int type
) { return type
> CSSPrimitiveValue::CSS_PERCENTAGE
&& type
< CSSPrimitiveValue::CSS_DEG
; }
87 static PassRefPtr
<CSSPrimitiveValue
> createIdentifier(int ident
);
88 static PassRefPtr
<CSSPrimitiveValue
> createColor(unsigned rgbValue
);
89 static PassRefPtr
<CSSPrimitiveValue
> create(double value
, UnitTypes type
);
90 static PassRefPtr
<CSSPrimitiveValue
> create(const String
& value
, UnitTypes type
);
92 template<typename T
> static PassRefPtr
<CSSPrimitiveValue
> create(T value
)
94 return adoptRef(new CSSPrimitiveValue(value
));
97 virtual ~CSSPrimitiveValue();
101 unsigned short primitiveType() const { return m_type
; }
103 bool isVariable() const { return m_type
== CSS_PARSER_VARIABLE_FUNCTION_SYNTAX
; }
106 * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
107 * the fontinfo in case val is defined in em or ex.
109 * The metrics have to be a bit different for screen and printer output.
110 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
112 * this is screen/printer dependent, so we probably need a config option for this,
113 * and some tool to calibrate.
115 int computeLengthInt(RenderStyle
*);
116 int computeLengthInt(RenderStyle
*, double multiplier
);
117 int computeLengthIntForLength(RenderStyle
*);
118 int computeLengthIntForLength(RenderStyle
*, double multiplier
);
119 short computeLengthShort(RenderStyle
*);
120 short computeLengthShort(RenderStyle
*, double multiplier
);
121 float computeLengthFloat(RenderStyle
*, bool computingFontSize
= false);
122 float computeLengthFloat(RenderStyle
*, double multiplier
, bool computingFontSize
= false);
123 double computeLengthDouble(RenderStyle
*, double multiplier
= 1.0, bool computingFontSize
= false);
126 void setPrimitiveType(unsigned short type
) { m_type
= type
; }
128 double getDoubleValue(unsigned short unitType
, ExceptionCode
&);
129 double getDoubleValue(unsigned short unitType
);
130 double getDoubleValue() const { return m_value
.num
; }
132 void setFloatValue(unsigned short unitType
, double floatValue
, ExceptionCode
&);
133 float getFloatValue(unsigned short unitType
, ExceptionCode
& ec
) { return static_cast<float>(getDoubleValue(unitType
, ec
)); }
134 float getFloatValue(unsigned short unitType
) { return static_cast<float>(getDoubleValue(unitType
)); }
135 float getFloatValue() const { return static_cast<float>(m_value
.num
); }
137 int getIntValue(unsigned short unitType
, ExceptionCode
& ec
) { return static_cast<int>(getDoubleValue(unitType
, ec
)); }
138 int getIntValue(unsigned short unitType
) { return static_cast<int>(getDoubleValue(unitType
)); }
139 int getIntValue() const { return static_cast<int>(m_value
.num
); }
141 void setStringValue(unsigned short stringType
, const String
& stringValue
, ExceptionCode
&);
142 String
getStringValue(ExceptionCode
&) const;
143 String
getStringValue() const;
145 Counter
* getCounterValue(ExceptionCode
&) const;
146 Counter
* getCounterValue() const { return m_type
!= CSS_COUNTER
? 0 : m_value
.counter
; }
148 Rect
* getRectValue(ExceptionCode
&) const;
149 Rect
* getRectValue() const { return m_type
!= CSS_RECT
? 0 : m_value
.rect
; }
151 unsigned getRGBColorValue(ExceptionCode
&) const;
152 unsigned getRGBColorValue() const { return m_type
!= CSS_RGBCOLOR
? 0 : m_value
.rgbcolor
; }
154 Pair
* getPairValue(ExceptionCode
&) const;
155 Pair
* getPairValue() const { return m_type
!= CSS_PAIR
? 0 : m_value
.pair
; }
157 DashboardRegion
* getDashboardRegionValue() const { return m_type
!= CSS_DASHBOARD_REGION
? 0 : m_value
.region
; }
160 template<typename T
> operator T() const; // Defined in CSSPrimitiveValueMappings.h
162 virtual bool parseString(const String
&, bool = false);
163 virtual String
cssText() const;
165 virtual bool isQuirkValue() { return false; }
167 virtual CSSParserValue
parserValue() const;
169 virtual void addSubresourceStyleURLs(ListHashSet
<KURL
>&, const CSSStyleSheet
*);
172 // FIXME: int vs. unsigned overloading is too subtle to distinguish the color and identifier cases.
173 CSSPrimitiveValue(int ident
);
174 CSSPrimitiveValue(double, UnitTypes
);
175 CSSPrimitiveValue(const String
&, UnitTypes
);
179 CSSPrimitiveValue(unsigned color
); // RGB value
180 CSSPrimitiveValue(const Length
&);
182 template<typename T
> CSSPrimitiveValue(T
); // Defined in CSSPrimitiveValueMappings.h
183 template<typename T
> CSSPrimitiveValue(T
* val
) { init(PassRefPtr
<T
>(val
)); }
184 template<typename T
> CSSPrimitiveValue(PassRefPtr
<T
> val
) { init(val
); }
186 static void create(int); // compile-time guard
187 static void create(unsigned); // compile-time guard
188 template<typename T
> operator T
*(); // compile-time guard
190 void init(PassRefPtr
<Counter
>);
191 void init(PassRefPtr
<Rect
>);
192 void init(PassRefPtr
<Pair
>);
193 void init(PassRefPtr
<DashboardRegion
>); // FIXME: Dashboard region should not be a primitive value.
195 virtual bool isPrimitiveValue() const { return true; }
197 virtual unsigned short cssValueType() const;
208 DashboardRegion
* region
;
212 } // namespace WebCore
214 #endif // CSSPrimitiveValue_h