summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa')
-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
-rw-r--r--xfa/fxfa/app/xfa_textlayout.cpp33
-rw-r--r--xfa/fxfa/app/xfa_textlayout.h29
7 files changed, 90 insertions, 104 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);
diff --git a/xfa/fxfa/app/xfa_textlayout.cpp b/xfa/fxfa/app/xfa_textlayout.cpp
index c0a8895bc7..b2030814bc 100644
--- a/xfa/fxfa/app/xfa_textlayout.cpp
+++ b/xfa/fxfa/app/xfa_textlayout.cpp
@@ -21,40 +21,11 @@
#include "xfa/fxfa/include/xfa_ffdoc.h"
#include "xfa/fxfa/include/xfa_fontmgr.h"
-CXFA_CSSTagProvider::~CXFA_CSSTagProvider() {
- FX_POSITION pos = m_Attributes.GetStartPosition();
- while (pos) {
- CFX_WideString *pName = NULL, *pValue = NULL;
- m_Attributes.GetNextAssoc(pos, (void*&)pName, (void*&)pValue);
- delete pName;
- delete pValue;
- }
-}
-void CXFA_CSSTagProvider::GetNextAttribute(FX_POSITION& pos,
- CFX_WideStringC& wsAttr,
- CFX_WideStringC& wsValue) {
- if (pos == NULL) {
- return;
- }
- CFX_WideString* pName = NULL;
- CFX_WideString* pValue = NULL;
- m_Attributes.GetNextAssoc(pos, (void*&)pName, (void*&)pValue);
- wsAttr = pName->AsStringC();
- wsValue = pValue->AsStringC();
-}
-void CXFA_CSSTagProvider::SetAttribute(const CFX_WideString& wsAttr,
- const CFX_WideString& wsValue) {
- CFX_WideString* pName = new CFX_WideString();
- CFX_WideString* pValue = new CFX_WideString();
- *pName = wsAttr;
- *pValue = wsValue;
- m_Attributes.SetAt(pName, pValue);
-}
void CXFA_TextParseContext::SetDecls(const IFDE_CSSDeclaration** ppDeclArray,
int32_t iDeclCount) {
- if (iDeclCount <= 0 || ppDeclArray == NULL) {
+ if (iDeclCount <= 0 || !ppDeclArray)
return;
- }
+
m_dwMatchedDecls = iDeclCount;
m_ppMatchedDecls = FX_Alloc(IFDE_CSSDeclaration*, iDeclCount);
FXSYS_memcpy(m_ppMatchedDecls, ppDeclArray,
diff --git a/xfa/fxfa/app/xfa_textlayout.h b/xfa/fxfa/app/xfa_textlayout.h
index 9c3184b48b..9cced6a65a 100644
--- a/xfa/fxfa/app/xfa_textlayout.h
+++ b/xfa/fxfa/app/xfa_textlayout.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXFA_APP_XFA_TEXTLAYOUT_H_
#define XFA_FXFA_APP_XFA_TEXTLAYOUT_H_
+#include <map>
+
#include "xfa/fde/css/fde_css.h"
#include "xfa/fde/fde_gedevice.h"
#include "xfa/fgas/layout/fgas_rtfbreak.h"
@@ -20,28 +22,31 @@ class CXFA_Font;
class CXFA_TextProvider;
class CXFA_TextTabstopsContext;
-class CXFA_CSSTagProvider : public IFDE_CSSTagProvider {
+class CXFA_CSSTagProvider {
public:
CXFA_CSSTagProvider() : m_bTagAviliable(FALSE), m_bContent(FALSE) {}
- virtual ~CXFA_CSSTagProvider();
+ ~CXFA_CSSTagProvider() {}
+
+ CFX_WideString GetTagName() { return m_wsTagName; }
+
+ using AttributeMap = std::map<CFX_WideString, CFX_WideString>;
+ AttributeMap::iterator begin() { return m_Attributes.begin(); }
+ AttributeMap::iterator end() { return m_Attributes.end(); }
+
+ bool empty() const { return m_Attributes.empty(); }
- // Note: |this| must outlive the use of GetTagName()'s result.
- virtual CFX_WideStringC GetTagName() { return m_wsTagName.AsStringC(); }
- virtual FX_POSITION GetFirstAttribute() {
- return m_Attributes.GetStartPosition();
- }
- virtual void GetNextAttribute(FX_POSITION& pos,
- CFX_WideStringC& wsAttr,
- CFX_WideStringC& wsValue);
void SetTagNameObj(const CFX_WideString& wsName) { m_wsTagName = wsName; }
void SetAttribute(const CFX_WideString& wsAttr,
- const CFX_WideString& wsValue);
+ const CFX_WideString& wsValue) {
+ m_Attributes.insert({wsAttr, wsValue});
+ }
+
FX_BOOL m_bTagAviliable;
FX_BOOL m_bContent;
protected:
CFX_WideString m_wsTagName;
- CFX_MapPtrToPtr m_Attributes;
+ AttributeMap m_Attributes;
};
class CXFA_TextParseContext : public CFX_Target {