summaryrefslogtreecommitdiff
path: root/xfa/fde/css/fde_css.h
blob: 90763d6c384d3beeb2bcc882693622c71ceb6c46 (plain)
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
327
328
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FDE_CSS_FDE_CSS_H_
#define XFA_FDE_CSS_FDE_CSS_H_

#include "core/fxge/fx_dib.h"
#include "xfa/fgas/crt/fgas_stream.h"
#include "xfa/fgas/crt/fgas_utils.h"
#include "xfa/fgas/font/cfgas_fontmgr.h"

class CFDE_CSSAccelerator;
class CFDE_CSSDeclaration;
class CFDE_CSSComputedStyle;
class CFDE_CSSSelector;
class CFDE_CSSStyleSheet;
class CXFA_CSSTagProvider;
class IFDE_CSSRule;
class IFDE_CSSValue;

enum FDE_CSSMEDIATYPE {
  FDE_CSSMEDIATYPE_Braille = 0x01,
  FDE_CSSMEDIATYPE_Emboss = 0x02,
  FDE_CSSMEDIATYPE_Handheld = 0x04,
  FDE_CSSMEDIATYPE_Print = 0x08,
  FDE_CSSMEDIATYPE_Projection = 0x10,
  FDE_CSSMEDIATYPE_Screen = 0x20,
  FDE_CSSMEDIATYPE_TTY = 0x40,
  FDE_CSSMEDIATYPE_TV = 0x80,
  FDE_CSSMEDIATYPE_ALL = 0xFF,
};

enum FDE_CSSVALUETYPE {
  FDE_CSSVALUETYPE_Primitive = 1 << 0,
  FDE_CSSVALUETYPE_List = 1 << 1,
  FDE_CSSVALUETYPE_Shorthand = 1 << 2,
  // Note the values below this comment must be > 0x0F so we can mask the above.
  FDE_CSSVALUETYPE_MaybeNumber = 1 << 4,
  FDE_CSSVALUETYPE_MaybeEnum = 1 << 5,
  FDE_CSSVALUETYPE_MaybeURI = 1 << 6,
  FDE_CSSVALUETYPE_MaybeString = 1 << 7,
  FDE_CSSVALUETYPE_MaybeColor = 1 << 8,
  FDE_CSSVALUETYPE_MaybeFunction = 1 << 9
};

enum class FDE_CSSPrimitiveType : uint8_t {
  Unknown = 0,
  Number,
  Percent,
  EMS,
  EXS,
  Pixels,
  CentiMeters,
  MilliMeters,
  Inches,
  Points,
  Picas,
  String,
  URI,
  RGB,
  Enum,
  Function,
};

enum class FDE_CSSPropertyValue : uint8_t {
  Bolder = 0,
  None,
  Dot,
  Sub,
  Top,
  Right,
  Normal,
  Auto,
  Text,
  XSmall,
  Thin,
  Small,
  Bottom,
  Underline,
  Double,
  Lighter,
  Oblique,
  Super,
  Center,
  XxLarge,
  Smaller,
  Baseline,
  Thick,
  Justify,
  Middle,
  Medium,
  ListItem,
  XxSmall,
  Bold,
  SmallCaps,
  Inline,
  Overline,
  TextBottom,
  Larger,
  InlineTable,
  InlineBlock,
  Blink,
  Block,
  Italic,
  LineThrough,
  XLarge,
  Large,
  Left,
  TextTop,
  LAST_MARKER
};

enum class FDE_CSSProperty : uint8_t {
  BorderLeft = 0,
  Top,
  Margin,
  TextIndent,
  Right,
  PaddingLeft,
  MarginLeft,
  Border,
  BorderTop,
  Bottom,
  PaddingRight,
  BorderBottom,
  FontFamily,
  FontWeight,
  Color,
  LetterSpacing,
  TextAlign,
  BorderRightWidth,
  VerticalAlign,
  PaddingTop,
  FontVariant,
  BorderWidth,
  BorderBottomWidth,
  BorderRight,
  FontSize,
  BorderSpacing,
  FontStyle,
  Font,
  LineHeight,
  MarginRight,
  BorderLeftWidth,
  Display,
  PaddingBottom,
  BorderTopWidth,
  WordSpacing,
  Left,
  TextDecoration,
  Padding,
  MarginBottom,
  MarginTop,
  LAST_MARKER
};

enum class FDE_CSSPseudo : uint8_t { After, Before, NONE };

