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_cssstylesheet.h" | 7 #include "xfa/fde/css/fde_cssstylesheet.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( | 203 FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( |
204 CFDE_CSSSyntaxParser* pSyntax) { | 204 CFDE_CSSSyntaxParser* pSyntax) { |
205 uint32_t dwMediaList = 0; | 205 uint32_t dwMediaList = 0; |
206 CFDE_CSSMediaRule* pMediaRule = nullptr; | 206 CFDE_CSSMediaRule* pMediaRule = nullptr; |
207 for (;;) { | 207 for (;;) { |
208 switch (pSyntax->DoSyntaxParse()) { | 208 switch (pSyntax->DoSyntaxParse()) { |
209 case FDE_CSSSYNTAXSTATUS_MediaType: { | 209 case FDE_CSSSYNTAXSTATUS_MediaType: { |
210 int32_t iLen; | 210 int32_t iLen; |
211 const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen); | 211 const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen); |
212 FDE_LPCCSSMEDIATYPETABLE pMediaType = | 212 const FDE_CSSMEDIATYPETABLE* pMediaType = |
213 FDE_GetCSSMediaTypeByName(CFX_WideStringC(psz, iLen)); | 213 FDE_GetCSSMediaTypeByName(CFX_WideStringC(psz, iLen)); |
214 if (pMediaType) | 214 if (pMediaType) |
215 dwMediaList |= pMediaType->wValue; | 215 dwMediaList |= pMediaType->wValue; |
216 } break; | 216 } break; |
217 case FDE_CSSSYNTAXSTATUS_StyleRule: | 217 case FDE_CSSSYNTAXSTATUS_StyleRule: |
218 if (pMediaRule) { | 218 if (pMediaRule) { |
219 FDE_CSSSYNTAXSTATUS eStatus = | 219 FDE_CSSSYNTAXSTATUS eStatus = |
220 LoadStyleRule(pSyntax, pMediaRule->GetArray()); | 220 LoadStyleRule(pSyntax, pMediaRule->GetArray()); |
221 if (eStatus < FDE_CSSSYNTAXSTATUS_None) { | 221 if (eStatus < FDE_CSSSYNTAXSTATUS_None) { |
222 return eStatus; | 222 return eStatus; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 } | 431 } |
432 | 432 |
433 IFDE_CSSRule* CFDE_CSSMediaRule::GetRule(int32_t index) { | 433 IFDE_CSSRule* CFDE_CSSMediaRule::GetRule(int32_t index) { |
434 return m_RuleArray.GetAt(index); | 434 return m_RuleArray.GetAt(index); |
435 } | 435 } |
436 | 436 |
437 bool FDE_IsCSSChar(FX_WCHAR wch) { | 437 bool FDE_IsCSSChar(FX_WCHAR wch) { |
438 return (wch >= 'a' && wch <= 'z') || (wch >= 'A' && wch <= 'Z'); | 438 return (wch >= 'a' && wch <= 'z') || (wch >= 'A' && wch <= 'Z'); |
439 } | 439 } |
440 | 440 |
441 int32_t FDE_GetCSSPersudoLen(const FX_WCHAR* psz, const FX_WCHAR* pEnd) { | 441 int32_t FDE_GetCSSPseudoLen(const FX_WCHAR* psz, const FX_WCHAR* pEnd) { |
442 ASSERT(*psz == ':'); | 442 ASSERT(*psz == ':'); |
443 const FX_WCHAR* pStart = psz; | 443 const FX_WCHAR* pStart = psz; |
444 while (psz < pEnd) { | 444 while (psz < pEnd) { |
445 FX_WCHAR wch = *psz; | 445 FX_WCHAR wch = *psz; |
446 if (FDE_IsCSSChar(wch) || wch == ':') { | 446 if (FDE_IsCSSChar(wch) || wch == ':') { |
447 ++psz; | 447 ++psz; |
448 } else { | 448 } else { |
449 break; | 449 break; |
450 } | 450 } |
451 } | 451 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 for (; psz < pEnd; ++psz) { | 497 for (; psz < pEnd; ++psz) { |
498 switch (*psz) { | 498 switch (*psz) { |
499 case '>': | 499 case '>': |
500 case '[': | 500 case '[': |
501 case '+': | 501 case '+': |
502 return nullptr; | 502 return nullptr; |
503 } | 503 } |
504 } | 504 } |
505 CFDE_CSSSelector* pFirst = nullptr; | 505 CFDE_CSSSelector* pFirst = nullptr; |
506 CFDE_CSSSelector* pLast = nullptr; | 506 CFDE_CSSSelector* pLast = nullptr; |
507 CFDE_CSSSelector* pPersudoFirst = nullptr; | 507 CFDE_CSSSelector* pPseudoFirst = nullptr; |
508 CFDE_CSSSelector* pPersudoLast = nullptr; | 508 CFDE_CSSSelector* pPseudoLast = nullptr; |
509 for (psz = pStart; psz < pEnd;) { | 509 for (psz = pStart; psz < pEnd;) { |
510 FX_WCHAR wch = *psz; | 510 FX_WCHAR wch = *psz; |
511 if (wch == '.' || wch == '#') { | 511 if (wch == '.' || wch == '#') { |
512 if (psz == pStart || psz[-1] == ' ') { | 512 if (psz == pStart || psz[-1] == ' ') { |
513 CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) | 513 CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) |
514 CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Element, L"*", 1, true); | 514 CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Element, L"*", 1, true); |
515 if (!p) | 515 if (!p) |
516 return nullptr; | 516 return nullptr; |
517 | 517 |
518 if (pFirst) { | 518 if (pFirst) { |
(...skipping 29 matching lines...) Expand all Loading... |
548 return nullptr; | 548 return nullptr; |
549 | 549 |
550 if (pFirst) { | 550 if (pFirst) { |
551 pFirst->SetType(FDE_CSSSELECTORTYPE_Descendant); | 551 pFirst->SetType(FDE_CSSSELECTORTYPE_Descendant); |
552 p->SetNext(pFirst); | 552 p->SetNext(pFirst); |
553 } | 553 } |
554 pFirst = p; | 554 pFirst = p; |
555 pLast = p; | 555 pLast = p; |
556 psz += iNameLen; | 556 psz += iNameLen; |
557 } else if (wch == ':') { | 557 } else if (wch == ':') { |
558 int32_t iNameLen = FDE_GetCSSPersudoLen(psz, pEnd); | 558 int32_t iNameLen = FDE_GetCSSPseudoLen(psz, pEnd); |
559 if (iNameLen == 0) { | 559 if (iNameLen == 0) { |
560 return nullptr; | 560 return nullptr; |
561 } | 561 } |
562 CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) | 562 CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) |
563 CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Persudo, psz, iNameLen, true); | 563 CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Pseudo, psz, iNameLen, true); |
564 if (!p) | 564 if (!p) |
565 return nullptr; | 565 return nullptr; |
566 | 566 |
567 if (pPersudoFirst) | 567 if (pPseudoFirst) |
568 pPersudoLast->SetNext(p); | 568 pPseudoLast->SetNext(p); |
569 else | 569 else |
570 pPersudoFirst = p; | 570 pPseudoFirst = p; |
571 pPersudoLast = p; | 571 pPseudoLast = p; |
572 psz += iNameLen; | 572 psz += iNameLen; |
573 } else if (wch == ' ') { | 573 } else if (wch == ' ') { |
574 psz++; | 574 psz++; |
575 } else { | 575 } else { |
576 return nullptr; | 576 return nullptr; |
577 } | 577 } |
578 } | 578 } |
579 if (!pPersudoFirst) | 579 if (!pPseudoFirst) |
580 return pFirst; | 580 return pFirst; |
581 | 581 |
582 pPersudoLast->SetNext(pFirst); | 582 pPseudoLast->SetNext(pFirst); |
583 return pPersudoFirst; | 583 return pPseudoFirst; |
584 } | 584 } |
585 | 585 |
586 CFDE_CSSDeclaration* CFDE_CSSFontFaceRule::GetDeclaration() { | 586 CFDE_CSSDeclaration* CFDE_CSSFontFaceRule::GetDeclaration() { |
587 return &m_Declaration; | 587 return &m_Declaration; |
588 } | 588 } |
OLD | NEW |