void HTMLBodyElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) { if (name == backgroundAttr) { String url = stripLeadingAndTrailingHTMLSpaces(value); if (!url.isEmpty()) { auto imageValue = CSSImageValue::create(document().completeURL(url).string()); imageValue.get().setInitiator(localName()); style.setProperty(CSSProperty(CSSPropertyBackgroundImage, WTF::move(imageValue))); } } else if (name == marginwidthAttr || name == leftmarginAttr) { addHTMLLengthToStyle(style, CSSPropertyMarginRight, value); addHTMLLengthToStyle(style, CSSPropertyMarginLeft, value); } else if (name == marginheightAttr || name == topmarginAttr) { addHTMLLengthToStyle(style, CSSPropertyMarginBottom, value); addHTMLLengthToStyle(style, CSSPropertyMarginTop, value); } else if (name == bgcolorAttr) { addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value); } else if (name == textAttr) { addHTMLColorToStyle(style, CSSPropertyColor, value); } else if (name == bgpropertiesAttr) { if (equalIgnoringCase(value, "fixed")) addPropertyToPresentationAttributeStyle(style, CSSPropertyBackgroundAttachment, CSSValueFixed); } else HTMLElement::collectStyleForPresentationAttribute(name, value, style); }
void HTMLPreElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) { if (name == wrapAttr) style.setProperty(CSSPropertyWhiteSpace, CSSValuePreWrap); else HTMLElement::collectStyleForPresentationAttribute(name, value, style); }
void HTMLTableElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) { if (name == widthAttr) addHTMLLengthToStyle(style, CSSPropertyWidth, value); else if (name == heightAttr) addHTMLLengthToStyle(style, CSSPropertyHeight, value); else if (name == borderAttr) addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, parseBorderWidthAttribute(value), CSSPrimitiveValue::CSS_PX); else if (name == bordercolorAttr) { if (!value.isEmpty()) addHTMLColorToStyle(style, CSSPropertyBorderColor, value); } else if (name == bgcolorAttr) addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value); else if (name == backgroundAttr) { String url = stripLeadingAndTrailingHTMLSpaces(value); if (!url.isEmpty()) style.setProperty(CSSProperty(CSSPropertyBackgroundImage, CSSImageValue::create(document().completeURL(url).string()))); } else if (name == valignAttr) { if (!value.isEmpty()) addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, value); } else if (name == cellspacingAttr) { if (!value.isEmpty()) addHTMLLengthToStyle(style, CSSPropertyBorderSpacing, value); } else if (name == vspaceAttr) { addHTMLLengthToStyle(style, CSSPropertyMarginTop, value); addHTMLLengthToStyle(style, CSSPropertyMarginBottom, value); } else if (name == hspaceAttr) { addHTMLLengthToStyle(style, CSSPropertyMarginLeft, value); addHTMLLengthToStyle(style, CSSPropertyMarginRight, value); } else if (name == alignAttr) { if (!value.isEmpty()) { if (equalIgnoringCase(value, "center")) { addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitMarginStart, CSSValueAuto); addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitMarginEnd, CSSValueAuto); } else addPropertyToPresentationAttributeStyle(style, CSSPropertyFloat, value); } } else if (name == rulesAttr) { // The presence of a valid rules attribute causes border collapsing to be enabled. if (m_rulesAttr != UnsetRules) addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderCollapse, CSSValueCollapse); } else if (name == frameAttr) { bool borderTop; bool borderRight; bool borderBottom; bool borderLeft; if (getBordersFromFrameAttributeValue(value, borderTop, borderRight, borderBottom, borderLeft)) { addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, CSSValueThin); addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderTopStyle, borderTop ? CSSValueSolid : CSSValueHidden); addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomStyle, borderBottom ? CSSValueSolid : CSSValueHidden); addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderLeftStyle, borderLeft ? CSSValueSolid : CSSValueHidden); addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderRightStyle, borderRight ? CSSValueSolid : CSSValueHidden); } } else HTMLElement::collectStyleForPresentationAttribute(name, value, style); }
CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context) { ASSERT(!string.isEmpty()); RefPtr<CSSValue> value = CSSParserFastPaths::maybeParseValue(propertyID, string, context.mode); if (value) return declaration.addParsedProperty(CSSProperty(propertyID, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged; CSSParser parser(context); return parser.parseValue(declaration, propertyID, string, important); }
void HTMLHRElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) { if (name == alignAttr) { if (equalLettersIgnoringASCIICase(value, "left")) { addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, 0, CSSPrimitiveValue::CSS_PX); addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, CSSValueAuto); } else if (equalLettersIgnoringASCIICase(value, "right")) { addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, CSSValueAuto); addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, 0, CSSPrimitiveValue::CSS_PX); } else { addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginLeft, CSSValueAuto); addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, CSSValueAuto); } } else if (name == widthAttr) { bool ok; int v = value.toInt(&ok); if (ok && !v) addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 1, CSSPrimitiveValue::CSS_PX); else addHTMLLengthToStyle(style, CSSPropertyWidth, value); } else if (name == colorAttr) { addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSValueSolid); addHTMLColorToStyle(style, CSSPropertyBorderColor, value); addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value); } else if (name == noshadeAttr) { if (!hasAttributeWithoutSynchronization(colorAttr)) { addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSValueSolid); RefPtr<CSSPrimitiveValue> darkGrayValue = CSSValuePool::singleton().createColorValue(Color::darkGray); style.setProperty(CSSPropertyBorderColor, darkGrayValue); style.setProperty(CSSPropertyBackgroundColor, darkGrayValue); } } else if (name == sizeAttr) { StringImpl* si = value.impl(); int size = si->toInt(); if (size <= 1) addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomWidth, 0, CSSPrimitiveValue::CSS_PX); else addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, size - 2, CSSPrimitiveValue::CSS_PX); } else HTMLElement::collectStyleForPresentationAttribute(name, value, style); }
void HTMLFontElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) { if (name == sizeAttr) { CSSValueID size = CSSValueInvalid; if (cssValueFromFontSizeNumber(value, size)) addPropertyToPresentationAttributeStyle(style, CSSPropertyFontSize, size); } else if (name == colorAttr) addHTMLColorToStyle(style, CSSPropertyColor, value); else if (name == faceAttr) { if (RefPtr<CSSValueList> fontFaceValue = cssValuePool().createFontFaceValue(value)) style.setProperty(CSSProperty(CSSPropertyFontFamily, fontFaceValue.release())); } else HTMLElement::collectStyleForPresentationAttribute(name, value, style); }
static Optional<FontTraitsMask> computeFontTraitsMask(MutableStyleProperties& style) { RefPtr<CSSValue> styleValue = style.getPropertyCSSValue(CSSPropertyFontStyle).get(); if (!styleValue) styleValue = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal).ptr(); FontTraitsMask styleMask; if (auto styleMaskOptional = CSSFontFace::calculateStyleMask(*styleValue)) styleMask = styleMaskOptional.value(); else return Nullopt; RefPtr<CSSValue> weightValue = style.getPropertyCSSValue(CSSPropertyFontWeight).get(); if (!weightValue) weightValue = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal).ptr(); FontTraitsMask weightMask; if (auto weightMaskOptional = CSSFontFace::calculateWeightMask(*weightValue)) weightMask = weightMaskOptional.value(); else return Nullopt; return static_cast<FontTraitsMask>(static_cast<unsigned>(styleMask) | static_cast<unsigned>(weightMask)); }
void HTMLTablePartElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) { if (name == bgcolorAttr) addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value); else if (name == backgroundAttr) { String url = stripLeadingAndTrailingHTMLSpaces(value); if (!url.isEmpty()) style.setProperty(CSSProperty(CSSPropertyBackgroundImage, CSSImageValue::create(document().completeURL(url).string()))); } else if (name == valignAttr) { if (equalIgnoringCase(value, "top")) addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, CSSValueTop); else if (equalIgnoringCase(value, "middle")) addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, CSSValueMiddle); else if (equalIgnoringCase(value, "bottom")) addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, CSSValueBottom); else if (equalIgnoringCase(value, "baseline")) addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, CSSValueBaseline); else addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, value); } else if (name == alignAttr) { if (equalIgnoringCase(value, "middle") || equalIgnoringCase(value, "center")) addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueWebkitCenter); else if (equalIgnoringCase(value, "absmiddle")) addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueCenter); else if (equalIgnoringCase(value, "left")) addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueWebkitLeft); else if (equalIgnoringCase(value, "right")) addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueWebkitRight); else addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, value); } else if (name == heightAttr) { if (!value.isEmpty()) addHTMLLengthToStyle(style, CSSPropertyHeight, value); } else HTMLElement::collectStyleForPresentationAttribute(name, value, style); }
void StyledElement::addPropertyToPresentationAttributeStyle(MutableStyleProperties& style, CSSPropertyID propertyID, const String& value) { style.setProperty(propertyID, value, false, &document().elementSheet().contents()); }
void StyledElement::addPropertyToPresentationAttributeStyle(MutableStyleProperties& style, CSSPropertyID propertyID, double value, CSSPrimitiveValue::UnitTypes unit) { style.setProperty(propertyID, cssValuePool().createValue(value, unit)); }
void StyledElement::addPropertyToPresentationAttributeStyle(MutableStyleProperties& style, CSSPropertyID propertyID, CSSValueID identifier) { style.setProperty(propertyID, cssValuePool().createIdentifierValue(identifier)); }
void StyledElement::addPropertyToPresentationAttributeStyle(MutableStyleProperties& style, CSSPropertyID propertyID, const String& value) { style.setProperty(propertyID, value, false, CSSParserContext(document())); }