|
1 /* |
|
2 * This file is part of the DOM implementation for KDE. |
|
3 * |
|
4 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
|
5 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
|
6 * |
|
7 * This library is free software; you can redistribute it and/or |
|
8 * modify it under the terms of the GNU Library General Public |
|
9 * License as published by the Free Software Foundation; either |
|
10 * version 2 of the License, or (at your option) any later version. |
|
11 * |
|
12 * This library is distributed in the hope that it will be useful, |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 * Library General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU Library General Public License |
|
18 * along with this library; see the file COPYING.LIB. If not, write to |
|
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
20 * Boston, MA 02110-1301, USA. |
|
21 */ |
|
22 |
|
23 #ifndef CSSPrimitiveValue_h |
|
24 #define CSSPrimitiveValue_h |
|
25 |
|
26 #include "CSSValue.h" |
|
27 #include <wtf/PassRefPtr.h> |
|
28 |
|
29 namespace WebCore { |
|
30 |
|
31 class Counter; |
|
32 class DashboardRegion; |
|
33 class Pair; |
|
34 class Rect; |
|
35 class RenderStyle; |
|
36 class StringImpl; |
|
37 |
|
38 typedef int ExceptionCode; |
|
39 |
|
40 class CSSPrimitiveValue : public CSSValue { |
|
41 public: |
|
42 enum UnitTypes { |
|
43 CSS_UNKNOWN = 0, |
|
44 CSS_NUMBER = 1, |
|
45 CSS_PERCENTAGE = 2, |
|
46 CSS_EMS = 3, |
|
47 CSS_EXS = 4, |
|
48 CSS_PX = 5, |
|
49 CSS_CM = 6, |
|
50 CSS_MM = 7, |
|
51 CSS_IN = 8, |
|
52 CSS_PT = 9, |
|
53 CSS_PC = 10, |
|
54 CSS_DEG = 11, |
|
55 CSS_RAD = 12, |
|
56 CSS_GRAD = 13, |
|
57 CSS_MS = 14, |
|
58 CSS_S = 15, |
|
59 CSS_HZ = 16, |
|
60 CSS_KHZ = 17, |
|
61 CSS_DIMENSION = 18, |
|
62 CSS_STRING = 19, |
|
63 CSS_URI = 20, |
|
64 CSS_IDENT = 21, |
|
65 CSS_ATTR = 22, |
|
66 CSS_COUNTER = 23, |
|
67 CSS_RECT = 24, |
|
68 CSS_RGBCOLOR = 25, |
|
69 CSS_PAIR = 100, // We envision this being exposed as a means of getting computed style values for pairs (border-spacing/radius, background-position, etc.) |
|
70 CSS_DASHBOARD_REGION = 101 // FIXME: What on earth is this doing as a primitive value? It should not be! |
|
71 }; |
|
72 |
|
73 // FIXME: int vs. unsigned overloading is too tricky for color vs. ident |
|
74 CSSPrimitiveValue(); |
|
75 CSSPrimitiveValue(int ident); |
|
76 CSSPrimitiveValue(double, UnitTypes); |
|
77 CSSPrimitiveValue(const String&, UnitTypes); |
|
78 CSSPrimitiveValue(PassRefPtr<Counter>); |
|
79 CSSPrimitiveValue(PassRefPtr<Rect>); |
|
80 CSSPrimitiveValue(unsigned color); // RGB value |
|
81 CSSPrimitiveValue(PassRefPtr<Pair>); |
|
82 CSSPrimitiveValue(PassRefPtr<DashboardRegion>); // FIXME: Why is dashboard region a primitive value? This makes no sense. |
|
83 |
|
84 virtual ~CSSPrimitiveValue(); |
|
85 |
|
86 void cleanup(); |
|
87 |
|
88 unsigned short primitiveType() const { return m_type; } |
|
89 |
|
90 /* |
|
91 * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get |
|
92 * the fontinfo in case val is defined in em or ex. |
|
93 * |
|
94 * The metrics have to be a bit different for screen and printer output. |
|
95 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi |
|
96 * |
|
97 * this is screen/printer dependent, so we probably need a config option for this, |
|
98 * and some tool to calibrate. |
|
99 */ |
|
100 int computeLengthInt(RenderStyle*); |
|
101 int computeLengthInt(RenderStyle*, double multiplier); |
|
102 int computeLengthIntForLength(RenderStyle*); |
|
103 int computeLengthIntForLength(RenderStyle*, double multiplier); |
|
104 short computeLengthShort(RenderStyle*); |
|
105 short computeLengthShort(RenderStyle*, double multiplier); |
|
106 float computeLengthFloat(RenderStyle*, bool applyZoomFactor = true); |
|
107 double computeLengthDouble(RenderStyle*, bool applyZoomFactor = true); |
|
108 |
|
109 // use with care!!! |
|
110 void setPrimitiveType(unsigned short type) { m_type = type; } |
|
111 |
|
112 double getDoubleValue(unsigned short unitType); |
|
113 double getDoubleValue() const { return m_value.num; } |
|
114 |
|
115 void setFloatValue(unsigned short unitType, double floatValue, ExceptionCode&); |
|
116 float getFloatValue(unsigned short unitType) { return static_cast<float>(getDoubleValue(unitType)); } |
|
117 float getFloatValue() const { return static_cast<float>(m_value.num); } |
|
118 int getIntValue(unsigned short unitType) { return static_cast<int>(getDoubleValue(unitType)); } |
|
119 int getIntValue() const { return static_cast<int>(m_value.num); } |
|
120 |
|
121 void setStringValue(unsigned short stringType, const String& stringValue, ExceptionCode&); |
|
122 String getStringValue() const; |
|
123 |
|
124 Counter* getCounterValue () const { return m_type != CSS_COUNTER ? 0 : m_value.counter; } |
|
125 Rect* getRectValue () const { return m_type != CSS_RECT ? 0 : m_value.rect; } |
|
126 unsigned getRGBColorValue() const { return m_type != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; } |
|
127 Pair* getPairValue() const { return m_type != CSS_PAIR ? 0 : m_value.pair; } |
|
128 |
|
129 DashboardRegion* getDashboardRegionValue () const { return m_type != CSS_DASHBOARD_REGION ? 0 : m_value.region; } |
|
130 |
|
131 virtual bool isPrimitiveValue() const { return true; } |
|
132 |
|
133 virtual unsigned short cssValueType() const; |
|
134 |
|
135 int getIdent(); |
|
136 |
|
137 virtual bool parseString(const String&, bool = false); |
|
138 virtual String cssText() const; |
|
139 |
|
140 virtual bool isQuirkValue() { return false; } |
|
141 |
|
142 protected: |
|
143 int m_type; |
|
144 union { |
|
145 int ident; |
|
146 double num; |
|
147 StringImpl* string; |
|
148 Counter* counter; |
|
149 Rect* rect; |
|
150 unsigned rgbcolor; |
|
151 Pair* pair; |
|
152 DashboardRegion* region; |
|
153 } m_value; |
|
154 }; |
|
155 |
|
156 } // namespace WebCore |
|
157 |
|
158 #endif // CSSPrimitiveValue_h |