summaryrefslogtreecommitdiff
path: root/xfa/fde/css/cfde_cssrulecollection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fde/css/cfde_cssrulecollection.cpp')
-rw-r--r--xfa/fde/css/cfde_cssrulecollection.cpp62
1 files changed, 17 insertions, 45 deletions
diff --git a/xfa/fde/css/cfde_cssrulecollection.cpp b/xfa/fde/css/cfde_cssrulecollection.cpp
index c140c8e682..a72e1bb0bd 100644
--- a/xfa/fde/css/cfde_cssrulecollection.cpp
+++ b/xfa/fde/css/cfde_cssrulecollection.cpp
@@ -7,9 +7,9 @@
#include "xfa/fde/css/cfde_cssrulecollection.h"
#include <algorithm>
-#include <map>
-#include <memory>
+#include <utility>
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/css/cfde_cssdeclaration.h"
#include "xfa/fde/css/cfde_cssselector.h"
#include "xfa/fde/css/cfde_cssstylerule.h"
@@ -17,15 +17,21 @@
#include "xfa/fde/css/cfde_csssyntaxparser.h"
#include "xfa/fde/css/cfde_csstagcache.h"
+CFDE_CSSRuleCollection::CFDE_CSSRuleCollection() : m_iSelectors(0) {}
+
+CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
+ Clear();
+}
+
void CFDE_CSSRuleCollection::Clear() {
m_TagRules.clear();
m_iSelectors = 0;
}
-CFDE_CSSRuleCollection::CFDE_CSSRuleCollection() : m_iSelectors(0) {}
-
-CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
- Clear();
+const std::vector<std::unique_ptr<CFDE_CSSRuleCollection::Data>>*
+CFDE_CSSRuleCollection::GetTagRuleData(uint32_t dwTagHash) const {
+ auto it = m_TagRules.find(dwTagHash);
+ return it != m_TagRules.end() ? &it->second : nullptr;
}
void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheet* sheet,
@@ -42,46 +48,12 @@ void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheet* pStyleSheet,
int32_t iSelectors = pStyleRule->CountSelectorLists();
for (int32_t i = 0; i < iSelectors; ++i) {
CFDE_CSSSelector* pSelector = pStyleRule->GetSelectorList(i);
- AddRuleTo(&m_TagRules, pSelector->GetNameHash(), pSelector, pDeclaration);
+ m_TagRules[pSelector->GetNameHash()].push_back(
+ pdfium::MakeUnique<Data>(pSelector, pDeclaration));
+ m_iSelectors++;
}
}
-void CFDE_CSSRuleCollection::AddRuleTo(std::map<uint32_t, Data*>* pMap,
- uint32_t dwKey,
- CFDE_CSSSelector* pSel,
- CFDE_CSSDeclaration* pDecl) {
- Data* pData = NewRuleData(pSel, pDecl);
- Data* pList = (*pMap)[dwKey];
- if (!pList) {
- (*pMap)[dwKey] = pData;
- } else if (AddRuleTo(&pList, pData)) {
- (*pMap)[dwKey] = pList;
- }
-}
-
-bool CFDE_CSSRuleCollection::AddRuleTo(Data** pList, Data* pData) {
- if (*pList) {
- pData->pNext = (*pList)->pNext;
- (*pList)->pNext = pData;
- return false;
- }
- *pList = pData;
- return true;
-}
-
-CFDE_CSSRuleCollection::Data* CFDE_CSSRuleCollection::NewRuleData(
- CFDE_CSSSelector* pSel,
- CFDE_CSSDeclaration* pDecl) {
- return new Data(pSel, pDecl, ++m_iSelectors);
-}
-
CFDE_CSSRuleCollection::Data::Data(CFDE_CSSSelector* pSel,
- CFDE_CSSDeclaration* pDecl,
- uint32_t dwPos)
- : pSelector(pSel), pDeclaration(pDecl), dwPriority(dwPos), pNext(nullptr) {
- static const uint32_t s_Specific[5] = {0x00010000, 0x00010000, 0x00100000,
- 0x00100000, 0x01000000};
- for (; pSel; pSel = pSel->GetNextSelector()) {
- dwPriority += s_Specific[static_cast<int>(pSel->GetType())];
- }
-}
+ CFDE_CSSDeclaration* pDecl)
+ : pSelector(pSel), pDeclaration(pDecl) {}