7#include "core/fxcrt/css/cfx_cssstyleselector.h"
12#include "core/fxcrt/css/cfx_csscolorvalue.h"
13#include "core/fxcrt/css/cfx_csscomputedstyle.h"
14#include "core/fxcrt/css/cfx_csscustomproperty.h"
15#include "core/fxcrt/css/cfx_cssdeclaration.h"
16#include "core/fxcrt/css/cfx_cssenumvalue.h"
17#include "core/fxcrt/css/cfx_csspropertyholder.h"
18#include "core/fxcrt/css/cfx_cssselector.h"
19#include "core/fxcrt/css/cfx_cssstylesheet.h"
20#include "core/fxcrt/css/cfx_csssyntaxparser.h"
21#include "core/fxcrt/css/cfx_cssvaluelist.h"
22#include "third_party/base/check.h"
23#include "third_party/base/containers/adapters.h"
30 DCHECK(fFontSize > 0);
31 m_fDefaultFontSize = fFontSize;
35 const CFX_CSSComputedStyle* pParentStyle) {
36 auto pStyle = pdfium::MakeRetain<CFX_CSSComputedStyle>();
38 pStyle->m_InheritedData = pParentStyle->m_InheritedData;
43 std::unique_ptr<CFX_CSSStyleSheet> pSheet) {
44 m_UAStyles = std::move(pSheet);
48 m_UARules.SetRulesFromSheet(m_UAStyles.get());
52 const WideString& tagname) {
53 std::vector<
const CFX_CSSDeclaration*> matchedDecls;
57 auto* rules = m_UARules.GetTagRuleData(tagname);
61 for (
const auto& d : *rules) {
62 if (MatchSelector(tagname, d->pSelector))
63 matchedDecls.push_back(d->pDeclaration);
75 return pSel
->name_hash() == FX_HashCode_GetLoweredW(tagname.AsStringView());
79 const std::vector<
const CFX_CSSDeclaration*>& declArray,
80 const WideString& styleString,
81 const WideString& alignString,
82 CFX_CSSComputedStyle* pDest) {
83 std::unique_ptr<CFX_CSSDeclaration> pDecl;
88 AppendInlineStyle(pDecl.get(), styleString);
92 alignString.AsStringView());
95 ApplyDeclarations(declArray, pDecl.get(), pDest);
99 const std::vector<
const CFX_CSSDeclaration*>& declArray,
101 CFX_CSSComputedStyle* pComputedStyle) {
102 std::vector<
const CFX_CSSPropertyHolder*> importants;
103 std::vector<
const CFX_CSSPropertyHolder*> normals;
104 std::vector<
const CFX_CSSCustomProperty*> customs;
106 for (
auto* decl : declArray)
107 ExtractValues(decl, &importants, &normals, &customs);
110 ExtractValues(extraDecl, &importants, &normals, &customs);
112 for (
auto* prop : normals)
113 ApplyProperty(prop->eProperty, prop->pValue, pComputedStyle);
115 for (
auto* prop : customs)
116 pComputedStyle->AddCustomStyle(*prop);
118 for (
auto* prop : importants)
119 ApplyProperty(prop->eProperty, prop->pValue, pComputedStyle);
124 std::vector<
const CFX_CSSPropertyHolder*>* importants,
125 std::vector<
const CFX_CSSPropertyHolder*>* normals,
126 std::vector<
const CFX_CSSCustomProperty*>* custom) {
127 for (
const auto& holder : *decl) {
128 if (holder->bImportant)
129 importants->push_back(holder.get());
131 normals->push_back(holder.get());
133 for (
auto it = decl->custom_begin(); it != decl->custom_end(); it++)
134 custom->push_back(it->get());
138 const WideString& style) {
140 DCHECK(!style.IsEmpty());
143 pSyntax->SetParseOnlyDeclarations();
151 WideStringView strValue = pSyntax->GetCurrentString();
154 wsName
= WideString(strValue);
156 if (property || iLen2 > 0) {
157 WideStringView strValue = pSyntax->GetCurrentString();
158 if (!strValue.IsEmpty()) {
160 pDecl->AddProperty(property, strValue);
173 CFX_CSSComputedStyle* pComputedStyle) {
176 RetainPtr<CFX_CSSValueList> value_list = pValue.As<CFX_CSSValueList>();
177 if (!value_list->values().empty()) {
180 pComputedStyle->m_InheritedData.m_pFontFamily =
std::move(value_list);
183 pComputedStyle->m_NonInheritedData.m_dwTextDecoration =
184 ToTextDecoration(value_list);
196 pComputedStyle->m_NonInheritedData.m_eDisplay =
197 ToDisplay(pValue.AsRaw<CFX_CSSEnumValue>()->Value());
201 float& fFontSize = pComputedStyle->m_InheritedData.m_fFontSize;
203 fFontSize = pValue.AsRaw<CFX_CSSNumberValue>()->Apply(fFontSize);
206 ToFontSize(pValue.AsRaw<CFX_CSSEnumValue>()->Value(), fFontSize);
211 RetainPtr<CFX_CSSNumberValue> v = pValue.As<CFX_CSSNumberValue>();
213 pComputedStyle->m_InheritedData.m_fLineHeight =
214 v->value() * pComputedStyle->m_InheritedData.m_fFontSize;
216 pComputedStyle->m_InheritedData.m_fLineHeight =
217 v->Apply(pComputedStyle->m_InheritedData.m_fFontSize);
223 pComputedStyle->m_InheritedData.m_eTextAlign =
224 ToTextAlign(pValue.AsRaw<CFX_CSSEnumValue>()->Value());
228 SetLengthWithPercent(pComputedStyle->m_InheritedData.m_TextIndent, eType,
229 pValue, pComputedStyle->m_InheritedData.m_fFontSize);
233 pComputedStyle->m_InheritedData.m_wFontWeight =
234 ToFontWeight(pValue.AsRaw<CFX_CSSEnumValue>()->Value());
237 static_cast<int32_t>(pValue.AsRaw<CFX_CSSNumberValue>()->value()) /
239 if (iValue >= 1 && iValue <= 9) {
240 pComputedStyle->m_InheritedData.m_wFontWeight = iValue * 100;
246 pComputedStyle->m_InheritedData.m_eFontStyle =
247 ToFontStyle(pValue.AsRaw<CFX_CSSEnumValue>()->Value());
252 pComputedStyle->m_InheritedData.m_dwFontColor =
253 pValue.AsRaw<CFX_CSSColorValue>()->Value();
257 if (SetLengthWithPercent(
258 pComputedStyle->m_NonInheritedData.m_MarginWidth.left, eType,
259 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
260 pComputedStyle->m_NonInheritedData.m_bHasMargin =
true;
264 if (SetLengthWithPercent(
265 pComputedStyle->m_NonInheritedData.m_MarginWidth.top, eType,
266 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
267 pComputedStyle->m_NonInheritedData.m_bHasMargin =
true;
271 if (SetLengthWithPercent(
272 pComputedStyle->m_NonInheritedData.m_MarginWidth.right, eType,
273 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
274 pComputedStyle->m_NonInheritedData.m_bHasMargin =
true;
278 if (SetLengthWithPercent(
279 pComputedStyle->m_NonInheritedData.m_MarginWidth.bottom, eType,
280 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
281 pComputedStyle->m_NonInheritedData.m_bHasMargin =
true;
285 if (SetLengthWithPercent(
286 pComputedStyle->m_NonInheritedData.m_PaddingWidth.left, eType,
287 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
288 pComputedStyle->m_NonInheritedData.m_bHasPadding =
true;
292 if (SetLengthWithPercent(
293 pComputedStyle->m_NonInheritedData.m_PaddingWidth.top, eType,
294 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
295 pComputedStyle->m_NonInheritedData.m_bHasPadding =
true;
299 if (SetLengthWithPercent(
300 pComputedStyle->m_NonInheritedData.m_PaddingWidth.right, eType,
301 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
302 pComputedStyle->m_NonInheritedData.m_bHasPadding =
true;
306 if (SetLengthWithPercent(
307 pComputedStyle->m_NonInheritedData.m_PaddingWidth.bottom, eType,
308 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
309 pComputedStyle->m_NonInheritedData.m_bHasPadding =
true;
313 if (SetLengthWithPercent(
314 pComputedStyle->m_NonInheritedData.m_BorderWidth.left, eType,
315 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
316 pComputedStyle->m_NonInheritedData.m_bHasBorder =
true;
320 if (SetLengthWithPercent(
321 pComputedStyle->m_NonInheritedData.m_BorderWidth.top, eType,
322 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
323 pComputedStyle->m_NonInheritedData.m_bHasBorder =
true;
327 if (SetLengthWithPercent(
328 pComputedStyle->m_NonInheritedData.m_BorderWidth.right, eType,
329 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
330 pComputedStyle->m_NonInheritedData.m_bHasBorder =
true;
334 if (SetLengthWithPercent(
335 pComputedStyle->m_NonInheritedData.m_BorderWidth.bottom, eType,
336 pValue, pComputedStyle->m_InheritedData.m_fFontSize)) {
337 pComputedStyle->m_NonInheritedData.m_bHasBorder =
true;
342 pComputedStyle->m_NonInheritedData.m_eVerticalAlignType =
343 ToVerticalAlign(pValue.AsRaw<CFX_CSSEnumValue>()->Value());
345 pComputedStyle->m_NonInheritedData.m_eVerticalAlignType =
347 pComputedStyle->m_NonInheritedData.m_fVerticalAlign =
348 pValue.AsRaw<CFX_CSSNumberValue>()->Apply(
349 pComputedStyle->m_InheritedData.m_fFontSize);
354 pComputedStyle->m_InheritedData.m_eFontVariant =
355 ToFontVariant(pValue.AsRaw<CFX_CSSEnumValue>()->Value());
360 pComputedStyle->m_InheritedData.m_LetterSpacing.Set(
363 if (pValue.AsRaw<CFX_CSSNumberValue>()->unit() ==
368 SetLengthWithPercent(pComputedStyle->m_InheritedData.m_LetterSpacing,
370 pComputedStyle->m_InheritedData.m_fFontSize);
375 pComputedStyle->m_InheritedData.m_WordSpacing.Set(
378 if (pValue.AsRaw<CFX_CSSNumberValue>()->unit() ==
382 SetLengthWithPercent(pComputedStyle->m_InheritedData.m_WordSpacing,
384 pComputedStyle->m_InheritedData.m_fFontSize);
388 SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Top, eType,
389 pValue, pComputedStyle->m_InheritedData.m_fFontSize);
392 SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Bottom, eType,
393 pValue, pComputedStyle->m_InheritedData.m_fFontSize);
396 SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Left, eType,
397 pValue, pComputedStyle->m_InheritedData.m_fFontSize);
400 SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Right, eType,
401 pValue, pComputedStyle->m_InheritedData.m_fFontSize);
472 RetainPtr<CFX_CSSNumberValue> v = pValue.As<CFX_CSSNumberValue>();
475 pValue.AsRaw<CFX_CSSNumberValue>()->value() / 100.0f);
479 float fValue = v->Apply(fFontSize);
483 switch (pValue.AsRaw<CFX_CSSEnumValue>()->Value()) {
507 float fCurFontSize) {
510 return m_fDefaultFontSize / 1.2f / 1.2f / 1.2f;
512 return m_fDefaultFontSize / 1.2f / 1.2f;
514 return m_fDefaultFontSize / 1.2f;
516 return m_fDefaultFontSize;
518 return m_fDefaultFontSize * 1.2f;
520 return m_fDefaultFontSize * 1.2f * 1.2f;
522 return m_fDefaultFontSize * 1.2f * 1.2f * 1.2f;
524 return fCurFontSize * 1.2f;
526 return fCurFontSize / 1.2f;
556 const RetainPtr<CFX_CSSValueList>& pValue) {
558 for (
const RetainPtr<CFX_CSSValue>& val :
559 pdfium::base::Reversed(pValue->values())) {
560 if (val->GetType() != CFX_CSSValue::PrimitiveType::kEnum)
563 switch (val.AsRaw<CFX_CSSEnumValue>()->Value()) {
564 case CFX_CSSPropertyValue::Underline:
565 dwDecoration |= CFX_CSSTEXTDECORATION::kUnderline;
567 case CFX_CSSPropertyValue::LineThrough:
568 dwDecoration |= CFX_CSSTEXTDECORATION::kLineThrough;
570 case CFX_CSSPropertyValue::Overline:
571 dwDecoration |= CFX_CSSTEXTDECORATION::kOverline;
573 case CFX_CSSPropertyValue::Blink:
574 dwDecoration |= CFX_CSSTEXTDECORATION::kBlink;
576 case CFX_CSSPropertyValue::Double:
577 dwDecoration |= CFX_CSSTEXTDECORATION::kDouble;
static const Property * GetPropertyByEnum(CFX_CSSProperty property)
static const Property * GetPropertyByName(WideStringView name)
void AddProperty(const WideString &prop, const WideString &value)
CFX_CSSLength & Set(CFX_CSSLengthUnit eUnit)
CFX_CSSLength & Set(CFX_CSSLengthUnit eUnit, float fValue)
bool is_descendant() const
uint32_t name_hash() const
const CFX_CSSSelector * next_selector() const
void SetUAStyleSheet(std::unique_ptr< CFX_CSSStyleSheet > pSheet)
void ComputeStyle(const std::vector< const CFX_CSSDeclaration * > &declArray, const WideString &styleString, const WideString &alignString, CFX_CSSComputedStyle *pDestStyle)
void SetDefaultFontSize(float fFontSize)
RetainPtr< CFX_CSSComputedStyle > CreateComputedStyle(const CFX_CSSComputedStyle *pParentStyle)
std::vector< const CFX_CSSDeclaration * > MatchDeclarations(const WideString &tagname)
WideString & operator=(WideString &&that) noexcept