summaryrefslogtreecommitdiff
path: root/xfa/fde/css
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fde/css')
-rw-r--r--xfa/fde/css/cfde_csscomputedstyle.cpp18
-rw-r--r--xfa/fde/css/cfde_csscomputedstyle.h8
-rw-r--r--xfa/fde/css/cfde_csscustomproperty.cpp15
-rw-r--r--xfa/fde/css/cfde_csscustomproperty.h13
-rw-r--r--xfa/fde/css/cfde_cssdeclaration.cpp106
-rw-r--r--xfa/fde/css/cfde_cssdeclaration.h37
-rw-r--r--xfa/fde/css/cfde_cssselector.cpp9
-rw-r--r--xfa/fde/css/cfde_cssselector.h4
-rw-r--r--xfa/fde/css/cfde_cssstyleselector.cpp37
-rw-r--r--xfa/fde/css/cfde_cssstylesheet.cpp51
-rw-r--r--xfa/fde/css/cfde_csssyntaxparser.cpp15
-rw-r--r--xfa/fde/css/cfde_csssyntaxparser.h4
12 files changed, 144 insertions, 173 deletions
diff --git a/xfa/fde/css/cfde_csscomputedstyle.cpp b/xfa/fde/css/cfde_csscomputedstyle.cpp
index b563bbf445..50247420be 100644
--- a/xfa/fde/css/cfde_csscomputedstyle.cpp
+++ b/xfa/fde/css/cfde_csscomputedstyle.cpp
@@ -14,12 +14,12 @@ CFDE_CSSComputedStyle::CFDE_CSSComputedStyle() {}
CFDE_CSSComputedStyle::~CFDE_CSSComputedStyle() {}
-bool CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideStringC& wsName,
+bool CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideString& wsName,
CFX_WideString& wsValue) const {
- for (int32_t i = pdfium::CollectionSize<int32_t>(m_CustomProperties) - 2;
- i > -1; i -= 2) {
- if (wsName == m_CustomProperties[i]) {
- wsValue = m_CustomProperties[i + 1];
+ for (auto iter = m_CustomProperties.rbegin();
+ iter != m_CustomProperties.rend(); iter++) {
+ if (wsName == iter->name()) {
+ wsValue = iter->value();
return true;
}
}
@@ -161,10 +161,10 @@ void CFDE_CSSComputedStyle::SetLetterSpacing(
m_InheritedData.m_LetterSpacing = letterSpacing;
}
-void CFDE_CSSComputedStyle::AddCustomStyle(const CFX_WideString& wsName,
- const CFX_WideString& wsValue) {
- m_CustomProperties.push_back(wsName);
- m_CustomProperties.push_back(wsValue);
+void CFDE_CSSComputedStyle::AddCustomStyle(const CFDE_CSSCustomProperty& prop) {
+ // Force the property to be copied so we aren't dependent on the lifetime
+ // of whatever currently owns it.
+ m_CustomProperties.push_back(prop);
}
CFDE_CSSComputedStyle::InheritedData::InheritedData()
diff --git a/xfa/fde/css/cfde_csscomputedstyle.h b/xfa/fde/css/cfde_csscomputedstyle.h
index 1f73d87631..92d832eff7 100644
--- a/xfa/fde/css/cfde_csscomputedstyle.h
+++ b/xfa/fde/css/cfde_csscomputedstyle.h
@@ -11,6 +11,7 @@
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_string.h"
+#include "xfa/fde/css/cfde_csscustomproperty.h"
#include "xfa/fde/css/fde_css.h"
class CFDE_CSSValueList;
@@ -88,10 +89,9 @@ class CFDE_CSSComputedStyle : public CFX_Retainable {
void SetNumberVerticalAlign(FX_FLOAT fAlign);
void SetTextDecoration(uint32_t dwTextDecoration);
void SetLetterSpacing(const FDE_CSSLength& letterSpacing);
- void AddCustomStyle(const CFX_WideString& wsName,
- const CFX_WideString& wsValue);
+ void AddCustomStyle(const CFDE_CSSCustomProperty& prop);
- bool GetCustomStyle(const CFX_WideStringC& wsName,
+ bool GetCustomStyle(const CFX_WideString& wsName,
CFX_WideString& wsValue) const;
InheritedData m_InheritedData;
@@ -104,7 +104,7 @@ class CFDE_CSSComputedStyle : public CFX_Retainable {
CFDE_CSSComputedStyle();
~CFDE_CSSComputedStyle() override;
- std::vector<CFX_WideString> m_CustomProperties;
+ std::vector<CFDE_CSSCustomProperty> m_CustomProperties;
};
#endif // XFA_FDE_CSS_CFDE_CSSCOMPUTEDSTYLE_H_
diff --git a/xfa/fde/css/cfde_csscustomproperty.cpp b/xfa/fde/css/cfde_csscustomproperty.cpp
new file mode 100644
index 0000000000..92b288eb4f
--- /dev/null
+++ b/xfa/fde/css/cfde_csscustomproperty.cpp
@@ -0,0 +1,15 @@
+// Copyright 2017 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.
+
+#include "xfa/fde/css/cfde_csscustomproperty.h"
+
+CFDE_CSSCustomProperty::CFDE_CSSCustomProperty(const CFX_WideString& name,
+ const CFX_WideString& value)
+ : name_(name), value_(value) {}
+
+CFDE_CSSCustomProperty::CFDE_CSSCustomProperty(
+ const CFDE_CSSCustomProperty& prop)
+ : name_(prop.name_), value_(prop.value_) {}
+
+CFDE_CSSCustomProperty::~CFDE_CSSCustomProperty() {}
diff --git a/xfa/fde/css/cfde_csscustomproperty.h b/xfa/fde/css/cfde_csscustomproperty.h
index 6e99630e1c..6970d49cbb 100644
--- a/xfa/fde/css/cfde_csscustomproperty.h
+++ b/xfa/fde/css/cfde_csscustomproperty.h
@@ -11,8 +11,17 @@
class CFDE_CSSCustomProperty {
public:
- const FX_WCHAR* pwsName;
- const FX_WCHAR* pwsValue;
+ CFDE_CSSCustomProperty(const CFX_WideString& name,
+ const CFX_WideString& value);
+ CFDE_CSSCustomProperty(const CFDE_CSSCustomProperty& prop);
+ ~CFDE_CSSCustomProperty();
+
+ CFX_WideString name() const { return name_; }
+ CFX_WideString value() const { return value_; }
+
+ private:
+ CFX_WideString name_;
+ CFX_WideString value_;
};
#endif // XFA_FDE_CSS_CFDE_CSSCUSTOMPROPERTY_H_
diff --git a/xfa/fde/css/cfde_cssdeclaration.cpp b/xfa/fde/css/cfde_cssdeclaration.cpp
index 4ed20eb0cc..481a31e423 100644
--- a/xfa/fde/css/cfde_cssdeclaration.cpp
+++ b/xfa/fde/css/cfde_cssdeclaration.cpp
@@ -144,28 +144,6 @@ CFDE_CSSValue* CFDE_CSSDeclaration::GetProperty(FDE_CSSProperty eProperty,
return nullptr;
}
-const FX_WCHAR* CFDE_CSSDeclaration::CopyToLocal(
- const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
- int32_t iValueLen) {
- ASSERT(iValueLen > 0);
- std::unordered_map<uint32_t, FX_WCHAR*>* pCache = pArgs->pStringCache;
- uint32_t key = 0;
- if (pCache) {
- key = FX_HashCode_GetW(CFX_WideStringC(pszValue, iValueLen), false);
- auto it = pCache->find(key);
- if (it != pCache->end())
- return it->second;
- }
- FX_WCHAR* psz = FX_Alloc(FX_WCHAR, iValueLen + 1);
- FXSYS_wcsncpy(psz, pszValue, iValueLen);
- psz[iValueLen] = '\0';
- if (pCache)
- (*pCache)[key] = psz;
-
- return psz;
-}
-
void CFDE_CSSDeclaration::AddPropertyHolder(FDE_CSSProperty eProperty,
CFX_RetainPtr<CFDE_CSSValue> pValue,
bool bImportant) {
@@ -176,10 +154,13 @@ void CFDE_CSSDeclaration::AddPropertyHolder(FDE_CSSProperty eProperty,
properties_.push_back(std::move(pHolder));
}
-void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
- int32_t iValueLen) {
- ASSERT(iValueLen > 0);
+void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable,
+ const CFX_WideStringC& value) {
+ ASSERT(!value.IsEmpty());
+
+ const FX_WCHAR* pszValue = value.c_str();
+ int32_t iValueLen = value.GetLength();
+
bool bImportant = false;
if (iValueLen >= 10 && pszValue[iValueLen - 10] == '!' &&
FXSYS_wcsnicmp(L"important", pszValue + iValueLen - 9, 9) == 0) {
@@ -188,7 +169,7 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyArgs* pArgs,
bImportant = true;
}
- const uint32_t dwType = pArgs->pProperty->dwType;
+ const uint32_t dwType = pTable->dwType;
switch (dwType & 0x0F) {
case FDE_CSSVALUETYPE_Primitive: {
static const uint32_t g_ValueGuessOrder[] = {
@@ -205,22 +186,22 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyArgs* pArgs,
CFX_RetainPtr<CFDE_CSSValue> pCSSValue;
switch (dwMatch) {
case FDE_CSSVALUETYPE_MaybeNumber:
- pCSSValue = ParseNumber(pArgs, pszValue, iValueLen);
+ pCSSValue = ParseNumber(pszValue, iValueLen);
break;
case FDE_CSSVALUETYPE_MaybeEnum:
- pCSSValue = ParseEnum(pArgs, pszValue, iValueLen);
+ pCSSValue = ParseEnum(pszValue, iValueLen);
break;
case FDE_CSSVALUETYPE_MaybeColor:
- pCSSValue = ParseColor(pArgs, pszValue, iValueLen);
+ pCSSValue = ParseColor(pszValue, iValueLen);
break;
case FDE_CSSVALUETYPE_MaybeString:
- pCSSValue = ParseString(pArgs, pszValue, iValueLen);
+ pCSSValue = ParseString(pszValue, iValueLen);
break;
default:
break;
}
if (pCSSValue) {
- AddPropertyHolder(pArgs->pProperty->eName, pCSSValue, bImportant);
+ AddPropertyHolder(pTable->eName, pCSSValue, bImportant);
return;
}
if (FDE_IsOnlyValue(dwType, g_ValueGuessOrder[i]))
@@ -230,9 +211,9 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyArgs* pArgs,
}
case FDE_CSSVALUETYPE_Shorthand: {
CFX_RetainPtr<CFDE_CSSValue> pWidth;
- switch (pArgs->pProperty->eName) {
+ switch (pTable->eName) {
case FDE_CSSProperty::Font:
- ParseFontProperty(pArgs, pszValue, iValueLen, bImportant);
+ ParseFontProperty(pszValue, iValueLen, bImportant);
return;
case FDE_CSSProperty::Border:
if (ParseBorderProperty(pszValue, iValueLen, pWidth)) {
@@ -280,7 +261,7 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyArgs* pArgs,
}
} break;
case FDE_CSSVALUETYPE_List:
- ParseValueListProperty(pArgs, pszValue, iValueLen, bImportant);
+ ParseValueListProperty(pTable, pszValue, iValueLen, bImportant);
return;
default:
ASSERT(false);
@@ -288,19 +269,13 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyArgs* pArgs,
}
}
-void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszName,
- int32_t iNameLen,
- const FX_WCHAR* pszValue,
- int32_t iValueLen) {
- auto pProperty = pdfium::MakeUnique<CFDE_CSSCustomProperty>();
- pProperty->pwsName = CopyToLocal(pArgs, pszName, iNameLen);
- pProperty->pwsValue = CopyToLocal(pArgs, pszValue, iValueLen);
- custom_properties_.push_back(std::move(pProperty));
+void CFDE_CSSDeclaration::AddProperty(const CFX_WideString& prop,
+ const CFX_WideString& value) {
+ custom_properties_.push_back(
+ pdfium::MakeUnique<CFDE_CSSCustomProperty>(prop, value));
}
CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseNumber(
- const FDE_CSSPropertyArgs* pArgs,
const FX_WCHAR* pszValue,
int32_t iValueLen) {
FX_FLOAT fValue;
@@ -311,7 +286,6 @@ CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseNumber(
}
CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseEnum(
- const FDE_CSSPropertyArgs* pArgs,
const FX_WCHAR* pszValue,
int32_t iValueLen) {
const FDE_CSSPropertyValueTable* pValue =
@@ -321,7 +295,6 @@ CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseEnum(
}
CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseColor(
- const FDE_CSSPropertyArgs* pArgs,
const FX_WCHAR* pszValue,
int32_t iValueLen) {
FX_ARGB dwColor;
@@ -331,7 +304,6 @@ CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseColor(
}
CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseString(
- const FDE_CSSPropertyArgs* pArgs,
const FX_WCHAR* pszValue,
int32_t iValueLen) {
int32_t iOffset;
@@ -341,20 +313,20 @@ CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseString(
if (iValueLen <= 0)
return nullptr;
- pszValue = CopyToLocal(pArgs, pszValue + iOffset, iValueLen);
- return pszValue ? pdfium::MakeRetain<CFDE_CSSStringValue>(pszValue) : nullptr;
+ return pdfium::MakeRetain<CFDE_CSSStringValue>(
+ CFX_WideString(pszValue + iOffset, iValueLen));
}
void CFDE_CSSDeclaration::ParseValueListProperty(
- const FDE_CSSPropertyArgs* pArgs,
+ const FDE_CSSPropertyTable* pTable,
const FX_WCHAR* pszValue,
int32_t iValueLen,
bool bImportant) {
FX_WCHAR separator =
- (pArgs->pProperty->eName == FDE_CSSProperty::FontFamily) ? ',' : ' ';
+ (pTable->eName == FDE_CSSProperty::FontFamily) ? ',' : ' ';
CFDE_CSSValueListParser parser(pszValue, iValueLen, separator);
- const uint32_t dwType = pArgs->pProperty->dwType;
+ const uint32_t dwType = pTable->dwType;
FDE_CSSPrimitiveType eType;
std::vector<CFX_RetainPtr<CFDE_CSSValue>> list;
while (parser.NextValue(eType, pszValue, iValueLen)) {
@@ -387,8 +359,8 @@ void CFDE_CSSDeclaration::ParseValueListProperty(
}
}
if (dwType & FDE_CSSVALUETYPE_MaybeString) {
- pszValue = CopyToLocal(pArgs, pszValue, iValueLen);
- list.push_back(pdfium::MakeRetain<CFDE_CSSStringValue>(pszValue));
+ list.push_back(pdfium::MakeRetain<CFDE_CSSStringValue>(
+ CFX_WideString(pszValue, iValueLen)));
}
break;
case FDE_CSSPrimitiveType::RGB:
@@ -406,7 +378,7 @@ void CFDE_CSSDeclaration::ParseValueListProperty(
if (list.empty())
return;
- switch (pArgs->pProperty->eName) {
+ switch (pTable->eName) {
case FDE_CSSProperty::BorderWidth:
Add4ValuesProperty(list, bImportant, FDE_CSSProperty::BorderLeftWidth,
FDE_CSSProperty::BorderTopWidth,
@@ -427,7 +399,7 @@ void CFDE_CSSDeclaration::ParseValueListProperty(
return;
default: {
auto pList = pdfium::MakeRetain<CFDE_CSSValueList>(list);
- AddPropertyHolder(pArgs->pProperty->eName, pList, bImportant);
+ AddPropertyHolder(pTable->eName, pList, bImportant);
return;
}
}
@@ -524,8 +496,7 @@ bool CFDE_CSSDeclaration::ParseBorderProperty(
return true;
}
-void CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
+void CFDE_CSSDeclaration::ParseFontProperty(const FX_WCHAR* pszValue,
int32_t iValueLen,
bool bImportant) {
CFDE_CSSValueListParser parser(pszValue, iValueLen, '/');
@@ -591,7 +562,7 @@ void CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPropertyArgs* pArgs,
}
if (pFontSize) {
familyList.push_back(pdfium::MakeRetain<CFDE_CSSStringValue>(
- CopyToLocal(pArgs, pszValue, iValueLen)));
+ CFX_WideString(pszValue, iValueLen)));
}
parser.m_Separator = ',';
break;
@@ -630,21 +601,26 @@ void CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPropertyArgs* pArgs,
}
}
- if (!pStyle)
+ if (!pStyle) {
pStyle =
pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Normal);
- if (!pVariant)
+ }
+ if (!pVariant) {
pVariant =
pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Normal);
- if (!pWeight)
+ }
+ if (!pWeight) {
pWeight =
pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Normal);
- if (!pFontSize)
+ }
+ if (!pFontSize) {
pFontSize =
pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Medium);
- if (!pLineHeight)
+ }
+ if (!pLineHeight) {
pLineHeight =
pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Normal);
+ }
AddPropertyHolder(FDE_CSSProperty::FontStyle, pStyle, bImportant);
AddPropertyHolder(FDE_CSSProperty::FontVariant, pVariant, bImportant);
diff --git a/xfa/fde/css/cfde_cssdeclaration.h b/xfa/fde/css/cfde_cssdeclaration.h
index 777864efea..7d61675bea 100644
--- a/xfa/fde/css/cfde_cssdeclaration.h
+++ b/xfa/fde/css/cfde_cssdeclaration.h
@@ -8,17 +8,11 @@
#define XFA_FDE_CSS_CFDE_CSSDECLARATION_H_
#include <memory>
-#include <unordered_map>
#include <utility>
#include <vector>
#include "xfa/fde/css/fde_cssdatatable.h"
-struct FDE_CSSPropertyArgs {
- std::unordered_map<uint32_t, FX_WCHAR*>* pStringCache;
- const FDE_CSSPropertyTable* pProperty;
-};
-
class CFDE_CSSPropertyHolder;
class CFDE_CSSCustomProperty;
@@ -52,14 +46,9 @@ class CFDE_CSSDeclaration {
bool empty() const { return properties_.empty(); }
- void AddProperty(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
- int32_t iValueLen);
- void AddProperty(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszName,
- int32_t iNameLen,
- const FX_WCHAR* pszValue,
- int32_t iValueLen);
+ void AddProperty(const FDE_CSSPropertyTable* pTable,
+ const CFX_WideStringC& value);
+ void AddProperty(const CFX_WideString& prop, const CFX_WideString& value);
size_t PropertyCountForTesting() const;
@@ -68,14 +57,13 @@ class CFDE_CSSDeclaration {
FX_ARGB* dwColor) const;
private:
- void ParseFontProperty(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
+ void ParseFontProperty(const FX_WCHAR* pszValue,
int32_t iValueLen,
bool bImportant);
bool ParseBorderProperty(const FX_WCHAR* pszValue,
int32_t iValueLen,
CFX_RetainPtr<CFDE_CSSValue>& pWidth) const;
- void ParseValueListProperty(const FDE_CSSPropertyArgs* pArgs,
+ void ParseValueListProperty(const FDE_CSSPropertyTable* pTable,
const FX_WCHAR* pszValue,
int32_t iValueLen,
bool bImportant);
@@ -85,21 +73,14 @@ class CFDE_CSSDeclaration {
FDE_CSSProperty eTop,
FDE_CSSProperty eRight,
FDE_CSSProperty eBottom);
- CFX_RetainPtr<CFDE_CSSValue> ParseNumber(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
+ CFX_RetainPtr<CFDE_CSSValue> ParseNumber(const FX_WCHAR* pszValue,
int32_t iValueLen);
- CFX_RetainPtr<CFDE_CSSValue> ParseEnum(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
+ CFX_RetainPtr<CFDE_CSSValue> ParseEnum(const FX_WCHAR* pszValue,
int32_t iValueLen);
- CFX_RetainPtr<CFDE_CSSValue> ParseColor(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
+ CFX_RetainPtr<CFDE_CSSValue> ParseColor(const FX_WCHAR* pszValue,
int32_t iValueLen);
- CFX_RetainPtr<CFDE_CSSValue> ParseString(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
+ CFX_RetainPtr<CFDE_CSSValue> ParseString(const FX_WCHAR* pszValue,
int32_t iValueLen);
- const FX_WCHAR* CopyToLocal(const FDE_CSSPropertyArgs* pArgs,
- const FX_WCHAR* pszValue,
- int32_t iValueLen);
void AddPropertyHolder(FDE_CSSProperty eProperty,
CFX_RetainPtr<CFDE_CSSValue> pValue,
bool bImportant);
diff --git a/xfa/fde/css/cfde_cssselector.cpp b/xfa/fde/css/cfde_cssselector.cpp
index 6d181ac325..03580236f5 100644
--- a/xfa/fde/css/cfde_cssselector.cpp
+++ b/xfa/fde/css/cfde_cssselector.cpp
@@ -53,13 +53,14 @@ CFDE_CSSSelector* CFDE_CSSSelector::GetNextSelector() const {
return m_pNext.get();
}
+// static.
std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString(
- const FX_WCHAR* psz,
- int32_t iLen) {
- ASSERT(psz && iLen > 0);
+ const CFX_WideStringC& str) {
+ ASSERT(!str.IsEmpty());
+ const FX_WCHAR* psz = str.c_str();
const FX_WCHAR* pStart = psz;
- const FX_WCHAR* pEnd = psz + iLen;
+ const FX_WCHAR* pEnd = psz + str.GetLength();
for (; psz < pEnd; ++psz) {
switch (*psz) {
case '>':
diff --git a/xfa/fde/css/cfde_cssselector.h b/xfa/fde/css/cfde_cssselector.h
index a5d9cf9c7c..d585b3f368 100644
--- a/xfa/fde/css/cfde_cssselector.h
+++ b/xfa/fde/css/cfde_cssselector.h
@@ -15,8 +15,8 @@
class CFDE_CSSSelector {
public:
- static std::unique_ptr<CFDE_CSSSelector> FromString(const FX_WCHAR* psz,
- int32_t iLen);
+ static std::unique_ptr<CFDE_CSSSelector> FromString(
+ const CFX_WideStringC& str);
CFDE_CSSSelector(FDE_CSSSelectorType eType,
const FX_WCHAR* psz,
diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp
index fa17f7b20b..1319a64a84 100644
--- a/xfa/fde/css/cfde_cssstyleselector.cpp
+++ b/xfa/fde/css/cfde_cssstyleselector.cpp
@@ -105,10 +105,8 @@ void CFDE_CSSStyleSelector::ComputeStyle(
if (!styleString.IsEmpty())
AppendInlineStyle(pDecl.get(), styleString);
if (!alignString.IsEmpty()) {
- FDE_CSSPropertyArgs args;
- args.pStringCache = nullptr;
- args.pProperty = FDE_GetCSSPropertyByEnum(FDE_CSSProperty::TextAlign);
- pDecl->AddProperty(&args, alignString.c_str(), alignString.GetLength());
+ pDecl->AddProperty(FDE_GetCSSPropertyByEnum(FDE_CSSProperty::TextAlign),
+ alignString.AsStringC());
}
}
ApplyDeclarations(declArray, pDecl.get(), pDest);
@@ -130,7 +128,7 @@ void CFDE_CSSStyleSelector::ApplyDeclarations(
for (auto& prop : normals)
ApplyProperty(prop->eProperty, prop->pValue.Get(), pComputedStyle);
for (auto& prop : customs)
- pComputedStyle->AddCustomStyle(prop->pwsName, prop->pwsValue);
+ pComputedStyle->AddCustomStyle(*prop);
for (auto& prop : importants)
ApplyProperty(prop->eProperty, prop->pValue.Get(), pComputedStyle);
}
@@ -159,28 +157,23 @@ void CFDE_CSSStyleSelector::AppendInlineStyle(CFDE_CSSDeclaration* pDecl,
return;
int32_t iLen2 = 0;
- const FX_WCHAR* psz2;
- FDE_CSSPropertyArgs args;
- args.pStringCache = nullptr;
- args.pProperty = nullptr;
+ const FDE_CSSPropertyTable* table = nullptr;
CFX_WideString wsName;
while (1) {
FDE_CSSSyntaxStatus eStatus = pSyntax->DoSyntaxParse();
if (eStatus == FDE_CSSSyntaxStatus::PropertyName) {
- psz2 = pSyntax->GetCurrentString(iLen2);
- args.pProperty = FDE_GetCSSPropertyByName(CFX_WideStringC(psz2, iLen2));
- if (!args.pProperty)
- wsName = CFX_WideStringC(psz2, iLen2);
+ CFX_WideStringC strValue = pSyntax->GetCurrentString();
+ table = FDE_GetCSSPropertyByName(strValue);
+ if (!table)
+ wsName = CFX_WideString(strValue);
} else if (eStatus == FDE_CSSSyntaxStatus::PropertyValue) {
- if (args.pProperty) {
- psz2 = pSyntax->GetCurrentString(iLen2);
- if (iLen2 > 0)
- pDecl->AddProperty(&args, psz2, iLen2);
- } else if (iLen2 > 0) {
- psz2 = pSyntax->GetCurrentString(iLen2);
- if (iLen2 > 0) {
- pDecl->AddProperty(&args, wsName.c_str(), wsName.GetLength(), psz2,
- iLen2);
+ if (table || iLen2 > 0) {
+ CFX_WideStringC strValue = pSyntax->GetCurrentString();
+ if (!strValue.IsEmpty()) {
+ if (table)
+ pDecl->AddProperty(table, strValue);
+ else if (iLen2 > 0)
+ pDecl->AddProperty(wsName, CFX_WideString(strValue));
}
}
} else {
diff --git a/xfa/fde/css/cfde_cssstylesheet.cpp b/xfa/fde/css/cfde_cssstylesheet.cpp
index b05e837f95..c8bf70ec23 100644
--- a/xfa/fde/css/cfde_cssstylesheet.cpp
+++ b/xfa/fde/css/cfde_cssstylesheet.cpp
@@ -63,45 +63,40 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule(
std::vector<std::unique_ptr<CFDE_CSSSelector>> selectors;
CFDE_CSSStyleRule* pStyleRule = nullptr;
- const FX_WCHAR* pszValue = nullptr;
int32_t iValueLen = 0;
- FDE_CSSPropertyArgs propertyArgs;
- propertyArgs.pStringCache = &m_StringCache;
- propertyArgs.pProperty = nullptr;
+ const FDE_CSSPropertyTable* propertyTable = nullptr;
CFX_WideString wsName;
while (1) {
switch (pSyntax->DoSyntaxParse()) {
case FDE_CSSSyntaxStatus::Selector: {
- pszValue = pSyntax->GetCurrentString(iValueLen);
- auto pSelector = CFDE_CSSSelector::FromString(pszValue, iValueLen);
+ CFX_WideStringC strValue = pSyntax->GetCurrentString();
+ auto pSelector = CFDE_CSSSelector::FromString(strValue);
if (pSelector)
selectors.push_back(std::move(pSelector));
break;
}
- case FDE_CSSSyntaxStatus::PropertyName:
- pszValue = pSyntax->GetCurrentString(iValueLen);
- propertyArgs.pProperty =
- FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen));
- if (!propertyArgs.pProperty)
- wsName = CFX_WideStringC(pszValue, iValueLen);
+ case FDE_CSSSyntaxStatus::PropertyName: {
+ CFX_WideStringC strValue = pSyntax->GetCurrentString();
+ propertyTable = FDE_GetCSSPropertyByName(strValue);
+ if (!propertyTable)
+ wsName = CFX_WideString(strValue);
break;
- case FDE_CSSSyntaxStatus::PropertyValue:
- if (propertyArgs.pProperty) {
- pszValue = pSyntax->GetCurrentString(iValueLen);
- if (iValueLen > 0) {
- pStyleRule->GetDeclaration()->AddProperty(&propertyArgs, pszValue,
- iValueLen);
- }
- } else if (iValueLen > 0) {
- pszValue = pSyntax->GetCurrentString(iValueLen);
- if (iValueLen > 0) {
- pStyleRule->GetDeclaration()->AddProperty(
- &propertyArgs, wsName.c_str(), wsName.GetLength(), pszValue,
- iValueLen);
+ }
+ case FDE_CSSSyntaxStatus::PropertyValue: {
+ if (propertyTable || iValueLen > 0) {
+ CFX_WideStringC strValue = pSyntax->GetCurrentString();
+ auto decl = pStyleRule->GetDeclaration();
+ if (!strValue.IsEmpty()) {
+ if (propertyTable) {
+ decl->AddProperty(propertyTable, strValue);
+ } else {
+ decl->AddProperty(wsName, CFX_WideString(strValue));
+ }
}
}
break;
- case FDE_CSSSyntaxStatus::DeclOpen:
+ }
+ case FDE_CSSSyntaxStatus::DeclOpen: {
if (!pStyleRule && !selectors.empty()) {
auto rule = pdfium::MakeUnique<CFDE_CSSStyleRule>();
pStyleRule = rule.get();
@@ -112,12 +107,14 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule(
return FDE_CSSSyntaxStatus::None;
}
break;
- case FDE_CSSSyntaxStatus::DeclClose:
+ }
+ case FDE_CSSSyntaxStatus::DeclClose: {
if (pStyleRule && pStyleRule->GetDeclaration()->empty()) {
ruleArray->pop_back();
pStyleRule = nullptr;
}
return FDE_CSSSyntaxStatus::None;
+ }
case FDE_CSSSyntaxStatus::EOS:
return FDE_CSSSyntaxStatus::EOS;
case FDE_CSSSyntaxStatus::Error:
diff --git a/xfa/fde/css/cfde_csssyntaxparser.cpp b/xfa/fde/css/cfde_csssyntaxparser.cpp
index f562a374ac..2f7bcce9d7 100644
--- a/xfa/fde/css/cfde_csssyntaxparser.cpp
+++ b/xfa/fde/css/cfde_csssyntaxparser.cpp
@@ -22,7 +22,7 @@ bool IsSelectorStart(FX_WCHAR wch) {
} // namespace
CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser()
- : m_iTextDatLen(0),
+ : m_iTextDataLen(0),
m_dwCheck((uint32_t)-1),
m_eMode(FDE_CSSSyntaxMode::RuleSet),
m_eStatus(FDE_CSSSyntaxStatus::None) {}
@@ -46,7 +46,7 @@ bool CFDE_CSSSyntaxParser::Init(const FX_WCHAR* pBuffer,
void CFDE_CSSSyntaxParser::Reset(bool bOnlyDeclaration) {
m_TextPlane.Reset();
m_TextData.Reset();
- m_iTextDatLen = 0;
+ m_iTextDataLen = 0;
m_dwCheck = (uint32_t)-1;
m_eStatus = FDE_CSSSyntaxStatus::None;
m_eMode = bOnlyDeclaration ? FDE_CSSSyntaxMode::PropertyName
@@ -102,7 +102,7 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() {
case ',':
m_TextPlane.MoveNext();
SwitchMode(FDE_CSSSyntaxMode::Selector);
- if (m_iTextDatLen > 0)
+ if (m_iTextDataLen > 0)
return FDE_CSSSyntaxStatus::Selector;
break;
case '{':
@@ -208,9 +208,9 @@ bool CFDE_CSSSyntaxParser::AppendChar(FX_WCHAR wch) {
}
int32_t CFDE_CSSSyntaxParser::SaveTextData() {
- m_iTextDatLen = m_TextData.TrimEnd();
+ m_iTextDataLen = m_TextData.TrimEnd();
m_TextData.Clear();
- return m_iTextDatLen;
+ return m_iTextDataLen;
}
void CFDE_CSSSyntaxParser::SwitchMode(FDE_CSSSyntaxMode eMode) {
@@ -234,7 +234,6 @@ bool CFDE_CSSSyntaxParser::RestoreMode() {
return true;
}
-const FX_WCHAR* CFDE_CSSSyntaxParser::GetCurrentString(int32_t& iLength) const {
- iLength = m_iTextDatLen;
- return m_TextData.GetBuffer();
+CFX_WideStringC CFDE_CSSSyntaxParser::GetCurrentString() const {
+ return CFX_WideStringC(m_TextData.GetBuffer(), m_iTextDataLen);
}
diff --git a/xfa/fde/css/cfde_csssyntaxparser.h b/xfa/fde/css/cfde_csssyntaxparser.h
index 19a48e2b61..b583b98b15 100644
--- a/xfa/fde/css/cfde_csssyntaxparser.h
+++ b/xfa/fde/css/cfde_csssyntaxparser.h
@@ -45,7 +45,7 @@ class CFDE_CSSSyntaxParser {
int32_t iTextDatSize = 32,
bool bOnlyDeclaration = false);
FDE_CSSSyntaxStatus DoSyntaxParse();
- const FX_WCHAR* GetCurrentString(int32_t& iLength) const;
+ CFX_WideStringC GetCurrentString() const;
protected:
void Reset(bool bOnlyDeclaration);
@@ -64,7 +64,7 @@ class CFDE_CSSSyntaxParser {
CFDE_CSSTextBuf m_TextData;
CFDE_CSSTextBuf m_TextPlane;
- int32_t m_iTextDatLen;
+ int32_t m_iTextDataLen;
uint32_t m_dwCheck;
FDE_CSSSyntaxMode m_eMode;
FDE_CSSSyntaxStatus m_eStatus;