summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-01-23 13:55:39 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-01-23 20:24:23 +0000
commitb76f49b36baffea2b2ecb90d67c7b6bb734e7bb9 (patch)
tree3331545c1296500ddf164267f4bb715c16e38bb3 /xfa
parent6414b273506f97012f82c8a32c020b483d5df31a (diff)
downloadpdfium-b76f49b36baffea2b2ecb90d67c7b6bb734e7bb9.tar.xz
Remove unused author and and user stylesheets
We only load atyles from the CXFA_TextParser which loads a static UserAgent stylesheet. This CL removes the User and Author styles from the system and simplifies the storage of the stylesheets. Change-Id: I7abcf39333655f8dd6bc2cfe685c8cf73b779c7d Reviewed-on: https://pdfium-review.googlesource.com/2293 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fde/css/cfde_cssrulecollection.cpp18
-rw-r--r--xfa/fde/css/cfde_cssrulecollection.h7
-rw-r--r--xfa/fde/css/cfde_cssstyleselector.cpp116
-rw-r--r--xfa/fde/css/cfde_cssstyleselector.h15
-rw-r--r--xfa/fde/css/cfde_cssstylesheet.cpp15
-rw-r--r--xfa/fde/css/cfde_cssstylesheet.h12
-rw-r--r--xfa/fde/css/fde_css.h12
-rw-r--r--xfa/fxfa/app/cxfa_textparser.cpp30
-rw-r--r--xfa/fxfa/app/cxfa_textparser.h4
9 files changed, 70 insertions, 159 deletions
diff --git a/xfa/fde/css/cfde_cssrulecollection.cpp b/xfa/fde/css/cfde_cssrulecollection.cpp
index 6f12105d85..7ef36f2093 100644
--- a/xfa/fde/css/cfde_cssrulecollection.cpp
+++ b/xfa/fde/css/cfde_cssrulecollection.cpp
@@ -34,20 +34,14 @@ CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
Clear();
}
-void CFDE_CSSRuleCollection::AddRulesFrom(
- const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& sheets,
- CFGAS_FontMgr* pFontMgr) {
- int32_t iSheets = sheets.GetSize();
- for (int32_t i = 0; i < iSheets; ++i) {
- CFDE_CSSStyleSheet* pSheet = sheets.GetAt(i);
- int32_t iRules = pSheet->CountRules();
- for (int32_t j = 0; j < iRules; j++) {
- AddRulesFrom(pSheet, pSheet->GetRule(j), pFontMgr);
- }
- }
+void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheet* sheet,
+ CFGAS_FontMgr* pFontMgr) {
+ int32_t iRules = sheet->CountRules();
+ for (int32_t j = 0; j < iRules; j++)
+ AddRulesFrom(sheet, sheet->GetRule(j), pFontMgr);
}
-void CFDE_CSSRuleCollection::AddRulesFrom(CFDE_CSSStyleSheet* pStyleSheet,
+void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheet* pStyleSheet,
CFDE_CSSStyleRule* pStyleRule,
CFGAS_FontMgr* pFontMgr) {
CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration();
diff --git a/xfa/fde/css/cfde_cssrulecollection.h b/xfa/fde/css/cfde_cssrulecollection.h
index 75e232abaa..87677457e4 100644
--- a/xfa/fde/css/cfde_cssrulecollection.h
+++ b/xfa/fde/css/cfde_cssrulecollection.h
@@ -32,8 +32,7 @@ class CFDE_CSSRuleCollection {
CFDE_CSSRuleCollection();
~CFDE_CSSRuleCollection();
- void AddRulesFrom(const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& sheets,
- CFGAS_FontMgr* pFontMgr);
+ void AddRulesFrom(const CFDE_CSSStyleSheet* sheet, CFGAS_FontMgr* pFontMgr);
void Clear();
int32_t CountSelectors() const { return m_iSelectors; }
@@ -55,8 +54,8 @@ class CFDE_CSSRuleCollection {
Data* GetUniversalRuleData() { return m_pUniversalRules; }
Data* GetPseudoRuleData() { return m_pPseudoRules; }
- protected:
- void AddRulesFrom(CFDE_CSSStyleSheet* pStyleSheet,
+ private:
+ void AddRulesFrom(const CFDE_CSSStyleSheet* pStyleSheet,
CFDE_CSSStyleRule* pRule,
CFGAS_FontMgr* pFontMgr);
void AddRuleTo(std::map<uint32_t, Data*>* pMap,
diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp
index 8452c78ff5..fb2a1e2fbb 100644
--- a/xfa/fde/css/cfde_cssstyleselector.cpp
+++ b/xfa/fde/css/cfde_cssstyleselector.cpp
@@ -7,6 +7,7 @@
#include "xfa/fde/css/cfde_cssstyleselector.h"
#include <algorithm>
+#include <utility>
#include "third_party/base/ptr_util.h"
#include "xfa/fde/css/cfde_cssaccelerator.h"
@@ -17,6 +18,7 @@
#include "xfa/fde/css/cfde_cssenumvalue.h"
#include "xfa/fde/css/cfde_csspropertyholder.h"
#include "xfa/fde/css/cfde_cssselector.h"
+#include "xfa/fde/css/cfde_cssstylesheet.h"
#include "xfa/fde/css/cfde_csssyntaxparser.h"
#include "xfa/fde/css/cfde_csstagcache.h"
#include "xfa/fde/css/cfde_cssvaluelist.h"
@@ -39,18 +41,9 @@ const T* ToValue(const CFDE_CSSValue* val) {
#define FDE_CSSUNIVERSALHASH ('*')
CFDE_CSSStyleSelector::CFDE_CSSStyleSelector(CFGAS_FontMgr* pFontMgr)
- : m_pFontMgr(pFontMgr), m_fDefFontSize(12.0f) {
- m_ePriorities[static_cast<int32_t>(FDE_CSSStyleSheetPriority::High)] =
- FDE_CSSStyleSheetGroup::Author;
- m_ePriorities[static_cast<int32_t>(FDE_CSSStyleSheetPriority::Mid)] =
- FDE_CSSStyleSheetGroup::User;
- m_ePriorities[static_cast<int32_t>(FDE_CSSStyleSheetPriority::Low)] =
- FDE_CSSStyleSheetGroup::UserAgent;
-}
+ : m_pFontMgr(pFontMgr), m_fDefFontSize(12.0f) {}
-CFDE_CSSStyleSelector::~CFDE_CSSStyleSelector() {
- Reset();
-}
+CFDE_CSSStyleSelector::~CFDE_CSSStyleSelector() {}
void CFDE_CSSStyleSelector::SetDefFontSize(FX_FLOAT fFontSize) {
ASSERT(fFontSize > 0);
@@ -72,49 +65,14 @@ CFDE_CSSComputedStyle* CFDE_CSSStyleSelector::CreateComputedStyle(
return pStyle;
}
-bool CFDE_CSSStyleSelector::SetStyleSheet(FDE_CSSStyleSheetGroup eType,
- CFDE_CSSStyleSheet* pSheet) {
- CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& dest =
- m_SheetGroups[static_cast<int32_t>(eType)];
- dest.RemoveAt(0, dest.GetSize());
- if (pSheet)
- dest.Add(pSheet);
- return true;
-}
-
-bool CFDE_CSSStyleSelector::SetStyleSheets(
- FDE_CSSStyleSheetGroup eType,
- const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>* pArray) {
- CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& dest =
- m_SheetGroups[static_cast<int32_t>(eType)];
- if (pArray)
- dest.Copy(*pArray);
- else
- dest.RemoveAt(0, dest.GetSize());
- return true;
-}
-
-void CFDE_CSSStyleSelector::SetStylePriority(
- FDE_CSSStyleSheetGroup eType,
- FDE_CSSStyleSheetPriority ePriority) {
- m_ePriorities[static_cast<int32_t>(ePriority)] = eType;
+void CFDE_CSSStyleSelector::SetUAStyleSheet(
+ std::unique_ptr<CFDE_CSSStyleSheet> pSheet) {
+ m_UAStyles = std::move(pSheet);
}
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], m_pFontMgr);
- }
-}
-
-void CFDE_CSSStyleSelector::Reset() {
- // TODO(dsinclair): Hard coded size bad. This should probably just be a map.
- for (int32_t iGroup = 0; iGroup < 3; ++iGroup) {
- m_RuleCollection[iGroup].Clear();
- }
+ m_UARules.Clear();
+ m_UARules.AddRulesFrom(m_UAStyles.get(), m_pFontMgr);
}
int32_t CFDE_CSSStyleSelector::MatchDeclarations(
@@ -126,39 +84,35 @@ int32_t CFDE_CSSStyleSelector::MatchDeclarations(
ASSERT(pCache && pCache->GetTag() == pTag);
matchedDecls.RemoveAt(0, matchedDecls.GetSize());
- // TODO(dsinclair): Hard coded size bad ...
- for (int32_t ePriority = 2; ePriority >= 0; --ePriority) {
- FDE_CSSStyleSheetGroup eGroup = m_ePriorities[ePriority];
- CFDE_CSSRuleCollection& rules =
- m_RuleCollection[static_cast<int32_t>(eGroup)];
- if (rules.CountSelectors() == 0)
- continue;
- if (ePseudoType == FDE_CSSPseudo::NONE) {
- MatchRules(pCache, rules.GetUniversalRuleData(), ePseudoType);
- if (pCache->HashTag()) {
- MatchRules(pCache, rules.GetTagRuleData(pCache->HashTag()),
- ePseudoType);
- }
- int32_t iCount = pCache->CountHashClass();
- for (int32_t i = 0; i < iCount; i++) {
- pCache->SetClassIndex(i);
- MatchRules(pCache, rules.GetClassRuleData(pCache->HashClass()),
- ePseudoType);
- }
- } else {
- MatchRules(pCache, rules.GetPseudoRuleData(), ePseudoType);
- }
+ if (m_UARules.CountSelectors() == 0)
+ return 0;
- std::sort(m_MatchedRules.begin(), m_MatchedRules.end(),
- [](const CFDE_CSSRuleCollection::Data* p1,
- const CFDE_CSSRuleCollection::Data* p2) {
- return p1->dwPriority < p2->dwPriority;
- });
- for (const auto& rule : m_MatchedRules)
- matchedDecls.Add(rule->pDeclaration);
- m_MatchedRules.clear();
+ if (ePseudoType == FDE_CSSPseudo::NONE) {
+ MatchRules(pCache, m_UARules.GetUniversalRuleData(), ePseudoType);
+ if (pCache->HashTag()) {
+ MatchRules(pCache, m_UARules.GetTagRuleData(pCache->HashTag()),
+ ePseudoType);
+ }
+ int32_t iCount = pCache->CountHashClass();
+ for (int32_t i = 0; i < iCount; i++) {
+ pCache->SetClassIndex(i);
+ MatchRules(pCache, m_UARules.GetClassRuleData(pCache->HashClass()),
+ ePseudoType);
+ }
+ } else {
+ MatchRules(pCache, m_UARules.GetPseudoRuleData(), ePseudoType);
}
+
+ std::sort(m_MatchedRules.begin(), m_MatchedRules.end(),
+ [](const CFDE_CSSRuleCollection::Data* p1,
+ const CFDE_CSSRuleCollection::Data* p2) {
+ return p1->dwPriority < p2->dwPriority;
+ });
+ for (const auto& rule : m_MatchedRules)
+ matchedDecls.Add(rule->pDeclaration);
+ m_MatchedRules.clear();
+
return matchedDecls.GetSize();
}
diff --git a/xfa/fde/css/cfde_cssstyleselector.h b/xfa/fde/css/cfde_cssstyleselector.h
index 1ddb67243c..4d6a7c8ed2 100644
--- a/xfa/fde/css/cfde_cssstyleselector.h
+++ b/xfa/fde/css/cfde_cssstyleselector.h
@@ -33,11 +33,8 @@ class CFDE_CSSStyleSelector {
void SetDefFontSize(FX_FLOAT fFontSize);
- bool SetStyleSheet(FDE_CSSStyleSheetGroup eType, CFDE_CSSStyleSheet* pSheet);
- bool SetStyleSheets(FDE_CSSStyleSheetGroup eType,
- const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>* pArray);
- void SetStylePriority(FDE_CSSStyleSheetGroup eType,
- FDE_CSSStyleSheetPriority ePriority);
+ void SetUAStyleSheet(std::unique_ptr<CFDE_CSSStyleSheet> pSheet);
+
void UpdateStyleIndex();
CFDE_CSSAccelerator* InitAccelerator();
CFDE_CSSComputedStyle* CreateComputedStyle(
@@ -51,8 +48,7 @@ class CFDE_CSSStyleSelector {
int32_t iDeclCount,
CFDE_CSSComputedStyle* pDestStyle);
- protected:
- void Reset();
+ private:
void MatchRules(CFDE_CSSTagCache* pCache,
CFDE_CSSRuleCollection::Data* pList,
FDE_CSSPseudo ePseudoType);
@@ -85,9 +81,8 @@ class CFDE_CSSStyleSelector {
CFGAS_FontMgr* const m_pFontMgr;
FX_FLOAT m_fDefFontSize;
- CFX_ArrayTemplate<CFDE_CSSStyleSheet*> m_SheetGroups[3];
- CFDE_CSSRuleCollection m_RuleCollection[3];
- FDE_CSSStyleSheetGroup m_ePriorities[3];
+ std::unique_ptr<CFDE_CSSStyleSheet> m_UAStyles;
+ CFDE_CSSRuleCollection m_UARules;
std::unique_ptr<CFDE_CSSAccelerator> m_pAccelerator;
std::vector<CFDE_CSSRuleCollection::Data*> m_MatchedRules;
};
diff --git a/xfa/fde/css/cfde_cssstylesheet.cpp b/xfa/fde/css/cfde_cssstylesheet.cpp
index 7dc122f1da..b05e837f95 100644
--- a/xfa/fde/css/cfde_cssstylesheet.cpp
+++ b/xfa/fde/css/cfde_cssstylesheet.cpp
@@ -15,7 +15,7 @@
#include "xfa/fde/css/fde_cssdatatable.h"
#include "xfa/fgas/crt/fgas_codepage.h"
-CFDE_CSSStyleSheet::CFDE_CSSStyleSheet() : m_wRefCount(1) {}
+CFDE_CSSStyleSheet::CFDE_CSSStyleSheet() {}
CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() {
Reset();
@@ -26,22 +26,11 @@ void CFDE_CSSStyleSheet::Reset() {
m_StringCache.clear();
}
-uint32_t CFDE_CSSStyleSheet::Retain() {
- return ++m_wRefCount;
-}
-
-uint32_t CFDE_CSSStyleSheet::Release() {
- uint32_t dwRefCount = --m_wRefCount;
- if (dwRefCount == 0)
- delete this;
- return dwRefCount;
-}
-
int32_t CFDE_CSSStyleSheet::CountRules() const {
return pdfium::CollectionSize<int32_t>(m_RuleArray);
}
-CFDE_CSSStyleRule* CFDE_CSSStyleSheet::GetRule(int32_t index) {
+CFDE_CSSStyleRule* CFDE_CSSStyleSheet::GetRule(int32_t index) const {
return m_RuleArray[index].get();
}
diff --git a/xfa/fde/css/cfde_cssstylesheet.h b/xfa/fde/css/cfde_cssstylesheet.h
index 8bbcc485bb..4de377219c 100644
--- a/xfa/fde/css/cfde_cssstylesheet.h
+++ b/xfa/fde/css/cfde_cssstylesheet.h
@@ -11,25 +11,20 @@
#include <unordered_map>
#include <vector>
-#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_string.h"
#include "xfa/fde/css/cfde_csssyntaxparser.h"
class CFDE_CSSStyleRule;
-class CFDE_CSSStyleSheet : public IFX_Retainable {
+class CFDE_CSSStyleSheet {
public:
CFDE_CSSStyleSheet();
- ~CFDE_CSSStyleSheet() override;
-
- // IFX_Retainable:
- uint32_t Retain() override;
- uint32_t Release() override;
+ ~CFDE_CSSStyleSheet();
bool LoadBuffer(const FX_WCHAR* pBuffer, int32_t iBufSize);
int32_t CountRules() const;
- CFDE_CSSStyleRule* GetRule(int32_t index);
+ CFDE_CSSStyleRule* GetRule(int32_t index) const;
private:
void Reset();
@@ -38,7 +33,6 @@ class CFDE_CSSStyleSheet : public IFX_Retainable {
std::vector<std::unique_ptr<CFDE_CSSStyleRule>>* ruleArray);
void SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax);
- uint16_t m_wRefCount;
std::vector<std::unique_ptr<CFDE_CSSStyleRule>> m_RuleArray;
std::unordered_map<uint32_t, FX_WCHAR*> m_StringCache;
};
diff --git a/xfa/fde/css/fde_css.h b/xfa/fde/css/fde_css.h
index 571f8a58d9..17ef7e46f0 100644
--- a/xfa/fde/css/fde_css.h
+++ b/xfa/fde/css/fde_css.h
@@ -191,18 +191,6 @@ enum FDE_CSSTEXTDECORATION {
FDE_CSSTEXTDECORATION_Double = 1 << 4,
};
-enum class FDE_CSSStyleSheetGroup : uint8_t {
- UserAgent = 0,
- User,
- Author,
-};
-
-enum class FDE_CSSStyleSheetPriority : uint8_t {
- High = 0,
- Mid,
- Low,
-};
-
class FDE_CSSLength {
public:
FDE_CSSLength() {}
diff --git a/xfa/fxfa/app/cxfa_textparser.cpp b/xfa/fxfa/app/cxfa_textparser.cpp
index 703d11ec11..6386edfad8 100644
--- a/xfa/fxfa/app/cxfa_textparser.cpp
+++ b/xfa/fxfa/app/cxfa_textparser.cpp
@@ -7,6 +7,7 @@
#include "xfa/fxfa/app/cxfa_textparser.h"
#include <algorithm>
+#include <utility>
#include "third_party/base/ptr_util.h"
#include "xfa/fde/css/cfde_cssaccelerator.h"
@@ -39,12 +40,10 @@ enum class TabStopStatus {
} // namespace
-CXFA_TextParser::CXFA_TextParser() : m_pUASheet(nullptr), m_bParsed(false) {}
+CXFA_TextParser::CXFA_TextParser()
+ : m_bParsed(false), m_cssInitialized(false) {}
CXFA_TextParser::~CXFA_TextParser() {
- if (m_pUASheet)
- m_pUASheet->Release();
-
for (auto& pair : m_mapXMLNodeToParseContext) {
if (pair.second)
delete pair.second;
@@ -76,14 +75,16 @@ void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) {
m_pSelector->SetDefFontSize(fFontSize);
}
- if (!m_pUASheet) {
- m_pUASheet = LoadDefaultSheetStyle();
- m_pSelector->SetStyleSheet(FDE_CSSStyleSheetGroup::UserAgent, m_pUASheet);
- m_pSelector->UpdateStyleIndex();
- }
+ if (m_cssInitialized)
+ return;
+
+ m_cssInitialized = true;
+ auto uaSheet = LoadDefaultSheetStyle();
+ m_pSelector->SetUAStyleSheet(std::move(uaSheet));
+ m_pSelector->UpdateStyleIndex();
}
-CFDE_CSSStyleSheet* CXFA_TextParser::LoadDefaultSheetStyle() {
+std::unique_ptr<CFDE_CSSStyleSheet> CXFA_TextParser::LoadDefaultSheetStyle() {
static const FX_WCHAR s_pStyle[] =
L"html,body,ol,p,ul{display:block}"
L"li{display:list-item}"
@@ -95,12 +96,9 @@ CFDE_CSSStyleSheet* CXFA_TextParser::LoadDefaultSheetStyle() {
L"sup{vertical-align:+15em;font-size:.66em}"
L"sub{vertical-align:-15em;font-size:.66em}";
- CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet();
- if (!pStyleSheet->LoadBuffer(s_pStyle, FXSYS_wcslen(s_pStyle))) {
- pStyleSheet->Release();
- pStyleSheet = nullptr;
- }
- return pStyleSheet;
+ auto sheet = pdfium::MakeUnique<CFDE_CSSStyleSheet>();
+ return sheet->LoadBuffer(s_pStyle, FXSYS_wcslen(s_pStyle)) ? std::move(sheet)
+ : nullptr;
}
CFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle(
diff --git a/xfa/fxfa/app/cxfa_textparser.h b/xfa/fxfa/app/cxfa_textparser.h
index a0b5ab1f29..7a94f83aeb 100644
--- a/xfa/fxfa/app/cxfa_textparser.h
+++ b/xfa/fxfa/app/cxfa_textparser.h
@@ -88,13 +88,13 @@ class CXFA_TextParser {
void ParseRichText(CFDE_XMLNode* pXMLNode,
CFDE_CSSComputedStyle* pParentStyle);
void ParseTagInfo(CFDE_XMLNode* pXMLNode, CXFA_CSSTagProvider& tagProvider);
- CFDE_CSSStyleSheet* LoadDefaultSheetStyle();
+ std::unique_ptr<CFDE_CSSStyleSheet> LoadDefaultSheetStyle();
CFDE_CSSComputedStyle* CreateStyle(CFDE_CSSComputedStyle* pParentStyle);
std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector;
- CFDE_CSSStyleSheet* m_pUASheet;
std::map<CFDE_XMLNode*, CXFA_TextParseContext*> m_mapXMLNodeToParseContext;
bool m_bParsed;
+ bool m_cssInitialized;
};
#endif // XFA_FXFA_APP_CXFA_TEXTPARSER_H_