OLD | NEW |
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 void CFDE_CSSStyleSelector::Reset() { | 191 void CFDE_CSSStyleSelector::Reset() { |
192 for (int32_t iGroup = 0; iGroup < FDE_CSSSTYLESHEETGROUP_MAX; ++iGroup) { | 192 for (int32_t iGroup = 0; iGroup < FDE_CSSSTYLESHEETGROUP_MAX; ++iGroup) { |
193 m_RuleCollection[iGroup].Clear(); | 193 m_RuleCollection[iGroup].Clear(); |
194 } | 194 } |
195 m_pRuleDataStore.reset(); | 195 m_pRuleDataStore.reset(); |
196 } | 196 } |
197 | 197 |
198 int32_t CFDE_CSSStyleSelector::MatchDeclarations( | 198 int32_t CFDE_CSSStyleSelector::MatchDeclarations( |
199 CXFA_CSSTagProvider* pTag, | 199 CXFA_CSSTagProvider* pTag, |
200 CFDE_CSSDeclarationArray& matchedDecls, | 200 CFDE_CSSDeclarationArray& matchedDecls, |
201 FDE_CSSPERSUDO ePersudoType) { | 201 FDE_CSSPSEUDO ePseudoType) { |
202 ASSERT(m_pAccelerator && pTag); | 202 ASSERT(pTag); |
203 | |
204 FDE_CSSTagCache* pCache = m_pAccelerator->GetTopElement(); | 203 FDE_CSSTagCache* pCache = m_pAccelerator->GetTopElement(); |
205 ASSERT(pCache && pCache->GetTag() == pTag); | 204 ASSERT(pCache && pCache->GetTag() == pTag); |
206 | 205 |
207 matchedDecls.RemoveAt(0, matchedDecls.GetSize()); | 206 matchedDecls.RemoveAt(0, matchedDecls.GetSize()); |
208 for (int32_t ePriority = FDE_CSSSTYLESHEETPRIORITY_MAX - 1; ePriority >= 0; | 207 for (int32_t ePriority = FDE_CSSSTYLESHEETPRIORITY_MAX - 1; ePriority >= 0; |
209 --ePriority) { | 208 --ePriority) { |
210 FDE_CSSSTYLESHEETGROUP eGroup = m_ePriorities[ePriority]; | 209 FDE_CSSSTYLESHEETGROUP eGroup = m_ePriorities[ePriority]; |
211 CFDE_CSSRuleCollection& rules = m_RuleCollection[eGroup]; | 210 CFDE_CSSRuleCollection& rules = m_RuleCollection[eGroup]; |
212 if (rules.CountSelectors() == 0) | 211 if (rules.CountSelectors() == 0) |
213 continue; | 212 continue; |
214 | 213 |
215 if (ePersudoType == FDE_CSSPERSUDO_NONE) { | 214 if (ePseudoType == FDE_CSSPSEUDO_NONE) { |
216 MatchRules(pCache, rules.GetUniversalRuleData(), ePersudoType); | 215 MatchRules(pCache, rules.GetUniversalRuleData(), ePseudoType); |
217 if (pCache->HashTag()) { | 216 if (pCache->HashTag()) { |
218 MatchRules(pCache, rules.GetTagRuleData(pCache->HashTag()), | 217 MatchRules(pCache, rules.GetTagRuleData(pCache->HashTag()), |
219 ePersudoType); | 218 ePseudoType); |
220 } | 219 } |
221 int32_t iCount = pCache->CountHashClass(); | 220 int32_t iCount = pCache->CountHashClass(); |
222 for (int32_t i = 0; i < iCount; i++) { | 221 for (int32_t i = 0; i < iCount; i++) { |
223 pCache->SetClassIndex(i); | 222 pCache->SetClassIndex(i); |
224 MatchRules(pCache, rules.GetClassRuleData(pCache->HashClass()), | 223 MatchRules(pCache, rules.GetClassRuleData(pCache->HashClass()), |
225 ePersudoType); | 224 ePseudoType); |
226 } | 225 } |
227 } else { | 226 } else { |
228 MatchRules(pCache, rules.GetPersudoRuleData(), ePersudoType); | 227 MatchRules(pCache, rules.GetPseudoRuleData(), ePseudoType); |
229 } | 228 } |
230 | 229 |
231 std::sort(m_MatchedRules.begin(), m_MatchedRules.end(), | 230 std::sort(m_MatchedRules.begin(), m_MatchedRules.end(), |
232 [](const FDE_CSSRuleData* p1, const FDE_CSSRuleData* p2) { | 231 [](const FDE_CSSRuleData* p1, const FDE_CSSRuleData* p2) { |
233 return p1->dwPriority < p2->dwPriority; | 232 return p1->dwPriority < p2->dwPriority; |
234 }); | 233 }); |
235 for (const auto& rule : m_MatchedRules) | 234 for (const auto& rule : m_MatchedRules) |
236 matchedDecls.Add(rule->pDeclaration); | 235 matchedDecls.Add(rule->pDeclaration); |
237 m_MatchedRules.clear(); | 236 m_MatchedRules.clear(); |
238 } | 237 } |
239 return matchedDecls.GetSize(); | 238 return matchedDecls.GetSize(); |
240 } | 239 } |
241 | 240 |
242 void CFDE_CSSStyleSelector::MatchRules(FDE_CSSTagCache* pCache, | 241 void CFDE_CSSStyleSelector::MatchRules(FDE_CSSTagCache* pCache, |
243 FDE_CSSRuleData* pList, | 242 FDE_CSSRuleData* pList, |
244 FDE_CSSPERSUDO ePersudoType) { | 243 FDE_CSSPSEUDO ePseudoType) { |
245 while (pList) { | 244 while (pList) { |
246 if (MatchSelector(pCache, pList->pSelector, ePersudoType)) | 245 if (MatchSelector(pCache, pList->pSelector, ePseudoType)) |
247 m_MatchedRules.push_back(pList); | 246 m_MatchedRules.push_back(pList); |
248 pList = pList->pNext; | 247 pList = pList->pNext; |
249 } | 248 } |
250 } | 249 } |
251 | 250 |
252 bool CFDE_CSSStyleSelector::MatchSelector(FDE_CSSTagCache* pCache, | 251 bool CFDE_CSSStyleSelector::MatchSelector(FDE_CSSTagCache* pCache, |
253 CFDE_CSSSelector* pSel, | 252 CFDE_CSSSelector* pSel, |
254 FDE_CSSPERSUDO ePersudoType) { | 253 FDE_CSSPSEUDO ePseudoType) { |
255 uint32_t dwHash; | 254 uint32_t dwHash; |
256 while (pSel && pCache) { | 255 while (pSel && pCache) { |
257 switch (pSel->GetType()) { | 256 switch (pSel->GetType()) { |
258 case FDE_CSSSELECTORTYPE_Descendant: | 257 case FDE_CSSSELECTORTYPE_Descendant: |
259 dwHash = pSel->GetNameHash(); | 258 dwHash = pSel->GetNameHash(); |
260 while ((pCache = pCache->GetParent()) != nullptr) { | 259 while ((pCache = pCache->GetParent()) != nullptr) { |
261 if (dwHash != FDE_CSSUNIVERSALHASH && dwHash != pCache->HashTag()) { | 260 if (dwHash != FDE_CSSUNIVERSALHASH && dwHash != pCache->HashTag()) { |
262 continue; | 261 continue; |
263 } | 262 } |
264 if (MatchSelector(pCache, pSel->GetNextSelector(), ePersudoType)) { | 263 if (MatchSelector(pCache, pSel->GetNextSelector(), ePseudoType)) { |
265 return true; | 264 return true; |
266 } | 265 } |
267 } | 266 } |
268 return false; | 267 return false; |
269 case FDE_CSSSELECTORTYPE_ID: | 268 case FDE_CSSSELECTORTYPE_ID: |
270 dwHash = pCache->HashID(); | 269 dwHash = pCache->HashID(); |
271 if (dwHash != pSel->GetNameHash()) { | 270 if (dwHash != pSel->GetNameHash()) { |
272 return false; | 271 return false; |
273 } | 272 } |
274 break; | 273 break; |
275 case FDE_CSSSELECTORTYPE_Class: | 274 case FDE_CSSSELECTORTYPE_Class: |
276 dwHash = pCache->HashClass(); | 275 dwHash = pCache->HashClass(); |
277 if (dwHash != pSel->GetNameHash()) { | 276 if (dwHash != pSel->GetNameHash()) { |
278 return false; | 277 return false; |
279 } | 278 } |
280 break; | 279 break; |
281 case FDE_CSSSELECTORTYPE_Element: | 280 case FDE_CSSSELECTORTYPE_Element: |
282 dwHash = pSel->GetNameHash(); | 281 dwHash = pSel->GetNameHash(); |
283 if (dwHash != FDE_CSSUNIVERSALHASH && dwHash != pCache->HashTag()) { | 282 if (dwHash != FDE_CSSUNIVERSALHASH && dwHash != pCache->HashTag()) { |
284 return false; | 283 return false; |
285 } | 284 } |
286 break; | 285 break; |
287 case FDE_CSSSELECTORTYPE_Persudo: | 286 case FDE_CSSSELECTORTYPE_Pseudo: |
288 dwHash = FDE_GetCSSPersudoByEnum(ePersudoType)->dwHash; | 287 dwHash = FDE_GetCSSPseudoByEnum(ePseudoType)->dwHash; |
289 if (dwHash != pSel->GetNameHash()) { | 288 if (dwHash != pSel->GetNameHash()) { |
290 return false; | 289 return false; |
291 } | 290 } |
292 break; | 291 break; |
293 default: | 292 default: |
294 ASSERT(false); | 293 ASSERT(false); |
295 break; | 294 break; |
296 } | 295 } |
297 pSel = pSel->GetNextSelector(); | 296 pSel = pSel->GetNextSelector(); |
298 } | 297 } |
(...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 m_MaxBoxSize.Set(FDE_CSSLENGTHUNIT_None); | 1932 m_MaxBoxSize.Set(FDE_CSSLENGTHUNIT_None); |
1934 m_eDisplay = FDE_CSSDISPLAY_Inline; | 1933 m_eDisplay = FDE_CSSDISPLAY_Inline; |
1935 m_fVerticalAlign = 0.0f; | 1934 m_fVerticalAlign = 0.0f; |
1936 m_ColumnCount.Set(FDE_CSSLENGTHUNIT_Auto); | 1935 m_ColumnCount.Set(FDE_CSSLENGTHUNIT_Auto); |
1937 m_ColumnGap.Set(FDE_CSSLENGTHUNIT_Normal); | 1936 m_ColumnGap.Set(FDE_CSSLENGTHUNIT_Normal); |
1938 m_bColumnRuleColorSame = true; | 1937 m_bColumnRuleColorSame = true; |
1939 m_ColumnWidth.Set(FDE_CSSLENGTHUNIT_Auto); | 1938 m_ColumnWidth.Set(FDE_CSSLENGTHUNIT_Auto); |
1940 m_ColumnRuleWidth.Set(FDE_CSSLENGTHUNIT_Auto); | 1939 m_ColumnRuleWidth.Set(FDE_CSSLENGTHUNIT_Auto); |
1941 m_eTextCombine = FDE_CSSTEXTCOMBINE_None; | 1940 m_eTextCombine = FDE_CSSTEXTCOMBINE_None; |
1942 } | 1941 } |
OLD | NEW |