summaryrefslogtreecommitdiff
path: root/xfa/fde
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fde')
-rw-r--r--xfa/fde/css/fde_css.h15
-rw-r--r--xfa/fde/css/fde_csscache.cpp35
-rw-r--r--xfa/fde/css/fde_csscache.h13
-rw-r--r--xfa/fde/css/fde_cssstyleselector.cpp64
-rw-r--r--xfa/fde/css/fde_cssstyleselector.h5
5 files changed, 71 insertions, 61 deletions
diff --git a/xfa/fde/css/fde_css.h b/xfa/fde/css/fde_css.h
index 566a94710c..a5573d702b 100644
--- a/xfa/fde/css/fde_css.h
+++ b/xfa/fde/css/fde_css.h
@@ -13,6 +13,7 @@
#include "xfa/fgas/font/fgas_font.h"
class CFDE_CSSAccelerator;
+class CXFA_CSSTagProvider;
class IFDE_CSSBoundaryStyle;
class IFDE_CSSComputedStyle;
class IFDE_CSSDeclaration;
@@ -24,7 +25,6 @@ class IFDE_CSSSelector;
class IFDE_CSSStyleSelector;
class IFDE_CSSStyleSheet;
class IFDE_CSSSyntaxParser;
-class IFDE_CSSTagProvider;
class IFDE_CSSValue;
class IFDE_CSSValueList;
@@ -881,15 +881,6 @@ enum FDE_CSSSTYLESHEETPRIORITY {
FDE_CSSSTYLESHEETPRIORITY_Low,
FDE_CSSSTYLESHEETPRIORITY_MAX,
};
-class IFDE_CSSTagProvider {
- public:
- virtual ~IFDE_CSSTagProvider() {}
- virtual CFX_WideStringC GetTagName() = 0;
- virtual FX_POSITION GetFirstAttribute() = 0;
- virtual void GetNextAttribute(FX_POSITION& pos,
- CFX_WideStringC& wsAttr,
- CFX_WideStringC& wsValue) = 0;
-};
class IFDE_CSSStyleSelector {
public:
@@ -909,10 +900,10 @@ class IFDE_CSSStyleSelector {
virtual IFDE_CSSComputedStyle* CreateComputedStyle(
IFDE_CSSComputedStyle* pParentStyle) = 0;
virtual int32_t MatchDeclarations(
- IFDE_CSSTagProvider* pTag,
+ CXFA_CSSTagProvider* pTag,
CFDE_CSSDeclarationArray& matchedDecls,
FDE_CSSPERSUDO ePersudoType = FDE_CSSPERSUDO_NONE) = 0;
- virtual void ComputeStyle(IFDE_CSSTagProvider* pTag,
+ virtual void ComputeStyle(CXFA_CSSTagProvider* pTag,
const IFDE_CSSDeclaration** ppDeclArray,
int32_t iDeclCount,
IFDE_CSSComputedStyle* pDestStyle) = 0;
diff --git a/xfa/fde/css/fde_csscache.cpp b/xfa/fde/css/fde_csscache.cpp
index 511c69798b..e23b4c6377 100644
--- a/xfa/fde/css/fde_csscache.cpp
+++ b/xfa/fde/css/fde_csscache.cpp
@@ -9,35 +9,40 @@
#include <algorithm>
#include "core/fxcrt/include/fx_ext.h"
+#include "xfa/fxfa/app/xfa_textlayout.h"
FDE_CSSCacheItem::FDE_CSSCacheItem(IFDE_CSSStyleSheet* p)
: pStylesheet(p), dwActivity(0) {
FXSYS_assert(pStylesheet);
pStylesheet->AddRef();
}
+
FDE_CSSCacheItem::~FDE_CSSCacheItem() {
pStylesheet->Release();
}
FDE_CSSTagCache::FDE_CSSTagCache(FDE_CSSTagCache* parent,
- IFDE_CSSTagProvider* tag)
+ CXFA_CSSTagProvider* tag)
: pTag(tag),
pParent(parent),
dwIDHash(0),
dwTagHash(0),
iClassIndex(0),
dwClassHashs(1) {
- FXSYS_assert(pTag != NULL);
- CFX_WideStringC wsValue, wsName = pTag->GetTagName();
- dwTagHash = FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE);
- FX_POSITION pos = pTag->GetFirstAttribute();
- while (pos != NULL) {
- pTag->GetNextAttribute(pos, wsName, wsValue);
+ static const uint32_t s_dwIDHash = FX_HashCode_String_GetW(L"id", 2, TRUE);
+ static const uint32_t s_dwClassHash =
+ FX_HashCode_String_GetW(L"class", 5, TRUE);
+
+ CFX_WideString wsTag = pTag->GetTagName();
+ dwTagHash = FX_HashCode_String_GetW(wsTag.c_str(), wsTag.GetLength(), TRUE);
+
+ for (auto it : *pTag) {
+ CFX_WideString wsValue = it.first;
+ CFX_WideString wsName = it.second;
+
uint32_t dwNameHash =
FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE);
- static const uint32_t s_dwIDHash = FX_HashCode_String_GetW(L"id", 2, TRUE);
- static const uint32_t s_dwClassHash =
- FX_HashCode_String_GetW(L"class", 5, TRUE);
+
if (dwNameHash == s_dwClassHash) {
uint32_t dwHash =
FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength());
@@ -47,6 +52,7 @@ FDE_CSSTagCache::FDE_CSSTagCache(FDE_CSSTagCache* parent,
}
}
}
+
FDE_CSSTagCache::FDE_CSSTagCache(const FDE_CSSTagCache& it)
: pTag(it.pTag),
pParent(it.pParent),
@@ -54,16 +60,17 @@ FDE_CSSTagCache::FDE_CSSTagCache(const FDE_CSSTagCache& it)
dwTagHash(it.dwTagHash),
iClassIndex(0),
dwClassHashs(1) {
- if (it.dwClassHashs.GetSize() > 0) {
+ if (it.dwClassHashs.GetSize() > 0)
dwClassHashs.Copy(it.dwClassHashs);
- }
}
-void CFDE_CSSAccelerator::OnEnterTag(IFDE_CSSTagProvider* pTag) {
+
+void CFDE_CSSAccelerator::OnEnterTag(CXFA_CSSTagProvider* pTag) {
FDE_CSSTagCache* pTop = GetTopElement();
FDE_CSSTagCache item(pTop, pTag);
m_Stack.Push(item);
}
-void CFDE_CSSAccelerator::OnLeaveTag(IFDE_CSSTagProvider* pTag) {
+
+void CFDE_CSSAccelerator::OnLeaveTag(CXFA_CSSTagProvider* pTag) {
FXSYS_assert(m_Stack.GetTopElement());
FXSYS_assert(m_Stack.GetTopElement()->GetTag() == pTag);
m_Stack.Pop();
diff --git a/xfa/fde/css/fde_csscache.h b/xfa/fde/css/fde_csscache.h
index 41908c1c6c..2cf007db79 100644
--- a/xfa/fde/css/fde_csscache.h
+++ b/xfa/fde/css/fde_csscache.h
@@ -23,13 +23,16 @@ class FDE_CSSCacheItem : public CFX_Target {
class FDE_CSSTagCache : public CFX_Target {
public:
- FDE_CSSTagCache(FDE_CSSTagCache* parent, IFDE_CSSTagProvider* tag);
+ FDE_CSSTagCache(FDE_CSSTagCache* parent, CXFA_CSSTagProvider* tag);
FDE_CSSTagCache(const FDE_CSSTagCache& it);
+
FDE_CSSTagCache* GetParent() const { return pParent; }
- IFDE_CSSTagProvider* GetTag() const { return pTag; }
+ CXFA_CSSTagProvider* GetTag() const { return pTag; }
+
uint32_t HashID() const { return dwIDHash; }
uint32_t HashTag() const { return dwTagHash; }
int32_t CountHashClass() const { return dwClassHashs.GetSize(); }
+
void SetClassIndex(int32_t index) { iClassIndex = index; }
uint32_t HashClass() const {
return iClassIndex < dwClassHashs.GetSize()
@@ -38,7 +41,7 @@ class FDE_CSSTagCache : public CFX_Target {
}
protected:
- IFDE_CSSTagProvider* pTag;
+ CXFA_CSSTagProvider* pTag;
FDE_CSSTagCache* pParent;
uint32_t dwIDHash;
uint32_t dwTagHash;
@@ -49,8 +52,8 @@ typedef CFX_ObjectStackTemplate<FDE_CSSTagCache> CFDE_CSSTagStack;
class CFDE_CSSAccelerator : public CFX_Target {
public:
- void OnEnterTag(IFDE_CSSTagProvider* pTag);
- void OnLeaveTag(IFDE_CSSTagProvider* pTag);
+ void OnEnterTag(CXFA_CSSTagProvider* pTag);
+ void OnLeaveTag(CXFA_CSSTagProvider* pTag);
void Clear() { m_Stack.RemoveAll(); }
diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp
index 60283a6628..30502303f4 100644
--- a/xfa/fde/css/fde_cssstyleselector.cpp
+++ b/xfa/fde/css/fde_cssstyleselector.cpp
@@ -10,6 +10,7 @@
#include "xfa/fde/css/fde_csscache.h"
#include "xfa/fde/css/fde_cssdeclaration.h"
+#include "xfa/fxfa/app/xfa_textlayout.h"
#define FDE_CSSUNIVERSALHASH ('*')
@@ -312,20 +313,22 @@ void CFDE_CSSStyleSelector::Reset() {
}
}
int32_t CFDE_CSSStyleSelector::MatchDeclarations(
- IFDE_CSSTagProvider* pTag,
+ CXFA_CSSTagProvider* pTag,
CFDE_CSSDeclarationArray& matchedDecls,
FDE_CSSPERSUDO ePersudoType) {
- FXSYS_assert(m_pAccelerator != NULL && pTag != NULL);
+ FXSYS_assert(m_pAccelerator && pTag);
+
FDE_CSSTagCache* pCache = m_pAccelerator->GetTopElement();
- FXSYS_assert(pCache != NULL && pCache->GetTag() == pTag);
+ FXSYS_assert(pCache && pCache->GetTag() == pTag);
+
matchedDecls.RemoveAt(0, matchedDecls.GetSize());
for (int32_t ePriority = FDE_CSSSTYLESHEETPRIORITY_MAX - 1; ePriority >= 0;
--ePriority) {
FDE_CSSSTYLESHEETGROUP eGroup = m_ePriorities[ePriority];
CFDE_CSSRuleCollection& rules = m_RuleCollection[eGroup];
- if (rules.CountSelectors() == 0) {
+ if (rules.CountSelectors() == 0)
continue;
- }
+
if (ePersudoType == FDE_CSSPERSUDO_NONE) {
MatchRules(pCache, rules.GetUniversalRuleData(), ePersudoType);
if (pCache->HashTag()) {
@@ -414,45 +417,47 @@ FX_BOOL CFDE_CSSStyleSelector::MatchSelector(FDE_CSSTagCache* pCache,
}
void CFDE_CSSStyleSelector::ComputeStyle(
- IFDE_CSSTagProvider* pTag,
+ CXFA_CSSTagProvider* pTag,
const IFDE_CSSDeclaration** ppDeclArray,
int32_t iDeclCount,
IFDE_CSSComputedStyle* pDestStyle) {
FXSYS_assert(iDeclCount >= 0);
FXSYS_assert(pDestStyle);
- FX_POSITION pos = pTag->GetFirstAttribute();
- if (pos != NULL) {
- if (m_pInlineStyleStore == NULL) {
+
+ static const uint32_t s_dwStyleHash =
+ FX_HashCode_String_GetW(L"style", 5, TRUE);
+ static const uint32_t s_dwAlignHash =
+ FX_HashCode_String_GetW(L"align", 5, TRUE);
+
+ if (!pTag->empty()) {
+ if (!m_pInlineStyleStore)
m_pInlineStyleStore = FX_CreateAllocator(FX_ALLOCTYPE_Static, 2048, 0);
- }
- CFDE_CSSDeclaration* pDecl = NULL;
- CFX_WideStringC wsAttri, wsValue;
- uint32_t dwAttriHash;
- do {
- pTag->GetNextAttribute(pos, wsAttri, wsValue);
- dwAttriHash =
+
+ CFDE_CSSDeclaration* pDecl = nullptr;
+ for (auto it : *pTag) {
+ CFX_WideString wsAttri = it.first;
+ CFX_WideString wsValue = it.second;
+
+ uint32_t dwAttriHash =
FX_HashCode_String_GetW(wsAttri.c_str(), wsAttri.GetLength(), TRUE);
- static const uint32_t s_dwStyleHash =
- FX_HashCode_String_GetW(L"style", 5, TRUE);
- static const uint32_t s_dwAlignHash =
- FX_HashCode_String_GetW(L"align", 5, TRUE);
if (dwAttriHash == s_dwStyleHash) {
- if (pDecl == NULL) {
+ if (!pDecl)
pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration;
- }
+
AppendInlineStyle(pDecl, wsValue.c_str(), wsValue.GetLength());
} else if (dwAttriHash == s_dwAlignHash) {
- if (pDecl == NULL) {
+ if (!pDecl)
pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration;
- }
+
FDE_CSSPROPERTYARGS args;
- args.pStringCache = NULL;
+ args.pStringCache = nullptr;
args.pStaticStore = m_pInlineStyleStore;
args.pProperty = FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY_TextAlign);
pDecl->AddProperty(&args, wsValue.c_str(), wsValue.GetLength());
}
- } while (pos != NULL);
- if (pDecl != NULL) {
+ }
+
+ if (pDecl) {
CFDE_CSSDeclarationArray decls;
decls.SetSize(iDeclCount + 1);
IFDE_CSSDeclaration** ppInline = decls.GetData();
@@ -466,12 +471,15 @@ void CFDE_CSSStyleSelector::ComputeStyle(
return;
}
}
+
if (iDeclCount > 0) {
- FXSYS_assert(ppDeclArray != NULL);
+ FXSYS_assert(ppDeclArray);
+
ApplyDeclarations(TRUE, ppDeclArray, iDeclCount, pDestStyle);
ApplyDeclarations(FALSE, ppDeclArray, iDeclCount, pDestStyle);
}
}
+
void CFDE_CSSStyleSelector::ApplyDeclarations(
FX_BOOL bPriority,
const IFDE_CSSDeclaration** ppDeclArray,
diff --git a/xfa/fde/css/fde_cssstyleselector.h b/xfa/fde/css/fde_cssstyleselector.h
index 93ea1f6057..8df8bd0250 100644
--- a/xfa/fde/css/fde_cssstyleselector.h
+++ b/xfa/fde/css/fde_cssstyleselector.h
@@ -18,6 +18,7 @@
class CFDE_CSSAccelerator;
class CFDE_CSSComputedStyle;
+class CXFA_CSSTagProvider;
class FDE_CSSRuleData : public CFX_Target {
public:
@@ -109,10 +110,10 @@ class CFDE_CSSStyleSelector : public IFDE_CSSStyleSelector, public CFX_Target {
virtual IFDE_CSSComputedStyle* CreateComputedStyle(
IFDE_CSSComputedStyle* pParentStyle);
virtual int32_t MatchDeclarations(
- IFDE_CSSTagProvider* pTag,
+ CXFA_CSSTagProvider* pTag,
CFDE_CSSDeclarationArray& matchedDecls,
FDE_CSSPERSUDO ePersudoType = FDE_CSSPERSUDO_NONE);
- virtual void ComputeStyle(IFDE_CSSTagProvider* pTag,
+ virtual void ComputeStyle(CXFA_CSSTagProvider* pTag,
const IFDE_CSSDeclaration** ppDeclArray,
int32_t iDeclCount,
IFDE_CSSComputedStyle* pDestStyle);