1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/URL.h>
#include <AK/WeakPtr.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Color.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/Loader/ImageResource.h>
namespace Web {
class Document;
namespace CSS {
enum class ValueID {
Invalid,
VendorSpecificLink,
VendorSpecificPaletteDesktopBackground,
VendorSpecificPaletteActiveWindowBorder1,
VendorSpecificPaletteActiveWindowBorder2,
VendorSpecificPaletteActiveWindowTitle,
VendorSpecificPaletteInactiveWindowBorder1,
VendorSpecificPaletteInactiveWindowBorder2,
VendorSpecificPaletteInactiveWindowTitle,
VendorSpecificPaletteMovingWindowBorder1,
VendorSpecificPaletteMovingWindowBorder2,
VendorSpecificPaletteMovingWindowTitle,
VendorSpecificPaletteHighlightWindowBorder1,
VendorSpecificPaletteHighlightWindowBorder2,
VendorSpecificPaletteHighlightWindowTitle,
VendorSpecificPaletteMenuStripe,
VendorSpecificPaletteMenuBase,
VendorSpecificPaletteMenuBaseText,
VendorSpecificPaletteMenuSelection,
VendorSpecificPaletteMenuSelectionText,
VendorSpecificPaletteWindow,
VendorSpecificPaletteWindowText,
VendorSpecificPaletteButton,
VendorSpecificPaletteButtonText,
VendorSpecificPaletteBase,
VendorSpecificPaletteBaseText,
VendorSpecificPaletteThreedHighlight,
VendorSpecificPaletteThreedShadow1,
VendorSpecificPaletteThreedShadow2,
VendorSpecificPaletteHoverHighlight,
VendorSpecificPaletteSelection,
VendorSpecificPaletteSelectionText,
VendorSpecificPaletteInactiveSelection,
VendorSpecificPaletteInactiveSelectionText,
VendorSpecificPaletteRubberBandFill,
VendorSpecificPaletteRubberBandBorder,
VendorSpecificPaletteLink,
VendorSpecificPaletteActiveLink,
VendorSpecificPaletteVisitedLink,
VendorSpecificPaletteRuler,
VendorSpecificPaletteRulerBorder,
VendorSpecificPaletteRulerActiveText,
VendorSpecificPaletteRulerInactiveText,
VendorSpecificPaletteTextCursor,
VendorSpecificPaletteFocusOutline,
VendorSpecificPaletteSyntaxComment,
VendorSpecificPaletteSyntaxNumber,
VendorSpecificPaletteSyntaxString,
VendorSpecificPaletteSyntaxType,
VendorSpecificPaletteSyntaxPunctuation,
VendorSpecificPaletteSyntaxOperator,
VendorSpecificPaletteSyntaxKeyword,
VendorSpecificPaletteSyntaxControlKeyword,
VendorSpecificPaletteSyntaxIdentifier,
VendorSpecificPaletteSyntaxPreprocessorStatement,
VendorSpecificPaletteSyntaxPreprocessorValue,
Center,
Left,
Right,
Justify,
VendorSpecificCenter,
};
enum class Position {
Static,
Relative,
Absolute,
Fixed,
Sticky,
};
}
class StyleValue : public RefCounted<StyleValue> {
public:
virtual ~StyleValue();
enum class Type {
Invalid,
Inherit,
Initial,
String,
Length,
Percentage,
Color,
Identifier,
Image,
Position,
};
Type type() const { return m_type; }
bool is_inherit() const { return type() == Type::Inherit; }
bool is_initial() const { return type() == Type::Initial; }
bool is_color() const { return type() == Type::Color; }
bool is_identifier() const { return type() == Type::Identifier; }
bool is_image() const { return type() == Type::Image; }
bool is_string() const { return type() == Type::String; }
bool is_length() const { return type() == Type::Length; }
bool is_percentage() const { return type() == Type::Percentage; }
bool is_position() const { return type() == Type::Position; }
virtual String to_string() const = 0;
virtual Length to_length() const { return {}; }
virtual Color to_color(const Document&) const { return {}; }
virtual bool is_auto() const { return false; }
protected:
explicit StyleValue(Type);
private:
Type m_type { Type::Invalid };
};
class StringStyleValue : public StyleValue {
public:
static NonnullRefPtr<StringStyleValue> create(const String& string)
{
return adopt(*new StringStyleValue(string));
}
virtual ~StringStyleValue() override { }
String to_string() const override { return m_string; }
private:
explicit StringStyleValue(const String& string)
: StyleValue(Type::String)
, m_string(string)
{
}
String m_string;
};
class LengthStyleValue : public StyleValue {
public:
static NonnullRefPtr<LengthStyleValue> create(const Length& length)
{
return adopt(*new LengthStyleValue(length));
}
virtual ~LengthStyleValue() override { }
virtual String to_string() const override { return m_length.to_string(); }
virtual Length to_length() const override { return m_length; }
const Length& length() const { return m_length; }
virtual bool is_auto() const override { return m_length.is_auto(); }
private:
explicit LengthStyleValue(const Length& length)
: StyleValue(Type::Length)
, m_length(length)
{
}
Length m_length;
};
class PercentageStyleValue : public StyleValue {
public:
static NonnullRefPtr<PercentageStyleValue> create(float percentage)
{
return adopt(*new PercentageStyleValue(percentage));
}
virtual ~PercentageStyleValue() override { }
virtual String to_string() const override { return String::format("%g%%", m_percentage); }
Length to_length(float reference) const { return Length((m_percentage / 100.0f) * reference, Length::Type::Px); }
private:
virtual Length to_length() const override { return {}; }
virtual bool is_auto() const override { return false; }
explicit PercentageStyleValue(float percentage)
: StyleValue(Type::Percentage)
, m_percentage(percentage)
{
}
float m_percentage { 0 };
};
class InitialStyleValue final : public StyleValue {
public:
static NonnullRefPtr<InitialStyleValue> create() { return adopt(*new InitialStyleValue); }
virtual ~InitialStyleValue() override { }
String to_string() const override { return "initial"; }
private:
InitialStyleValue()
: StyleValue(Type::Initial)
{
}
};
class InheritStyleValue final : public StyleValue {
public:
static NonnullRefPtr<InheritStyleValue> create() { return adopt(*new InheritStyleValue); }
virtual ~InheritStyleValue() override { }
String to_string() const override { return "inherit"; }
private:
InheritStyleValue()
: StyleValue(Type::Inherit)
{
}
};
class ColorStyleValue : public StyleValue {
public:
static NonnullRefPtr<ColorStyleValue> create(Color color)
{
return adopt(*new ColorStyleValue(color));
}
virtual ~ColorStyleValue() override { }
Color color() const { return m_color; }
String to_string() const override { return m_color.to_string(); }
Color to_color(const Document&) const override { return m_color; }
private:
explicit ColorStyleValue(Color color)
: StyleValue(Type::Color)
, m_color(color)
{
}
Color m_color;
};
class IdentifierStyleValue final : public StyleValue {
public:
static NonnullRefPtr<IdentifierStyleValue> create(CSS::ValueID id)
{
return adopt(*new IdentifierStyleValue(id));
}
virtual ~IdentifierStyleValue() override { }
CSS::ValueID id() const { return m_id; }
virtual String to_string() const override;
virtual Color to_color(const Document&) const override;
private:
explicit IdentifierStyleValue(CSS::ValueID id)
: StyleValue(Type::Identifier)
, m_id(id)
{
}
CSS::ValueID m_id { CSS::ValueID::Invalid };
};
class ImageStyleValue final
: public StyleValue
, public ImageResourceClient {
public:
static NonnullRefPtr<ImageStyleValue> create(const URL& url, Document& document) { return adopt(*new ImageStyleValue(url, document)); }
virtual ~ImageStyleValue() override { }
String to_string() const override { return String::format("Image{%s}", m_url.to_string().characters()); }
const Gfx::Bitmap* bitmap() const { return m_bitmap; }
private:
ImageStyleValue(const URL&, Document&);
// ^ResourceClient
virtual void resource_did_load() override;
URL m_url;
WeakPtr<Document> m_document;
RefPtr<Gfx::Bitmap> m_bitmap;
};
}
|