summaryrefslogtreecommitdiff
path: root/xfa/fde
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-01-23 15:38:28 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-01-24 14:28:24 +0000
commit1339133720c3b8bce77e970b479ec179160f30b5 (patch)
tree5927042eab27eaa4a96cf4276dec54d3e8a44a23 /xfa/fde
parent3d328767f9c0c04b62173aac03c35aab3fb87ffe (diff)
downloadpdfium-1339133720c3b8bce77e970b479ec179160f30b5.tar.xz
Remove ID, Class and Universal selector code
The UA style defined in CXFA_TextParser does not specify any ID, Class or Universal selectors. Remove related code. Change-Id: I9f2d760ee86f309a9cfa8a0f1f3e3dd7a15ef4c8 Reviewed-on: https://pdfium-review.googlesource.com/2295 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fde')
-rw-r--r--xfa/fde/css/cfde_cssrulecollection.cpp40
-rw-r--r--xfa/fde/css/cfde_cssrulecollection.h15
-rw-r--r--xfa/fde/css/cfde_cssselector.cpp29
-rw-r--r--xfa/fde/css/cfde_cssstyleselector.cpp32
-rw-r--r--xfa/fde/css/cfde_csstagcache.cpp26
-rw-r--r--xfa/fde/css/cfde_csstagcache.h14
-rw-r--r--xfa/fde/css/fde_css.h7
7 files changed, 10 insertions, 153 deletions
diff --git a/xfa/fde/css/cfde_cssrulecollection.cpp b/xfa/fde/css/cfde_cssrulecollection.cpp
index db3342cfc6..c140c8e682 100644
--- a/xfa/fde/css/cfde_cssrulecollection.cpp
+++ b/xfa/fde/css/cfde_cssrulecollection.cpp
@@ -17,18 +17,12 @@
#include "xfa/fde/css/cfde_csssyntaxparser.h"
#include "xfa/fde/css/cfde_csstagcache.h"
-#define FDE_CSSUNIVERSALHASH ('*')
-
void CFDE_CSSRuleCollection::Clear() {
- m_IDRules.clear();
m_TagRules.clear();
- m_ClassRules.clear();
- m_pUniversalRules = nullptr;
m_iSelectors = 0;
}
-CFDE_CSSRuleCollection::CFDE_CSSRuleCollection()
- : m_pUniversalRules(nullptr), m_iSelectors(0) {}
+CFDE_CSSRuleCollection::CFDE_CSSRuleCollection() : m_iSelectors(0) {}
CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
Clear();
@@ -48,31 +42,7 @@ 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);
- 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;
- }
+ AddRuleTo(&m_TagRules, pSelector->GetNameHash(), pSelector, pDeclaration);
}
}
@@ -112,10 +82,6 @@ CFDE_CSSRuleCollection::Data::Data(CFDE_CSSSelector* pSel,
static const uint32_t s_Specific[5] = {0x00010000, 0x00010000, 0x00100000,
0x00100000, 0x01000000};
for (; pSel; pSel = pSel->GetNextSelector()) {
- FDE_CSSSelectorType eType = pSel->GetType();
- if (eType > FDE_CSSSelectorType::Descendant ||
- pSel->GetNameHash() != FDE_CSSUNIVERSALHASH) {
- dwPriority += s_Specific[static_cast<int>(eType)];
- }
+ dwPriority += s_Specific[static_cast<int>(pSel->GetType())];
}
}
diff --git a/xfa/fde/css/cfde_cssrulecollection.h b/xfa/fde/css/cfde_cssrulecollection.h
index 03698748e6..47e7696c34 100644
--- a/xfa/fde/css/cfde_cssrulecollection.h
+++ b/xfa/fde/css/cfde_cssrulecollection.h
@@ -36,23 +36,11 @@ class CFDE_CSSRuleCollection {
void Clear();
int32_t CountSelectors() const { return m_iSelectors; }
- Data* GetIDRuleData(uint32_t dwIDHash) {
- auto it = m_IDRules.find(dwIDHash);
- return it != m_IDRules.end() ? it->second : nullptr;
- }
-
Data* GetTagRuleData(uint32_t dwTagHash) {
auto it = m_TagRules.find(dwTagHash);
return it != m_TagRules.end() ? it->second : nullptr;
}
- Data* GetClassRuleData(uint32_t dwIDHash) {
- auto it = m_ClassRules.find(dwIDHash);
- return it != m_ClassRules.end() ? it->second : nullptr;
- }
-
- Data* GetUniversalRuleData() { return m_pUniversalRules; }
-
private:
void AddRulesFrom(const CFDE_CSSStyleSheet* pStyleSheet,
CFDE_CSSStyleRule* pRule,
@@ -64,10 +52,7 @@ class CFDE_CSSRuleCollection {
bool AddRuleTo(Data** pList, Data* pData);
Data* NewRuleData(CFDE_CSSSelector* pSel, CFDE_CSSDeclaration* pDecl);
- std::map<uint32_t, Data*> m_IDRules;
std::map<uint32_t, Data*> m_TagRules;
- std::map<uint32_t, Data*> m_ClassRules;
- Data* m_pUniversalRules;
int32_t m_iSelectors;
};
diff --git a/xfa/fde/css/cfde_cssselector.cpp b/xfa/fde/css/cfde_cssselector.cpp
index bd800c0fa5..718cb46415 100644
--- a/xfa/fde/css/cfde_cssselector.cpp
+++ b/xfa/fde/css/cfde_cssselector.cpp
@@ -78,34 +78,7 @@ std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString(
for (psz = pStart; psz < pEnd;) {
FX_WCHAR wch = *psz;
- if (wch == '.' || wch == '#') {
- if (psz == pStart || psz[-1] == ' ') {
- auto p = pdfium::MakeUnique<CFDE_CSSSelector>(
- FDE_CSSSelectorType::Element, L"*", 1, true);
-
- if (pFirst) {
- pFirst->SetType(FDE_CSSSelectorType::Descendant);
- p->SetNext(std::move(pFirst));
- }
- pFirst = std::move(p);
- pLast = pFirst.get();
- }
- ASSERT(pLast);
-
- int32_t iNameLen = GetCSSNameLen(++psz, pEnd);
- if (iNameLen == 0)
- return nullptr;
-
- FDE_CSSSelectorType eType =
- wch == '.' ? FDE_CSSSelectorType::Class : FDE_CSSSelectorType::ID;
- auto p =
- pdfium::MakeUnique<CFDE_CSSSelector>(eType, psz, iNameLen, false);
-
- p->SetNext(pLast->ReleaseNextSelector());
- pLast->SetNext(std::move(p));
- pLast = pLast->GetNextSelector();
- psz += iNameLen;
- } else if (IsCSSChar(wch) || wch == '*') {
+ if (IsCSSChar(wch) || wch == '*') {
int32_t iNameLen = wch == '*' ? 1 : GetCSSNameLen(psz, pEnd);
if (iNameLen == 0)
return nullptr;
diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp
index c4156c4d49..b7275fca93 100644
--- a/xfa/fde/css/cfde_cssstyleselector.cpp
+++ b/xfa/fde/css/cfde_cssstyleselector.cpp
@@ -38,8 +38,6 @@ const T* ToValue(const CFDE_CSSValue* val) {
} // namespace
-#define FDE_CSSUNIVERSALHASH ('*')
-
CFDE_CSSStyleSelector::CFDE_CSSStyleSelector(CFGAS_FontMgr* pFontMgr)
: m_pFontMgr(pFontMgr), m_fDefFontSize(12.0f) {}
@@ -87,15 +85,8 @@ int32_t CFDE_CSSStyleSelector::MatchDeclarations(
if (m_UARules.CountSelectors() == 0)
return 0;
- MatchRules(pCache, m_UARules.GetUniversalRuleData());
- if (pCache->HashTag()) {
+ if (pCache->HashTag())
MatchRules(pCache, m_UARules.GetTagRuleData(pCache->HashTag()));
- }
- int32_t iCount = pCache->CountHashClass();
- for (int32_t i = 0; i < iCount; i++) {
- pCache->SetClassIndex(i);
- MatchRules(pCache, m_UARules.GetClassRuleData(pCache->HashClass()));
- }
std::sort(m_MatchedRules.begin(), m_MatchedRules.end(),
[](const CFDE_CSSRuleCollection::Data* p1,
@@ -126,31 +117,16 @@ bool CFDE_CSSStyleSelector::MatchSelector(CFDE_CSSTagCache* pCache,
case FDE_CSSSelectorType::Descendant:
dwHash = pSel->GetNameHash();
while ((pCache = pCache->GetParent()) != nullptr) {
- if (dwHash != FDE_CSSUNIVERSALHASH && dwHash != pCache->HashTag()) {
+ if (dwHash != pCache->HashTag())
continue;
- }
- if (MatchSelector(pCache, pSel->GetNextSelector())) {
+ if (MatchSelector(pCache, pSel->GetNextSelector()))
return true;
- }
}
return false;
- case FDE_CSSSelectorType::ID:
- dwHash = pCache->HashID();
- if (dwHash != pSel->GetNameHash()) {
- return false;
- }
- break;
- case FDE_CSSSelectorType::Class:
- dwHash = pCache->HashClass();
- if (dwHash != pSel->GetNameHash()) {
- return false;
- }
- break;
case FDE_CSSSelectorType::Element:
dwHash = pSel->GetNameHash();
- if (dwHash != FDE_CSSUNIVERSALHASH && dwHash != pCache->HashTag()) {
+ if (dwHash != pCache->HashTag())
return false;
- }
break;
default:
ASSERT(false);
diff --git a/xfa/fde/css/cfde_csstagcache.cpp b/xfa/fde/css/cfde_csstagcache.cpp
index 13e37982df..df2c2ce342 100644
--- a/xfa/fde/css/cfde_csstagcache.cpp
+++ b/xfa/fde/css/cfde_csstagcache.cpp
@@ -13,32 +13,8 @@
CFDE_CSSTagCache::CFDE_CSSTagCache(CFDE_CSSTagCache* parent,
CXFA_CSSTagProvider* tag)
- : pTag(tag), pParent(parent), dwIDHash(0), dwTagHash(0), iClassIndex(0) {
- static const uint32_t s_dwIDHash = FX_HashCode_GetW(L"id", true);
- static const uint32_t s_dwClassHash = FX_HashCode_GetW(L"class", true);
+ : pTag(tag), pParent(parent), dwTagHash(0) {
dwTagHash = FX_HashCode_GetW(pTag->GetTagName().AsStringC(), true);
-
- for (auto it : *pTag) {
- CFX_WideString wsValue = it.first;
- CFX_WideString wsName = it.second;
- uint32_t dwNameHash = FX_HashCode_GetW(wsName.AsStringC(), true);
- if (dwNameHash == s_dwClassHash) {
- uint32_t dwHash = FX_HashCode_GetW(wsValue.AsStringC(), false);
- dwClassHashes.push_back(dwHash);
- } else if (dwNameHash == s_dwIDHash) {
- dwIDHash = FX_HashCode_GetW(wsValue.AsStringC(), false);
- }
- }
-}
-
-CFDE_CSSTagCache::CFDE_CSSTagCache(const CFDE_CSSTagCache& it)
- : pTag(it.pTag),
- pParent(it.pParent),
- dwIDHash(it.dwIDHash),
- dwTagHash(it.dwTagHash),
- iClassIndex(0) {
- std::copy(it.dwClassHashes.begin(), it.dwClassHashes.end(),
- dwClassHashes.begin());
}
CFDE_CSSTagCache::~CFDE_CSSTagCache() {}
diff --git a/xfa/fde/css/cfde_csstagcache.h b/xfa/fde/css/cfde_csstagcache.h
index 6d9b4e7054..dae35fb479 100644
--- a/xfa/fde/css/cfde_csstagcache.h
+++ b/xfa/fde/css/cfde_csstagcache.h
@@ -17,30 +17,16 @@ class CXFA_CSSTagProvider;
class CFDE_CSSTagCache {
public:
CFDE_CSSTagCache(CFDE_CSSTagCache* parent, CXFA_CSSTagProvider* tag);
- CFDE_CSSTagCache(const CFDE_CSSTagCache& it);
~CFDE_CSSTagCache();
CFDE_CSSTagCache* GetParent() const { return pParent; }
CXFA_CSSTagProvider* GetTag() const { return pTag; }
- uint32_t HashID() const { return dwIDHash; }
uint32_t HashTag() const { return dwTagHash; }
- int32_t CountHashClass() const {
- return pdfium::CollectionSize<int32_t>(dwClassHashes);
- }
- void SetClassIndex(int32_t index) { iClassIndex = index; }
- uint32_t HashClass() const {
- return iClassIndex < pdfium::CollectionSize<int32_t>(dwClassHashes)
- ? dwClassHashes[iClassIndex]
- : 0;
- }
private:
CXFA_CSSTagProvider* pTag;
CFDE_CSSTagCache* pParent;
- uint32_t dwIDHash;
uint32_t dwTagHash;
- int32_t iClassIndex;
- std::vector<uint32_t> dwClassHashes;
};
#endif // XFA_FDE_CSS_CFDE_CSSTAGCACHE_H_
diff --git a/xfa/fde/css/fde_css.h b/xfa/fde/css/fde_css.h
index f131f0b34b..6c2629f5ec 100644
--- a/xfa/fde/css/fde_css.h
+++ b/xfa/fde/css/fde_css.h
@@ -125,12 +125,7 @@ enum class FDE_CSSProperty : uint8_t {
LAST_MARKER
};
-enum class FDE_CSSSelectorType : uint8_t {
- Element = 0,
- Descendant,
- Class,
- ID,
-};
+enum class FDE_CSSSelectorType : uint8_t { Element = 0, Descendant };
enum class FDE_CSSLengthUnit : uint8_t {
Auto,