summaryrefslogtreecommitdiff
path: root/xfa/fde
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/fde
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/fde')
-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
7 files changed, 54 insertions, 141 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() {}