diff options
author | weili <weili@chromium.org> | 2016-06-18 06:25:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-18 06:25:37 -0700 |
commit | eec3a366adbfada36b98f1de651546ee09df8fc0 (patch) | |
tree | 794aa8c69392b60d8737a8a5b424732b98bdd4b4 /xfa/fde/css | |
parent | 4ce94e118d66064715de5baebeb4b2b580dcac66 (diff) | |
download | pdfium-eec3a366adbfada36b98f1de651546ee09df8fc0.tar.xz |
Make code compile with clang_use_chrome_plugin (final)
This change mainly contains files in xfa/ and fxjse/ directories
which were not covered by previous changes.
This is part of the efforts to make PDFium code compilable
by Clang chromium style plugins. After this change, PDFium can be
compiled with "clang_use_chrome_plugin=true" for GN build. Since
clang_use_chrome_plugin is true by default, we no longer need to
set this parameter explicitly.
The changes are mainly the following:
-- move inline constructor/destructor of complex class/struct out-of-line;
-- add constructor/destructor of complex class/struct if not
explicitly defined;
-- add explicit out-of-line copy constructor when needed;
-- move inline virtual functions out-of-line;
-- Properly mark virtual functions with 'override';
-- some minor cleanups;
BUG=pdfium:469
Review-Url: https://codereview.chromium.org/2072803002
Diffstat (limited to 'xfa/fde/css')
-rw-r--r-- | xfa/fde/css/fde_css.cpp | 27 | ||||
-rw-r--r-- | xfa/fde/css/fde_css.h | 24 | ||||
-rw-r--r-- | xfa/fde/css/fde_csscache.cpp | 6 | ||||
-rw-r--r-- | xfa/fde/css/fde_csscache.h | 6 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssdatatable.cpp | 72 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssdatatable.h | 76 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssstyleselector.cpp | 250 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssstyleselector.h | 276 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssstylesheet.cpp | 89 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssstylesheet.h | 61 | ||||
-rw-r--r-- | xfa/fde/css/fde_csssyntax.h | 3 |
11 files changed, 577 insertions, 313 deletions
diff --git a/xfa/fde/css/fde_css.cpp b/xfa/fde/css/fde_css.cpp new file mode 100644 index 0000000000..053b2774e6 --- /dev/null +++ b/xfa/fde/css/fde_css.cpp @@ -0,0 +1,27 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fde/css/fde_css.h" + +FDE_CSSVALUETYPE IFDE_CSSPrimitiveValue::GetType() const { + return FDE_CSSVALUETYPE_Primitive; +} + +FDE_CSSVALUETYPE IFDE_CSSValueList::GetType() const { + return FDE_CSSVALUETYPE_List; +} + +FDE_CSSRULETYPE IFDE_CSSStyleRule::GetType() const { + return FDE_CSSRULETYPE_Style; +} + +FDE_CSSRULETYPE IFDE_CSSMediaRule::GetType() const { + return FDE_CSSRULETYPE_Media; +} + +FDE_CSSRULETYPE IFDE_CSSFontFaceRule::GetType() const { + return FDE_CSSRULETYPE_FontFace; +} diff --git a/xfa/fde/css/fde_css.h b/xfa/fde/css/fde_css.h index 551f8f8962..a0ede3d9f7 100644 --- a/xfa/fde/css/fde_css.h +++ b/xfa/fde/css/fde_css.h @@ -690,9 +690,9 @@ class IFDE_CSSValue { class IFDE_CSSPrimitiveValue : public IFDE_CSSValue { public: - virtual FDE_CSSVALUETYPE GetType() const { - return FDE_CSSVALUETYPE_Primitive; - } + // IFDE_CSSValue + FDE_CSSVALUETYPE GetType() const override; + virtual FDE_CSSPRIMITIVETYPE GetPrimitiveType() const = 0; virtual FX_ARGB GetRGBColor() const = 0; virtual FX_FLOAT GetFloat() const = 0; @@ -705,7 +705,9 @@ class IFDE_CSSPrimitiveValue : public IFDE_CSSValue { class IFDE_CSSValueList : public IFDE_CSSValue { public: - virtual FDE_CSSVALUETYPE GetType() const { return FDE_CSSVALUETYPE_List; } + // IFDE_CSSValue + FDE_CSSVALUETYPE GetType() const override; + virtual int32_t CountValues() const = 0; virtual IFDE_CSSValue* GetValue(int32_t index) const = 0; }; @@ -715,11 +717,14 @@ class IFDE_CSSRule { virtual ~IFDE_CSSRule() {} virtual FDE_CSSRULETYPE GetType() const = 0; }; + typedef CFX_MassArrayTemplate<IFDE_CSSRule*> CFDE_CSSRuleArray; class IFDE_CSSStyleRule : public IFDE_CSSRule { public: - virtual FDE_CSSRULETYPE GetType() const { return FDE_CSSRULETYPE_Style; } + // IFDE_CSSValue + FDE_CSSRULETYPE GetType() const override; + virtual int32_t CountSelectorLists() const = 0; virtual CFDE_CSSSelector* GetSelectorList(int32_t index) const = 0; virtual CFDE_CSSDeclaration* GetDeclaration() = 0; @@ -727,7 +732,9 @@ class IFDE_CSSStyleRule : public IFDE_CSSRule { class IFDE_CSSMediaRule : public IFDE_CSSRule { public: - virtual FDE_CSSRULETYPE GetType() const { return FDE_CSSRULETYPE_Media; } + // IFDE_CSSValue + FDE_CSSRULETYPE GetType() const override; + virtual uint32_t GetMediaList() const = 0; virtual int32_t CountRules() const = 0; virtual IFDE_CSSRule* GetRule(int32_t index) = 0; @@ -735,7 +742,9 @@ class IFDE_CSSMediaRule : public IFDE_CSSRule { class IFDE_CSSFontFaceRule : public IFDE_CSSRule { public: - virtual FDE_CSSRULETYPE GetType() const { return FDE_CSSRULETYPE_FontFace; } + // IFDE_CSSValue + FDE_CSSRULETYPE GetType() const override; + virtual CFDE_CSSDeclaration* GetDeclaration() = 0; }; @@ -760,6 +769,7 @@ class IFDE_CSSStyleSheet : public IFX_Retainable { virtual int32_t CountRules() const = 0; virtual IFDE_CSSRule* GetRule(int32_t index) = 0; }; + typedef CFX_ArrayTemplate<IFDE_CSSStyleSheet*> CFDE_CSSStyleSheetArray; struct FDE_CSSLENGTH { diff --git a/xfa/fde/css/fde_csscache.cpp b/xfa/fde/css/fde_csscache.cpp index 76a893d2d1..a355a43c61 100644 --- a/xfa/fde/css/fde_csscache.cpp +++ b/xfa/fde/css/fde_csscache.cpp @@ -56,6 +56,12 @@ FDE_CSSTagCache::FDE_CSSTagCache(const FDE_CSSTagCache& it) dwClassHashs.Copy(it.dwClassHashs); } +FDE_CSSTagCache::~FDE_CSSTagCache() {} + +CFDE_CSSAccelerator::CFDE_CSSAccelerator() {} + +CFDE_CSSAccelerator::~CFDE_CSSAccelerator() {} + void CFDE_CSSAccelerator::OnEnterTag(CXFA_CSSTagProvider* pTag) { FDE_CSSTagCache* pTop = GetTopElement(); FDE_CSSTagCache item(pTop, pTag); diff --git a/xfa/fde/css/fde_csscache.h b/xfa/fde/css/fde_csscache.h index 28962e45eb..bab86ea880 100644 --- a/xfa/fde/css/fde_csscache.h +++ b/xfa/fde/css/fde_csscache.h @@ -15,7 +15,7 @@ class FDE_CSSCacheItem : public CFX_Target { public: explicit FDE_CSSCacheItem(IFDE_CSSStyleSheet* p); - ~FDE_CSSCacheItem(); + ~FDE_CSSCacheItem() override; IFDE_CSSStyleSheet* pStylesheet; uint32_t dwActivity; @@ -25,6 +25,7 @@ class FDE_CSSTagCache : public CFX_Target { public: FDE_CSSTagCache(FDE_CSSTagCache* parent, CXFA_CSSTagProvider* tag); FDE_CSSTagCache(const FDE_CSSTagCache& it); + ~FDE_CSSTagCache() override; FDE_CSSTagCache* GetParent() const { return pParent; } CXFA_CSSTagProvider* GetTag() const { return pTag; } @@ -52,6 +53,9 @@ typedef CFX_ObjectStackTemplate<FDE_CSSTagCache> CFDE_CSSTagStack; class CFDE_CSSAccelerator : public CFX_Target { public: + CFDE_CSSAccelerator(); + ~CFDE_CSSAccelerator() override; + void OnEnterTag(CXFA_CSSTagProvider* pTag); void OnLeaveTag(CXFA_CSSTagProvider* pTag); diff --git a/xfa/fde/css/fde_cssdatatable.cpp b/xfa/fde/css/fde_cssdatatable.cpp index ac8c466932..c2767e7eb2 100644 --- a/xfa/fde/css/fde_cssdatatable.cpp +++ b/xfa/fde/css/fde_cssdatatable.cpp @@ -795,6 +795,14 @@ CFDE_CSSValueList::CFDE_CSSValueList(IFX_MemoryAllocator* pStaticStore, m_ppList = (IFDE_CSSValue**)pStaticStore->Alloc(iByteCount); FXSYS_memcpy(m_ppList, list.GetData(), iByteCount); } + +int32_t CFDE_CSSValueList::CountValues() const { + return m_iCount; +} + +IFDE_CSSValue* CFDE_CSSValueList::GetValue(int32_t index) const { + return m_ppList[index]; +} FX_BOOL CFDE_CSSValueListParser::NextValue(FDE_CSSPRIMITIVETYPE& eType, const FX_WCHAR*& pStart, int32_t& iLength) { @@ -896,3 +904,67 @@ int32_t CFDE_CSSValueListParser::SkipTo(FX_WCHAR wch, } return m_pCur - pStart; } + +CFDE_CSSPrimitiveValue::CFDE_CSSPrimitiveValue( + const CFDE_CSSPrimitiveValue& src) = default; + +CFDE_CSSPrimitiveValue::CFDE_CSSPrimitiveValue(FX_ARGB color) + : m_eType(FDE_CSSPRIMITIVETYPE_RGB), m_dwColor(color) {} + +CFDE_CSSPrimitiveValue::CFDE_CSSPrimitiveValue(FDE_CSSPROPERTYVALUE eValue) + : m_eType(FDE_CSSPRIMITIVETYPE_Enum), m_eEnum(eValue) {} + +CFDE_CSSPrimitiveValue::CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, + FX_FLOAT fValue) + : m_eType(eType), m_fNumber(fValue) {} + +CFDE_CSSPrimitiveValue::CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, + const FX_WCHAR* pValue) + : m_eType(eType), m_pString(pValue) { + ASSERT(m_pString != nullptr); +} + +CFDE_CSSPrimitiveValue::CFDE_CSSPrimitiveValue(CFDE_CSSFunction* pFunction) + : m_eType(FDE_CSSPRIMITIVETYPE_Function), m_pFunction(pFunction) {} + +FDE_CSSPRIMITIVETYPE CFDE_CSSPrimitiveValue::GetPrimitiveType() const { + return m_eType; +} + +FX_ARGB CFDE_CSSPrimitiveValue::GetRGBColor() const { + ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_RGB); + return m_dwColor; +} + +FX_FLOAT CFDE_CSSPrimitiveValue::GetFloat() const { + ASSERT(m_eType >= FDE_CSSPRIMITIVETYPE_Number && + m_eType <= FDE_CSSPRIMITIVETYPE_PC); + return m_fNumber; +} + +const FX_WCHAR* CFDE_CSSPrimitiveValue::GetString(int32_t& iLength) const { + ASSERT(m_eType >= FDE_CSSPRIMITIVETYPE_String && + m_eType <= FDE_CSSPRIMITIVETYPE_URI); + iLength = FXSYS_wcslen(m_pString); + return m_pString; +} + +FDE_CSSPROPERTYVALUE CFDE_CSSPrimitiveValue::GetEnum() const { + ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Enum); + return m_eEnum; +} + +const FX_WCHAR* CFDE_CSSPrimitiveValue::GetFuncName() const { + ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); + return m_pFunction->GetFuncName(); +} + +int32_t CFDE_CSSPrimitiveValue::CountArgs() const { + ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); + return m_pFunction->CountArgs(); +} + +IFDE_CSSValue* CFDE_CSSPrimitiveValue::GetArgs(int32_t index) const { + ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); + return m_pFunction->GetArgs(index); +} diff --git a/xfa/fde/css/fde_cssdatatable.h b/xfa/fde/css/fde_cssdatatable.h index d61ff09ae7..252efdce50 100644 --- a/xfa/fde/css/fde_cssdatatable.h +++ b/xfa/fde/css/fde_cssdatatable.h @@ -27,56 +27,26 @@ class CFDE_CSSFunction : public CFX_Target { IFDE_CSSValueList* m_pArgList; const FX_WCHAR* m_pszFuncName; }; + class CFDE_CSSPrimitiveValue : public IFDE_CSSPrimitiveValue, public CFX_Target { public: - CFDE_CSSPrimitiveValue(const CFDE_CSSPrimitiveValue& src) { *this = src; } - CFDE_CSSPrimitiveValue(FX_ARGB color) - : m_eType(FDE_CSSPRIMITIVETYPE_RGB), m_dwColor(color) {} - CFDE_CSSPrimitiveValue(FDE_CSSPROPERTYVALUE eValue) - : m_eType(FDE_CSSPRIMITIVETYPE_Enum), m_eEnum(eValue) {} - CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, FX_FLOAT fValue) - : m_eType(eType), m_fNumber(fValue) {} - CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, const FX_WCHAR* pValue) - : m_eType(eType), m_pString(pValue) { - ASSERT(m_pString); - } - CFDE_CSSPrimitiveValue(CFDE_CSSFunction* pFunction) - : m_eType(FDE_CSSPRIMITIVETYPE_Function), m_pFunction(pFunction) {} - - virtual FDE_CSSPRIMITIVETYPE GetPrimitiveType() const { return m_eType; } - - virtual FX_ARGB GetRGBColor() const { - ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_RGB); - return m_dwColor; - } - virtual FX_FLOAT GetFloat() const { - ASSERT(m_eType >= FDE_CSSPRIMITIVETYPE_Number && - m_eType <= FDE_CSSPRIMITIVETYPE_PC); - return m_fNumber; - } - virtual const FX_WCHAR* GetString(int32_t& iLength) const { - ASSERT(m_eType >= FDE_CSSPRIMITIVETYPE_String && - m_eType <= FDE_CSSPRIMITIVETYPE_URI); - iLength = FXSYS_wcslen(m_pString); - return m_pString; - } - virtual FDE_CSSPROPERTYVALUE GetEnum() const { - ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Enum); - return m_eEnum; - } - virtual const FX_WCHAR* GetFuncName() const { - ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); - return m_pFunction->GetFuncName(); - } - virtual int32_t CountArgs() const { - ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); - return m_pFunction->CountArgs(); - } - virtual IFDE_CSSValue* GetArgs(int32_t index) const { - ASSERT(m_eType == FDE_CSSPRIMITIVETYPE_Function); - return m_pFunction->GetArgs(index); - } + explicit CFDE_CSSPrimitiveValue(FX_ARGB color); + explicit CFDE_CSSPrimitiveValue(FDE_CSSPROPERTYVALUE eValue); + explicit CFDE_CSSPrimitiveValue(CFDE_CSSFunction* pFunction); + CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, FX_FLOAT fValue); + CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, const FX_WCHAR* pValue); + CFDE_CSSPrimitiveValue(const CFDE_CSSPrimitiveValue& src); + + // IFDE_CSSPrimitiveValue + FDE_CSSPRIMITIVETYPE GetPrimitiveType() const override; + FX_ARGB GetRGBColor() const override; + FX_FLOAT GetFloat() const override; + const FX_WCHAR* GetString(int32_t& iLength) const override; + FDE_CSSPROPERTYVALUE GetEnum() const override; + const FX_WCHAR* GetFuncName() const override; + int32_t CountArgs() const override; + IFDE_CSSValue* GetArgs(int32_t index) const override; FDE_CSSPRIMITIVETYPE m_eType; union { @@ -87,21 +57,24 @@ class CFDE_CSSPrimitiveValue : public IFDE_CSSPrimitiveValue, CFDE_CSSFunction* m_pFunction; }; }; + typedef CFX_ArrayTemplate<IFDE_CSSPrimitiveValue*> CFDE_CSSPrimitiveArray; typedef CFX_ArrayTemplate<IFDE_CSSValue*> CFDE_CSSValueArray; + class CFDE_CSSValueList : public IFDE_CSSValueList, public CFX_Target { public: CFDE_CSSValueList(IFX_MemoryAllocator* pStaticStore, const CFDE_CSSValueArray& list); - virtual int32_t CountValues() const { return m_iCount; } - virtual IFDE_CSSValue* GetValue(int32_t index) const { - return m_ppList[index]; - } + + // IFDE_CSSValueList + int32_t CountValues() const override; + IFDE_CSSValue* GetValue(int32_t index) const override; protected: IFDE_CSSValue** m_ppList; int32_t m_iCount; }; + class CFDE_CSSValueListParser : public CFX_Target { public: CFDE_CSSValueListParser(const FX_WCHAR* psz, int32_t iLen, FX_WCHAR separator) @@ -117,6 +90,7 @@ class CFDE_CSSValueListParser : public CFX_Target { int32_t SkipTo(FX_WCHAR wch, FX_BOOL bWSSeparator = FALSE, FX_BOOL bBrContinue = FALSE); + const FX_WCHAR* m_pCur; const FX_WCHAR* m_pEnd; }; diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp index 007657d154..6082136fe0 100644 --- a/xfa/fde/css/fde_cssstyleselector.cpp +++ b/xfa/fde/css/fde_cssstyleselector.cpp @@ -74,6 +74,12 @@ void CFDE_CSSCounterStyle::DoUpdateIndex(IFDE_CSSValueList* pList) { } } } + +CFDE_CSSCounterStyle::CFDE_CSSCounterStyle() + : m_pCounterInc(nullptr), m_pCounterReset(nullptr), m_bIndexDirty(FALSE) {} + +CFDE_CSSCounterStyle::~CFDE_CSSCounterStyle() {} + void CFDE_CSSCounterStyle::UpdateIndex() { if (!m_bIndexDirty) { return; @@ -98,6 +104,7 @@ FDE_CSSRuleData::FDE_CSSRuleData(CFDE_CSSSelector* pSel, } } } + void CFDE_CSSRuleCollection::Clear() { m_IDRules.RemoveAll(); m_TagRules.RemoveAll(); @@ -106,6 +113,17 @@ void CFDE_CSSRuleCollection::Clear() { m_pStaticStore = nullptr; m_iSelectors = 0; } + +CFDE_CSSRuleCollection::CFDE_CSSRuleCollection() + : m_pStaticStore(nullptr), + m_pUniversalRules(nullptr), + m_pPersudoRules(nullptr), + m_iSelectors(0) {} + +CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() { + Clear(); +} + void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets, uint32_t dwMediaList, IFGAS_FontMgr* pFontMgr) { @@ -120,6 +138,7 @@ void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets, } } } + void CFDE_CSSRuleCollection::AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet, IFDE_CSSRule* pRule, uint32_t dwMediaList, @@ -179,6 +198,7 @@ void CFDE_CSSRuleCollection::AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet, break; } } + void CFDE_CSSRuleCollection::AddRuleTo(CFX_MapPtrToPtr& map, uint32_t dwKey, CFDE_CSSSelector* pSel, @@ -1783,3 +1803,233 @@ FDE_CSSFONTVARIANT CFDE_CSSStyleSelector::ToFontVariant( return eValue == FDE_CSSPROPERTYVALUE_SmallCaps ? FDE_CSSFONTVARIANT_SmallCaps : FDE_CSSFONTVARIANT_Normal; } + +CFDE_CSSComputedStyle::CFDE_CSSComputedStyle(IFX_MemoryAllocator* pAlloc) + : m_dwRefCount(1), m_pAllocator(pAlloc) {} + +CFDE_CSSComputedStyle::~CFDE_CSSComputedStyle() {} + +uint32_t CFDE_CSSComputedStyle::Retain() { + return ++m_dwRefCount; +} + +uint32_t CFDE_CSSComputedStyle::Release() { + uint32_t dwRefCount = --m_dwRefCount; + if (dwRefCount == 0) { + delete m_NonInheritedData.m_pCounterStyle; + FXTARGET_DeleteWith(CFDE_CSSComputedStyle, m_pAllocator, this); + } + return dwRefCount; +} + +void CFDE_CSSComputedStyle::Reset() { + m_InheritedData.Reset(); + m_NonInheritedData.Reset(); +} + +IFDE_CSSFontStyle* CFDE_CSSComputedStyle::GetFontStyles() { + return static_cast<IFDE_CSSFontStyle*>(this); +} + +IFDE_CSSBoundaryStyle* CFDE_CSSComputedStyle::GetBoundaryStyles() { + return static_cast<IFDE_CSSBoundaryStyle*>(this); +} + +IFDE_CSSPositionStyle* CFDE_CSSComputedStyle::GetPositionStyles() { + return static_cast<IFDE_CSSPositionStyle*>(this); +} + +IFDE_CSSParagraphStyle* CFDE_CSSComputedStyle::GetParagraphStyles() { + return static_cast<IFDE_CSSParagraphStyle*>(this); +} + +FX_BOOL CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideStringC& wsName, + CFX_WideString& wsValue) const { + for (int32_t i = m_CustomProperties.GetSize() - 2; i > -1; i -= 2) { + if (wsName == m_CustomProperties[i]) { + wsValue = m_CustomProperties[i + 1]; + return TRUE; + } + } + return FALSE; +} + +int32_t CFDE_CSSComputedStyle::CountFontFamilies() const { + return m_InheritedData.m_pFontFamily + ? m_InheritedData.m_pFontFamily->CountValues() + : 0; +} + +const FX_WCHAR* CFDE_CSSComputedStyle::GetFontFamily(int32_t index) const { + return (static_cast<IFDE_CSSPrimitiveValue*>( + m_InheritedData.m_pFontFamily->GetValue(index))) + ->GetString(index); +} + +uint16_t CFDE_CSSComputedStyle::GetFontWeight() const { + return m_InheritedData.m_wFontWeight; +} + +FDE_CSSFONTVARIANT CFDE_CSSComputedStyle::GetFontVariant() const { + return static_cast<FDE_CSSFONTVARIANT>(m_InheritedData.m_eFontVariant); +} + +FDE_CSSFONTSTYLE CFDE_CSSComputedStyle::GetFontStyle() const { + return static_cast<FDE_CSSFONTSTYLE>(m_InheritedData.m_eFontStyle); +} + +FX_FLOAT CFDE_CSSComputedStyle::GetFontSize() const { + return m_InheritedData.m_fFontSize; +} + +FX_ARGB CFDE_CSSComputedStyle::GetColor() const { + return m_InheritedData.m_dwFontColor; +} + +void CFDE_CSSComputedStyle::SetFontWeight(uint16_t wFontWeight) { + m_InheritedData.m_wFontWeight = wFontWeight; +} + +void CFDE_CSSComputedStyle::SetFontVariant(FDE_CSSFONTVARIANT eFontVariant) { + m_InheritedData.m_eFontVariant = eFontVariant; +} + +void CFDE_CSSComputedStyle::SetFontStyle(FDE_CSSFONTSTYLE eFontStyle) { + m_InheritedData.m_eFontStyle = eFontStyle; +} + +void CFDE_CSSComputedStyle::SetFontSize(FX_FLOAT fFontSize) { + m_InheritedData.m_fFontSize = fFontSize; +} + +void CFDE_CSSComputedStyle::SetColor(FX_ARGB dwFontColor) { + m_InheritedData.m_dwFontColor = dwFontColor; +} + +const FDE_CSSRECT* CFDE_CSSComputedStyle::GetBorderWidth() const { + return m_NonInheritedData.m_bHasBorder ? &(m_NonInheritedData.m_BorderWidth) + : nullptr; +} + +const FDE_CSSRECT* CFDE_CSSComputedStyle::GetMarginWidth() const { + return m_NonInheritedData.m_bHasMargin ? &(m_NonInheritedData.m_MarginWidth) + : nullptr; +} + +const FDE_CSSRECT* CFDE_CSSComputedStyle::GetPaddingWidth() const { + return m_NonInheritedData.m_bHasPadding ? &(m_NonInheritedData.m_PaddingWidth) + : nullptr; +} + +void CFDE_CSSComputedStyle::SetMarginWidth(const FDE_CSSRECT& rect) { + m_NonInheritedData.m_MarginWidth = rect; + m_NonInheritedData.m_bHasMargin = TRUE; +} + +void CFDE_CSSComputedStyle::SetPaddingWidth(const FDE_CSSRECT& rect) { + m_NonInheritedData.m_PaddingWidth = rect; + m_NonInheritedData.m_bHasPadding = TRUE; +} + +FDE_CSSDISPLAY CFDE_CSSComputedStyle::GetDisplay() const { + return static_cast<FDE_CSSDISPLAY>(m_NonInheritedData.m_eDisplay); +} + +FX_FLOAT CFDE_CSSComputedStyle::GetLineHeight() const { + return m_InheritedData.m_fLineHeight; +} + +const FDE_CSSLENGTH& CFDE_CSSComputedStyle::GetTextIndent() const { + return m_InheritedData.m_TextIndent; +} + +FDE_CSSTEXTALIGN CFDE_CSSComputedStyle::GetTextAlign() const { + return static_cast<FDE_CSSTEXTALIGN>(m_InheritedData.m_eTextAligh); +} + +FDE_CSSVERTICALALIGN CFDE_CSSComputedStyle::GetVerticalAlign() const { + return static_cast<FDE_CSSVERTICALALIGN>(m_NonInheritedData.m_eVerticalAlign); +} + +FX_FLOAT CFDE_CSSComputedStyle::GetNumberVerticalAlign() const { + return m_NonInheritedData.m_fVerticalAlign; +} + +uint32_t CFDE_CSSComputedStyle::GetTextDecoration() const { + return m_NonInheritedData.m_dwTextDecoration; +} + +const FDE_CSSLENGTH& CFDE_CSSComputedStyle::GetLetterSpacing() const { + return m_InheritedData.m_LetterSpacing; +} + +void CFDE_CSSComputedStyle::SetLineHeight(FX_FLOAT fLineHeight) { + m_InheritedData.m_fLineHeight = fLineHeight; +} + +void CFDE_CSSComputedStyle::SetTextIndent(const FDE_CSSLENGTH& textIndent) { + m_InheritedData.m_TextIndent = textIndent; +} + +void CFDE_CSSComputedStyle::SetTextAlign(FDE_CSSTEXTALIGN eTextAlign) { + m_InheritedData.m_eTextAligh = eTextAlign; +} + +void CFDE_CSSComputedStyle::SetNumberVerticalAlign(FX_FLOAT fAlign) { + m_NonInheritedData.m_eVerticalAlign = FDE_CSSVERTICALALIGN_Number, + m_NonInheritedData.m_fVerticalAlign = fAlign; +} + +void CFDE_CSSComputedStyle::SetTextDecoration(uint32_t dwTextDecoration) { + m_NonInheritedData.m_dwTextDecoration = dwTextDecoration; +} + +void CFDE_CSSComputedStyle::SetLetterSpacing( + const FDE_CSSLENGTH& letterSpacing) { + m_InheritedData.m_LetterSpacing = letterSpacing; +} + +void CFDE_CSSComputedStyle::AddCustomStyle(const CFX_WideString& wsName, + const CFX_WideString& wsValue) { + m_CustomProperties.Add(wsName); + m_CustomProperties.Add(wsValue); +} + +CFDE_CSSInheritedData::CFDE_CSSInheritedData() { + Reset(); +} + +void CFDE_CSSInheritedData::Reset() { + FXSYS_memset(this, 0, sizeof(CFDE_CSSInheritedData)); + m_LetterSpacing.Set(FDE_CSSLENGTHUNIT_Normal); + m_WordSpacing.Set(FDE_CSSLENGTHUNIT_Normal); + m_TextIndent.Set(FDE_CSSLENGTHUNIT_Point, 0); + m_fFontSize = 12.0f; + m_fLineHeight = 14.0f; + m_wFontWeight = 400; + m_dwFontColor = 0xFF000000; + m_iWidows = 2; + m_bTextEmphasisColorCurrent = TRUE; + m_iOrphans = 2; +} + +CFDE_CSSNonInheritedData::CFDE_CSSNonInheritedData() { + Reset(); +} + +void CFDE_CSSNonInheritedData::Reset() { + FXSYS_memset(this, 0, sizeof(CFDE_CSSNonInheritedData)); + m_PaddingWidth.Set(FDE_CSSLENGTHUNIT_Point, 0); + m_MarginWidth = m_PaddingWidth; + m_BorderWidth = m_PaddingWidth; + m_MinBoxSize.Set(FDE_CSSLENGTHUNIT_Point, 0); + m_MaxBoxSize.Set(FDE_CSSLENGTHUNIT_None); + m_eDisplay = FDE_CSSDISPLAY_Inline; + m_fVerticalAlign = 0.0f; + m_ColumnCount.Set(FDE_CSSLENGTHUNIT_Auto); + m_ColumnGap.Set(FDE_CSSLENGTHUNIT_Normal); + m_bColumnRuleColorSame = TRUE; + m_ColumnWidth.Set(FDE_CSSLENGTHUNIT_Auto); + m_ColumnRuleWidth.Set(FDE_CSSLENGTHUNIT_Auto); + m_eTextCombine = FDE_CSSTEXTCOMBINE_None; +} diff --git a/xfa/fde/css/fde_cssstyleselector.h b/xfa/fde/css/fde_cssstyleselector.h index 3af75a7b9e..042e989242 100644 --- a/xfa/fde/css/fde_cssstyleselector.h +++ b/xfa/fde/css/fde_cssstyleselector.h @@ -34,12 +34,8 @@ class FDE_CSSRuleData : public CFX_Target { class CFDE_CSSRuleCollection : public CFX_Target { public: - CFDE_CSSRuleCollection() - : m_pStaticStore(nullptr), - m_pUniversalRules(nullptr), - m_pPersudoRules(nullptr), - m_iSelectors(0) {} - ~CFDE_CSSRuleCollection() { Clear(); } + CFDE_CSSRuleCollection(); + ~CFDE_CSSRuleCollection() override; void AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets, uint32_t dwMediaList, @@ -211,33 +207,29 @@ struct FDE_CSSCOUNTERDATA { class CFDE_CSSCounterStyle { public: - CFDE_CSSCounterStyle() : m_pCounterInc(nullptr), m_pCounterReset(nullptr) {} + CFDE_CSSCounterStyle(); + ~CFDE_CSSCounterStyle(); void SetCounterIncrementList(IFDE_CSSValueList* pList) { m_pCounterInc = pList; m_bIndexDirty = TRUE; } - void SetCounterResetList(IFDE_CSSValueList* pList) { m_pCounterReset = pList; m_bIndexDirty = TRUE; } - int32_t CountCounters() { UpdateIndex(); return m_arrCounterData.GetSize(); } - FX_BOOL GetCounterIncrement(int32_t index, int32_t& iValue) { UpdateIndex(); return m_arrCounterData.ElementAt(index).GetCounterIncrement(iValue); } - FX_BOOL GetCounterReset(int32_t index, int32_t& iValue) { UpdateIndex(); return m_arrCounterData.ElementAt(index).GetCounterReset(iValue); } - const FX_WCHAR* GetCounterIdentifier(int32_t index) { UpdateIndex(); return m_arrCounterData.ElementAt(index).m_pszIdent; @@ -256,19 +248,9 @@ class CFDE_CSSCounterStyle { class CFDE_CSSInheritedData { public: - void Reset() { - FXSYS_memset(this, 0, sizeof(CFDE_CSSInheritedData)); - m_LetterSpacing.Set(FDE_CSSLENGTHUNIT_Normal); - m_WordSpacing.Set(FDE_CSSLENGTHUNIT_Normal); - m_TextIndent.Set(FDE_CSSLENGTHUNIT_Point, 0); - m_fFontSize = 12.0f; - m_fLineHeight = 14.0f; - m_wFontWeight = 400; - m_dwFontColor = 0xFF000000; - m_iWidows = 2; - m_bTextEmphasisColorCurrent = TRUE; - m_iOrphans = 2; - } + CFDE_CSSInheritedData(); + + void Reset(); const FX_WCHAR* m_pszListStyleImage; FDE_CSSLENGTH m_LetterSpacing; @@ -306,21 +288,9 @@ class CFDE_CSSInheritedData { class CFDE_CSSNonInheritedData { public: - void Reset() { - FXSYS_memset(this, 0, sizeof(CFDE_CSSNonInheritedData)); - m_MarginWidth = m_BorderWidth = - m_PaddingWidth.Set(FDE_CSSLENGTHUNIT_Point, 0); - m_MinBoxSize.Set(FDE_CSSLENGTHUNIT_Point, 0); - m_MaxBoxSize.Set(FDE_CSSLENGTHUNIT_None); - m_eDisplay = FDE_CSSDISPLAY_Inline; - m_fVerticalAlign = 0.0f; - m_ColumnCount.Set(FDE_CSSLENGTHUNIT_Auto); - m_ColumnGap.Set(FDE_CSSLENGTHUNIT_Normal); - m_bColumnRuleColorSame = TRUE; - m_ColumnWidth.Set(FDE_CSSLENGTHUNIT_Auto); - m_ColumnRuleWidth.Set(FDE_CSSLENGTHUNIT_Auto); - m_eTextCombine = FDE_CSSTEXTCOMBINE_None; - } + CFDE_CSSNonInheritedData(); + + void Reset(); IFDE_CSSValueList* m_pContentList; CFDE_CSSCounterStyle* m_pCounterStyle; @@ -385,196 +355,62 @@ class CFDE_CSSComputedStyle : public IFDE_CSSComputedStyle, public IFDE_CSSParagraphStyle, public CFX_Target { public: - CFDE_CSSComputedStyle(IFX_MemoryAllocator* pAlloc) - : m_dwRefCount(1), m_pAllocator(pAlloc) {} - - ~CFDE_CSSComputedStyle() override {} - - // IFX_Retainable: - uint32_t Retain() override { return ++m_dwRefCount; } - uint32_t Release() override { - uint32_t dwRefCount = --m_dwRefCount; - if (dwRefCount == 0) { - delete m_NonInheritedData.m_pCounterStyle; - FXTARGET_DeleteWith(CFDE_CSSComputedStyle, m_pAllocator, this); - } - return dwRefCount; - } - - // IFDE_CSSComputedStyle: - void Reset() override { - m_InheritedData.Reset(); - m_NonInheritedData.Reset(); - } - - IFDE_CSSFontStyle* GetFontStyles() override { - return static_cast<IFDE_CSSFontStyle*>(this); - } - - IFDE_CSSBoundaryStyle* GetBoundaryStyles() override { - return static_cast<IFDE_CSSBoundaryStyle*>(this); - } - - IFDE_CSSPositionStyle* GetPositionStyles() override { - return static_cast<IFDE_CSSPositionStyle*>(this); - } - - IFDE_CSSParagraphStyle* GetParagraphStyles() override { - return static_cast<IFDE_CSSParagraphStyle*>(this); - } - + CFDE_CSSComputedStyle(IFX_MemoryAllocator* pAlloc); + ~CFDE_CSSComputedStyle() override; + + // IFX_Retainable + uint32_t Retain() override; + uint32_t Release() override; + + // IFDE_CSSComputedStyle + void Reset() override; + IFDE_CSSFontStyle* GetFontStyles() override; + IFDE_CSSBoundaryStyle* GetBoundaryStyles() override; + IFDE_CSSPositionStyle* GetPositionStyles() override; + IFDE_CSSParagraphStyle* GetParagraphStyles() override; FX_BOOL GetCustomStyle(const CFX_WideStringC& wsName, - CFX_WideString& wsValue) const override { - for (int32_t i = m_CustomProperties.GetSize() - 2; i > -1; i -= 2) { - if (wsName == m_CustomProperties[i]) { - wsValue = m_CustomProperties[i + 1]; - return TRUE; - } - } - return FALSE; - } + CFX_WideString& wsValue) const override; // IFDE_CSSFontStyle: - int32_t CountFontFamilies() const override { - return m_InheritedData.m_pFontFamily - ? m_InheritedData.m_pFontFamily->CountValues() - : 0; - } - - const FX_WCHAR* GetFontFamily(int32_t index) const override { - return (static_cast<IFDE_CSSPrimitiveValue*>( - m_InheritedData.m_pFontFamily->GetValue(index))) - ->GetString(index); - } - - uint16_t GetFontWeight() const override { - return m_InheritedData.m_wFontWeight; - } - - FDE_CSSFONTVARIANT GetFontVariant() const override { - return static_cast<FDE_CSSFONTVARIANT>(m_InheritedData.m_eFontVariant); - } - - FDE_CSSFONTSTYLE GetFontStyle() const override { - return static_cast<FDE_CSSFONTSTYLE>(m_InheritedData.m_eFontStyle); - } - - FX_FLOAT GetFontSize() const override { return m_InheritedData.m_fFontSize; } - - FX_ARGB GetColor() const override { return m_InheritedData.m_dwFontColor; } - - void SetFontWeight(uint16_t wFontWeight) override { - m_InheritedData.m_wFontWeight = wFontWeight; - } - - void SetFontVariant(FDE_CSSFONTVARIANT eFontVariant) override { - m_InheritedData.m_eFontVariant = eFontVariant; - } - - void SetFontStyle(FDE_CSSFONTSTYLE eFontStyle) override { - m_InheritedData.m_eFontStyle = eFontStyle; - } - - void SetFontSize(FX_FLOAT fFontSize) override { - m_InheritedData.m_fFontSize = fFontSize; - } - - void SetColor(FX_ARGB dwFontColor) override { - m_InheritedData.m_dwFontColor = dwFontColor; - } + int32_t CountFontFamilies() const override; + const FX_WCHAR* GetFontFamily(int32_t index) const override; + uint16_t GetFontWeight() const override; + FDE_CSSFONTVARIANT GetFontVariant() const override; + FDE_CSSFONTSTYLE GetFontStyle() const override; + FX_FLOAT GetFontSize() const override; + FX_ARGB GetColor() const override; + void SetFontWeight(uint16_t wFontWeight) override; + void SetFontVariant(FDE_CSSFONTVARIANT eFontVariant) override; + void SetFontStyle(FDE_CSSFONTSTYLE eFontStyle) override; + void SetFontSize(FX_FLOAT fFontSize) override; + void SetColor(FX_ARGB dwFontColor) override; // IFDE_CSSBoundaryStyle: - const FDE_CSSRECT* GetBorderWidth() const override { - return m_NonInheritedData.m_bHasBorder ? &(m_NonInheritedData.m_BorderWidth) - : nullptr; - } - - const FDE_CSSRECT* GetMarginWidth() const override { - return m_NonInheritedData.m_bHasMargin ? &(m_NonInheritedData.m_MarginWidth) - : nullptr; - } - - const FDE_CSSRECT* GetPaddingWidth() const override { - return m_NonInheritedData.m_bHasPadding - ? &(m_NonInheritedData.m_PaddingWidth) - : nullptr; - } - - void SetMarginWidth(const FDE_CSSRECT& rect) override { - m_NonInheritedData.m_MarginWidth = rect; - m_NonInheritedData.m_bHasMargin = TRUE; - } - - void SetPaddingWidth(const FDE_CSSRECT& rect) override { - m_NonInheritedData.m_PaddingWidth = rect; - m_NonInheritedData.m_bHasPadding = TRUE; - } + const FDE_CSSRECT* GetBorderWidth() const override; + const FDE_CSSRECT* GetMarginWidth() const override; + const FDE_CSSRECT* GetPaddingWidth() const override; + void SetMarginWidth(const FDE_CSSRECT& rect) override; + void SetPaddingWidth(const FDE_CSSRECT& rect) override; // IFDE_CSSPositionStyle: - FDE_CSSDISPLAY GetDisplay() const override { - return static_cast<FDE_CSSDISPLAY>(m_NonInheritedData.m_eDisplay); - } + FDE_CSSDISPLAY GetDisplay() const override; // IFDE_CSSParagraphStyle: - FX_FLOAT GetLineHeight() const override { - return m_InheritedData.m_fLineHeight; - } - - const FDE_CSSLENGTH& GetTextIndent() const override { - return m_InheritedData.m_TextIndent; - } - - FDE_CSSTEXTALIGN GetTextAlign() const override { - return static_cast<FDE_CSSTEXTALIGN>(m_InheritedData.m_eTextAligh); - } - - FDE_CSSVERTICALALIGN GetVerticalAlign() const override { - return static_cast<FDE_CSSVERTICALALIGN>( - m_NonInheritedData.m_eVerticalAlign); - } - - FX_FLOAT GetNumberVerticalAlign() const override { - return m_NonInheritedData.m_fVerticalAlign; - } - - uint32_t GetTextDecoration() const override { - return m_NonInheritedData.m_dwTextDecoration; - } - - const FDE_CSSLENGTH& GetLetterSpacing() const override { - return m_InheritedData.m_LetterSpacing; - } - - void SetLineHeight(FX_FLOAT fLineHeight) override { - m_InheritedData.m_fLineHeight = fLineHeight; - } - - void SetTextIndent(const FDE_CSSLENGTH& textIndent) override { - m_InheritedData.m_TextIndent = textIndent; - } - - void SetTextAlign(FDE_CSSTEXTALIGN eTextAlign) override { - m_InheritedData.m_eTextAligh = eTextAlign; - } - - void SetNumberVerticalAlign(FX_FLOAT fAlign) override { - m_NonInheritedData.m_eVerticalAlign = FDE_CSSVERTICALALIGN_Number, - m_NonInheritedData.m_fVerticalAlign = fAlign; - } - - void SetTextDecoration(uint32_t dwTextDecoration) override { - m_NonInheritedData.m_dwTextDecoration = dwTextDecoration; - } - - void SetLetterSpacing(const FDE_CSSLENGTH& letterSpacing) override { - m_InheritedData.m_LetterSpacing = letterSpacing; - } - + FX_FLOAT GetLineHeight() const override; + const FDE_CSSLENGTH& GetTextIndent() const override; + FDE_CSSTEXTALIGN GetTextAlign() const override; + FDE_CSSVERTICALALIGN GetVerticalAlign() const override; + FX_FLOAT GetNumberVerticalAlign() const override; + uint32_t GetTextDecoration() const override; + const FDE_CSSLENGTH& GetLetterSpacing() const override; + void SetLineHeight(FX_FLOAT fLineHeight) override; + void SetTextIndent(const FDE_CSSLENGTH& textIndent) override; + void SetTextAlign(FDE_CSSTEXTALIGN eTextAlign) override; + void SetNumberVerticalAlign(FX_FLOAT fAlign) override; + void SetTextDecoration(uint32_t dwTextDecoration) override; + void SetLetterSpacing(const FDE_CSSLENGTH& letterSpacing) override; void AddCustomStyle(const CFX_WideString& wsName, - const CFX_WideString& wsValue) { - m_CustomProperties.Add(wsName); - m_CustomProperties.Add(wsValue); - } + const CFX_WideString& wsValue); uint32_t m_dwRefCount; IFX_MemoryAllocator* m_pAllocator; diff --git a/xfa/fde/css/fde_cssstylesheet.cpp b/xfa/fde/css/fde_cssstylesheet.cpp index 6708ca2e72..f0b071223f 100644 --- a/xfa/fde/css/fde_cssstylesheet.cpp +++ b/xfa/fde/css/fde_cssstylesheet.cpp @@ -59,6 +59,7 @@ IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromStream( } return pStyleSheet; } + IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromBuffer( const CFX_WideString& szUrl, const FX_WCHAR* pBuffer, @@ -72,6 +73,7 @@ IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromBuffer( } return pStyleSheet; } + CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(uint32_t dwMediaList) : m_wCodePage(FX_CODEPAGE_UTF8), m_wRefCount(1), @@ -79,9 +81,11 @@ CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(uint32_t dwMediaList) m_pAllocator(nullptr) { ASSERT(m_dwMediaList > 0); } + CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() { Reset(); } + void CFDE_CSSStyleSheet::Reset() { for (int32_t i = m_RuleArray.GetSize() - 1; i >= 0; --i) { IFDE_CSSRule* pRule = m_RuleArray.GetAt(i); @@ -106,9 +110,11 @@ void CFDE_CSSStyleSheet::Reset() { delete m_pAllocator; m_pAllocator = nullptr; } + uint32_t CFDE_CSSStyleSheet::Retain() { return ++m_wRefCount; } + uint32_t CFDE_CSSStyleSheet::Release() { uint32_t dwRefCount = --m_wRefCount; if (dwRefCount == 0) { @@ -116,9 +122,24 @@ uint32_t CFDE_CSSStyleSheet::Release() { } return dwRefCount; } + +FX_BOOL CFDE_CSSStyleSheet::GetUrl(CFX_WideString& szUrl) { + szUrl = m_szUrl; + return szUrl.GetLength() > 0; +} + +uint32_t CFDE_CSSStyleSheet::GetMediaList() const { + return m_dwMediaList; +} + +uint16_t CFDE_CSSStyleSheet::GetCodePage() const { + return m_wCodePage; +} + int32_t CFDE_CSSStyleSheet::CountRules() const { return m_RuleArray.GetSize(); } + IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { return m_RuleArray.GetAt(index); } @@ -178,6 +199,7 @@ FX_BOOL CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) { m_StringCache.clear(); return eStatus != FDE_CSSSYNTAXSTATUS_Error; } + FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( CFDE_CSSSyntaxParser* pSyntax) { uint32_t dwMediaList = 0; @@ -216,6 +238,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( } } } + FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( CFDE_CSSSyntaxParser* pSyntax, CFDE_CSSRuleArray& ruleArray) { @@ -280,6 +303,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( } } } + FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule( CFDE_CSSSyntaxParser* pSyntax, CFDE_CSSRuleArray& ruleArray) { @@ -318,6 +342,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule( } } } + FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadImportRule( CFDE_CSSSyntaxParser* pSyntax) { for (;;) { @@ -330,10 +355,12 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadImportRule( } } } + FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadPageRule( CFDE_CSSSyntaxParser* pSyntax) { return SkipRuleSet(pSyntax); } + FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::SkipRuleSet( CFDE_CSSSyntaxParser* pSyntax) { for (;;) { @@ -349,6 +376,21 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::SkipRuleSet( } } } + +CFDE_CSSStyleRule::CFDE_CSSStyleRule() : m_ppSelector(NULL), m_iSelectors(0) {} + +int32_t CFDE_CSSStyleRule::CountSelectorLists() const { + return m_iSelectors; +} + +CFDE_CSSSelector* CFDE_CSSStyleRule::GetSelectorList(int32_t index) const { + return m_ppSelector[index]; +} + +CFDE_CSSDeclaration* CFDE_CSSStyleRule::GetDeclaration() { + return &m_Declaration; +} + void CFDE_CSSStyleRule::SetSelector(IFX_MemoryAllocator* pStaticStore, const CFDE_CSSSelectorArray& list) { ASSERT(!m_ppSelector); @@ -359,6 +401,10 @@ void CFDE_CSSStyleRule::SetSelector(IFX_MemoryAllocator* pStaticStore, m_ppSelector[i] = list.GetAt(i); } } + +CFDE_CSSMediaRule::CFDE_CSSMediaRule(uint32_t dwMediaList) + : m_dwMediaList(dwMediaList) {} + CFDE_CSSMediaRule::~CFDE_CSSMediaRule() { for (int32_t i = m_RuleArray.GetSize() - 1; i >= 0; --i) { IFDE_CSSRule* pRule = m_RuleArray.GetAt(i); @@ -372,9 +418,23 @@ CFDE_CSSMediaRule::~CFDE_CSSMediaRule() { } } } -inline FX_BOOL FDE_IsCSSChar(FX_WCHAR wch) { + +uint32_t CFDE_CSSMediaRule::GetMediaList() const { + return m_dwMediaList; +} + +int32_t CFDE_CSSMediaRule::CountRules() const { + return m_RuleArray.GetSize(); +} + +IFDE_CSSRule* CFDE_CSSMediaRule::GetRule(int32_t index) { + return m_RuleArray.GetAt(index); +} + +FX_BOOL FDE_IsCSSChar(FX_WCHAR wch) { return (wch >= 'a' && wch <= 'z') || (wch >= 'A' && wch <= 'Z'); } + int32_t FDE_GetCSSPersudoLen(const FX_WCHAR* psz, const FX_WCHAR* pEnd) { ASSERT(*psz == ':'); const FX_WCHAR* pStart = psz; @@ -388,6 +448,7 @@ int32_t FDE_GetCSSPersudoLen(const FX_WCHAR* psz, const FX_WCHAR* pEnd) { } return psz - pStart; } + int32_t FDE_GetCSSNameLen(const FX_WCHAR* psz, const FX_WCHAR* pEnd) { const FX_WCHAR* pStart = psz; while (psz < pEnd) { @@ -401,11 +462,33 @@ int32_t FDE_GetCSSNameLen(const FX_WCHAR* psz, const FX_WCHAR* pEnd) { } return psz - pStart; } + +CFDE_CSSSelector::CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType, + const FX_WCHAR* psz, + int32_t iLen, + bool bIgnoreCase) + : m_eType(eType), + m_dwHash(FX_HashCode_GetW(CFX_WideStringC(psz, iLen), bIgnoreCase)), + m_pNext(nullptr) {} + +FDE_CSSSELECTORTYPE CFDE_CSSSelector::GetType() const { + return m_eType; +} + +uint32_t CFDE_CSSSelector::GetNameHash() const { + return m_dwHash; +} + +CFDE_CSSSelector* CFDE_CSSSelector::GetNextSelector() const { + return m_pNext; +} + CFDE_CSSSelector* CFDE_CSSSelector::FromString( IFX_MemoryAllocator* pStaticStore, const FX_WCHAR* psz, int32_t iLen) { ASSERT(pStaticStore && psz && iLen > 0); + const FX_WCHAR* pStart = psz; const FX_WCHAR* pEnd = psz + iLen; for (; psz < pEnd; ++psz) { @@ -496,3 +579,7 @@ CFDE_CSSSelector* CFDE_CSSSelector::FromString( pPersudoLast->SetNext(pFirst); return pPersudoFirst; } + +CFDE_CSSDeclaration* CFDE_CSSFontFaceRule::GetDeclaration() { + return &m_Declaration; +} diff --git a/xfa/fde/css/fde_cssstylesheet.h b/xfa/fde/css/fde_cssstylesheet.h index 4c51579661..83eac993e7 100644 --- a/xfa/fde/css/fde_cssstylesheet.h +++ b/xfa/fde/css/fde_cssstylesheet.h @@ -19,42 +19,37 @@ class CFDE_CSSSelector : public CFX_Target { CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType, const FX_WCHAR* psz, int32_t iLen, - bool bIgnoreCase) - : m_eType(eType), - m_dwHash(FX_HashCode_GetW(CFX_WideStringC(psz, iLen), bIgnoreCase)), - m_pNext(nullptr) {} - virtual FDE_CSSSELECTORTYPE GetType() const { return m_eType; } + bool bIgnoreCase); - virtual uint32_t GetNameHash() const { return m_dwHash; } + virtual FDE_CSSSELECTORTYPE GetType() const; + virtual uint32_t GetNameHash() const; + virtual CFDE_CSSSelector* GetNextSelector() const; - virtual CFDE_CSSSelector* GetNextSelector() const { return m_pNext; } static CFDE_CSSSelector* FromString(IFX_MemoryAllocator* pStaticStore, const FX_WCHAR* psz, int32_t iLen); + void SetNext(CFDE_CSSSelector* pNext) { m_pNext = pNext; } protected: - static CFDE_CSSSelector* ParseSelector(IFX_MemoryAllocator* pStaticStore, - const FX_WCHAR* psz, - int32_t& iOff, - int32_t iLen, - FDE_CSSSELECTORTYPE eType); void SetType(FDE_CSSSELECTORTYPE eType) { m_eType = eType; } + FDE_CSSSELECTORTYPE m_eType; uint32_t m_dwHash; CFDE_CSSSelector* m_pNext; }; + typedef CFX_ArrayTemplate<CFDE_CSSSelector*> CFDE_CSSSelectorArray; class CFDE_CSSStyleRule : public IFDE_CSSStyleRule, public CFX_Target { public: - CFDE_CSSStyleRule() : m_ppSelector(nullptr), m_iSelectors(0) {} - int32_t CountSelectorLists() const override { return m_iSelectors; } - CFDE_CSSSelector* GetSelectorList(int32_t index) const override { - return m_ppSelector[index]; - } + CFDE_CSSStyleRule(); + + // IFDE_CSSStyleRule + int32_t CountSelectorLists() const override; + CFDE_CSSSelector* GetSelectorList(int32_t index) const override; + CFDE_CSSDeclaration* GetDeclaration() override; - CFDE_CSSDeclaration* GetDeclaration() override { return &m_Declaration; } CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } void SetSelector(IFX_MemoryAllocator* pStaticStore, const CFDE_CSSSelectorArray& list); @@ -64,37 +59,42 @@ class CFDE_CSSStyleRule : public IFDE_CSSStyleRule, public CFX_Target { CFDE_CSSSelector** m_ppSelector; int32_t m_iSelectors; }; + class CFDE_CSSMediaRule : public IFDE_CSSMediaRule, public CFX_Target { public: - CFDE_CSSMediaRule(uint32_t dwMediaList) : m_dwMediaList(dwMediaList) {} - ~CFDE_CSSMediaRule(); + explicit CFDE_CSSMediaRule(uint32_t dwMediaList); + ~CFDE_CSSMediaRule() override; - virtual uint32_t GetMediaList() const { return m_dwMediaList; } + // IFDE_CSSMediaRule + uint32_t GetMediaList() const override; + int32_t CountRules() const override; + IFDE_CSSRule* GetRule(int32_t index) override; - virtual int32_t CountRules() const { return m_RuleArray.GetSize(); } - virtual IFDE_CSSRule* GetRule(int32_t index) { - return m_RuleArray.GetAt(index); - } CFDE_CSSRuleArray& GetArray() { return m_RuleArray; } protected: uint32_t m_dwMediaList; CFDE_CSSRuleArray m_RuleArray; }; + class CFDE_CSSFontFaceRule : public IFDE_CSSFontFaceRule, public CFX_Target { public: - CFDE_CSSDeclaration* GetDeclaration() override { return &m_Declaration; } + // IFDE_CSSFontFaceRule + CFDE_CSSDeclaration* GetDeclaration() override; + CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } protected: CFDE_CSSDeclaration m_Declaration; }; + #define FDE_CSSSWITCHDEFAULTS() \ case FDE_CSSSYNTAXSTATUS_EOS: \ return FDE_CSSSYNTAXSTATUS_EOS; \ case FDE_CSSSYNTAXSTATUS_Error: \ default: \ return FDE_CSSSYNTAXSTATUS_Error; + class CFDE_CSSStyleSheet : public IFDE_CSSStyleSheet, public CFX_Target { public: CFDE_CSSStyleSheet(uint32_t dwMediaList); @@ -105,12 +105,9 @@ class CFDE_CSSStyleSheet : public IFDE_CSSStyleSheet, public CFX_Target { uint32_t Release() override; // IFDE_CSSStyleSheet: - FX_BOOL GetUrl(CFX_WideString& szUrl) override { - szUrl = m_szUrl; - return szUrl.GetLength() > 0; - } - uint32_t GetMediaList() const override { return m_dwMediaList; } - uint16_t GetCodePage() const override { return m_wCodePage; } + FX_BOOL GetUrl(CFX_WideString& szUrl) override; + uint32_t GetMediaList() const override; + uint16_t GetCodePage() const override; int32_t CountRules() const override; IFDE_CSSRule* GetRule(int32_t index) override; diff --git a/xfa/fde/css/fde_csssyntax.h b/xfa/fde/css/fde_csssyntax.h index a4e9249055..294dfcb540 100644 --- a/xfa/fde/css/fde_csssyntax.h +++ b/xfa/fde/css/fde_csssyntax.h @@ -14,7 +14,8 @@ class CFDE_CSSTextBuf : public CFX_Target { public: CFDE_CSSTextBuf(); - ~CFDE_CSSTextBuf(); + ~CFDE_CSSTextBuf() override; + FX_BOOL AttachBuffer(const FX_WCHAR* pBuffer, int32_t iBufLen); FX_BOOL EstimateSize(int32_t iAllocSize); int32_t LoadFromStream(IFX_Stream* pTxtStream, |