summaryrefslogtreecommitdiff
path: root/xfa/fde
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fde')
-rw-r--r--xfa/fde/css/cfde_cssfontfacerule.cpp12
-rw-r--r--xfa/fde/css/cfde_cssfontfacerule.h24
-rw-r--r--xfa/fde/css/cfde_cssmediarule.cpp26
-rw-r--r--xfa/fde/css/cfde_cssmediarule.h31
-rw-r--r--xfa/fde/css/cfde_cssrule.cpp11
-rw-r--r--xfa/fde/css/cfde_cssrule.h25
-rw-r--r--xfa/fde/css/cfde_cssrulecollection.cpp102
-rw-r--r--xfa/fde/css/cfde_cssrulecollection.h6
-rw-r--r--xfa/fde/css/cfde_cssstylerule.cpp2
-rw-r--r--xfa/fde/css/cfde_cssstylerule.h5
-rw-r--r--xfa/fde/css/cfde_cssstyleselector.cpp4
-rw-r--r--xfa/fde/css/cfde_cssstyleselector.h2
-rw-r--r--xfa/fde/css/cfde_cssstylesheet.cpp158
-rw-r--r--xfa/fde/css/cfde_cssstylesheet.h21
-rw-r--r--xfa/fde/css/cfde_cssstylesheet_unittest.cpp20
-rw-r--r--xfa/fde/css/cfde_csssyntaxparser.cpp140
-rw-r--r--xfa/fde/css/cfde_csssyntaxparser.h14
-rw-r--r--xfa/fde/css/fde_css.h14
-rw-r--r--xfa/fde/css/fde_cssdatatable.cpp30
-rw-r--r--xfa/fde/css/fde_cssdatatable.h8
20 files changed, 68 insertions, 587 deletions
diff --git a/xfa/fde/css/cfde_cssfontfacerule.cpp b/xfa/fde/css/cfde_cssfontfacerule.cpp
deleted file mode 100644
index 5d56eb8c6c..0000000000
--- a/xfa/fde/css/cfde_cssfontfacerule.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-// 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.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fde/css/cfde_cssfontfacerule.h"
-
-CFDE_CSSFontFaceRule::CFDE_CSSFontFaceRule()
- : CFDE_CSSRule(FDE_CSSRuleType::FontFace) {}
-
-CFDE_CSSFontFaceRule::~CFDE_CSSFontFaceRule() {}
diff --git a/xfa/fde/css/cfde_cssfontfacerule.h b/xfa/fde/css/cfde_cssfontfacerule.h
deleted file mode 100644
index e5249ccf18..0000000000
--- a/xfa/fde/css/cfde_cssfontfacerule.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FDE_CSS_CFDE_CSSFONTFACERULE_H_
-#define XFA_FDE_CSS_CFDE_CSSFONTFACERULE_H_
-
-#include "xfa/fde/css/cfde_cssdeclaration.h"
-#include "xfa/fde/css/cfde_cssrule.h"
-
-class CFDE_CSSFontFaceRule : public CFDE_CSSRule {
- public:
- CFDE_CSSFontFaceRule();
- ~CFDE_CSSFontFaceRule() override;
-
- CFDE_CSSDeclaration* GetDeclaration() { return &m_Declaration; }
-
- private:
- CFDE_CSSDeclaration m_Declaration;
-};
-
-#endif // XFA_FDE_CSS_CFDE_CSSFONTFACERULE_H_
diff --git a/xfa/fde/css/cfde_cssmediarule.cpp b/xfa/fde/css/cfde_cssmediarule.cpp
deleted file mode 100644
index 751f9d9fa1..0000000000
--- a/xfa/fde/css/cfde_cssmediarule.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fde/css/cfde_cssmediarule.h"
-
-#include "third_party/base/stl_util.h"
-
-CFDE_CSSMediaRule::CFDE_CSSMediaRule(uint32_t dwMediaList)
- : CFDE_CSSRule(FDE_CSSRuleType::Media), m_dwMediaList(dwMediaList) {}
-
-CFDE_CSSMediaRule::~CFDE_CSSMediaRule() {}
-
-uint32_t CFDE_CSSMediaRule::GetMediaList() const {
- return m_dwMediaList;
-}
-
-int32_t CFDE_CSSMediaRule::CountRules() const {
- return pdfium::CollectionSize<int32_t>(m_RuleArray);
-}
-
-CFDE_CSSRule* CFDE_CSSMediaRule::GetRule(int32_t index) {
- return m_RuleArray[index].get();
-}
diff --git a/xfa/fde/css/cfde_cssmediarule.h b/xfa/fde/css/cfde_cssmediarule.h
deleted file mode 100644
index 59febb2008..0000000000
--- a/xfa/fde/css/cfde_cssmediarule.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// 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.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FDE_CSS_CFDE_CSSMEDIARULE_H_
-#define XFA_FDE_CSS_CFDE_CSSMEDIARULE_H_
-
-#include <memory>
-#include <vector>
-
-#include "xfa/fde/css/cfde_cssrule.h"
-
-class CFDE_CSSMediaRule : public CFDE_CSSRule {
- public:
- explicit CFDE_CSSMediaRule(uint32_t dwMediaList);
- ~CFDE_CSSMediaRule() override;
-
- uint32_t GetMediaList() const;
- int32_t CountRules() const;
- CFDE_CSSRule* GetRule(int32_t index);
-
- std::vector<std::unique_ptr<CFDE_CSSRule>>& GetArray() { return m_RuleArray; }
-
- protected:
- uint32_t m_dwMediaList;
- std::vector<std::unique_ptr<CFDE_CSSRule>> m_RuleArray;
-};
-
-#endif // XFA_FDE_CSS_CFDE_CSSMEDIARULE_H_
diff --git a/xfa/fde/css/cfde_cssrule.cpp b/xfa/fde/css/cfde_cssrule.cpp
deleted file mode 100644
index 7a46703881..0000000000
--- a/xfa/fde/css/cfde_cssrule.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// 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.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fde/css/cfde_cssrule.h"
-
-CFDE_CSSRule::CFDE_CSSRule(FDE_CSSRuleType type) : m_type(type) {}
-
-CFDE_CSSRule::~CFDE_CSSRule() {}
diff --git a/xfa/fde/css/cfde_cssrule.h b/xfa/fde/css/cfde_cssrule.h
deleted file mode 100644
index 946132179b..0000000000
--- a/xfa/fde/css/cfde_cssrule.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FDE_CSS_CFDE_CSSRULE_H_
-#define XFA_FDE_CSS_CFDE_CSSRULE_H_
-
-#include "xfa/fde/css/fde_css.h"
-
-class CFDE_CSSRule {
- public:
- virtual ~CFDE_CSSRule();
-
- FDE_CSSRuleType GetType() const { return m_type; }
-
- protected:
- explicit CFDE_CSSRule(FDE_CSSRuleType type);
-
- private:
- FDE_CSSRuleType m_type;
-};
-
-#endif // XFA_FDE_CSS_CFDE_CSSRULE_H_
diff --git a/xfa/fde/css/cfde_cssrulecollection.cpp b/xfa/fde/css/cfde_cssrulecollection.cpp
index 286f619b68..6f12105d85 100644
--- a/xfa/fde/css/cfde_cssrulecollection.cpp
+++ b/xfa/fde/css/cfde_cssrulecollection.cpp
@@ -11,8 +11,6 @@
#include <memory>
#include "xfa/fde/css/cfde_cssdeclaration.h"
-#include "xfa/fde/css/cfde_cssmediarule.h"
-#include "xfa/fde/css/cfde_cssrule.h"
#include "xfa/fde/css/cfde_cssselector.h"
#include "xfa/fde/css/cfde_cssstylerule.h"
#include "xfa/fde/css/cfde_cssstylesheet.h"
@@ -38,78 +36,54 @@ CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
void CFDE_CSSRuleCollection::AddRulesFrom(
const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& sheets,
- uint32_t dwMediaList,
CFGAS_FontMgr* pFontMgr) {
int32_t iSheets = sheets.GetSize();
for (int32_t i = 0; i < iSheets; ++i) {
CFDE_CSSStyleSheet* pSheet = sheets.GetAt(i);
- if (uint32_t dwMatchMedia = pSheet->GetMediaList() & dwMediaList) {
- int32_t iRules = pSheet->CountRules();
- for (int32_t j = 0; j < iRules; j++) {
- AddRulesFrom(pSheet, pSheet->GetRule(j), dwMatchMedia, pFontMgr);
- }
+ int32_t iRules = pSheet->CountRules();
+ for (int32_t j = 0; j < iRules; j++) {
+ AddRulesFrom(pSheet, pSheet->GetRule(j), pFontMgr);
}
}
}
void CFDE_CSSRuleCollection::AddRulesFrom(CFDE_CSSStyleSheet* pStyleSheet,
- CFDE_CSSRule* pRule,
- uint32_t dwMediaList,
+ CFDE_CSSStyleRule* pStyleRule,
CFGAS_FontMgr* pFontMgr) {
- switch (pRule->GetType()) {
- case FDE_CSSRuleType::Style: {
- CFDE_CSSStyleRule* pStyleRule = static_cast<CFDE_CSSStyleRule*>(pRule);
- CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration();
- int32_t iSelectors = pStyleRule->CountSelectorLists();
- for (int32_t i = 0; i < iSelectors; ++i) {
- CFDE_CSSSelector* pSelector = pStyleRule->GetSelectorList(i);
- if (pSelector->GetType() == FDE_CSSSelectorType::Pseudo) {
- Data* pData = NewRuleData(pSelector, pDeclaration);
- AddRuleTo(&m_pPseudoRules, pData);
- continue;
- }
- if (pSelector->GetNameHash() != FDE_CSSUNIVERSALHASH) {
- AddRuleTo(&m_TagRules, pSelector->GetNameHash(), pSelector,
- pDeclaration);
- continue;
- }
- CFDE_CSSSelector* pNext = pSelector->GetNextSelector();
- if (!pNext) {
- Data* pData = NewRuleData(pSelector, pDeclaration);
- AddRuleTo(&m_pUniversalRules, pData);
- continue;
- }
- switch (pNext->GetType()) {
- case FDE_CSSSelectorType::ID:
- AddRuleTo(&m_IDRules, pNext->GetNameHash(), pSelector,
- pDeclaration);
- break;
- case FDE_CSSSelectorType::Class:
- AddRuleTo(&m_ClassRules, pNext->GetNameHash(), pSelector,
- pDeclaration);
- break;
- case FDE_CSSSelectorType::Descendant:
- case FDE_CSSSelectorType::Element:
- AddRuleTo(&m_pUniversalRules, NewRuleData(pSelector, pDeclaration));
- break;
- default:
- ASSERT(false);
- break;
- }
- }
- } break;
- case FDE_CSSRuleType::Media: {
- CFDE_CSSMediaRule* pMediaRule = static_cast<CFDE_CSSMediaRule*>(pRule);
- if (pMediaRule->GetMediaList() & dwMediaList) {
- int32_t iRules = pMediaRule->CountRules();
- for (int32_t i = 0; i < iRules; ++i) {
- AddRulesFrom(pStyleSheet, pMediaRule->GetRule(i), dwMediaList,
- pFontMgr);
- }
- }
- } break;
- default:
- break;
+ CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration();
+ int32_t iSelectors = pStyleRule->CountSelectorLists();
+ for (int32_t i = 0; i < iSelectors; ++i) {
+ CFDE_CSSSelector* pSelector = pStyleRule->GetSelectorList(i);
+ if (pSelector->GetType() == FDE_CSSSelectorType::Pseudo) {
+ Data* pData = NewRuleData(pSelector, pDeclaration);
+ AddRuleTo(&m_pPseudoRules, pData);
+ continue;
+ }
+ if (pSelector->GetNameHash() != FDE_CSSUNIVERSALHASH) {
+ AddRuleTo(&m_TagRules, pSelector->GetNameHash(), pSelector, pDeclaration);
+ continue;
+ }
+ CFDE_CSSSelector* pNext = pSelector->GetNextSelector();
+ if (!pNext) {
+ Data* pData = NewRuleData(pSelector, pDeclaration);
+ AddRuleTo(&m_pUniversalRules, pData);
+ continue;
+ }
+ switch (pNext->GetType()) {
+ case FDE_CSSSelectorType::ID:
+ AddRuleTo(&m_IDRules, pNext->GetNameHash(), pSelector, pDeclaration);
+ break;
+ case FDE_CSSSelectorType::Class:
+ AddRuleTo(&m_ClassRules, pNext->GetNameHash(), pSelector, pDeclaration);
+ break;
+ case FDE_CSSSelectorType::Descendant:
+ case FDE_CSSSelectorType::Element:
+ AddRuleTo(&m_pUniversalRules, NewRuleData(pSelector, pDeclaration));
+ break;
+ default:
+ ASSERT(false);
+ break;
+ }
}
}
diff --git a/xfa/fde/css/cfde_cssrulecollection.h b/xfa/fde/css/cfde_cssrulecollection.h
index 1433a5a5f2..75e232abaa 100644
--- a/xfa/fde/css/cfde_cssrulecollection.h
+++ b/xfa/fde/css/cfde_cssrulecollection.h
@@ -12,8 +12,8 @@
#include "core/fxcrt/fx_basic.h"
class CFDE_CSSDeclaration;
-class CFDE_CSSRule;
class CFDE_CSSSelector;
+class CFDE_CSSStyleRule;
class CFDE_CSSStyleSheet;
class CFGAS_FontMgr;
@@ -33,7 +33,6 @@ class CFDE_CSSRuleCollection {
~CFDE_CSSRuleCollection();
void AddRulesFrom(const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& sheets,
- uint32_t dwMediaList,
CFGAS_FontMgr* pFontMgr);
void Clear();
int32_t CountSelectors() const { return m_iSelectors; }
@@ -58,8 +57,7 @@ class CFDE_CSSRuleCollection {
protected:
void AddRulesFrom(CFDE_CSSStyleSheet* pStyleSheet,
- CFDE_CSSRule* pRule,
- uint32_t dwMediaList,
+ CFDE_CSSStyleRule* pRule,
CFGAS_FontMgr* pFontMgr);
void AddRuleTo(std::map<uint32_t, Data*>* pMap,
uint32_t dwKey,
diff --git a/xfa/fde/css/cfde_cssstylerule.cpp b/xfa/fde/css/cfde_cssstylerule.cpp
index 09c4a43f34..04f6cfff08 100644
--- a/xfa/fde/css/cfde_cssstylerule.cpp
+++ b/xfa/fde/css/cfde_cssstylerule.cpp
@@ -6,7 +6,7 @@
#include "xfa/fde/css/cfde_cssstylerule.h"
-CFDE_CSSStyleRule::CFDE_CSSStyleRule() : CFDE_CSSRule(FDE_CSSRuleType::Style) {}
+CFDE_CSSStyleRule::CFDE_CSSStyleRule() {}
CFDE_CSSStyleRule::~CFDE_CSSStyleRule() {}
diff --git a/xfa/fde/css/cfde_cssstylerule.h b/xfa/fde/css/cfde_cssstylerule.h
index bed0a5ec12..075ab8d478 100644
--- a/xfa/fde/css/cfde_cssstylerule.h
+++ b/xfa/fde/css/cfde_cssstylerule.h
@@ -11,13 +11,12 @@
#include <vector>
#include "xfa/fde/css/cfde_cssdeclaration.h"
-#include "xfa/fde/css/cfde_cssrule.h"
#include "xfa/fde/css/cfde_cssselector.h"
-class CFDE_CSSStyleRule : public CFDE_CSSRule {
+class CFDE_CSSStyleRule {
public:
CFDE_CSSStyleRule();
- ~CFDE_CSSStyleRule() override;
+ ~CFDE_CSSStyleRule();
size_t CountSelectorLists() const;
CFDE_CSSSelector* GetSelectorList(int32_t index) const;
diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp
index 1539894017..8452c78ff5 100644
--- a/xfa/fde/css/cfde_cssstyleselector.cpp
+++ b/xfa/fde/css/cfde_cssstyleselector.cpp
@@ -100,13 +100,13 @@ void CFDE_CSSStyleSelector::SetStylePriority(
m_ePriorities[static_cast<int32_t>(ePriority)] = eType;
}
-void CFDE_CSSStyleSelector::UpdateStyleIndex(uint32_t dwMediaList) {
+void CFDE_CSSStyleSelector::UpdateStyleIndex() {
Reset();
// TODO(dsinclair): Hard coded size bad. This should probably just be a map.
for (int32_t iGroup = 0; iGroup < 3; ++iGroup) {
CFDE_CSSRuleCollection& rules = m_RuleCollection[iGroup];
- rules.AddRulesFrom(m_SheetGroups[iGroup], dwMediaList, m_pFontMgr);
+ rules.AddRulesFrom(m_SheetGroups[iGroup], m_pFontMgr);
}
}
diff --git a/xfa/fde/css/cfde_cssstyleselector.h b/xfa/fde/css/cfde_cssstyleselector.h
index 6a7ae99216..1ddb67243c 100644
--- a/xfa/fde/css/cfde_cssstyleselector.h
+++ b/xfa/fde/css/cfde_cssstyleselector.h
@@ -38,7 +38,7 @@ class CFDE_CSSStyleSelector {
const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>* pArray);
void SetStylePriority(FDE_CSSStyleSheetGroup eType,
FDE_CSSStyleSheetPriority ePriority);
- void UpdateStyleIndex(uint32_t dwMediaList);
+ void UpdateStyleIndex();
CFDE_CSSAccelerator* InitAccelerator();
CFDE_CSSComputedStyle* CreateComputedStyle(
CFDE_CSSComputedStyle* pParentStyle);
diff --git a/xfa/fde/css/cfde_cssstylesheet.cpp b/xfa/fde/css/cfde_cssstylesheet.cpp
index 4ff1b97916..7dc122f1da 100644
--- a/xfa/fde/css/cfde_cssstylesheet.cpp
+++ b/xfa/fde/css/cfde_cssstylesheet.cpp
@@ -11,17 +11,11 @@
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
#include "xfa/fde/css/cfde_cssdeclaration.h"
-#include "xfa/fde/css/cfde_cssfontfacerule.h"
-#include "xfa/fde/css/cfde_cssmediarule.h"
-#include "xfa/fde/css/cfde_cssrule.h"
#include "xfa/fde/css/cfde_cssstylerule.h"
#include "xfa/fde/css/fde_cssdatatable.h"
#include "xfa/fgas/crt/fgas_codepage.h"
-CFDE_CSSStyleSheet::CFDE_CSSStyleSheet()
- : m_wRefCount(1), m_dwMediaList(FDE_CSSMEDIATYPE_ALL) {
- ASSERT(m_dwMediaList > 0);
-}
+CFDE_CSSStyleSheet::CFDE_CSSStyleSheet() : m_wRefCount(1) {}
CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() {
Reset();
@@ -43,45 +37,27 @@ uint32_t CFDE_CSSStyleSheet::Release() {
return dwRefCount;
}
-uint32_t CFDE_CSSStyleSheet::GetMediaList() const {
- return m_dwMediaList;
-}
-
int32_t CFDE_CSSStyleSheet::CountRules() const {
return pdfium::CollectionSize<int32_t>(m_RuleArray);
}
-CFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) {
+CFDE_CSSStyleRule* CFDE_CSSStyleSheet::GetRule(int32_t index) {
return m_RuleArray[index].get();
}
-bool CFDE_CSSStyleSheet::LoadFromBuffer(const FX_WCHAR* pBuffer,
- int32_t iBufSize) {
+bool CFDE_CSSStyleSheet::LoadBuffer(const FX_WCHAR* pBuffer, int32_t iBufSize) {
ASSERT(pBuffer && iBufSize > 0);
auto pSyntax = pdfium::MakeUnique<CFDE_CSSSyntaxParser>();
- return pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax.get());
-}
+ if (!pSyntax->Init(pBuffer, iBufSize))
+ return false;
-bool CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) {
Reset();
FDE_CSSSyntaxStatus eStatus;
do {
switch (eStatus = pSyntax->DoSyntaxParse()) {
case FDE_CSSSyntaxStatus::StyleRule:
- eStatus = LoadStyleRule(pSyntax, &m_RuleArray);
- break;
- case FDE_CSSSyntaxStatus::MediaRule:
- eStatus = LoadMediaRule(pSyntax);
- break;
- case FDE_CSSSyntaxStatus::FontFaceRule:
- eStatus = LoadFontFaceRule(pSyntax, &m_RuleArray);
- break;
- case FDE_CSSSyntaxStatus::ImportRule:
- eStatus = LoadImportRule(pSyntax);
- break;
- case FDE_CSSSyntaxStatus::PageRule:
- eStatus = LoadPageRule(pSyntax);
+ eStatus = LoadStyleRule(pSyntax.get(), &m_RuleArray);
break;
default:
break;
@@ -92,53 +68,9 @@ bool CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) {
return eStatus != FDE_CSSSyntaxStatus::Error;
}
-FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadMediaRule(
- CFDE_CSSSyntaxParser* pSyntax) {
- uint32_t dwMediaList = 0;
- CFDE_CSSMediaRule* pMediaRule = nullptr;
- for (;;) {
- switch (pSyntax->DoSyntaxParse()) {
- case FDE_CSSSyntaxStatus::MediaType: {
- int32_t iLen;
- const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen);
- const FDE_CSSMEDIATYPETABLE* pMediaType =
- FDE_GetCSSMediaTypeByName(CFX_WideStringC(psz, iLen));
- if (pMediaType)
- dwMediaList |= pMediaType->wValue;
- } break;
- case FDE_CSSSyntaxStatus::StyleRule:
- if (pMediaRule) {
- FDE_CSSSyntaxStatus eStatus =
- LoadStyleRule(pSyntax, &pMediaRule->GetArray());
- if (eStatus < FDE_CSSSyntaxStatus::None) {
- return eStatus;
- }
- } else {
- SkipRuleSet(pSyntax);
- }
- break;
- case FDE_CSSSyntaxStatus::DeclOpen:
- if ((dwMediaList & m_dwMediaList) > 0 && !pMediaRule) {
- m_RuleArray.push_back(
- pdfium::MakeUnique<CFDE_CSSMediaRule>(dwMediaList));
- pMediaRule =
- static_cast<CFDE_CSSMediaRule*>(m_RuleArray.back().get());
- }
- break;
- case FDE_CSSSyntaxStatus::DeclClose:
- return FDE_CSSSyntaxStatus::None;
- case FDE_CSSSyntaxStatus::EOS:
- return FDE_CSSSyntaxStatus::EOS;
- case FDE_CSSSyntaxStatus::Error:
- default:
- return FDE_CSSSyntaxStatus::Error;
- }
- }
-}
-
FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule(
CFDE_CSSSyntaxParser* pSyntax,
- std::vector<std::unique_ptr<CFDE_CSSRule>>* ruleArray) {
+ std::vector<std::unique_ptr<CFDE_CSSStyleRule>>* ruleArray) {
std::vector<std::unique_ptr<CFDE_CSSSelector>> selectors;
CFDE_CSSStyleRule* pStyleRule = nullptr;
@@ -148,7 +80,7 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule(
propertyArgs.pStringCache = &m_StringCache;
propertyArgs.pProperty = nullptr;
CFX_WideString wsName;
- for (;;) {
+ while (1) {
switch (pSyntax->DoSyntaxParse()) {
case FDE_CSSSyntaxStatus::Selector: {
pszValue = pSyntax->GetCurrentString(iValueLen);
@@ -206,74 +138,8 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule(
}
}
-FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadFontFaceRule(
- CFDE_CSSSyntaxParser* pSyntax,
- std::vector<std::unique_ptr<CFDE_CSSRule>>* ruleArray) {
- CFDE_CSSFontFaceRule* pFontFaceRule = nullptr;
- const FX_WCHAR* pszValue = nullptr;
- int32_t iValueLen = 0;
- FDE_CSSPropertyArgs propertyArgs;
- propertyArgs.pStringCache = &m_StringCache;
- propertyArgs.pProperty = nullptr;
- for (;;) {
- switch (pSyntax->DoSyntaxParse()) {
- case FDE_CSSSyntaxStatus::PropertyName:
- pszValue = pSyntax->GetCurrentString(iValueLen);
- propertyArgs.pProperty =
- FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen));
- break;
- case FDE_CSSSyntaxStatus::PropertyValue:
- if (propertyArgs.pProperty) {
- pszValue = pSyntax->GetCurrentString(iValueLen);
- if (iValueLen > 0) {
- pFontFaceRule->GetDeclaration()->AddProperty(&propertyArgs,
- pszValue, iValueLen);
- }
- }
- break;
- case FDE_CSSSyntaxStatus::DeclOpen:
- if (!pFontFaceRule) {
- auto rule = pdfium::MakeUnique<CFDE_CSSFontFaceRule>();
- pFontFaceRule = rule.get();
- ruleArray->push_back(std::move(rule));
- }
- break;
- case FDE_CSSSyntaxStatus::DeclClose:
- return FDE_CSSSyntaxStatus::None;
- case FDE_CSSSyntaxStatus::EOS:
- return FDE_CSSSyntaxStatus::EOS;
- case FDE_CSSSyntaxStatus::Error:
- default:
- return FDE_CSSSyntaxStatus::Error;
- }
- }
-}
-
-FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadImportRule(
- CFDE_CSSSyntaxParser* pSyntax) {
- for (;;) {
- switch (pSyntax->DoSyntaxParse()) {
- case FDE_CSSSyntaxStatus::ImportClose:
- return FDE_CSSSyntaxStatus::None;
- case FDE_CSSSyntaxStatus::URI:
- break;
- case FDE_CSSSyntaxStatus::EOS:
- return FDE_CSSSyntaxStatus::EOS;
- case FDE_CSSSyntaxStatus::Error:
- default:
- return FDE_CSSSyntaxStatus::Error;
- }
- }
-}
-
-FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadPageRule(
- CFDE_CSSSyntaxParser* pSyntax) {
- return SkipRuleSet(pSyntax);
-}
-
-FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::SkipRuleSet(
- CFDE_CSSSyntaxParser* pSyntax) {
- for (;;) {
+void CFDE_CSSStyleSheet::SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax) {
+ while (1) {
switch (pSyntax->DoSyntaxParse()) {
case FDE_CSSSyntaxStatus::Selector:
case FDE_CSSSyntaxStatus::DeclOpen:
@@ -281,12 +147,10 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::SkipRuleSet(
case FDE_CSSSyntaxStatus::PropertyValue:
break;
case FDE_CSSSyntaxStatus::DeclClose:
- return FDE_CSSSyntaxStatus::None;
case FDE_CSSSyntaxStatus::EOS:
- return FDE_CSSSyntaxStatus::EOS;
case FDE_CSSSyntaxStatus::Error:
default:
- return FDE_CSSSyntaxStatus::Error;
+ return;
}
}
}
diff --git a/xfa/fde/css/cfde_cssstylesheet.h b/xfa/fde/css/cfde_cssstylesheet.h
index 2268efa2e4..8bbcc485bb 100644
--- a/xfa/fde/css/cfde_cssstylesheet.h
+++ b/xfa/fde/css/cfde_cssstylesheet.h
@@ -15,7 +15,7 @@
#include "core/fxcrt/fx_string.h"
#include "xfa/fde/css/cfde_csssyntaxparser.h"
-class CFDE_CSSRule;
+class CFDE_CSSStyleRule;
class CFDE_CSSStyleSheet : public IFX_Retainable {
public:
@@ -26,29 +26,20 @@ class CFDE_CSSStyleSheet : public IFX_Retainable {
uint32_t Retain() override;
uint32_t Release() override;
- bool LoadFromBuffer(const FX_WCHAR* pBuffer, int32_t iBufSize);
+ bool LoadBuffer(const FX_WCHAR* pBuffer, int32_t iBufSize);
- uint32_t GetMediaList() const;
int32_t CountRules() const;
- CFDE_CSSRule* GetRule(int32_t index);
+ CFDE_CSSStyleRule* GetRule(int32_t index);
private:
void Reset();
- bool LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax);
FDE_CSSSyntaxStatus LoadStyleRule(
CFDE_CSSSyntaxParser* pSyntax,
- std::vector<std::unique_ptr<CFDE_CSSRule>>* ruleArray);
- FDE_CSSSyntaxStatus LoadImportRule(CFDE_CSSSyntaxParser* pSyntax);
- FDE_CSSSyntaxStatus LoadPageRule(CFDE_CSSSyntaxParser* pSyntax);
- FDE_CSSSyntaxStatus LoadMediaRule(CFDE_CSSSyntaxParser* pSyntax);
- FDE_CSSSyntaxStatus LoadFontFaceRule(
- CFDE_CSSSyntaxParser* pSyntax,
- std::vector<std::unique_ptr<CFDE_CSSRule>>* ruleArray);
- FDE_CSSSyntaxStatus SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax);
+ std::vector<std::unique_ptr<CFDE_CSSStyleRule>>* ruleArray);
+ void SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax);
uint16_t m_wRefCount;
- uint32_t m_dwMediaList;
- std::vector<std::unique_ptr<CFDE_CSSRule>> m_RuleArray;
+ std::vector<std::unique_ptr<CFDE_CSSStyleRule>> m_RuleArray;
std::unordered_map<uint32_t, FX_WCHAR*> m_StringCache;
};
diff --git a/xfa/fde/css/cfde_cssstylesheet_unittest.cpp b/xfa/fde/css/cfde_cssstylesheet_unittest.cpp
index 080b45aa1b..1c50f65607 100644
--- a/xfa/fde/css/cfde_cssstylesheet_unittest.cpp
+++ b/xfa/fde/css/cfde_cssstylesheet_unittest.cpp
@@ -15,7 +15,6 @@
#include "xfa/fde/css/cfde_cssdeclaration.h"
#include "xfa/fde/css/cfde_cssenumvalue.h"
#include "xfa/fde/css/cfde_cssnumbervalue.h"
-#include "xfa/fde/css/cfde_cssrule.h"
#include "xfa/fde/css/cfde_cssstylerule.h"
#include "xfa/fde/css/cfde_cssvaluelist.h"
@@ -33,13 +32,10 @@ class CFDE_CSSStyleSheetTest : public testing::Test {
size_t decl_count) {
ASSERT(sheet_);
- EXPECT_TRUE(sheet_->LoadFromBuffer(buf, FXSYS_wcslen(buf)));
+ EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
EXPECT_EQ(sheet_->CountRules(), 1);
- CFDE_CSSRule* rule = sheet_->GetRule(0);
- EXPECT_EQ(rule->GetType(), FDE_CSSRuleType::Style);
-
- CFDE_CSSStyleRule* style = static_cast<CFDE_CSSStyleRule*>(rule);
+ CFDE_CSSStyleRule* style = sheet_->GetRule(0);
EXPECT_EQ(selectors.size(), style->CountSelectorLists());
for (size_t i = 0; i < selectors.size(); i++) {
@@ -93,13 +89,10 @@ class CFDE_CSSStyleSheetTest : public testing::Test {
TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) {
const FX_WCHAR* buf =
L"a { border: 10px; }\nb { text-decoration: underline; }";
- EXPECT_TRUE(sheet_->LoadFromBuffer(buf, FXSYS_wcslen(buf)));
+ EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
EXPECT_EQ(2, sheet_->CountRules());
- CFDE_CSSRule* rule = sheet_->GetRule(0);
- EXPECT_EQ(FDE_CSSRuleType::Style, rule->GetType());
-
- CFDE_CSSStyleRule* style = static_cast<CFDE_CSSStyleRule*>(rule);
+ CFDE_CSSStyleRule* style = sheet_->GetRule(0);
EXPECT_EQ(1UL, style->CountSelectorLists());
bool found_selector = false;
@@ -123,10 +116,7 @@ TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) {
VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0,
FDE_CSSNumberType::Pixels);
- rule = sheet_->GetRule(1);
- EXPECT_EQ(FDE_CSSRuleType::Style, rule->GetType());
-
- style = static_cast<CFDE_CSSStyleRule*>(rule);
+ style = sheet_->GetRule(1);
EXPECT_EQ(1UL, style->CountSelectorLists());
found_selector = false;
diff --git a/xfa/fde/css/cfde_csssyntaxparser.cpp b/xfa/fde/css/cfde_csssyntaxparser.cpp
index a24b4eee66..f562a374ac 100644
--- a/xfa/fde/css/cfde_csssyntaxparser.cpp
+++ b/xfa/fde/css/cfde_csssyntaxparser.cpp
@@ -19,20 +19,6 @@ bool IsSelectorStart(FX_WCHAR wch) {
(wch >= 'A' && wch <= 'Z');
}
-bool ParseCSSURI(const FX_WCHAR* pszValue, int32_t* iOffset, int32_t* iLength) {
- ASSERT(pszValue && *iLength > 0);
- if (*iLength < 6 || pszValue[*iLength - 1] != ')' ||
- FXSYS_wcsnicmp(L"url(", pszValue, 4)) {
- return false;
- }
- if (CFDE_CSSDeclaration::ParseCSSString(pszValue + 4, *iLength - 5, iOffset,
- iLength)) {
- *iOffset += 4;
- return true;
- }
- return false;
-}
-
} // namespace
CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser()
@@ -85,10 +71,6 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() {
switch (m_eMode) {
case FDE_CSSSyntaxMode::RuleSet:
switch (wch) {
- case '@':
- m_TextPlane.MoveNext();
- SwitchMode(FDE_CSSSyntaxMode::AtRule);
- break;
case '}':
m_TextPlane.MoveNext();
if (RestoreMode())
@@ -194,128 +176,6 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() {
}
m_TextPlane.MoveNext();
break;
- case FDE_CSSSyntaxMode::MediaType:
- switch (wch) {
- case ',':
- m_TextPlane.MoveNext();
- SwitchMode(FDE_CSSSyntaxMode::MediaType);
- if (m_iTextDatLen > 0)
- return FDE_CSSSyntaxStatus::MediaType;
- break;
- case '{': {
- if (m_ModeStack.empty() ||
- m_ModeStack.top() != FDE_CSSSyntaxMode::MediaRule) {
- m_eStatus = FDE_CSSSyntaxStatus::Error;
- return m_eStatus;
- }
-
- if (m_TextData.GetLength() > 0) {
- SaveTextData();
- return FDE_CSSSyntaxStatus::MediaType;
- }
- m_TextPlane.MoveNext();
-
- // Replace the MediaRule with a RuleSet rule.
- m_ModeStack.top() = FDE_CSSSyntaxMode::RuleSet;
-
- SwitchMode(FDE_CSSSyntaxMode::RuleSet);
- return FDE_CSSSyntaxStatus::DeclOpen;
- }
- case ';': {
- if (m_ModeStack.empty() ||
- m_ModeStack.top() != FDE_CSSSyntaxMode::Import) {
- m_eStatus = FDE_CSSSyntaxStatus::Error;
- return m_eStatus;
- }
-
- if (m_TextData.GetLength() > 0) {
- SaveTextData();
- if (IsImportEnabled())
- return FDE_CSSSyntaxStatus::MediaType;
- } else {
- bool bEnabled = IsImportEnabled();
- m_TextPlane.MoveNext();
- m_ModeStack.pop();
- SwitchMode(FDE_CSSSyntaxMode::RuleSet);
- if (bEnabled) {
- DisableImport();
- return FDE_CSSSyntaxStatus::ImportClose;
- }
- }
- } break;
- case '/':
- if (m_TextPlane.GetNextChar() == '*') {
- if (SwitchToComment() > 0)
- return FDE_CSSSyntaxStatus::MediaType;
- break;
- }
- default:
- AppendChar(wch);
- break;
- }
- break;
- case FDE_CSSSyntaxMode::URI: {
- if (m_ModeStack.empty() ||
- m_ModeStack.top() != FDE_CSSSyntaxMode::Import) {
- m_eStatus = FDE_CSSSyntaxStatus::Error;
- return m_eStatus;
- }
-
- if (wch <= ' ' || wch == ';') {
- int32_t iURIStart, iURILength = m_TextData.GetLength();
- if (iURILength > 0 &&
- ParseCSSURI(m_TextData.GetBuffer(), &iURIStart, &iURILength)) {
- m_TextData.Subtract(iURIStart, iURILength);
- SwitchMode(FDE_CSSSyntaxMode::MediaType);
- if (IsImportEnabled())
- return FDE_CSSSyntaxStatus::URI;
- break;
- }
- }
- AppendChar(wch);
- } break;
- case FDE_CSSSyntaxMode::AtRule:
- if (wch > ' ') {
- AppendChar(wch);
- } else {
- int32_t iLen = m_TextData.GetLength();
- const FX_WCHAR* psz = m_TextData.GetBuffer();
- if (FXSYS_wcsncmp(L"charset", psz, iLen) == 0) {
- SwitchMode(FDE_CSSSyntaxMode::Charset);
- } else if (FXSYS_wcsncmp(L"import", psz, iLen) == 0) {
- m_ModeStack.push(FDE_CSSSyntaxMode::Import);
- SwitchMode(FDE_CSSSyntaxMode::URI);
- if (IsImportEnabled())
- return FDE_CSSSyntaxStatus::ImportRule;
- break;
- } else if (FXSYS_wcsncmp(L"media", psz, iLen) == 0) {
- m_ModeStack.push(FDE_CSSSyntaxMode::MediaRule);
- SwitchMode(FDE_CSSSyntaxMode::MediaType);
- return FDE_CSSSyntaxStatus::MediaRule;
- } else if (FXSYS_wcsncmp(L"font-face", psz, iLen) == 0) {
- SwitchMode(FDE_CSSSyntaxMode::Selector);
- return FDE_CSSSyntaxStatus::FontFaceRule;
- } else if (FXSYS_wcsncmp(L"page", psz, iLen) == 0) {
- SwitchMode(FDE_CSSSyntaxMode::Selector);
- return FDE_CSSSyntaxStatus::PageRule;
- } else {
- SwitchMode(FDE_CSSSyntaxMode::UnknownRule);
- }
- }
- break;
- case FDE_CSSSyntaxMode::Charset:
- if (wch == ';') {
- m_TextPlane.MoveNext();
- SwitchMode(FDE_CSSSyntaxMode::RuleSet);
- if (IsCharsetEnabled()) {
- DisableCharset();
- if (m_iTextDatLen > 0)
- return FDE_CSSSyntaxStatus::Charset;
- }
- } else {
- AppendChar(wch);
- }
- break;
case FDE_CSSSyntaxMode::UnknownRule:
if (wch == ';')
SwitchMode(FDE_CSSSyntaxMode::RuleSet);
diff --git a/xfa/fde/css/cfde_csssyntaxparser.h b/xfa/fde/css/cfde_csssyntaxparser.h
index 131fe4bf21..19a48e2b61 100644
--- a/xfa/fde/css/cfde_csssyntaxparser.h
+++ b/xfa/fde/css/cfde_csssyntaxparser.h
@@ -17,13 +17,7 @@
enum class FDE_CSSSyntaxMode {
RuleSet,
Comment,
- AtRule,
UnknownRule,
- Charset,
- Import,
- MediaRule,
- URI,
- MediaType,
Selector,
PropertyName,
PropertyValue,
@@ -33,15 +27,7 @@ enum class FDE_CSSSyntaxStatus : uint8_t {
Error,
EOS,
None,
- Charset,
- ImportRule,
- ImportClose,
- PageRule,
StyleRule,
- FontFaceRule,
- MediaRule,
- MediaType,
- URI,
Selector,
DeclOpen,
DeclClose,
diff --git a/xfa/fde/css/fde_css.h b/xfa/fde/css/fde_css.h
index 2194657670..571f8a58d9 100644
--- a/xfa/fde/css/fde_css.h
+++ b/xfa/fde/css/fde_css.h
@@ -12,18 +12,6 @@
#include "xfa/fgas/crt/fgas_utils.h"
#include "xfa/fgas/font/cfgas_fontmgr.h"
-enum FDE_CSSMEDIATYPE {
- FDE_CSSMEDIATYPE_Braille = 0x01,
- FDE_CSSMEDIATYPE_Emboss = 0x02,
- FDE_CSSMEDIATYPE_Handheld = 0x04,
- FDE_CSSMEDIATYPE_Print = 0x08,
- FDE_CSSMEDIATYPE_Projection = 0x10,
- FDE_CSSMEDIATYPE_Screen = 0x20,
- FDE_CSSMEDIATYPE_TTY = 0x40,
- FDE_CSSMEDIATYPE_TV = 0x80,
- FDE_CSSMEDIATYPE_ALL = 0xFF,
-};
-
enum FDE_CSSVALUETYPE {
FDE_CSSVALUETYPE_Primitive = 1 << 0,
FDE_CSSVALUETYPE_List = 1 << 1,
@@ -147,8 +135,6 @@ enum class FDE_CSSSelectorType : uint8_t {
ID,
};
-enum class FDE_CSSRuleType : uint8_t { Style, Media, FontFace };
-
enum class FDE_CSSLengthUnit : uint8_t {
Auto,
None,
diff --git a/xfa/fde/css/fde_cssdatatable.cpp b/xfa/fde/css/fde_cssdatatable.cpp
index fd4ef6bffb..a8a0920afa 100644
--- a/xfa/fde/css/fde_cssdatatable.cpp
+++ b/xfa/fde/css/fde_cssdatatable.cpp
@@ -173,14 +173,6 @@ static_assert(g_iCSSPropertyValueCount ==
static_cast<int32_t>(FDE_CSSPropertyValue::LAST_MARKER),
"Property value table differs in size from property value enum");
-static const FDE_CSSMEDIATYPETABLE g_FDE_CSSMediaTypes[] = {
- {0xF09, FDE_CSSMEDIATYPE_Emboss}, {FDE_CSSMEDIATYPE_Screen},
- {0x536A, FDE_CSSMEDIATYPE_TV}, {0x741D, FDE_CSSMEDIATYPE_Projection},
- {0x76ED, FDE_CSSMEDIATYPE_Print}, {0x7CFB, FDE_CSSMEDIATYPE_Braille},
- {0x9578, FDE_CSSMEDIATYPE_Handheld}, {0xC8E1, FDE_CSSMEDIATYPE_TTY},
- {0xD0F9, FDE_CSSMEDIATYPE_ALL},
-};
-
static const FDE_CSSLengthUnitTable g_FDE_CSSLengthUnits[] = {
{0x0672, FDE_CSSNumberType::EMS},
{0x067D, FDE_CSSNumberType::EXS},
@@ -259,28 +251,6 @@ const FDE_CSSPropertyValueTable* FDE_GetCSSPropertyValueByName(
return nullptr;
}
-const FDE_CSSMEDIATYPETABLE* FDE_GetCSSMediaTypeByName(
- const CFX_WideStringC& wsName) {
- ASSERT(!wsName.IsEmpty());
- uint16_t wHash = FX_HashCode_GetW(wsName, true);
- int32_t iEnd =
- sizeof(g_FDE_CSSMediaTypes) / sizeof(FDE_CSSMEDIATYPETABLE) - 1;
- int32_t iMid, iStart = 0;
- uint16_t uMid;
- do {
- iMid = (iStart + iEnd) / 2;
- uMid = g_FDE_CSSMediaTypes[iMid].wHash;
- if (wHash == uMid) {
- return g_FDE_CSSMediaTypes + iMid;
- } else if (wHash > uMid) {
- iStart = iMid + 1;
- } else {
- iEnd = iMid - 1;
- }
- } while (iStart <= iEnd);
- return nullptr;
-}
-
const FDE_CSSLengthUnitTable* FDE_GetCSSLengthUnitByName(
const CFX_WideStringC& wsName) {
ASSERT(!wsName.IsEmpty());
diff --git a/xfa/fde/css/fde_cssdatatable.h b/xfa/fde/css/fde_cssdatatable.h
index 4769f16658..a9de83a088 100644
--- a/xfa/fde/css/fde_cssdatatable.h
+++ b/xfa/fde/css/fde_cssdatatable.h
@@ -31,11 +31,6 @@ struct FDE_CSSPropertyValueTable {
uint32_t dwHash;
};
-struct FDE_CSSMEDIATYPETABLE {
- uint16_t wHash;
- uint16_t wValue;
-};
-
struct FDE_CSSLengthUnitTable {
uint16_t wHash;
FDE_CSSNumberType wValue;
@@ -59,9 +54,6 @@ const FDE_CSSPropertyTable* FDE_GetCSSPropertyByEnum(FDE_CSSProperty eName);
const FDE_CSSPropertyValueTable* FDE_GetCSSPropertyValueByName(
const CFX_WideStringC& wsName);
-const FDE_CSSMEDIATYPETABLE* FDE_GetCSSMediaTypeByName(
- const CFX_WideStringC& wsName);
-
const FDE_CSSLengthUnitTable* FDE_GetCSSLengthUnitByName(
const CFX_WideStringC& wsName);