enum class FDE_CSSSelectorType : uint8_t {
  Element = 0,
  Descendant,
  Class,
  Pseudo,
  ID,
};

enum class FDE_CSSRuleType : uint8_t { Style, Media, FontFace };

enum class FDE_CSSSyntaxStatus : uint8_t {
  Error,
  EOS,
  None,
  Charset,
  ImportRule,
  ImportClose,
  PageRule,
  StyleRule,
  FontFaceRule,
  MediaRule,
  MediaType,
  URI,
  Selector,
  DeclOpen,
  DeclClose,
  PropertyName,
  PropertyValue,
};

enum class FDE_CSSLengthUnit : uint8_t {
  Auto,
  None,
  Normal,
  Point,
  Percent,
};

enum class FDE_CSSDisplay : uint8_t {
  None,
  ListItem,
  Block,
  Inline,
  InlineBlock,
  InlineTable,
};

enum class FDE_CSSFontStyle : uint8_t {
  Normal,
  Italic,
};

enum class FDE_CSSTextAlign : uint8_t {
  Left,
  Right,
  Center,
  Justify,
  JustifyAll,
};

enum class FDE_CSSVerticalAlign : uint8_t {
  Baseline,
  Sub,
  Super,
  Top,
  TextTop,
  Middle,
  Bottom,
  TextBottom,
  Number,
};

enum class FDE_CSSFontVariant : uint8_t {
  Normal,
  SmallCaps,
};

enum FDE_CSSTEXTDECORATION {
  FDE_CSSTEXTDECORATION_None = 0,
  FDE_CSSTEXTDECORATION_Underline = 1 << 0,
  FDE_CSSTEXTDECORATION_Overline = 1 << 1,
  FDE_CSSTEXTDECORATION_LineThrough = 1 << 2,
  FDE_CSSTEXTDECORATION_Blink = 1 << 3,
  FDE_CSSTEXTDECORATION_Double = 1 << 4,
};

enum class FDE_CSSStyleSheetGroup : uint8_t {
  UserAgent = 0,
  User,
  Author,
};

enum class FDE_CSSStyleSheetPriority : uint8_t {
  High = 0,
  Mid,
  Low,
};

class IFDE_CSSValue {
 public:
  virtual ~IFDE_CSSValue() {}
  virtual FDE_CSSVALUETYPE GetType() const = 0;
};

class IFDE_CSSRule {
 public:
  virtual ~IFDE_CSSRule() {}
  virtual FDE_CSSRuleType GetType() const = 0;
};

struct FDE_CSSLENGTH {
  FDE_CSSLENGTH() {}

  explicit FDE_CSSLENGTH(FDE_CSSLengthUnit eUnit) : m_unit(eUnit) {}

  FDE_CSSLENGTH(FDE_CSSLengthUnit eUnit, FX_FLOAT fValue)
      : m_unit(eUnit), m_fValue(fValue) {}

  FDE_CSSLENGTH& Set(FDE_CSSLengthUnit eUnit) {
    m_unit = eUnit;
    return *this;
  }

  FDE_CSSLENGTH& Set(FDE_CSSLengthUnit eUnit, FX_FLOAT fValue) {
    m_unit = eUnit;
    m_fValue = fValue;
    return *this;
  }

  FDE_CSSLengthUnit GetUnit() const { return m_unit; }

  FX_FLOAT GetValue() const { return m_fValue; }
  bool NonZero() const { return static_cast<int>(m_fValue) != 0; }

 private:
  FDE_CSSLengthUnit m_unit;
  FX_FLOAT m_fValue;
};

struct FDE_CSSRECT {
  FDE_CSSRECT() {}

  FDE_CSSRECT(FDE_CSSLengthUnit eUnit, FX_FLOAT val)
      : left(eUnit, val),
        top(eUnit, val),
        right(eUnit, val),
        bottom(eUnit, val) {}

  FDE_CSSRECT& Set(FDE_CSSLengthUnit eUnit) {
    left.Set(eUnit);
    top.Set(eUnit);
    right.Set(eUnit);
    bottom.Set(eUnit);
    return *this;
  }
  FDE_CSSRECT& Set(FDE_CSSLengthUnit eUnit, FX_FLOAT fValue) {
    left.Set(eUnit, fValue);
    top.Set(eUnit, fValue);
    right.Set(eUnit, fValue);
    bottom.Set(eUnit, fValue);
    return *this;
  }

  FDE_CSSLENGTH left, top, right, bottom;
};

#endif  // XFA_FDE_CSS_FDE_CSS_H_