From 55c62a48d36c042499c68b0aca60bc34fa2b5c99 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 1 Feb 2018 17:46:34 +0000 Subject: Convert CFX_CSSPropertyTable to CFX_CSSData This converts the existing class naming and references. The ::Entry struct is converted to ::Property. The GetBy* methods are renamed to GetPropertyBy*. Free functions from other parts of the CSS code base are merged into the class. GetCSSPropertyValueByName becomes ::GetPropertyValueByName with a return value of ::PropertyValue*. GetCSSLengthUnitByName becomes ::GetLengthUnitByName with a return value of ::LengthUnit*. GetCSSColorByName becomes ::GetColorByName with a return value of ::Color*. BUG=pdfium:998 Change-Id: I5b78c69d0fe53ad714ac3545cfdda8c26b95e4d5 Reviewed-on: https://pdfium-review.googlesource.com/25010 Reviewed-by: dsinclair Reviewed-by: Henrique Nakashima Commit-Queue: Ryan Harrison --- BUILD.gn | 4 +- core/fxcrt/css/cfx_css.h | 4 +- core/fxcrt/css/cfx_cssdata.cpp | 256 ++++++++++++++++++++++++++++++++ core/fxcrt/css/cfx_cssdata.h | 50 +++++++ core/fxcrt/css/cfx_cssdeclaration.cpp | 175 ++++------------------ core/fxcrt/css/cfx_cssdeclaration.h | 6 +- core/fxcrt/css/cfx_csspropertytable.cpp | 142 ------------------ core/fxcrt/css/cfx_csspropertytable.h | 31 ---- core/fxcrt/css/cfx_cssstyleselector.cpp | 14 +- core/fxcrt/css/cfx_cssstylesheet.cpp | 14 +- core/fxcrt/css/cfx_csssyntaxparser.cpp | 2 +- 11 files changed, 355 insertions(+), 343 deletions(-) create mode 100644 core/fxcrt/css/cfx_cssdata.cpp create mode 100644 core/fxcrt/css/cfx_cssdata.h delete mode 100644 core/fxcrt/css/cfx_csspropertytable.cpp delete mode 100644 core/fxcrt/css/cfx_csspropertytable.h diff --git a/BUILD.gn b/BUILD.gn index 79c9747edf..54aa448b89 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -907,6 +907,8 @@ jumbo_static_library("fxcrt") { "core/fxcrt/css/cfx_csscomputedstyle.h", "core/fxcrt/css/cfx_csscustomproperty.cpp", "core/fxcrt/css/cfx_csscustomproperty.h", + "core/fxcrt/css/cfx_cssdata.cpp", + "core/fxcrt/css/cfx_cssdata.h", "core/fxcrt/css/cfx_cssdeclaration.cpp", "core/fxcrt/css/cfx_cssdeclaration.h", "core/fxcrt/css/cfx_cssenumvalue.cpp", @@ -917,8 +919,6 @@ jumbo_static_library("fxcrt") { "core/fxcrt/css/cfx_cssnumbervalue.h", "core/fxcrt/css/cfx_csspropertyholder.cpp", "core/fxcrt/css/cfx_csspropertyholder.h", - "core/fxcrt/css/cfx_csspropertytable.cpp", - "core/fxcrt/css/cfx_csspropertytable.h", "core/fxcrt/css/cfx_cssrulecollection.cpp", "core/fxcrt/css/cfx_cssrulecollection.h", "core/fxcrt/css/cfx_cssselector.cpp", diff --git a/core/fxcrt/css/cfx_css.h b/core/fxcrt/css/cfx_css.h index 0ccaaf2bc8..32f376f327 100644 --- a/core/fxcrt/css/cfx_css.h +++ b/core/fxcrt/css/cfx_css.h @@ -32,7 +32,7 @@ enum class CFX_CSSPrimitiveType : uint8_t { }; // Any entries added/removed here, will need to be mirrored in -// propertyValueTable, in core/fxcrt/css/cfx_cssdeclaration.cpp. +// propertyValueTable, in core/fxcrt/css/cfx_cssdata.cpp. enum class CFX_CSSPropertyValue : uint8_t { Bolder = 0, None, @@ -81,7 +81,7 @@ enum class CFX_CSSPropertyValue : uint8_t { }; // Any entries added/removed here, will need to be mirrored in -// propertyTable, in core/fxcrt/css/cfx_csspropertytable.cpp. +// propertyTable, in core/fxcrt/css/cfx_cssdata.cpp. enum class CFX_CSSProperty : uint8_t { BorderLeft = 0, Top, diff --git a/core/fxcrt/css/cfx_cssdata.cpp b/core/fxcrt/css/cfx_cssdata.cpp new file mode 100644 index 0000000000..fed03f8107 --- /dev/null +++ b/core/fxcrt/css/cfx_cssdata.cpp @@ -0,0 +1,256 @@ +// Copyright 2018 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_cssdata.h" + +#include +#include + +#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" + +namespace { + +const CFX_CSSData::Property propertyTable[] = { + {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_CSSData::PropertyValue propertyValueTable[] = { + {CFX_CSSPropertyValue::Bolder, L"bolder", 0x009F1058}, + {CFX_CSSPropertyValue::None, L"none", 0x048B6670}, + {CFX_CSSPropertyValue::Dot, L"dot", 0x0A48CB27}, + {CFX_CSSPropertyValue::Sub, L"sub", 0x0BD37FAA}, + {CFX_CSSPropertyValue::Top, L"top", 0x0BEDAF33}, + {CFX_CSSPropertyValue::Right, L"right", 0x193ADE3E}, + {CFX_CSSPropertyValue::Normal, L"normal", 0x247CF3E9}, + {CFX_CSSPropertyValue::Auto, L"auto", 0x2B35B6D9}, + {CFX_CSSPropertyValue::Text, L"text", 0x2D08AF85}, + {CFX_CSSPropertyValue::XSmall, L"x-small", 0x2D2FCAFE}, + {CFX_CSSPropertyValue::Thin, L"thin", 0x2D574D53}, + {CFX_CSSPropertyValue::Small, L"small", 0x316A3739}, + {CFX_CSSPropertyValue::Bottom, L"bottom", 0x399F02B5}, + {CFX_CSSPropertyValue::Underline, L"underline", 0x3A0273A6}, + {CFX_CSSPropertyValue::Double, L"double", 0x3D98515B}, + {CFX_CSSPropertyValue::Lighter, L"lighter", 0x45BEB7AF}, + {CFX_CSSPropertyValue::Oblique, L"oblique", 0x53EBDDB1}, + {CFX_CSSPropertyValue::Super, L"super", 0x6A4F842F}, + {CFX_CSSPropertyValue::Center, L"center", 0x6C51AFC1}, + {CFX_CSSPropertyValue::XxLarge, L"xx-large", 0x70BB1508}, + {CFX_CSSPropertyValue::Smaller, L"smaller", 0x849769F0}, + {CFX_CSSPropertyValue::Baseline, L"baseline", 0x87436BA3}, + {CFX_CSSPropertyValue::Thick, L"thick", 0x8CC35EB3}, + {CFX_CSSPropertyValue::Justify, L"justify", 0x8D269CAE}, + {CFX_CSSPropertyValue::Middle, L"middle", 0x947FA00F}, + {CFX_CSSPropertyValue::Medium, L"medium", 0xA084A381}, + {CFX_CSSPropertyValue::ListItem, L"list-item", 0xA32382B8}, + {CFX_CSSPropertyValue::XxSmall, L"xx-small", 0xADE1FC76}, + {CFX_CSSPropertyValue::Bold, L"bold", 0xB18313A1}, + {CFX_CSSPropertyValue::SmallCaps, L"small-caps", 0xB299428D}, + {CFX_CSSPropertyValue::Inline, L"inline", 0xC02D649F}, + {CFX_CSSPropertyValue::Overline, L"overline", 0xC0EC9FA4}, + {CFX_CSSPropertyValue::TextBottom, L"text-bottom", 0xC7D08D87}, + {CFX_CSSPropertyValue::Larger, L"larger", 0xCD3C409D}, + {CFX_CSSPropertyValue::InlineTable, L"inline-table", 0xD131F494}, + {CFX_CSSPropertyValue::InlineBlock, L"inline-block", 0xD26A8BD7}, + {CFX_CSSPropertyValue::Blink, L"blink", 0xDC36E390}, + {CFX_CSSPropertyValue::Block, L"block", 0xDCD480AB}, + {CFX_CSSPropertyValue::Italic, L"italic", 0xE31D5396}, + {CFX_CSSPropertyValue::LineThrough, L"line-through", 0xE4C5A276}, + {CFX_CSSPropertyValue::XLarge, L"x-large", 0xF008E390}, + {CFX_CSSPropertyValue::Large, L"large", 0xF4434FCB}, + {CFX_CSSPropertyValue::Left, L"left", 0xF5AD782B}, + {CFX_CSSPropertyValue::TextTop, L"text-top", 0xFCB58D45}, +}; + +const CFX_CSSData::LengthUnit lengthUnitTable[] = { + {L"cm", CFX_CSSNumberType::CentiMeters}, {L"em", CFX_CSSNumberType::EMS}, + {L"ex", CFX_CSSNumberType::EXS}, {L"in", CFX_CSSNumberType::Inches}, + {L"mm", CFX_CSSNumberType::MilliMeters}, {L"pc", CFX_CSSNumberType::Picas}, + {L"pt", CFX_CSSNumberType::Points}, {L"px", CFX_CSSNumberType::Pixels}, +}; + +// 16 colours from CSS 2.0 + alternate spelling of grey/gray. +const CFX_CSSData::Color colorTable[] = { + {L"aqua", 0xff00ffff}, {L"black", 0xff000000}, {L"blue", 0xff0000ff}, + {L"fuchsia", 0xffff00ff}, {L"gray", 0xff808080}, {L"green", 0xff008000}, + {L"grey", 0xff808080}, {L"lime", 0xff00ff00}, {L"maroon", 0xff800000}, + {L"navy", 0xff000080}, {L"olive", 0xff808000}, {L"orange", 0xffffa500}, + {L"purple", 0xff800080}, {L"red", 0xffff0000}, {L"silver", 0xffc0c0c0}, + {L"teal", 0xff008080}, {L"white", 0xffffffff}, {L"yellow", 0xffffff00}, +}; + +} // namespace + +const CFX_CSSData::Property* CFX_CSSData::GetPropertyByName( + WideStringView name) { + if (name.IsEmpty()) + return nullptr; + + uint32_t hash = FX_HashCode_GetW(name, true); + auto* result = + std::lower_bound(std::begin(propertyTable), std::end(propertyTable), hash, + [](const CFX_CSSData::Property& iter, + const uint32_t& hash) { return iter.dwHash < hash; }); + + if (result != std::end(propertyTable) && result->dwHash == hash) + return result; + return nullptr; +} + +const CFX_CSSData::Property* CFX_CSSData::GetPropertyByEnum( + CFX_CSSProperty property) { + return &propertyTable[static_cast(property)]; +} + +const CFX_CSSData::PropertyValue* CFX_CSSData::GetPropertyValueByName( + WideStringView wsName) { + if (wsName.IsEmpty()) + return nullptr; + + uint32_t hash = FX_HashCode_GetW(wsName, true); + auto* result = std::lower_bound( + std::begin(propertyValueTable), std::end(propertyValueTable), hash, + [](const PropertyValue& iter, const uint32_t& hash) { + return iter.dwHash < hash; + }); + + if (result != std::end(propertyValueTable) && result->dwHash == hash) + return result; + return nullptr; +} + +const CFX_CSSData::LengthUnit* CFX_CSSData::GetLengthUnitByName( + WideStringView wsName) { + if (wsName.IsEmpty() || wsName.GetLength() != 2) + return nullptr; + + WideString lowerName = WideString(wsName); + lowerName.MakeLower(); + + for (auto* iter = std::begin(lengthUnitTable); + iter != std::end(lengthUnitTable); ++iter) { + if (lowerName.Compare(iter->value) == 0) + return iter; + } + + return nullptr; +} + +const CFX_CSSData::Color* CFX_CSSData::GetColorByName(WideStringView wsName) { + if (wsName.IsEmpty()) + return nullptr; + + WideString lowerName = WideString(wsName); + lowerName.MakeLower(); + + for (auto* iter = std::begin(colorTable); iter != std::end(colorTable); + ++iter) { + if (lowerName.Compare(iter->name) == 0) + return iter; + } + return nullptr; +} diff --git a/core/fxcrt/css/cfx_cssdata.h b/core/fxcrt/css/cfx_cssdata.h new file mode 100644 index 0000000000..e7bf57c26d --- /dev/null +++ b/core/fxcrt/css/cfx_cssdata.h @@ -0,0 +1,50 @@ +// Copyright 2018 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 CORE_FXCRT_CSS_CFX_CSSDATA_H_ +#define CORE_FXCRT_CSS_CFX_CSSDATA_H_ + +#include +#include + +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_cssnumbervalue.h" +#include "core/fxcrt/css/cfx_cssvalue.h" +#include "core/fxcrt/string_view_template.h" + +class CFX_CSSData { + public: + struct Property { + CFX_CSSProperty eName; + const wchar_t* pszName; + uint32_t dwHash; + uint32_t dwType; + }; + + struct PropertyValue { + CFX_CSSPropertyValue eName; + const wchar_t* pszName; + uint32_t dwHash; + }; + + struct LengthUnit { + const wchar_t* value; + CFX_CSSNumberType type; + }; + + struct Color { + const wchar_t* name; + FX_ARGB value; + }; + + static const Property* GetPropertyByName(WideStringView name); + static const Property* GetPropertyByEnum(CFX_CSSProperty property); + static const PropertyValue* GetPropertyValueByName(WideStringView wsName); + static const LengthUnit* GetLengthUnitByName(WideStringView wsName); + static const Color* GetColorByName(WideStringView wsName); +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSDATA_H_ diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp index d5026a70df..ba92be3b96 100644 --- a/core/fxcrt/css/cfx_cssdeclaration.cpp +++ b/core/fxcrt/css/cfx_cssdeclaration.cpp @@ -24,130 +24,6 @@ uint8_t Hex2Dec(uint8_t hexHigh, uint8_t hexLow) { return (FXSYS_HexCharToInt(hexHigh) << 4) + FXSYS_HexCharToInt(hexLow); } -struct CFX_CSSPropertyValueEntry { - CFX_CSSPropertyValue eName; - const wchar_t* pszName; - uint32_t dwHash; -}; - -const CFX_CSSPropertyValueEntry propertyValueTable[] = { - {CFX_CSSPropertyValue::Bolder, L"bolder", 0x009F1058}, - {CFX_CSSPropertyValue::None, L"none", 0x048B6670}, - {CFX_CSSPropertyValue::Dot, L"dot", 0x0A48CB27}, - {CFX_CSSPropertyValue::Sub, L"sub", 0x0BD37FAA}, - {CFX_CSSPropertyValue::Top, L"top", 0x0BEDAF33}, - {CFX_CSSPropertyValue::Right, L"right", 0x193ADE3E}, - {CFX_CSSPropertyValue::Normal, L"normal", 0x247CF3E9}, - {CFX_CSSPropertyValue::Auto, L"auto", 0x2B35B6D9}, - {CFX_CSSPropertyValue::Text, L"text", 0x2D08AF85}, - {CFX_CSSPropertyValue::XSmall, L"x-small", 0x2D2FCAFE}, - {CFX_CSSPropertyValue::Thin, L"thin", 0x2D574D53}, - {CFX_CSSPropertyValue::Small, L"small", 0x316A3739}, - {CFX_CSSPropertyValue::Bottom, L"bottom", 0x399F02B5}, - {CFX_CSSPropertyValue::Underline, L"underline", 0x3A0273A6}, - {CFX_CSSPropertyValue::Double, L"double", 0x3D98515B}, - {CFX_CSSPropertyValue::Lighter, L"lighter", 0x45BEB7AF}, - {CFX_CSSPropertyValue::Oblique, L"oblique", 0x53EBDDB1}, - {CFX_CSSPropertyValue::Super, L"super", 0x6A4F842F}, - {CFX_CSSPropertyValue::Center, L"center", 0x6C51AFC1}, - {CFX_CSSPropertyValue::XxLarge, L"xx-large", 0x70BB1508}, - {CFX_CSSPropertyValue::Smaller, L"smaller", 0x849769F0}, - {CFX_CSSPropertyValue::Baseline, L"baseline", 0x87436BA3}, - {CFX_CSSPropertyValue::Thick, L"thick", 0x8CC35EB3}, - {CFX_CSSPropertyValue::Justify, L"justify", 0x8D269CAE}, - {CFX_CSSPropertyValue::Middle, L"middle", 0x947FA00F}, - {CFX_CSSPropertyValue::Medium, L"medium", 0xA084A381}, - {CFX_CSSPropertyValue::ListItem, L"list-item", 0xA32382B8}, - {CFX_CSSPropertyValue::XxSmall, L"xx-small", 0xADE1FC76}, - {CFX_CSSPropertyValue::Bold, L"bold", 0xB18313A1}, - {CFX_CSSPropertyValue::SmallCaps, L"small-caps", 0xB299428D}, - {CFX_CSSPropertyValue::Inline, L"inline", 0xC02D649F}, - {CFX_CSSPropertyValue::Overline, L"overline", 0xC0EC9FA4}, - {CFX_CSSPropertyValue::TextBottom, L"text-bottom", 0xC7D08D87}, - {CFX_CSSPropertyValue::Larger, L"larger", 0xCD3C409D}, - {CFX_CSSPropertyValue::InlineTable, L"inline-table", 0xD131F494}, - {CFX_CSSPropertyValue::InlineBlock, L"inline-block", 0xD26A8BD7}, - {CFX_CSSPropertyValue::Blink, L"blink", 0xDC36E390}, - {CFX_CSSPropertyValue::Block, L"block", 0xDCD480AB}, - {CFX_CSSPropertyValue::Italic, L"italic", 0xE31D5396}, - {CFX_CSSPropertyValue::LineThrough, L"line-through", 0xE4C5A276}, - {CFX_CSSPropertyValue::XLarge, L"x-large", 0xF008E390}, - {CFX_CSSPropertyValue::Large, L"large", 0xF4434FCB}, - {CFX_CSSPropertyValue::Left, L"left", 0xF5AD782B}, - {CFX_CSSPropertyValue::TextTop, L"text-top", 0xFCB58D45}, -}; - -struct CFX_CSSLengthUnitEntry { - const wchar_t* value; - CFX_CSSNumberType type; -}; -const CFX_CSSLengthUnitEntry lengthUnitTable[] = { - {L"cm", CFX_CSSNumberType::CentiMeters}, {L"em", CFX_CSSNumberType::EMS}, - {L"ex", CFX_CSSNumberType::EXS}, {L"in", CFX_CSSNumberType::Inches}, - {L"mm", CFX_CSSNumberType::MilliMeters}, {L"pc", CFX_CSSNumberType::Picas}, - {L"pt", CFX_CSSNumberType::Points}, {L"px", CFX_CSSNumberType::Pixels}, -}; - -struct CFX_CSSColorEntry { - const wchar_t* name; - FX_ARGB value; -}; -// 16 colours from CSS 2.0 + alternate spelling of grey/gray. -const CFX_CSSColorEntry colorTable[] = { - {L"aqua", 0xff00ffff}, {L"black", 0xff000000}, {L"blue", 0xff0000ff}, - {L"fuchsia", 0xffff00ff}, {L"gray", 0xff808080}, {L"green", 0xff008000}, - {L"grey", 0xff808080}, {L"lime", 0xff00ff00}, {L"maroon", 0xff800000}, - {L"navy", 0xff000080}, {L"olive", 0xff808000}, {L"orange", 0xffffa500}, - {L"purple", 0xff800080}, {L"red", 0xffff0000}, {L"silver", 0xffc0c0c0}, - {L"teal", 0xff008080}, {L"white", 0xffffffff}, {L"yellow", 0xffffff00}, -}; - -const CFX_CSSPropertyValueEntry* GetCSSPropertyValueByName( - WideStringView wsName) { - if (wsName.IsEmpty()) - return nullptr; - - uint32_t hash = FX_HashCode_GetW(wsName, true); - auto* result = std::lower_bound( - std::begin(propertyValueTable), std::end(propertyValueTable), hash, - [](const CFX_CSSPropertyValueEntry& iter, const uint32_t& hash) { - return iter.dwHash < hash; - }); - if (result != std::end(propertyValueTable) && result->dwHash == hash) - return result; - return nullptr; -} - -const CFX_CSSLengthUnitEntry* GetCSSLengthUnitByName(WideStringView wsName) { - if (wsName.IsEmpty() || wsName.GetLength() != 2) - return nullptr; - - WideString lowerName = WideString(wsName); - lowerName.MakeLower(); - - for (auto* iter = std::begin(lengthUnitTable); - iter != std::end(lengthUnitTable); ++iter) { - if (lowerName.Compare(iter->value) == 0) - return iter; - } - return nullptr; -} - -const CFX_CSSColorEntry* GetCSSColorByName(WideStringView wsName) { - if (wsName.IsEmpty()) - return nullptr; - - WideString lowerName = WideString(wsName); - lowerName.MakeLower(); - - for (auto* iter = std::begin(colorTable); iter != std::end(colorTable); - ++iter) { - if (lowerName.Compare(iter->name) == 0) - return iter; - } - return nullptr; -} - bool ParseCSSNumber(const wchar_t* pszValue, int32_t iValueLen, float& fValue, @@ -164,8 +40,8 @@ bool ParseCSSNumber(const wchar_t* pszValue, if (iValueLen >= 1 && *pszValue == '%') { eUnit = CFX_CSSNumberType::Percent; } else if (iValueLen == 2) { - const CFX_CSSLengthUnitEntry* pUnit = - GetCSSLengthUnitByName(WideStringView(pszValue, 2)); + const CFX_CSSData::LengthUnit* pUnit = + CFX_CSSData::GetLengthUnitByName(WideStringView(pszValue, 2)); if (pUnit) eUnit = pUnit->type; } @@ -245,8 +121,8 @@ bool CFX_CSSDeclaration::ParseCSSColor(const wchar_t* pszValue, return true; } - const CFX_CSSColorEntry* pColor = - GetCSSColorByName(WideStringView(pszValue, iValueLen)); + const CFX_CSSData::Color* pColor = + CFX_CSSData::GetColorByName(WideStringView(pszValue, iValueLen)); if (!pColor) return false; @@ -280,7 +156,7 @@ void CFX_CSSDeclaration::AddPropertyHolder(CFX_CSSProperty eProperty, properties_.push_back(std::move(pHolder)); } -void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable::Entry* pEntry, +void CFX_CSSDeclaration::AddProperty(const CFX_CSSData::Property* property, const WideStringView& value) { ASSERT(!value.IsEmpty()); @@ -294,7 +170,7 @@ void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable::Entry* pEntry, bImportant = true; } - const uint32_t dwType = pEntry->dwType; + const uint32_t dwType = property->dwType; switch (dwType & 0x0F) { case CFX_CSSVALUETYPE_Primitive: { static const uint32_t g_ValueGuessOrder[] = { @@ -326,7 +202,7 @@ void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable::Entry* pEntry, break; } if (pCSSValue) { - AddPropertyHolder(pEntry->eName, pCSSValue, bImportant); + AddPropertyHolder(property->eName, pCSSValue, bImportant); return; } @@ -337,7 +213,7 @@ void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable::Entry* pEntry, } case CFX_CSSVALUETYPE_Shorthand: { RetainPtr pWidth; - switch (pEntry->eName) { + switch (property->eName) { case CFX_CSSProperty::Font: ParseFontProperty(pszValue, iValueLen, bImportant); return; @@ -387,7 +263,7 @@ void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable::Entry* pEntry, } } break; case CFX_CSSVALUETYPE_List: - ParseValueListProperty(pEntry, pszValue, iValueLen, bImportant); + ParseValueListProperty(property, pszValue, iValueLen, bImportant); return; default: NOTREACHED(); @@ -412,8 +288,8 @@ RetainPtr CFX_CSSDeclaration::ParseNumber(const wchar_t* pszValue, RetainPtr CFX_CSSDeclaration::ParseEnum(const wchar_t* pszValue, int32_t iValueLen) { - const CFX_CSSPropertyValueEntry* pValue = - GetCSSPropertyValueByName(WideStringView(pszValue, iValueLen)); + const CFX_CSSData::PropertyValue* pValue = + CFX_CSSData::GetPropertyValueByName(WideStringView(pszValue, iValueLen)); return pValue ? pdfium::MakeRetain(pValue->eName) : nullptr; } @@ -439,15 +315,15 @@ RetainPtr CFX_CSSDeclaration::ParseString(const wchar_t* pszValue, } void CFX_CSSDeclaration::ParseValueListProperty( - const CFX_CSSPropertyTable::Entry* pEntry, + const CFX_CSSData::Property* pProperty, const wchar_t* pszValue, int32_t iValueLen, bool bImportant) { wchar_t separator = - (pEntry->eName == CFX_CSSProperty::FontFamily) ? ',' : ' '; + (pProperty->eName == CFX_CSSProperty::FontFamily) ? ',' : ' '; CFX_CSSValueListParser parser(pszValue, iValueLen, separator); - const uint32_t dwType = pEntry->dwType; + const uint32_t dwType = pProperty->dwType; CFX_CSSPrimitiveType eType; std::vector> list; while (parser.NextValue(&eType, &pszValue, &iValueLen)) { @@ -470,8 +346,9 @@ void CFX_CSSDeclaration::ParseValueListProperty( } } if (dwType & CFX_CSSVALUETYPE_MaybeEnum) { - const CFX_CSSPropertyValueEntry* pValue = - GetCSSPropertyValueByName(WideStringView(pszValue, iValueLen)); + const CFX_CSSData::PropertyValue* pValue = + CFX_CSSData::GetPropertyValueByName( + WideStringView(pszValue, iValueLen)); if (pValue) { list.push_back(pdfium::MakeRetain(pValue->eName)); continue; @@ -497,7 +374,7 @@ void CFX_CSSDeclaration::ParseValueListProperty( if (list.empty()) return; - switch (pEntry->eName) { + switch (pProperty->eName) { case CFX_CSSProperty::BorderWidth: Add4ValuesProperty(list, bImportant, CFX_CSSProperty::BorderLeftWidth, CFX_CSSProperty::BorderTopWidth, @@ -518,7 +395,7 @@ void CFX_CSSDeclaration::ParseValueListProperty( return; default: { auto pList = pdfium::MakeRetain(list); - AddPropertyHolder(pEntry->eName, pList, bImportant); + AddPropertyHolder(pProperty->eName, pList, bImportant); return; } } @@ -582,13 +459,14 @@ bool CFX_CSSDeclaration::ParseBorderProperty( break; } case CFX_CSSPrimitiveType::String: { - const CFX_CSSColorEntry* pColorItem = - GetCSSColorByName(WideStringView(pszValue, iValueLen)); + const CFX_CSSData::Color* pColorItem = + CFX_CSSData::GetColorByName(WideStringView(pszValue, iValueLen)); if (pColorItem) continue; - const CFX_CSSPropertyValueEntry* pValue = - GetCSSPropertyValueByName(WideStringView(pszValue, iValueLen)); + const CFX_CSSData::PropertyValue* pValue = + CFX_CSSData::GetPropertyValueByName( + WideStringView(pszValue, iValueLen)); if (!pValue) continue; @@ -629,8 +507,9 @@ void CFX_CSSDeclaration::ParseFontProperty(const wchar_t* pszValue, while (parser.NextValue(&eType, &pszValue, &iValueLen)) { switch (eType) { case CFX_CSSPrimitiveType::String: { - const CFX_CSSPropertyValueEntry* pValue = - GetCSSPropertyValueByName(WideStringView(pszValue, iValueLen)); + const CFX_CSSData::PropertyValue* pValue = + CFX_CSSData::GetPropertyValueByName( + WideStringView(pszValue, iValueLen)); if (pValue) { switch (pValue->eName) { case CFX_CSSPropertyValue::XxSmall: diff --git a/core/fxcrt/css/cfx_cssdeclaration.h b/core/fxcrt/css/cfx_cssdeclaration.h index 0dad046a19..8d67bb7944 100644 --- a/core/fxcrt/css/cfx_cssdeclaration.h +++ b/core/fxcrt/css/cfx_cssdeclaration.h @@ -11,7 +11,7 @@ #include #include -#include "core/fxcrt/css/cfx_csspropertytable.h" +#include "core/fxcrt/css/cfx_cssdata.h" class CFX_CSSPropertyHolder; class CFX_CSSCustomProperty; @@ -47,7 +47,7 @@ class CFX_CSSDeclaration { bool empty() const { return properties_.empty(); } - void AddProperty(const CFX_CSSPropertyTable::Entry* pEntry, + void AddProperty(const CFX_CSSData::Property* property, const WideStringView& value); void AddProperty(const WideString& prop, const WideString& value); @@ -64,7 +64,7 @@ class CFX_CSSDeclaration { bool ParseBorderProperty(const wchar_t* pszValue, int32_t iValueLen, RetainPtr& pWidth) const; - void ParseValueListProperty(const CFX_CSSPropertyTable::Entry* pEntry, + void ParseValueListProperty(const CFX_CSSData::Property* pProperty, const wchar_t* pszValue, int32_t iValueLen, bool bImportant); diff --git a/core/fxcrt/css/cfx_csspropertytable.cpp b/core/fxcrt/css/cfx_csspropertytable.cpp deleted file mode 100644 index 61294d26b2..0000000000 --- a/core/fxcrt/css/cfx_csspropertytable.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// 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_csspropertytable.h" - -#include -#include - -#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" - -namespace { -const CFX_CSSPropertyTable::Entry propertyTable[] = { - {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}, -}; -} // namespace - -const CFX_CSSPropertyTable::Entry* CFX_CSSPropertyTable::GetByName( - WideStringView name) { - if (name.IsEmpty()) - return nullptr; - - uint32_t hash = FX_HashCode_GetW(name, true); - - auto cmpFunc = [](const CFX_CSSPropertyTable::Entry& iter, - const uint32_t& hash) { return iter.dwHash < hash; }; - - auto* result = std::lower_bound(std::begin(propertyTable), - std::end(propertyTable), hash, cmpFunc); - if (result != std::end(propertyTable) && result->dwHash == hash) - return result; - return nullptr; -} - -const CFX_CSSPropertyTable::Entry* CFX_CSSPropertyTable::GetByEnum( - CFX_CSSProperty property) { - return &propertyTable[static_cast(property)]; -} diff --git a/core/fxcrt/css/cfx_csspropertytable.h b/core/fxcrt/css/cfx_csspropertytable.h deleted file mode 100644 index 924e962676..0000000000 --- a/core/fxcrt/css/cfx_csspropertytable.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2018 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 CORE_FXCRT_CSS_CFX_CSSPROPERTYTABLE_H_ -#define CORE_FXCRT_CSS_CFX_CSSPROPERTYTABLE_H_ - -#include -#include - -#include "core/fxcrt/css/cfx_css.h" -#include "core/fxcrt/css/cfx_cssnumbervalue.h" -#include "core/fxcrt/css/cfx_cssvalue.h" -#include "core/fxcrt/string_view_template.h" - -class CFX_CSSPropertyTable { - public: - struct Entry { - CFX_CSSProperty eName; - const wchar_t* pszName; - uint32_t dwHash; - uint32_t dwType; - }; - - static const Entry* GetByName(WideStringView nam); - static const Entry* GetByEnum(CFX_CSSProperty property); -}; - -#endif // CORE_FXCRT_CSS_CFX_CSSPROPERTYTABLE_H_ diff --git a/core/fxcrt/css/cfx_cssstyleselector.cpp b/core/fxcrt/css/cfx_cssstyleselector.cpp index f079a35f59..4a47798d31 100644 --- a/core/fxcrt/css/cfx_cssstyleselector.cpp +++ b/core/fxcrt/css/cfx_cssstyleselector.cpp @@ -91,7 +91,7 @@ void CFX_CSSStyleSelector::ComputeStyle( AppendInlineStyle(pDecl.get(), styleString); if (!alignString.IsEmpty()) { pDecl->AddProperty( - CFX_CSSPropertyTable::GetByEnum(CFX_CSSProperty::TextAlign), + CFX_CSSData::GetPropertyByEnum(CFX_CSSProperty::TextAlign), alignString.AsStringView()); } } @@ -144,21 +144,21 @@ void CFX_CSSStyleSelector::AppendInlineStyle(CFX_CSSDeclaration* pDecl, auto pSyntax = pdfium::MakeUnique( style.c_str(), style.GetLength(), 32, true); int32_t iLen2 = 0; - const CFX_CSSPropertyTable::Entry* entry = nullptr; + const CFX_CSSData::Property* property = nullptr; WideString wsName; while (1) { CFX_CSSSyntaxStatus eStatus = pSyntax->DoSyntaxParse(); if (eStatus == CFX_CSSSyntaxStatus::PropertyName) { WideStringView strValue = pSyntax->GetCurrentString(); - entry = CFX_CSSPropertyTable::GetByName(strValue); - if (!entry) + property = CFX_CSSData::GetPropertyByName(strValue); + if (!property) wsName = WideString(strValue); } else if (eStatus == CFX_CSSSyntaxStatus::PropertyValue) { - if (entry || iLen2 > 0) { + if (property || iLen2 > 0) { WideStringView strValue = pSyntax->GetCurrentString(); if (!strValue.IsEmpty()) { - if (entry) - pDecl->AddProperty(entry, strValue); + if (property) + pDecl->AddProperty(property, strValue); else if (iLen2 > 0) pDecl->AddProperty(wsName, WideString(strValue)); } diff --git a/core/fxcrt/css/cfx_cssstylesheet.cpp b/core/fxcrt/css/cfx_cssstylesheet.cpp index 01c68fce7d..c7300fb37c 100644 --- a/core/fxcrt/css/cfx_cssstylesheet.cpp +++ b/core/fxcrt/css/cfx_cssstylesheet.cpp @@ -8,8 +8,8 @@ #include +#include "core/fxcrt/css/cfx_cssdata.h" #include "core/fxcrt/css/cfx_cssdeclaration.h" -#include "core/fxcrt/css/cfx_csspropertytable.h" #include "core/fxcrt/css/cfx_cssstylerule.h" #include "core/fxcrt/fx_codepage.h" #include "third_party/base/ptr_util.h" @@ -62,7 +62,7 @@ CFX_CSSSyntaxStatus CFX_CSSStyleSheet::LoadStyleRule( CFX_CSSStyleRule* pStyleRule = nullptr; int32_t iValueLen = 0; - const CFX_CSSPropertyTable::Entry* entry = nullptr; + const CFX_CSSData::Property* property = nullptr; WideString wsName; while (1) { switch (pSyntax->DoSyntaxParse()) { @@ -75,18 +75,18 @@ CFX_CSSSyntaxStatus CFX_CSSStyleSheet::LoadStyleRule( } case CFX_CSSSyntaxStatus::PropertyName: { WideStringView strValue = pSyntax->GetCurrentString(); - entry = CFX_CSSPropertyTable::GetByName(strValue); - if (!entry) + property = CFX_CSSData::GetPropertyByName(strValue); + if (!property) wsName = WideString(strValue); break; } case CFX_CSSSyntaxStatus::PropertyValue: { - if (entry || iValueLen > 0) { + if (property || iValueLen > 0) { WideStringView strValue = pSyntax->GetCurrentString(); auto* decl = pStyleRule->GetDeclaration(); if (!strValue.IsEmpty()) { - if (entry) { - decl->AddProperty(entry, strValue); + if (property) { + decl->AddProperty(property, strValue); } else { decl->AddProperty(wsName, WideString(strValue)); } diff --git a/core/fxcrt/css/cfx_csssyntaxparser.cpp b/core/fxcrt/css/cfx_csssyntaxparser.cpp index e24c17c16c..b557bf090b 100644 --- a/core/fxcrt/css/cfx_csssyntaxparser.cpp +++ b/core/fxcrt/css/cfx_csssyntaxparser.cpp @@ -8,8 +8,8 @@ #include +#include "core/fxcrt/css/cfx_cssdata.h" #include "core/fxcrt/css/cfx_cssdeclaration.h" -#include "core/fxcrt/css/cfx_csspropertytable.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" #include "third_party/base/logging.h" -- cgit v1.2.3