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

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

Issue 1911843002: Remove IFDE_CSSTagProvider. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « xfa/fde/css/fde_cssstyleselector.h ('k') | xfa/fxfa/app/xfa_textlayout.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10
11 #include "xfa/fde/css/fde_csscache.h" 11 #include "xfa/fde/css/fde_csscache.h"
12 #include "xfa/fde/css/fde_cssdeclaration.h" 12 #include "xfa/fde/css/fde_cssdeclaration.h"
13 #include "xfa/fxfa/app/xfa_textlayout.h"
13 14
14 #define FDE_CSSUNIVERSALHASH ('*') 15 #define FDE_CSSUNIVERSALHASH ('*')
15 16
16 int32_t CFDE_CSSCounterStyle::FindIndex(const FX_WCHAR* pszIdentifier) { 17 int32_t CFDE_CSSCounterStyle::FindIndex(const FX_WCHAR* pszIdentifier) {
17 int32_t iCount = m_arrCounterData.GetSize(); 18 int32_t iCount = m_arrCounterData.GetSize();
18 for (int32_t i = 0; i < iCount; i++) { 19 for (int32_t i = 0; i < iCount; i++) {
19 if (FXSYS_wcscmp(pszIdentifier, m_arrCounterData.ElementAt(i).m_pszIdent) == 20 if (FXSYS_wcscmp(pszIdentifier, m_arrCounterData.ElementAt(i).m_pszIdent) ==
20 0) { 21 0) {
21 return i; 22 return i;
22 } 23 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 void CFDE_CSSStyleSelector::Reset() { 306 void CFDE_CSSStyleSelector::Reset() {
306 for (int32_t iGroup = 0; iGroup < FDE_CSSSTYLESHEETGROUP_MAX; ++iGroup) { 307 for (int32_t iGroup = 0; iGroup < FDE_CSSSTYLESHEETGROUP_MAX; ++iGroup) {
307 m_RuleCollection[iGroup].Clear(); 308 m_RuleCollection[iGroup].Clear();
308 } 309 }
309 if (m_pRuleDataStore != NULL) { 310 if (m_pRuleDataStore != NULL) {
310 m_pRuleDataStore->Release(); 311 m_pRuleDataStore->Release();
311 m_pRuleDataStore = NULL; 312 m_pRuleDataStore = NULL;
312 } 313 }
313 } 314 }
314 int32_t CFDE_CSSStyleSelector::MatchDeclarations( 315 int32_t CFDE_CSSStyleSelector::MatchDeclarations(
315 IFDE_CSSTagProvider* pTag, 316 CXFA_CSSTagProvider* pTag,
316 CFDE_CSSDeclarationArray& matchedDecls, 317 CFDE_CSSDeclarationArray& matchedDecls,
317 FDE_CSSPERSUDO ePersudoType) { 318 FDE_CSSPERSUDO ePersudoType) {
318 FXSYS_assert(m_pAccelerator != NULL && pTag != NULL); 319 FXSYS_assert(m_pAccelerator && pTag);
320
319 FDE_CSSTagCache* pCache = m_pAccelerator->GetTopElement(); 321 FDE_CSSTagCache* pCache = m_pAccelerator->GetTopElement();
320 FXSYS_assert(pCache != NULL && pCache->GetTag() == pTag); 322 FXSYS_assert(pCache && pCache->GetTag() == pTag);
323
321 matchedDecls.RemoveAt(0, matchedDecls.GetSize()); 324 matchedDecls.RemoveAt(0, matchedDecls.GetSize());
322 for (int32_t ePriority = FDE_CSSSTYLESHEETPRIORITY_MAX - 1; ePriority >= 0; 325 for (int32_t ePriority = FDE_CSSSTYLESHEETPRIORITY_MAX - 1; ePriority >= 0;
323 --ePriority) { 326 --ePriority) {
324 FDE_CSSSTYLESHEETGROUP eGroup = m_ePriorities[ePriority]; 327 FDE_CSSSTYLESHEETGROUP eGroup = m_ePriorities[ePriority];
325 CFDE_CSSRuleCollection& rules = m_RuleCollection[eGroup]; 328 CFDE_CSSRuleCollection& rules = m_RuleCollection[eGroup];
326 if (rules.CountSelectors() == 0) { 329 if (rules.CountSelectors() == 0)
327 continue; 330 continue;
328 } 331
329 if (ePersudoType == FDE_CSSPERSUDO_NONE) { 332 if (ePersudoType == FDE_CSSPERSUDO_NONE) {
330 MatchRules(pCache, rules.GetUniversalRuleData(), ePersudoType); 333 MatchRules(pCache, rules.GetUniversalRuleData(), ePersudoType);
331 if (pCache->HashTag()) { 334 if (pCache->HashTag()) {
332 MatchRules(pCache, rules.GetTagRuleData(pCache->HashTag()), 335 MatchRules(pCache, rules.GetTagRuleData(pCache->HashTag()),
333 ePersudoType); 336 ePersudoType);
334 } 337 }
335 int32_t iCount = pCache->CountHashClass(); 338 int32_t iCount = pCache->CountHashClass();
336 for (int32_t i = 0; i < iCount; i++) { 339 for (int32_t i = 0; i < iCount; i++) {
337 pCache->SetClassIndex(i); 340 pCache->SetClassIndex(i);
338 MatchRules(pCache, rules.GetClassRuleData(pCache->HashClass()), 341 MatchRules(pCache, rules.GetClassRuleData(pCache->HashClass()),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 default: 410 default:
408 FXSYS_assert(FALSE); 411 FXSYS_assert(FALSE);
409 break; 412 break;
410 } 413 }
411 pSel = pSel->GetNextSelector(); 414 pSel = pSel->GetNextSelector();
412 } 415 }
413 return pSel == NULL && pCache != NULL; 416 return pSel == NULL && pCache != NULL;
414 } 417 }
415 418
416 void CFDE_CSSStyleSelector::ComputeStyle( 419 void CFDE_CSSStyleSelector::ComputeStyle(
417 IFDE_CSSTagProvider* pTag, 420 CXFA_CSSTagProvider* pTag,
418 const IFDE_CSSDeclaration** ppDeclArray, 421 const IFDE_CSSDeclaration** ppDeclArray,
419 int32_t iDeclCount, 422 int32_t iDeclCount,
420 IFDE_CSSComputedStyle* pDestStyle) { 423 IFDE_CSSComputedStyle* pDestStyle) {
421 FXSYS_assert(iDeclCount >= 0); 424 FXSYS_assert(iDeclCount >= 0);
422 FXSYS_assert(pDestStyle); 425 FXSYS_assert(pDestStyle);
423 FX_POSITION pos = pTag->GetFirstAttribute(); 426
424 if (pos != NULL) { 427 static const uint32_t s_dwStyleHash =
425 if (m_pInlineStyleStore == NULL) { 428 FX_HashCode_String_GetW(L"style", 5, TRUE);
429 static const uint32_t s_dwAlignHash =
430 FX_HashCode_String_GetW(L"align", 5, TRUE);
431
432 if (!pTag->empty()) {
433 if (!m_pInlineStyleStore)
426 m_pInlineStyleStore = FX_CreateAllocator(FX_ALLOCTYPE_Static, 2048, 0); 434 m_pInlineStyleStore = FX_CreateAllocator(FX_ALLOCTYPE_Static, 2048, 0);
427 } 435
428 CFDE_CSSDeclaration* pDecl = NULL; 436 CFDE_CSSDeclaration* pDecl = nullptr;
429 CFX_WideStringC wsAttri, wsValue; 437 for (auto it : *pTag) {
430 uint32_t dwAttriHash; 438 CFX_WideString wsAttri = it.first;
431 do { 439 CFX_WideString wsValue = it.second;
432 pTag->GetNextAttribute(pos, wsAttri, wsValue); 440
433 dwAttriHash = 441 uint32_t dwAttriHash =
434 FX_HashCode_String_GetW(wsAttri.c_str(), wsAttri.GetLength(), TRUE); 442 FX_HashCode_String_GetW(wsAttri.c_str(), wsAttri.GetLength(), TRUE);
435 static const uint32_t s_dwStyleHash =
436 FX_HashCode_String_GetW(L"style", 5, TRUE);
437 static const uint32_t s_dwAlignHash =
438 FX_HashCode_String_GetW(L"align", 5, TRUE);
439 if (dwAttriHash == s_dwStyleHash) { 443 if (dwAttriHash == s_dwStyleHash) {
440 if (pDecl == NULL) { 444 if (!pDecl)
441 pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration; 445 pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration;
442 } 446
443 AppendInlineStyle(pDecl, wsValue.c_str(), wsValue.GetLength()); 447 AppendInlineStyle(pDecl, wsValue.c_str(), wsValue.GetLength());
444 } else if (dwAttriHash == s_dwAlignHash) { 448 } else if (dwAttriHash == s_dwAlignHash) {
445 if (pDecl == NULL) { 449 if (!pDecl)
446 pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration; 450 pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration;
447 } 451
448 FDE_CSSPROPERTYARGS args; 452 FDE_CSSPROPERTYARGS args;
449 args.pStringCache = NULL; 453 args.pStringCache = nullptr;
450 args.pStaticStore = m_pInlineStyleStore; 454 args.pStaticStore = m_pInlineStyleStore;
451 args.pProperty = FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY_TextAlign); 455 args.pProperty = FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY_TextAlign);
452 pDecl->AddProperty(&args, wsValue.c_str(), wsValue.GetLength()); 456 pDecl->AddProperty(&args, wsValue.c_str(), wsValue.GetLength());
453 } 457 }
454 } while (pos != NULL); 458 }
455 if (pDecl != NULL) { 459
460 if (pDecl) {
456 CFDE_CSSDeclarationArray decls; 461 CFDE_CSSDeclarationArray decls;
457 decls.SetSize(iDeclCount + 1); 462 decls.SetSize(iDeclCount + 1);
458 IFDE_CSSDeclaration** ppInline = decls.GetData(); 463 IFDE_CSSDeclaration** ppInline = decls.GetData();
459 FXSYS_memcpy(ppInline, ppDeclArray, 464 FXSYS_memcpy(ppInline, ppDeclArray,
460 iDeclCount * sizeof(IFDE_CSSDeclaration*)); 465 iDeclCount * sizeof(IFDE_CSSDeclaration*));
461 ppInline[iDeclCount++] = pDecl; 466 ppInline[iDeclCount++] = pDecl;
462 ApplyDeclarations(TRUE, (const IFDE_CSSDeclaration**)ppInline, iDeclCount, 467 ApplyDeclarations(TRUE, (const IFDE_CSSDeclaration**)ppInline, iDeclCount,
463 pDestStyle); 468 pDestStyle);
464 ApplyDeclarations(FALSE, (const IFDE_CSSDeclaration**)ppInline, 469 ApplyDeclarations(FALSE, (const IFDE_CSSDeclaration**)ppInline,
465 iDeclCount, pDestStyle); 470 iDeclCount, pDestStyle);
466 return; 471 return;
467 } 472 }
468 } 473 }
474
469 if (iDeclCount > 0) { 475 if (iDeclCount > 0) {
470 FXSYS_assert(ppDeclArray != NULL); 476 FXSYS_assert(ppDeclArray);
477
471 ApplyDeclarations(TRUE, ppDeclArray, iDeclCount, pDestStyle); 478 ApplyDeclarations(TRUE, ppDeclArray, iDeclCount, pDestStyle);
472 ApplyDeclarations(FALSE, ppDeclArray, iDeclCount, pDestStyle); 479 ApplyDeclarations(FALSE, ppDeclArray, iDeclCount, pDestStyle);
473 } 480 }
474 } 481 }
482
475 void CFDE_CSSStyleSelector::ApplyDeclarations( 483 void CFDE_CSSStyleSelector::ApplyDeclarations(
476 FX_BOOL bPriority, 484 FX_BOOL bPriority,
477 const IFDE_CSSDeclaration** ppDeclArray, 485 const IFDE_CSSDeclaration** ppDeclArray,
478 int32_t iDeclCount, 486 int32_t iDeclCount,
479 IFDE_CSSComputedStyle* pDestStyle) { 487 IFDE_CSSComputedStyle* pDestStyle) {
480 CFDE_CSSComputedStyle* pComputedStyle = (CFDE_CSSComputedStyle*)pDestStyle; 488 CFDE_CSSComputedStyle* pComputedStyle = (CFDE_CSSComputedStyle*)pDestStyle;
481 IFDE_CSSValue* pVal; 489 IFDE_CSSValue* pVal;
482 FX_BOOL bImportant; 490 FX_BOOL bImportant;
483 int32_t i; 491 int32_t i;
484 if (bPriority) { 492 if (bPriority) {
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 return FDE_CSSTEXTTRANSFORM_LowerCase; 1788 return FDE_CSSTEXTTRANSFORM_LowerCase;
1781 default: 1789 default:
1782 return FDE_CSSTEXTTRANSFORM_None; 1790 return FDE_CSSTEXTTRANSFORM_None;
1783 } 1791 }
1784 } 1792 }
1785 FDE_CSSFONTVARIANT CFDE_CSSStyleSelector::ToFontVariant( 1793 FDE_CSSFONTVARIANT CFDE_CSSStyleSelector::ToFontVariant(
1786 FDE_CSSPROPERTYVALUE eValue) { 1794 FDE_CSSPROPERTYVALUE eValue) {
1787 return eValue == FDE_CSSPROPERTYVALUE_SmallCaps ? FDE_CSSFONTVARIANT_SmallCaps 1795 return eValue == FDE_CSSPROPERTYVALUE_SmallCaps ? FDE_CSSFONTVARIANT_SmallCaps
1788 : FDE_CSSFONTVARIANT_Normal; 1796 : FDE_CSSFONTVARIANT_Normal;
1789 } 1797 }
OLDNEW
« no previous file with comments | « xfa/fde/css/fde_cssstyleselector.h ('k') | xfa/fxfa/app/xfa_textlayout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698