summaryrefslogtreecommitdiff
path: root/core/fxcrt/css/cfx_cssdatatable.cpp
blob: 8b2100aaa275a49d09e6fbe9fa1f3d2d9b80371d (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
// 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

#include "core/fxcrt/css/cfx_cssdatatable.h"

#include <algorithm>
#include <utility>

#include "core/fxcrt/css/cfx_cssstyleselector.h"
#include "core/fxcrt/css/cfx_cssvaluelistparser.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"

static const CFX_CSSPropertyTable g_CFX_CSSProperties[] = {
    {CFX_CSSProperty::BorderLeft, L"border-left", 0x04080036,
     CFX_CSSVALUETYPE_Shorthand},
    {CFX_CSSProperty::Top, L"top", 0x0BEDAF33,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::Margin, L"margin", 0x0CB016BE,
     CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::TextIndent, L"text-indent", 0x169ADB74,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::Right, L"right", 0x193ADE3E,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::PaddingLeft, L"padding-left", 0x228CF02F,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::MarginLeft, L"margin-left", 0x297C5656,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
         CFX_CSSVALUETYPE_MaybeEnum},
    {CFX_CSSProperty::Border, L"border", 0x2A23349E,
     CFX_CSSVALUETYPE_Shorthand},
    {CFX_CSSProperty::BorderTop, L"border-top", 0x2B866ADE,
     CFX_CSSVALUETYPE_Shorthand},
    {CFX_CSSProperty::Bottom, L"bottom", 0x399F02B5,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::PaddingRight, L"padding-right", 0x3F616AC2,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::BorderBottom, L"border-bottom", 0x452CE780,
     CFX_CSSVALUETYPE_Shorthand},
    {CFX_CSSProperty::FontFamily, L"font-family", 0x574686E6,
     CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeString},
    {CFX_CSSProperty::FontWeight, L"font-weight", 0x6692F60C,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::Color, L"color", 0x6E67921F,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeColor},
    {CFX_CSSProperty::LetterSpacing, L"letter-spacing", 0x70536102,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::TextAlign, L"text-align", 0x7553F1BD,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum},
    {CFX_CSSProperty::BorderRightWidth, L"border-right-width", 0x8F5A6036,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::VerticalAlign, L"vertical-align", 0x934A87D2,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::PaddingTop, L"padding-top", 0x959D22B7,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::FontVariant, L"font-variant", 0x9C785779,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum},
    {CFX_CSSProperty::BorderWidth, L"border-width", 0xA8DE4FEB,
     CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::BorderBottomWidth, L"border-bottom-width", 0xAE41204D,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::BorderRight, L"border-right", 0xB78E9EA9,
     CFX_CSSVALUETYPE_Shorthand},
    {CFX_CSSProperty::FontSize, L"font-size", 0xB93956DF,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::BorderSpacing, L"border-spacing", 0xC72030F0,
     CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::FontStyle, L"font-style", 0xCB1950F5,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum},
    {CFX_CSSProperty::Font, L"font", 0xCD308B77, CFX_CSSVALUETYPE_Shorthand},
    {CFX_CSSProperty::LineHeight, L"line-height", 0xCFCACE2E,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::MarginRight, L"margin-right", 0xD13C58C9,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
         CFX_CSSVALUETYPE_MaybeEnum},
    {CFX_CSSProperty::BorderLeftWidth, L"border-left-width", 0xD1E93D83,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::Display, L"display", 0xD4224C36,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum},
    {CFX_CSSProperty::PaddingBottom, L"padding-bottom", 0xE555B3B9,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::BorderTopWidth, L"border-top-width", 0xED2CB62B,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::WordSpacing, L"word-spacing", 0xEDA63BAE,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::Left, L"left", 0xF5AD782B,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum |
         CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::TextDecoration, L"text-decoration", 0xF7C634BA,
     CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum},
    {CFX_CSSProperty::Padding, L"padding", 0xF8C373F7,
     CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeNumber},
    {CFX_CSSProperty::MarginBottom, L"margin-bottom", 0xF93485A0,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
         CFX_CSSVALUETYPE_MaybeEnum},
    {CFX_CSSProperty::MarginTop, L"margin-top", 0xFE51DCFE,
     CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
         CFX_CSSVALUETYPE_MaybeEnum},
};

const CFX_CSSPropertyTable* CFX_GetCSSPropertyByName(WideStringView name) {
  if (name.IsEmpty())
    return nullptr;

  uint32_t hash = FX_HashCode_GetW(name, true);

  auto cmpFunc = [](const CFX_CSSPropertyTable& iter, const uint32_t& hash) {
    return iter.dwHash < hash;
  };

  auto* result = std::lower_bound(std::begin(g_CFX_CSSProperties),
                                  std::end(g_CFX_CSSProperties), hash, cmpFunc);
  if (result != std::end(g_CFX_CSSProperties) && result->dwHash == hash)
    return result;
  return nullptr;
}

const CFX_CSSPropertyTable* CFX_GetCSSPropertyByEnum(CFX_CSSProperty eName) {
  return &g_CFX_CSSProperties[static_cast<uint8_t>(eName)];
}