summaryrefslogtreecommitdiff
path: root/core/fxcrt/css
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-01-31 15:47:32 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-31 15:47:32 +0000
commit41b45a88f14ea546d1b46b7c30a1c9c1db778ac3 (patch)
treeffad96b6e33807ed3f78056c9ba879e1c3dceab3 /core/fxcrt/css
parent3f3f5130e91c9a868831ee80840f027111ee6f3b (diff)
downloadpdfium-41b45a88f14ea546d1b46b7c30a1c9c1db778ac3.tar.xz
Clean up CSS property table
Reorganizes the free functions to be static methods on a class. Converts the Table struct to be an Entry struct defined in the class. Change-Id: I9eca0dfb15187af10cbe2dc4b4c2756d55d957be Reviewed-on: https://pdfium-review.googlesource.com/24712 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/css')
-rw-r--r--core/fxcrt/css/cfx_cssdatatable.h28
-rw-r--r--core/fxcrt/css/cfx_cssdeclaration.cpp20
-rw-r--r--core/fxcrt/css/cfx_cssdeclaration.h6
-rw-r--r--core/fxcrt/css/cfx_csspropertytable.cpp (renamed from core/fxcrt/css/cfx_cssdatatable.cpp)25
-rw-r--r--core/fxcrt/css/cfx_csspropertytable.h31
-rw-r--r--core/fxcrt/css/cfx_cssstyleselector.cpp17
-rw-r--r--core/fxcrt/css/cfx_cssstylesheet.cpp14
-rw-r--r--core/fxcrt/css/cfx_csssyntaxparser.cpp2
8 files changed, 75 insertions, 68 deletions
diff --git a/core/fxcrt/css/cfx_cssdatatable.h b/core/fxcrt/css/cfx_cssdatatable.h
deleted file mode 100644
index b8476175f6..0000000000
--- a/core/fxcrt/css/cfx_cssdatatable.h
+++ /dev/null
@@ -1,28 +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
-
-#ifndef CORE_FXCRT_CSS_CFX_CSSDATATABLE_H_
-#define CORE_FXCRT_CSS_CFX_CSSDATATABLE_H_
-
-#include <memory>
-#include <vector>
-
-#include "core/fxcrt/css/cfx_css.h"
-#include "core/fxcrt/css/cfx_cssnumbervalue.h"
-#include "core/fxcrt/css/cfx_cssvalue.h"
-#include "core/fxcrt/fx_system.h"
-
-struct CFX_CSSPropertyTable {
- CFX_CSSProperty eName;
- const wchar_t* pszName;
- uint32_t dwHash;
- uint32_t dwType;
-};
-
-const CFX_CSSPropertyTable* CFX_GetCSSPropertyByName(WideStringView wsName);
-const CFX_CSSPropertyTable* CFX_GetCSSPropertyByEnum(CFX_CSSProperty eName);
-
-#endif // CORE_FXCRT_CSS_CFX_CSSDATATABLE_H_
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index 90bdf4e0ea..e771f6277d 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -307,7 +307,7 @@ void CFX_CSSDeclaration::AddPropertyHolder(CFX_CSSProperty eProperty,
properties_.push_back(std::move(pHolder));
}
-void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable* pTable,
+void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable::Entry* pEntry,
const WideStringView& value) {
ASSERT(!value.IsEmpty());
@@ -321,7 +321,7 @@ void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable* pTable,
bImportant = true;
}
- const uint32_t dwType = pTable->dwType;
+ const uint32_t dwType = pEntry->dwType;
switch (dwType & 0x0F) {
case CFX_CSSVALUETYPE_Primitive: {
static const uint32_t g_ValueGuessOrder[] = {
@@ -353,7 +353,7 @@ void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable* pTable,
break;
}
if (pCSSValue) {
- AddPropertyHolder(pTable->eName, pCSSValue, bImportant);
+ AddPropertyHolder(pEntry->eName, pCSSValue, bImportant);
return;
}
@@ -364,7 +364,7 @@ void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable* pTable,
}
case CFX_CSSVALUETYPE_Shorthand: {
RetainPtr<CFX_CSSValue> pWidth;
- switch (pTable->eName) {
+ switch (pEntry->eName) {
case CFX_CSSProperty::Font:
ParseFontProperty(pszValue, iValueLen, bImportant);
return;
@@ -414,7 +414,7 @@ void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable* pTable,
}
} break;
case CFX_CSSVALUETYPE_List:
- ParseValueListProperty(pTable, pszValue, iValueLen, bImportant);
+ ParseValueListProperty(pEntry, pszValue, iValueLen, bImportant);
return;
default:
NOTREACHED();
@@ -466,15 +466,15 @@ RetainPtr<CFX_CSSValue> CFX_CSSDeclaration::ParseString(const wchar_t* pszValue,
}
void CFX_CSSDeclaration::ParseValueListProperty(
- const CFX_CSSPropertyTable* pTable,
+ const CFX_CSSPropertyTable::Entry* pEntry,
const wchar_t* pszValue,
int32_t iValueLen,
bool bImportant) {
wchar_t separator =
- (pTable->eName == CFX_CSSProperty::FontFamily) ? ',' : ' ';
+ (pEntry->eName == CFX_CSSProperty::FontFamily) ? ',' : ' ';
CFX_CSSValueListParser parser(pszValue, iValueLen, separator);
- const uint32_t dwType = pTable->dwType;
+ const uint32_t dwType = pEntry->dwType;
CFX_CSSPrimitiveType eType;
std::vector<RetainPtr<CFX_CSSValue>> list;
while (parser.NextValue(&eType, &pszValue, &iValueLen)) {
@@ -524,7 +524,7 @@ void CFX_CSSDeclaration::ParseValueListProperty(
if (list.empty())
return;
- switch (pTable->eName) {
+ switch (pEntry->eName) {
case CFX_CSSProperty::BorderWidth:
Add4ValuesProperty(list, bImportant, CFX_CSSProperty::BorderLeftWidth,
CFX_CSSProperty::BorderTopWidth,
@@ -545,7 +545,7 @@ void CFX_CSSDeclaration::ParseValueListProperty(
return;
default: {
auto pList = pdfium::MakeRetain<CFX_CSSValueList>(list);
- AddPropertyHolder(pTable->eName, pList, bImportant);
+ AddPropertyHolder(pEntry->eName, pList, bImportant);
return;
}
}
diff --git a/core/fxcrt/css/cfx_cssdeclaration.h b/core/fxcrt/css/cfx_cssdeclaration.h
index 7dd0bba90e..0dad046a19 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.h
+++ b/core/fxcrt/css/cfx_cssdeclaration.h
@@ -11,7 +11,7 @@
#include <utility>
#include <vector>
-#include "core/fxcrt/css/cfx_cssdatatable.h"
+#include "core/fxcrt/css/cfx_csspropertytable.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* pTable,
+ void AddProperty(const CFX_CSSPropertyTable::Entry* pEntry,
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<CFX_CSSValue>& pWidth) const;
- void ParseValueListProperty(const CFX_CSSPropertyTable* pTable,
+ void ParseValueListProperty(const CFX_CSSPropertyTable::Entry* pEntry,
const wchar_t* pszValue,
int32_t iValueLen,
bool bImportant);
diff --git a/core/fxcrt/css/cfx_cssdatatable.cpp b/core/fxcrt/css/cfx_csspropertytable.cpp
index 8b2100aaa2..61294d26b2 100644
--- a/core/fxcrt/css/cfx_cssdatatable.cpp
+++ b/core/fxcrt/css/cfx_csspropertytable.cpp
@@ -4,7 +4,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fxcrt/css/cfx_cssdatatable.h"
+#include "core/fxcrt/css/cfx_csspropertytable.h"
#include <algorithm>
#include <utility>
@@ -14,7 +14,8 @@
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
-static const CFX_CSSPropertyTable g_CFX_CSSProperties[] = {
+namespace {
+const CFX_CSSPropertyTable::Entry propertyTable[] = {
{CFX_CSSProperty::BorderLeft, L"border-left", 0x04080036,
CFX_CSSVALUETYPE_Shorthand},
{CFX_CSSProperty::Top, L"top", 0x0BEDAF33,
@@ -116,24 +117,26 @@ static const CFX_CSSPropertyTable g_CFX_CSSProperties[] = {
CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber |
CFX_CSSVALUETYPE_MaybeEnum},
};
+} // namespace
-const CFX_CSSPropertyTable* CFX_GetCSSPropertyByName(WideStringView name) {
+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& iter, const uint32_t& hash) {
- return iter.dwHash < hash;
- };
+ auto cmpFunc = [](const CFX_CSSPropertyTable::Entry& 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)
+ 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* CFX_GetCSSPropertyByEnum(CFX_CSSProperty eName) {
- return &g_CFX_CSSProperties[static_cast<uint8_t>(eName)];
+const CFX_CSSPropertyTable::Entry* CFX_CSSPropertyTable::GetByEnum(
+ CFX_CSSProperty property) {
+ return &propertyTable[static_cast<uint8_t>(property)];
}
diff --git a/core/fxcrt/css/cfx_csspropertytable.h b/core/fxcrt/css/cfx_csspropertytable.h
new file mode 100644
index 0000000000..924e962676
--- /dev/null
+++ b/core/fxcrt/css/cfx_csspropertytable.h
@@ -0,0 +1,31 @@
+// 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 <memory>
+#include <vector>
+
+#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 cb9ab2f499..f079a35f59 100644
--- a/core/fxcrt/css/cfx_cssstyleselector.cpp
+++ b/core/fxcrt/css/cfx_cssstyleselector.cpp
@@ -90,8 +90,9 @@ void CFX_CSSStyleSelector::ComputeStyle(
if (!styleString.IsEmpty())
AppendInlineStyle(pDecl.get(), styleString);
if (!alignString.IsEmpty()) {
- pDecl->AddProperty(CFX_GetCSSPropertyByEnum(CFX_CSSProperty::TextAlign),
- alignString.AsStringView());
+ pDecl->AddProperty(
+ CFX_CSSPropertyTable::GetByEnum(CFX_CSSProperty::TextAlign),
+ alignString.AsStringView());
}
}
ApplyDeclarations(declArray, pDecl.get(), pDest);
@@ -143,21 +144,21 @@ void CFX_CSSStyleSelector::AppendInlineStyle(CFX_CSSDeclaration* pDecl,
auto pSyntax = pdfium::MakeUnique<CFX_CSSSyntaxParser>(
style.c_str(), style.GetLength(), 32, true);
int32_t iLen2 = 0;
- const CFX_CSSPropertyTable* table = nullptr;
+ const CFX_CSSPropertyTable::Entry* entry = nullptr;
WideString wsName;
while (1) {
CFX_CSSSyntaxStatus eStatus = pSyntax->DoSyntaxParse();
if (eStatus == CFX_CSSSyntaxStatus::PropertyName) {
WideStringView strValue = pSyntax->GetCurrentString();
- table = CFX_GetCSSPropertyByName(strValue);
- if (!table)
+ entry = CFX_CSSPropertyTable::GetByName(strValue);
+ if (!entry)
wsName = WideString(strValue);
} else if (eStatus == CFX_CSSSyntaxStatus::PropertyValue) {
- if (table || iLen2 > 0) {
+ if (entry || iLen2 > 0) {
WideStringView strValue = pSyntax->GetCurrentString();
if (!strValue.IsEmpty()) {
- if (table)
- pDecl->AddProperty(table, strValue);
+ if (entry)
+ pDecl->AddProperty(entry, 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 183765f3b0..01c68fce7d 100644
--- a/core/fxcrt/css/cfx_cssstylesheet.cpp
+++ b/core/fxcrt/css/cfx_cssstylesheet.cpp
@@ -8,8 +8,8 @@
#include <utility>
-#include "core/fxcrt/css/cfx_cssdatatable.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* propertyTable = nullptr;
+ const CFX_CSSPropertyTable::Entry* entry = 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();
- propertyTable = CFX_GetCSSPropertyByName(strValue);
- if (!propertyTable)
+ entry = CFX_CSSPropertyTable::GetByName(strValue);
+ if (!entry)
wsName = WideString(strValue);
break;
}
case CFX_CSSSyntaxStatus::PropertyValue: {
- if (propertyTable || iValueLen > 0) {
+ if (entry || iValueLen > 0) {
WideStringView strValue = pSyntax->GetCurrentString();
auto* decl = pStyleRule->GetDeclaration();
if (!strValue.IsEmpty()) {
- if (propertyTable) {
- decl->AddProperty(propertyTable, strValue);
+ if (entry) {
+ decl->AddProperty(entry, strValue);
} else {
decl->AddProperty(wsName, WideString(strValue));
}
diff --git a/core/fxcrt/css/cfx_csssyntaxparser.cpp b/core/fxcrt/css/cfx_csssyntaxparser.cpp
index 066b82b5d6..e24c17c16c 100644
--- a/core/fxcrt/css/cfx_csssyntaxparser.cpp
+++ b/core/fxcrt/css/cfx_csssyntaxparser.cpp
@@ -8,8 +8,8 @@
#include <algorithm>
-#include "core/fxcrt/css/cfx_cssdatatable.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"