Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: xfa/fde/css/fde_cssstyleselector.cpp

Issue 2072803002: Make code compile with clang_use_chrome_plugin (final) (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: tidy Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fde/css/fde_cssstyleselector.h" 7 #include "xfa/fde/css/fde_cssstyleselector.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 if (bDefIncrement) { 67 if (bDefIncrement) {
68 data.m_bIncrement = TRUE; 68 data.m_bIncrement = TRUE;
69 data.m_iIncVal += (int32_t)fValue; 69 data.m_iIncVal += (int32_t)fValue;
70 } else { 70 } else {
71 data.m_bReset = TRUE; 71 data.m_bReset = TRUE;
72 data.m_iResetVal = (int32_t)fValue; 72 data.m_iResetVal = (int32_t)fValue;
73 } 73 }
74 } 74 }
75 } 75 }
76 } 76 }
77
78 CFDE_CSSCounterStyle::CFDE_CSSCounterStyle()
79 : m_pCounterInc(nullptr), m_pCounterReset(nullptr), m_bIndexDirty(FALSE) {}
80
81 CFDE_CSSCounterStyle::~CFDE_CSSCounterStyle() {}
82
77 void CFDE_CSSCounterStyle::UpdateIndex() { 83 void CFDE_CSSCounterStyle::UpdateIndex() {
78 if (!m_bIndexDirty) { 84 if (!m_bIndexDirty) {
79 return; 85 return;
80 } 86 }
81 m_arrCounterData.RemoveAll(); 87 m_arrCounterData.RemoveAll();
82 DoUpdateIndex(m_pCounterInc); 88 DoUpdateIndex(m_pCounterInc);
83 DoUpdateIndex(m_pCounterReset); 89 DoUpdateIndex(m_pCounterReset);
84 m_bIndexDirty = FALSE; 90 m_bIndexDirty = FALSE;
85 } 91 }
86 92
87 FDE_CSSRuleData::FDE_CSSRuleData(CFDE_CSSSelector* pSel, 93 FDE_CSSRuleData::FDE_CSSRuleData(CFDE_CSSSelector* pSel,
88 CFDE_CSSDeclaration* pDecl, 94 CFDE_CSSDeclaration* pDecl,
89 uint32_t dwPos) 95 uint32_t dwPos)
90 : pSelector(pSel), pDeclaration(pDecl), dwPriority(dwPos), pNext(nullptr) { 96 : pSelector(pSel), pDeclaration(pDecl), dwPriority(dwPos), pNext(nullptr) {
91 static const uint32_t s_Specific[5] = {0x00010000, 0x00010000, 0x00100000, 97 static const uint32_t s_Specific[5] = {0x00010000, 0x00010000, 0x00100000,
92 0x00100000, 0x01000000}; 98 0x00100000, 0x01000000};
93 for (; pSel; pSel = pSel->GetNextSelector()) { 99 for (; pSel; pSel = pSel->GetNextSelector()) {
94 FDE_CSSSELECTORTYPE eType = pSel->GetType(); 100 FDE_CSSSELECTORTYPE eType = pSel->GetType();
95 if (eType > FDE_CSSSELECTORTYPE_Descendant || 101 if (eType > FDE_CSSSELECTORTYPE_Descendant ||
96 pSel->GetNameHash() != FDE_CSSUNIVERSALHASH) { 102 pSel->GetNameHash() != FDE_CSSUNIVERSALHASH) {
97 dwPriority += s_Specific[eType]; 103 dwPriority += s_Specific[eType];
98 } 104 }
99 } 105 }
100 } 106 }
107
101 void CFDE_CSSRuleCollection::Clear() { 108 void CFDE_CSSRuleCollection::Clear() {
102 m_IDRules.RemoveAll(); 109 m_IDRules.RemoveAll();
103 m_TagRules.RemoveAll(); 110 m_TagRules.RemoveAll();
104 m_ClassRules.RemoveAll(); 111 m_ClassRules.RemoveAll();
105 m_pUniversalRules = nullptr; 112 m_pUniversalRules = nullptr;
106 m_pStaticStore = nullptr; 113 m_pStaticStore = nullptr;
107 m_iSelectors = 0; 114 m_iSelectors = 0;
108 } 115 }
116
117 CFDE_CSSRuleCollection::CFDE_CSSRuleCollection()
118 : m_pStaticStore(nullptr),
119 m_pUniversalRules(nullptr),
120 m_pPersudoRules(nullptr),
121 m_iSelectors(0) {}
122
123 CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
124 Clear();
125 }
126
109 void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets, 127 void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets,
110 uint32_t dwMediaList, 128 uint32_t dwMediaList,
111 IFGAS_FontMgr* pFontMgr) { 129 IFGAS_FontMgr* pFontMgr) {
112 int32_t iSheets = sheets.GetSize(); 130 int32_t iSheets = sheets.GetSize();
113 for (int32_t i = 0; i < iSheets; ++i) { 131 for (int32_t i = 0; i < iSheets; ++i) {
114 IFDE_CSSStyleSheet* pSheet = sheets.GetAt(i); 132 IFDE_CSSStyleSheet* pSheet = sheets.GetAt(i);
115 if (uint32_t dwMatchMedia = pSheet->GetMediaList() & dwMediaList) { 133 if (uint32_t dwMatchMedia = pSheet->GetMediaList() & dwMediaList) {
116 int32_t iRules = pSheet->CountRules(); 134 int32_t iRules = pSheet->CountRules();
117 for (int32_t j = 0; j < iRules; j++) { 135 for (int32_t j = 0; j < iRules; j++) {
118 AddRulesFrom(pSheet, pSheet->GetRule(j), dwMatchMedia, pFontMgr); 136 AddRulesFrom(pSheet, pSheet->GetRule(j), dwMatchMedia, pFontMgr);
119 } 137 }
120 } 138 }
121 } 139 }
122 } 140 }
141
123 void CFDE_CSSRuleCollection::AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet, 142 void CFDE_CSSRuleCollection::AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet,
124 IFDE_CSSRule* pRule, 143 IFDE_CSSRule* pRule,
125 uint32_t dwMediaList, 144 uint32_t dwMediaList,
126 IFGAS_FontMgr* pFontMgr) { 145 IFGAS_FontMgr* pFontMgr) {
127 switch (pRule->GetType()) { 146 switch (pRule->GetType()) {
128 case FDE_CSSRULETYPE_Style: { 147 case FDE_CSSRULETYPE_Style: {
129 IFDE_CSSStyleRule* pStyleRule = static_cast<IFDE_CSSStyleRule*>(pRule); 148 IFDE_CSSStyleRule* pStyleRule = static_cast<IFDE_CSSStyleRule*>(pRule);
130 CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration(); 149 CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration();
131 int32_t iSelectors = pStyleRule->CountSelectorLists(); 150 int32_t iSelectors = pStyleRule->CountSelectorLists();
132 for (int32_t i = 0; i < iSelectors; ++i) { 151 for (int32_t i = 0; i < iSelectors; ++i) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 for (int32_t i = 0; i < iRules; ++i) { 191 for (int32_t i = 0; i < iRules; ++i) {
173 AddRulesFrom(pStyleSheet, pMediaRule->GetRule(i), dwMediaList, 192 AddRulesFrom(pStyleSheet, pMediaRule->GetRule(i), dwMediaList,
174 pFontMgr); 193 pFontMgr);
175 } 194 }
176 } 195 }
177 } break; 196 } break;
178 default: 197 default:
179 break; 198 break;
180 } 199 }
181 } 200 }
201
182 void CFDE_CSSRuleCollection::AddRuleTo(CFX_MapPtrToPtr& map, 202 void CFDE_CSSRuleCollection::AddRuleTo(CFX_MapPtrToPtr& map,
183 uint32_t dwKey, 203 uint32_t dwKey,
184 CFDE_CSSSelector* pSel, 204 CFDE_CSSSelector* pSel,
185 CFDE_CSSDeclaration* pDecl) { 205 CFDE_CSSDeclaration* pDecl) {
186 void* pKey = (void*)(uintptr_t)dwKey; 206 void* pKey = (void*)(uintptr_t)dwKey;
187 FDE_CSSRuleData* pData = NewRuleData(pSel, pDecl); 207 FDE_CSSRuleData* pData = NewRuleData(pSel, pDecl);
188 FDE_CSSRuleData* pList = nullptr; 208 FDE_CSSRuleData* pList = nullptr;
189 if (!map.Lookup(pKey, (void*&)pList)) { 209 if (!map.Lookup(pKey, (void*&)pList)) {
190 map.SetAt(pKey, pData); 210 map.SetAt(pKey, pData);
191 } else if (AddRuleTo(pList, pData)) { 211 } else if (AddRuleTo(pList, pData)) {
(...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 return FDE_CSSTEXTTRANSFORM_LowerCase; 1796 return FDE_CSSTEXTTRANSFORM_LowerCase;
1777 default: 1797 default:
1778 return FDE_CSSTEXTTRANSFORM_None; 1798 return FDE_CSSTEXTTRANSFORM_None;
1779 } 1799 }
1780 } 1800 }
1781 FDE_CSSFONTVARIANT CFDE_CSSStyleSelector::ToFontVariant( 1801 FDE_CSSFONTVARIANT CFDE_CSSStyleSelector::ToFontVariant(
1782 FDE_CSSPROPERTYVALUE eValue) { 1802 FDE_CSSPROPERTYVALUE eValue) {
1783 return eValue == FDE_CSSPROPERTYVALUE_SmallCaps ? FDE_CSSFONTVARIANT_SmallCaps 1803 return eValue == FDE_CSSPROPERTYVALUE_SmallCaps ? FDE_CSSFONTVARIANT_SmallCaps
1784 : FDE_CSSFONTVARIANT_Normal; 1804 : FDE_CSSFONTVARIANT_Normal;
1785 } 1805 }
1806
1807 CFDE_CSSComputedStyle::CFDE_CSSComputedStyle(IFX_MemoryAllocator* pAlloc)
1808 : m_dwRefCount(1), m_pAllocator(pAlloc) {}
1809
1810 CFDE_CSSComputedStyle::~CFDE_CSSComputedStyle() {}
1811
1812 uint32_t CFDE_CSSComputedStyle::Retain() {
1813 return ++m_dwRefCount;
1814 }
1815
1816 uint32_t CFDE_CSSComputedStyle::Release() {
1817 uint32_t dwRefCount = --m_dwRefCount;
1818 if (dwRefCount == 0) {
1819 delete m_NonInheritedData.m_pCounterStyle;
1820 FXTARGET_DeleteWith(CFDE_CSSComputedStyle, m_pAllocator, this);
1821 }
1822 return dwRefCount;
1823 }
1824
1825 void CFDE_CSSComputedStyle::Reset() {
1826 m_InheritedData.Reset();
1827 m_NonInheritedData.Reset();
1828 }
1829
1830 IFDE_CSSFontStyle* CFDE_CSSComputedStyle::GetFontStyles() {
1831 return static_cast<IFDE_CSSFontStyle*>(this);
1832 }
1833
1834 IFDE_CSSBoundaryStyle* CFDE_CSSComputedStyle::GetBoundaryStyles() {
1835 return static_cast<IFDE_CSSBoundaryStyle*>(this);
1836 }
1837
1838 IFDE_CSSPositionStyle* CFDE_CSSComputedStyle::GetPositionStyles() {
1839 return static_cast<IFDE_CSSPositionStyle*>(this);
1840 }
1841
1842 IFDE_CSSParagraphStyle* CFDE_CSSComputedStyle::GetParagraphStyles() {
1843 return static_cast<IFDE_CSSParagraphStyle*>(this);
1844 }
1845
1846 FX_BOOL CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideStringC& wsName,
1847 CFX_WideString& wsValue) const {
1848 for (int32_t i = m_CustomProperties.GetSize() - 2; i > -1; i -= 2) {
1849 if (wsName == m_CustomProperties[i]) {
1850 wsValue = m_CustomProperties[i + 1];
1851 return TRUE;
1852 }
1853 }
1854 return FALSE;
1855 }
1856
1857 int32_t CFDE_CSSComputedStyle::CountFontFamilies() const {
1858 return m_InheritedData.m_pFontFamily
1859 ? m_InheritedData.m_pFontFamily->CountValues()
1860 : 0;
1861 }
1862
1863 const FX_WCHAR* CFDE_CSSComputedStyle::GetFontFamily(int32_t index) const {
1864 return (static_cast<IFDE_CSSPrimitiveValue*>(
1865 m_InheritedData.m_pFontFamily->GetValue(index)))
1866 ->GetString(index);
1867 }
1868
1869 uint16_t CFDE_CSSComputedStyle::GetFontWeight() const {
1870 return m_InheritedData.m_wFontWeight;
1871 }
1872
1873 FDE_CSSFONTVARIANT CFDE_CSSComputedStyle::GetFontVariant() const {
1874 return static_cast<FDE_CSSFONTVARIANT>(m_InheritedData.m_eFontVariant);
1875 }
1876
1877 FDE_CSSFONTSTYLE CFDE_CSSComputedStyle::GetFontStyle() const {
1878 return static_cast<FDE_CSSFONTSTYLE>(m_InheritedData.m_eFontStyle);
1879 }
1880
1881 FX_FLOAT CFDE_CSSComputedStyle::GetFontSize() const {
1882 return m_InheritedData.m_fFontSize;
1883 }
1884
1885 FX_ARGB CFDE_CSSComputedStyle::GetColor() const {
1886 return m_InheritedData.m_dwFontColor;
1887 }
1888
1889 void CFDE_CSSComputedStyle::SetFontWeight(uint16_t wFontWeight) {
1890 m_InheritedData.m_wFontWeight = wFontWeight;
1891 }
1892
1893 void CFDE_CSSComputedStyle::SetFontVariant(FDE_CSSFONTVARIANT eFontVariant) {
1894 m_InheritedData.m_eFontVariant = eFontVariant;
1895 }
1896
1897 void CFDE_CSSComputedStyle::SetFontStyle(FDE_CSSFONTSTYLE eFontStyle) {
1898 m_InheritedData.m_eFontStyle = eFontStyle;
1899 }
1900
1901 void CFDE_CSSComputedStyle::SetFontSize(FX_FLOAT fFontSize) {
1902 m_InheritedData.m_fFontSize = fFontSize;
1903 }
1904
1905 void CFDE_CSSComputedStyle::SetColor(FX_ARGB dwFontColor) {
1906 m_InheritedData.m_dwFontColor = dwFontColor;
1907 }
1908
1909 const FDE_CSSRECT* CFDE_CSSComputedStyle::GetBorderWidth() const {
1910 return m_NonInheritedData.m_bHasBorder ? &(m_NonInheritedData.m_BorderWidth)
1911 : nullptr;
1912 }
1913
1914 const FDE_CSSRECT* CFDE_CSSComputedStyle::GetMarginWidth() const {
1915 return m_NonInheritedData.m_bHasMargin ? &(m_NonInheritedData.m_MarginWidth)
1916 : nullptr;
1917 }
1918
1919 const FDE_CSSRECT* CFDE_CSSComputedStyle::GetPaddingWidth() const {
1920 return m_NonInheritedData.m_bHasPadding ? &(m_NonInheritedData.m_PaddingWidth)
1921 : nullptr;
1922 }
1923
1924 void CFDE_CSSComputedStyle::SetMarginWidth(const FDE_CSSRECT& rect) {
1925 m_NonInheritedData.m_MarginWidth = rect;
1926 m_NonInheritedData.m_bHasMargin = TRUE;
1927 }
1928
1929 void CFDE_CSSComputedStyle::SetPaddingWidth(const FDE_CSSRECT& rect) {
1930 m_NonInheritedData.m_PaddingWidth = rect;
1931 m_NonInheritedData.m_bHasPadding = TRUE;
1932 }
1933
1934 FDE_CSSDISPLAY CFDE_CSSComputedStyle::GetDisplay() const {
1935 return static_cast<FDE_CSSDISPLAY>(m_NonInheritedData.m_eDisplay);
1936 }
1937
1938 FX_FLOAT CFDE_CSSComputedStyle::GetLineHeight() const {
1939 return m_InheritedData.m_fLineHeight;
1940 }
1941
1942 const FDE_CSSLENGTH& CFDE_CSSComputedStyle::GetTextIndent() const {
1943 return m_InheritedData.m_TextIndent;
1944 }
1945
1946 FDE_CSSTEXTALIGN CFDE_CSSComputedStyle::GetTextAlign() const {
1947 return static_cast<FDE_CSSTEXTALIGN>(m_InheritedData.m_eTextAligh);
1948 }
1949
1950 FDE_CSSVERTICALALIGN CFDE_CSSComputedStyle::GetVerticalAlign() const {
1951 return static_cast<FDE_CSSVERTICALALIGN>(m_NonInheritedData.m_eVerticalAlign);
1952 }
1953
1954 FX_FLOAT CFDE_CSSComputedStyle::GetNumberVerticalAlign() const {
1955 return m_NonInheritedData.m_fVerticalAlign;
1956 }
1957
1958 uint32_t CFDE_CSSComputedStyle::GetTextDecoration() const {
1959 return m_NonInheritedData.m_dwTextDecoration;
1960 }
1961
1962 const FDE_CSSLENGTH& CFDE_CSSComputedStyle::GetLetterSpacing() const {
1963 return m_InheritedData.m_LetterSpacing;
1964 }
1965
1966 void CFDE_CSSComputedStyle::SetLineHeight(FX_FLOAT fLineHeight) {
1967 m_InheritedData.m_fLineHeight = fLineHeight;
1968 }
1969
1970 void CFDE_CSSComputedStyle::SetTextIndent(const FDE_CSSLENGTH& textIndent) {
1971 m_InheritedData.m_TextIndent = textIndent;
1972 }
1973
1974 void CFDE_CSSComputedStyle::SetTextAlign(FDE_CSSTEXTALIGN eTextAlign) {
1975 m_InheritedData.m_eTextAligh = eTextAlign;
1976 }
1977
1978 void CFDE_CSSComputedStyle::SetNumberVerticalAlign(FX_FLOAT fAlign) {
1979 m_NonInheritedData.m_eVerticalAlign = FDE_CSSVERTICALALIGN_Number,
1980 m_NonInheritedData.m_fVerticalAlign = fAlign;
1981 }
1982
1983 void CFDE_CSSComputedStyle::SetTextDecoration(uint32_t dwTextDecoration) {
1984 m_NonInheritedData.m_dwTextDecoration = dwTextDecoration;
1985 }
1986
1987 void CFDE_CSSComputedStyle::SetLetterSpacing(
1988 const FDE_CSSLENGTH& letterSpacing) {
1989 m_InheritedData.m_LetterSpacing = letterSpacing;
1990 }
1991
1992 void CFDE_CSSComputedStyle::AddCustomStyle(const CFX_WideString& wsName,
1993 const CFX_WideString& wsValue) {
1994 m_CustomProperties.Add(wsName);
1995 m_CustomProperties.Add(wsValue);
1996 }
1997
1998 CFDE_CSSInheritedData::CFDE_CSSInheritedData() {
1999 Reset();
2000 }
2001
2002 void CFDE_CSSInheritedData::Reset() {
2003 FXSYS_memset(this, 0, sizeof(CFDE_CSSInheritedData));
2004 m_LetterSpacing.Set(FDE_CSSLENGTHUNIT_Normal);
2005 m_WordSpacing.Set(FDE_CSSLENGTHUNIT_Normal);
2006 m_TextIndent.Set(FDE_CSSLENGTHUNIT_Point, 0);
2007 m_fFontSize = 12.0f;
2008 m_fLineHeight = 14.0f;
2009 m_wFontWeight = 400;
2010 m_dwFontColor = 0xFF000000;
2011 m_iWidows = 2;
2012 m_bTextEmphasisColorCurrent = TRUE;
2013 m_iOrphans = 2;
2014 }
2015
2016 CFDE_CSSNonInheritedData::CFDE_CSSNonInheritedData() {
2017 Reset();
2018 }
2019
2020 void CFDE_CSSNonInheritedData::Reset() {
2021 FXSYS_memset(this, 0, sizeof(CFDE_CSSNonInheritedData));
2022 m_PaddingWidth.Set(FDE_CSSLENGTHUNIT_Point, 0);
2023 m_MarginWidth = m_PaddingWidth;
2024 m_BorderWidth = m_PaddingWidth;
2025 m_MinBoxSize.Set(FDE_CSSLENGTHUNIT_Point, 0);
2026 m_MaxBoxSize.Set(FDE_CSSLENGTHUNIT_None);
2027 m_eDisplay = FDE_CSSDISPLAY_Inline;
2028 m_fVerticalAlign = 0.0f;
2029 m_ColumnCount.Set(FDE_CSSLENGTHUNIT_Auto);
2030 m_ColumnGap.Set(FDE_CSSLENGTHUNIT_Normal);
2031 m_bColumnRuleColorSame = TRUE;
2032 m_ColumnWidth.Set(FDE_CSSLENGTHUNIT_Auto);
2033 m_ColumnRuleWidth.Set(FDE_CSSLENGTHUNIT_Auto);
2034 m_eTextCombine = FDE_CSSTEXTCOMBINE_None;
2035 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698