summaryrefslogtreecommitdiff
path: root/xfa/fde/css/cfde_cssstylesheet.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-01-23 13:54:53 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-01-23 19:48:54 +0000
commit6414b273506f97012f82c8a32c020b483d5df31a (patch)
treef790a25f03e78fe084ee22cb16418d95deaf3dd3 /xfa/fde/css/cfde_cssstylesheet.cpp
parenta0b2d23d1121202d3821291483943a47a3c9e32e (diff)
downloadpdfium-6414b273506f97012f82c8a32c020b483d5df31a.tar.xz
Cleanup CSS parsing
This Cl removes unused CSS parsing code. The only caller of CFDE_CSSStyleSheet::LoadeBuffer is from CXFA_TextParser which provides a static string. So, we know there are no Media rules, Import rules, FontFace rules or Page rules in the input style. These rules are also not allowed in inline styles. This CL removes the supporting code. Change-Id: I3a559352b2dd0769c465cbd3da40d1db5f9577b0 Reviewed-on: https://pdfium-review.googlesource.com/2330 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde/css/cfde_cssstylesheet.cpp')
-rw-r--r--xfa/fde/css/cfde_cssstylesheet.cpp158
1 files changed, 11 insertions, 147 deletions
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;
}
}
}