1 // Copyright 2014 PDFium Authors. All rights reserved.
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 #include "core/fxcrt/css/cfx_cssdatatable.h"
8
9 #include <utility>
10
11 #include "core/fxcrt/css/cfx_cssstyleselector.h"
12 #include "core/fxcrt/css/cfx_cssvaluelistparser.h"
13 #include "core/fxcrt/fx_codepage.h"
14 #include "core/fxcrt/fx_extension.h"
15
16 static const CFX_CSSPropertyTable g_CFX_CSSProperties[] = {
17 {CFX_CSSProperty::BorderLeft, L"border-left", 0x04080036,
18 CFX_CSSVALUETYPE_Shorthand},
19 {CFX_CSSProperty::Top, L"top", 0x0BEDAF33,
20 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
21 CFX_CSSVALUETYPE_MaybeNumber},
22 {CFX_CSSProperty::Margin, L"margin", 0x0CB016BE,
23 CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum |
24 CFX_CSSVALUETYPE_MaybeNumber},
25 {CFX_CSSProperty::TextIndent, L"text-indent", 0x169ADB74,
26 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
27 {CFX_CSSProperty::Right, L"right", 0x193ADE3E,
28 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
29 CFX_CSSVALUETYPE_MaybeNumber},
30 {CFX_CSSProperty::PaddingLeft, L"padding-left", 0x228CF02F,
31 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
32 {CFX_CSSProperty::MarginLeft, L"margin-left", 0x297C5656,
33 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
34 CFX_CSSVALUETYPE_MaybeEnum},
35 {CFX_CSSProperty::Border, L"border", 0x2A23349E,
36 CFX_CSSVALUETYPE_Shorthand},
37 {CFX_CSSProperty::BorderTop, L"border-top", 0x2B866ADE,
38 CFX_CSSVALUETYPE_Shorthand},
39 {CFX_CSSProperty::Bottom, L"bottom", 0x399F02B5,
40 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
41 CFX_CSSVALUETYPE_MaybeNumber},
42 {CFX_CSSProperty::PaddingRight, L"padding-right", 0x3F616AC2,
43 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
44 {CFX_CSSProperty::BorderBottom, L"border-bottom", 0x452CE780,
45 CFX_CSSVALUETYPE_Shorthand},
46 {CFX_CSSProperty::FontFamily, L"font-family", 0x574686E6,
47 CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeString},
48 {CFX_CSSProperty::FontWeight, L"font-weight", 0x6692F60C,
49 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
50 CFX_CSSVALUETYPE_MaybeNumber},
51 {CFX_CSSProperty::Color, L"color", 0x6E67921F,
52 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
53 CFX_CSSVALUETYPE_MaybeColor},
54 {CFX_CSSProperty::LetterSpacing, L"letter-spacing", 0x70536102,
55 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
56 CFX_CSSVALUETYPE_MaybeNumber},
57 {CFX_CSSProperty::TextAlign, L"text-align", 0x7553F1BD,
58 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum},
59 {CFX_CSSProperty::BorderRightWidth, L"border-right-width", 0x8F5A6036,
60 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
61 CFX_CSSVALUETYPE_MaybeNumber},
62 {CFX_CSSProperty::VerticalAlign, L"vertical-align", 0x934A87D2,
63 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
64 CFX_CSSVALUETYPE_MaybeNumber},
65 {CFX_CSSProperty::PaddingTop, L"padding-top", 0x959D22B7,
66 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
67 {CFX_CSSProperty::FontVariant, L"font-variant", 0x9C785779,
68 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum},
69 {CFX_CSSProperty::BorderWidth, L"border-width", 0xA8DE4FEB,
70 CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum |
71 CFX_CSSVALUETYPE_MaybeNumber},
72 {CFX_CSSProperty::BorderBottomWidth, L"border-bottom-width", 0xAE41204D,
73 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
74 CFX_CSSVALUETYPE_MaybeNumber},
75 {CFX_CSSProperty::BorderRight, L"border-right", 0xB78E9EA9,
76 CFX_CSSVALUETYPE_Shorthand},
77 {CFX_CSSProperty::FontSize, L"font-size", 0xB93956DF,
78 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
79 CFX_CSSVALUETYPE_MaybeNumber},
80 {CFX_CSSProperty::BorderSpacing, L"border-spacing", 0xC72030F0,
81 CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeNumber},
82 {CFX_CSSProperty::FontStyle, L"font-style", 0xCB1950F5,
83 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum},
84 {CFX_CSSProperty::Font, L"font", 0xCD308B77, CFX_CSSVALUETYPE_Shorthand},
85 {CFX_CSSProperty::LineHeight, L"line-height", 0xCFCACE2E,
86 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
87 CFX_CSSVALUETYPE_MaybeNumber},
88 {CFX_CSSProperty::MarginRight, L"margin-right", 0xD13C58C9,
89 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
90 CFX_CSSVALUETYPE_MaybeEnum},
91 {CFX_CSSProperty::BorderLeftWidth, L"border-left-width", 0xD1E93D83,
92 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
93 CFX_CSSVALUETYPE_MaybeNumber},
94 {CFX_CSSProperty::Display, L"display", 0xD4224C36,
95 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum},
96 {CFX_CSSProperty::PaddingBottom, L"padding-bottom", 0xE555B3B9,
97 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
98 {CFX_CSSProperty::BorderTopWidth, L"border-top-width", 0xED2CB62B,
99 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
100 CFX_CSSVALUETYPE_MaybeNumber},
101 {CFX_CSSProperty::WordSpacing, L"word-spacing", 0xEDA63BAE,
102 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
103 CFX_CSSVALUETYPE_MaybeNumber},
104 {CFX_CSSProperty::Left, L"left", 0xF5AD782B,
105 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
106 CFX_CSSVALUETYPE_MaybeNumber},
107 {CFX_CSSProperty::TextDecoration, L"text-decoration", 0xF7C634BA,
108 CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum},
109 {CFX_CSSProperty::Padding, L"padding", 0xF8C373F7,
110 CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeNumber},
111 {CFX_CSSProperty::MarginBottom, L"margin-bottom", 0xF93485A0,
112 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
113 CFX_CSSVALUETYPE_MaybeEnum},
114 {CFX_CSSProperty::MarginTop, L"margin-top", 0xFE51DCFE,
115 CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
116 CFX_CSSVALUETYPE_MaybeEnum},
117 };
118 const int32_t g_iCSSPropertyCount =
119 sizeof(g_CFX_CSSProperties) / sizeof(CFX_CSSPropertyTable);
120 static_assert(g_iCSSPropertyCount ==
121 static_cast<int32_t>(CFX_CSSProperty::LAST_MARKER),
122 "Property table differs in size from property enum");
123
CFX_GetCSSPropertyByName(const WideStringView & wsName)124 const CFX_CSSPropertyTable* CFX_GetCSSPropertyByName(
125 const WideStringView& wsName) {
126 ASSERT(!wsName.IsEmpty());
127 uint32_t dwHash = FX_HashCode_GetW(wsName, true);
128 int32_t iEnd = g_iCSSPropertyCount;
129 int32_t iMid, iStart = 0;
130 uint32_t dwMid;
131 do {
132 iMid = (iStart + iEnd) / 2;
133 dwMid = g_CFX_CSSProperties[iMid].dwHash;
134 if (dwHash == dwMid) {
135 return g_CFX_CSSProperties + iMid;
136 } else if (dwHash > dwMid) {
137 iStart = iMid + 1;
138 } else {
139 iEnd = iMid - 1;
140 }
141 } while (iStart <= iEnd);
142 return nullptr;
143 }
144
CFX_GetCSSPropertyByEnum(CFX_CSSProperty eName)145 const CFX_CSSPropertyTable* CFX_GetCSSPropertyByEnum(CFX_CSSProperty eName) {
146 return g_CFX_CSSProperties + static_cast<int>(eName);
147 }
148