• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXCRT_CSS_CFX_CSS_H_
8 #define CORE_FXCRT_CSS_CFX_CSS_H_
9 
10 #include <stdint.h>
11 
12 #include <type_traits>
13 
14 enum CFX_CSSVALUETYPE {
15   CFX_CSSVALUETYPE_Primitive = 1 << 0,
16   CFX_CSSVALUETYPE_List = 1 << 1,
17   CFX_CSSVALUETYPE_Shorthand = 1 << 2,
18   // Note the values below this comment must be > 0x0F so we can mask the above.
19   CFX_CSSVALUETYPE_MaybeNumber = 1 << 4,
20   CFX_CSSVALUETYPE_MaybeEnum = 1 << 5,
21   CFX_CSSVALUETYPE_MaybeString = 1 << 7,
22   CFX_CSSVALUETYPE_MaybeColor = 1 << 8
23 };
24 using CFX_CSSValueTypeMask = std::underlying_type<CFX_CSSVALUETYPE>::type;
25 
26 #undef CSS_PROP____
27 #define CSS_PROP____(a, b, c, d) a,
28 enum class CFX_CSSProperty : uint8_t {
29 #include "core/fxcrt/css/properties.inc"
30 };
31 #undef CSS_PROP____
32 
33 #undef CSS_PROP_VALUE____
34 #define CSS_PROP_VALUE____(a, b, c) a,
35 enum class CFX_CSSPropertyValue : uint8_t {
36 #include "core/fxcrt/css/property_values.inc"
37 };
38 #undef CSS_PROP_VALUE____
39 
40 enum class CFX_CSSLengthUnit : uint8_t {
41   Auto,
42   None,
43   Normal,
44   Point,
45   Percent,
46 };
47 
48 enum class CFX_CSSDisplay : uint8_t {
49   None,
50   ListItem,
51   Block,
52   Inline,
53   InlineBlock,
54   InlineTable,
55 };
56 
57 enum class CFX_CSSFontStyle : uint8_t {
58   Normal,
59   Italic,
60 };
61 
62 enum class CFX_CSSTextAlign : uint8_t {
63   Left,
64   Right,
65   Center,
66   Justify,
67   JustifyAll,
68 };
69 
70 enum class CFX_CSSVerticalAlign : uint8_t {
71   Baseline,
72   Sub,
73   Super,
74   Top,
75   TextTop,
76   Middle,
77   Bottom,
78   TextBottom,
79   Number,
80 };
81 
82 enum class CFX_CSSFontVariant : uint8_t {
83   Normal,
84   SmallCaps,
85 };
86 
87 enum class CFX_CSSTEXTDECORATION : uint8_t {
88   kNone = 0,
89   kUnderline = 1 << 0,
90   kOverline = 1 << 1,
91   kLineThrough = 1 << 2,
92   kBlink = 1 << 3,
93   kDouble = 1 << 4,
94 };
95 
96 class CFX_CSSLength {
97  public:
98   CFX_CSSLength() = default;
99 
CFX_CSSLength(CFX_CSSLengthUnit eUnit,float fValue)100   CFX_CSSLength(CFX_CSSLengthUnit eUnit, float fValue)
101       : m_unit(eUnit), m_fValue(fValue) {}
102 
Set(CFX_CSSLengthUnit eUnit)103   CFX_CSSLength& Set(CFX_CSSLengthUnit eUnit) {
104     m_unit = eUnit;
105     return *this;
106   }
107 
Set(CFX_CSSLengthUnit eUnit,float fValue)108   CFX_CSSLength& Set(CFX_CSSLengthUnit eUnit, float fValue) {
109     m_unit = eUnit;
110     m_fValue = fValue;
111     return *this;
112   }
113 
GetUnit()114   CFX_CSSLengthUnit GetUnit() const { return m_unit; }
115 
GetValue()116   float GetValue() const { return m_fValue; }
NonZero()117   bool NonZero() const { return static_cast<int>(m_fValue) != 0; }
118 
119  private:
120   CFX_CSSLengthUnit m_unit;
121   float m_fValue;
122 };
123 
124 class CFX_CSSRect {
125  public:
126   CFX_CSSRect() = default;
127 
CFX_CSSRect(CFX_CSSLengthUnit eUnit,float val)128   CFX_CSSRect(CFX_CSSLengthUnit eUnit, float val)
129       : left(eUnit, val),
130         top(eUnit, val),
131         right(eUnit, val),
132         bottom(eUnit, val) {}
133 
Set(CFX_CSSLengthUnit eUnit)134   CFX_CSSRect& Set(CFX_CSSLengthUnit eUnit) {
135     left.Set(eUnit);
136     top.Set(eUnit);
137     right.Set(eUnit);
138     bottom.Set(eUnit);
139     return *this;
140   }
Set(CFX_CSSLengthUnit eUnit,float fValue)141   CFX_CSSRect& Set(CFX_CSSLengthUnit eUnit, float fValue) {
142     left.Set(eUnit, fValue);
143     top.Set(eUnit, fValue);
144     right.Set(eUnit, fValue);
145     bottom.Set(eUnit, fValue);
146     return *this;
147   }
148 
149   CFX_CSSLength left;
150   CFX_CSSLength top;
151   CFX_CSSLength right;
152   CFX_CSSLength bottom;
153 };
154 
155 #endif  // CORE_FXCRT_CSS_CFX_CSS_H_
156