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
27 #include <wtf/Forward.h>
28 #include <wtf/PassRefPtr.h>
33 class DashboardRegion;
41 class CSSPrimitiveValue : public CSSValue {
70 CSS_PAIR = 100, // We envision this being exposed as a means of getting computed style values for pairs (border-spacing/radius, background-position, etc.)
71 CSS_DASHBOARD_REGION = 101, // FIXME: Dashboard region should not be a primitive value.
72 CSS_UNICODE_RANGE = 102,
74 // These next types are just used internally to allow us to translate back and forth from CSSPrimitiveValues to CSSParserValues.
75 CSS_PARSER_OPERATOR = 103,
76 CSS_PARSER_INTEGER = 104,
77 CSS_PARSER_VARIABLE_FUNCTION_SYNTAX = 105,
78 CSS_PARSER_HEXCOLOR = 106,
80 // This is used internally for unknown identifiers
81 CSS_PARSER_IDENTIFIER = 107,
83 // These are from CSS3 Values and Units, but that isn't a finished standard yet
88 static bool isUnitTypeLength(int type) { return (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) ||
89 type == CSSPrimitiveValue::CSS_REMS; }
91 static PassRefPtr<CSSPrimitiveValue> createIdentifier(int ident);
92 static PassRefPtr<CSSPrimitiveValue> createColor(unsigned rgbValue);
93 static PassRefPtr<CSSPrimitiveValue> create(double value, UnitTypes type);
94 static PassRefPtr<CSSPrimitiveValue> create(const String& value, UnitTypes type);
96 template<typename T> static PassRefPtr<CSSPrimitiveValue> create(T value)
98 return adoptRef(new CSSPrimitiveValue(value));
101 virtual ~CSSPrimitiveValue();
105 unsigned short primitiveType() const { return m_type; }
107 bool isVariable() const { return m_type == CSS_PARSER_VARIABLE_FUNCTION_SYNTAX; }
110 * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
111 * the fontinfo in case val is defined in em or ex.
113 * The metrics have to be a bit different for screen and printer output.
114 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
116 * this is screen/printer dependent, so we probably need a config option for this,
117 * and some tool to calibrate.
119 int computeLengthInt(RenderStyle* currStyle, RenderStyle* rootStyle);
120 int computeLengthInt(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
121 int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle);
122 int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
123 short computeLengthShort(RenderStyle* currStyle, RenderStyle* rootStyle);
124 short computeLengthShort(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
125 float computeLengthFloat(RenderStyle* currStyle, RenderStyle* rootStyle, bool computingFontSize = false);
126 float computeLengthFloat(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize = false);
127 double computeLengthDouble(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
130 void setPrimitiveType(unsigned short type) { m_type = type; }
132 double getDoubleValue(unsigned short unitType, ExceptionCode&);
133 double getDoubleValue(unsigned short unitType);
134 double getDoubleValue() const { return m_value.num; }
136 void setFloatValue(unsigned short unitType, double floatValue, ExceptionCode&);
137 float getFloatValue(unsigned short unitType, ExceptionCode& ec) { return static_cast<float>(getDoubleValue(unitType, ec)); }
138 float getFloatValue(unsigned short unitType) { return static_cast<float>(getDoubleValue(unitType)); }
139 float getFloatValue() const { return static_cast<float>(m_value.num); }
141 int getIntValue(unsigned short unitType, ExceptionCode& ec) { return static_cast<int>(getDoubleValue(unitType, ec)); }
142 int getIntValue(unsigned short unitType) { return static_cast<int>(getDoubleValue(unitType)); }
143 int getIntValue() const { return static_cast<int>(m_value.num); }
145 void setStringValue(unsigned short stringType, const String& stringValue, ExceptionCode&);
146 String getStringValue(ExceptionCode&) const;
147 String getStringValue() const;
149 Counter* getCounterValue(ExceptionCode&) const;
150 Counter* getCounterValue() const { return m_type != CSS_COUNTER ? 0 : m_value.counter; }
152 Rect* getRectValue(ExceptionCode&) const;
153 Rect* getRectValue() const { return m_type != CSS_RECT ? 0 : m_value.rect; }
155 PassRefPtr<RGBColor> getRGBColorValue(ExceptionCode&) const;
156 RGBA32 getRGBA32Value() const { return m_type != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; }
158 Pair* getPairValue(ExceptionCode&) const;
159 Pair* getPairValue() const { return m_type != CSS_PAIR ? 0 : m_value.pair; }
161 DashboardRegion* getDashboardRegionValue() const { return m_type != CSS_DASHBOARD_REGION ? 0 : m_value.region; }
164 template<typename T> inline operator T() const; // Defined in CSSPrimitiveValueMappings.h
166 virtual bool parseString(const String&, bool = false);
167 virtual String cssText() const;
169 virtual bool isQuirkValue() { return false; }
171 virtual CSSParserValue parserValue() const;
173 virtual void addSubresourceStyleURLs(ListHashSet<KURL>&, const CSSStyleSheet*);
176 // FIXME: int vs. unsigned overloading is too subtle to distinguish the color and identifier cases.
177 CSSPrimitiveValue(int ident);
178 CSSPrimitiveValue(double, UnitTypes);
179 CSSPrimitiveValue(const String&, UnitTypes);
183 CSSPrimitiveValue(unsigned color); // RGB value
184 CSSPrimitiveValue(const Length&);
186 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMappings.h
187 template<typename T> CSSPrimitiveValue(T* val) { init(PassRefPtr<T>(val)); }
188 template<typename T> CSSPrimitiveValue(PassRefPtr<T> val) { init(val); }
190 static void create(int); // compile-time guard
191 static void create(unsigned); // compile-time guard
192 template<typename T> operator T*(); // compile-time guard
194 static PassRefPtr<CSSPrimitiveValue> createUncachedIdentifier(int identifier);
195 static PassRefPtr<CSSPrimitiveValue> createUncachedColor(unsigned rgbValue);
196 static PassRefPtr<CSSPrimitiveValue> createUncached(double value, UnitTypes type);
198 void init(PassRefPtr<Counter>);
199 void init(PassRefPtr<Rect>);
200 void init(PassRefPtr<Pair>);
201 void init(PassRefPtr<DashboardRegion>); // FIXME: Dashboard region should not be a primitive value.
203 virtual bool isPrimitiveValue() const { return true; }
205 virtual unsigned short cssValueType() const;
208 mutable unsigned m_hasCachedCSSText : 1;
217 DashboardRegion* region;
221 } // namespace WebCore
223 #endif // CSSPrimitiveValue_h