FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( IFDE_CSSSyntaxParser* pSyntax) { FX_DWORD dwMediaList = 0; CFDE_CSSMediaRule* pMediaRule = NULL; for (;;) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_MediaType: { int32_t iLen; const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen); FDE_LPCCSSMEDIATYPETABLE pMediaType = FDE_GetCSSMediaTypeByName(psz, iLen); if (pMediaType != NULL) { dwMediaList |= pMediaType->wValue; } } break; case FDE_CSSSYNTAXSTATUS_StyleRule: if (pMediaRule == NULL) { SkipRuleSet(pSyntax); } else { FDE_CSSSYNTAXSTATUS eStatus = LoadStyleRule(pSyntax, pMediaRule->GetArray()); if (eStatus < FDE_CSSSYNTAXSTATUS_None) { return eStatus; } } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: if ((dwMediaList & m_dwMediaList) > 0 && pMediaRule == NULL) { pMediaRule = FDE_NewWith(m_pAllocator) CFDE_CSSMediaRule(dwMediaList); m_RuleArray.Add(pMediaRule); } break; case FDE_CSSSYNTAXSTATUS_DeclClose: return FDE_CSSSYNTAXSTATUS_None; FDE_CSSSWITCHDEFAULTS(); } } }
FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadPageRule( IFDE_CSSSyntaxParser* pSyntax) { return SkipRuleSet(pSyntax); }
FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( IFDE_CSSSyntaxParser* pSyntax, CFDE_CSSRuleArray& ruleArray) { m_Selectors.RemoveAt(0, m_Selectors.GetSize()); CFDE_CSSStyleRule* pStyleRule = NULL; const FX_WCHAR* pszValue = NULL; int32_t iValueLen = 0; FDE_CSSPROPERTYARGS propertyArgs; propertyArgs.pStaticStore = m_pAllocator; propertyArgs.pStringCache = &m_StringCache; propertyArgs.pProperty = NULL; CFX_WideString wsName; for (;;) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_Selector: { pszValue = pSyntax->GetCurrentString(iValueLen); IFDE_CSSSelector* pSelector = CFDE_CSSSelector::FromString(m_pAllocator, pszValue, iValueLen); if (pSelector != NULL) { m_Selectors.Add(pSelector); } } break; case FDE_CSSSYNTAXSTATUS_PropertyName: pszValue = pSyntax->GetCurrentString(iValueLen); propertyArgs.pProperty = FDE_GetCSSPropertyByName(pszValue, iValueLen); if (propertyArgs.pProperty == NULL) { wsName = CFX_WideStringC(pszValue, iValueLen); } break; case FDE_CSSSYNTAXSTATUS_PropertyValue: if (propertyArgs.pProperty != NULL) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pStyleRule->GetDeclImp().AddProperty(&propertyArgs, pszValue, iValueLen); } } else if (iValueLen > 0) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pStyleRule->GetDeclImp().AddProperty( &propertyArgs, wsName, wsName.GetLength(), pszValue, iValueLen); } } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: if (pStyleRule == NULL && m_Selectors.GetSize() > 0) { pStyleRule = FDE_NewWith(m_pAllocator) CFDE_CSSStyleRule; pStyleRule->SetSelector(m_pAllocator, m_Selectors); ruleArray.Add(pStyleRule); } else { SkipRuleSet(pSyntax); return FDE_CSSSYNTAXSTATUS_None; } break; case FDE_CSSSYNTAXSTATUS_DeclClose: if (pStyleRule != NULL && pStyleRule->GetDeclImp().GetStartPosition() == NULL) { pStyleRule->~CFDE_CSSStyleRule(); ruleArray.RemoveLast(1); } return FDE_CSSSYNTAXSTATUS_None; FDE_CSSSWITCHDEFAULTS(); } } }
CFX_CSSSyntaxStatus CFX_CSSStyleSheet::LoadStyleRule( CFX_CSSSyntaxParser* pSyntax, std::vector<std::unique_ptr<CFX_CSSStyleRule>>* ruleArray) { std::vector<std::unique_ptr<CFX_CSSSelector>> selectors; CFX_CSSStyleRule* pStyleRule = nullptr; int32_t iValueLen = 0; const CFX_CSSData::Property* property = nullptr; WideString wsName; while (1) { switch (pSyntax->DoSyntaxParse()) { case CFX_CSSSyntaxStatus::Selector: { WideStringView strValue = pSyntax->GetCurrentString(); auto pSelector = CFX_CSSSelector::FromString(strValue); if (pSelector) selectors.push_back(std::move(pSelector)); break; } case CFX_CSSSyntaxStatus::PropertyName: { WideStringView strValue = pSyntax->GetCurrentString(); property = CFX_CSSData::GetPropertyByName(strValue); if (!property) wsName = WideString(strValue); break; } case CFX_CSSSyntaxStatus::PropertyValue: { if (property || iValueLen > 0) { WideStringView strValue = pSyntax->GetCurrentString(); auto* decl = pStyleRule->GetDeclaration(); if (!strValue.IsEmpty()) { if (property) { decl->AddProperty(property, strValue); } else { decl->AddProperty(wsName, WideString(strValue)); } } } break; } case CFX_CSSSyntaxStatus::DeclOpen: { if (!pStyleRule && !selectors.empty()) { auto rule = pdfium::MakeUnique<CFX_CSSStyleRule>(); pStyleRule = rule.get(); pStyleRule->SetSelector(&selectors); ruleArray->push_back(std::move(rule)); } else { SkipRuleSet(pSyntax); return CFX_CSSSyntaxStatus::None; } break; } case CFX_CSSSyntaxStatus::DeclClose: { if (pStyleRule && pStyleRule->GetDeclaration()->empty()) { ruleArray->pop_back(); pStyleRule = nullptr; } return CFX_CSSSyntaxStatus::None; } case CFX_CSSSyntaxStatus::EOS: return CFX_CSSSyntaxStatus::EOS; case CFX_CSSSyntaxStatus::Error: default: return CFX_CSSSyntaxStatus::Error; } } }