#include "config.h"
#include "StyleResolver.h"
#include "CSSCalculationValue.h"
#include "CSSCursorImageValue.h"
#include "CSSCustomPropertyValue.h"
#include "CSSDefaultStyleSheets.h"
#include "CSSFilterImageValue.h"
#include "CSSFontSelector.h"
#include "CSSFunctionValue.h"
#include "CSSGradientValue.h"
#include "CSSImageSetValue.h"
#include "CSSImageValue.h"
#include "CSSKeyframeRule.h"
#include "CSSKeyframesRule.h"
#include "CSSParser.h"
#include "CSSPrimitiveValueMappings.h"
#include "CSSPropertyNames.h"
#include "CSSReflectValue.h"
#include "CSSSelector.h"
#include "CSSShadowValue.h"
#include "CSSStyleRule.h"
#include "CSSStyleSheet.h"
#include "CSSValueList.h"
#include "CSSValuePool.h"
#include "CachedResourceLoader.h"
#include "ElementRuleCollector.h"
#include "FilterOperation.h"
#include "Frame.h"
#include "FrameSelection.h"
#include "FrameView.h"
#include "HTMLInputElement.h"
#include "HTMLMarqueeElement.h"
#include "HTMLNames.h"
#include "HTMLSlotElement.h"
#include "HTMLTableElement.h"
#include "HTMLTextAreaElement.h"
#include "InspectorInstrumentation.h"
#include "KeyframeList.h"
#include "Logging.h"
#include "MathMLElement.h"
#include "MathMLNames.h"
#include "MediaList.h"
#include "MediaQueryEvaluator.h"
#include "NodeRenderStyle.h"
#include "PageRuleCollector.h"
#include "Pair.h"
#include "RenderScrollbar.h"
#include "RenderStyleConstants.h"
#include "RenderTheme.h"
#include "RenderView.h"
#include "RuleSet.h"
#include "RuntimeEnabledFeatures.h"
#include "SVGDocument.h"
#include "SVGDocumentExtensions.h"
#include "SVGFontFaceElement.h"
#include "SVGNames.h"
#include "SVGSVGElement.h"
#include "SVGURIReference.h"
#include "Settings.h"
#include "ShadowRoot.h"
#include "SharedStringHash.h"
#include "StyleBuilder.h"
#include "StyleColor.h"
#include "StyleCachedImage.h"
#include "StyleFontSizeFunctions.h"
#include "StyleGeneratedImage.h"
#include "StyleProperties.h"
#include "StylePropertyShorthand.h"
#include "StyleRule.h"
#include "StyleSheetContents.h"
#include "TransformFunctions.h"
#include "TransformOperations.h"
#include "UserAgentStyleSheets.h"
#include "ViewportStyleResolver.h"
#include "VisitedLinkState.h"
#include "WebKitFontFamilyNames.h"
#include <bitset>
#include <wtf/Seconds.h>
#include <wtf/StdLibExtras.h>
#include <wtf/Vector.h>
#include <wtf/text/AtomicStringHash.h>
#if ENABLE(DASHBOARD_SUPPORT)
#endif
#if ENABLE(VIDEO_TRACK)
#endif
namespace WebCore {
using namespace HTMLNames;
static const CSSPropertyID firstLowPriorityProperty = static_cast<CSSPropertyID>(lastHighPriorityProperty + 1);
static void extractDirectionAndWritingMode(const RenderStyle&, const StyleResolver::MatchResult&, TextDirection&, WritingMode&);
inline void StyleResolver::State::cacheBorderAndBackground()
{
m_hasUAAppearance = m_style->hasAppearance();
if (m_hasUAAppearance) {
m_borderData = m_style->border();
m_backgroundData = m_style->backgroundLayers();
m_backgroundColor = m_style->backgroundColor();
}
}
inline void StyleResolver::State::clear()
{
m_element = nullptr;
m_parentStyle = nullptr;
m_ownedParentStyle = nullptr;
m_cssToLengthConversionData = CSSToLengthConversionData();
}
void StyleResolver::MatchResult::addMatchedProperties(const StyleProperties& properties, StyleRule* rule, unsigned linkMatchType, PropertyWhitelistType propertyWhitelistType, Style::ScopeOrdinal styleScopeOrdinal)
{
m_matchedProperties.grow(m_matchedProperties.size() + 1);
StyleResolver::MatchedProperties& newProperties = m_matchedProperties.last();
newProperties.properties = const_cast<StyleProperties*>(&properties);
newProperties.linkMatchType = linkMatchType;
newProperties.whitelistType = propertyWhitelistType;
newProperties.styleScopeOrdinal = styleScopeOrdinal;
matchedRules.append(rule);
if (styleScopeOrdinal != Style::ScopeOrdinal::Element)
isCacheable = false;
if (isCacheable) {
for (unsigned i = 0, count = properties.propertyCount(); i < count; ++i) {
StyleProperties::PropertyReference current = properties.propertyAt(i);
if (!current.isInherited()) {
const CSSValue& value = *current.value();
if (value.isInheritedValue()) {
isCacheable = false;
break;
}
if (is<CSSPrimitiveValue>(value) && downcast<CSSPrimitiveValue>(value).valueID() == CSSValueCurrentcolor) {
isCacheable = false;
break;
}
if (value.hasVariableReferences()) {
isCacheable = false;
break;
}
}
}
}
}
StyleResolver::StyleResolver(Document& document)
: m_ruleSets(*this)
, m_matchedPropertiesCacheAdditionsSinceLastSweep(0)
, m_matchedPropertiesCacheSweepTimer(*this, &StyleResolver::sweepMatchedPropertiesCache)
, m_document(document)
, m_matchAuthorAndUserStyles(m_document.settings().authorAndUserStylesEnabled())
#if ENABLE(CSS_DEVICE_ADAPTATION)
, m_viewportStyleResolver(ViewportStyleResolver::create(&document))
#endif
, m_styleMap(this)
{
Element* root = m_document.documentElement();
CSSDefaultStyleSheets::initDefaultStyle(root);
FrameView* view = m_document.view();
if (view)
m_mediaQueryEvaluator = MediaQueryEvaluator { view->mediaType() };
else
m_mediaQueryEvaluator = MediaQueryEvaluator { "all" };
if (root) {
m_rootDefaultStyle = styleForElement(*root, m_document.renderStyle(), nullptr, MatchOnlyUserAgentRules).renderStyle;
m_document.fontSelector().incrementIsComputingRootStyleFont();
m_rootDefaultStyle->fontCascade().update(&m_document.fontSelector());
m_rootDefaultStyle->fontCascade().primaryFont();
m_document.fontSelector().decrementIsComputingRootStyleFont();
}
if (m_rootDefaultStyle && view)
m_mediaQueryEvaluator = MediaQueryEvaluator { view->mediaType(), m_document, m_rootDefaultStyle.get() };
m_ruleSets.resetAuthorStyle();
m_ruleSets.resetUserAgentMediaQueryStyle();
}
void StyleResolver::addCurrentSVGFontFaceRules()
{
#if ENABLE(SVG_FONTS)
if (m_document.svgExtensions()) {
const HashSet<SVGFontFaceElement*>& svgFontFaceElements = m_document.svgExtensions()->svgFontFaceElements();
for (auto* svgFontFaceElement : svgFontFaceElements)
m_document.fontSelector().addFontFaceRule(svgFontFaceElement->fontFaceRule(), svgFontFaceElement->isInUserAgentShadowTree());
}
#endif
}
void StyleResolver::appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>& styleSheets)
{
m_ruleSets.appendAuthorStyleSheets(styleSheets, &m_mediaQueryEvaluator, m_inspectorCSSOMWrappers, this);
if (auto renderView = document().renderView())
renderView->style().fontCascade().update(&document().fontSelector());
#if ENABLE(CSS_DEVICE_ADAPTATION)
viewportStyleResolver()->resolve();
#endif
}
void StyleResolver::addKeyframeStyle(Ref<StyleRuleKeyframes>&& rule)
{
AtomicString s(rule->name());
m_keyframesRuleMap.set(s.impl(), WTFMove(rule));
}
StyleResolver::~StyleResolver()
{
RELEASE_ASSERT(!m_isDeleted);
m_isDeleted = true;
#if ENABLE(CSS_DEVICE_ADAPTATION)
m_viewportStyleResolver->clearDocument();
#endif
}
void StyleResolver::sweepMatchedPropertiesCache()
{
Vector<unsigned, 16> toRemove;
MatchedPropertiesCache::iterator it = m_matchedPropertiesCache.begin();
MatchedPropertiesCache::iterator end = m_matchedPropertiesCache.end();
for (; it != end; ++it) {
Vector<MatchedProperties>& matchedProperties = it->value.matchedProperties;
for (size_t i = 0; i < matchedProperties.size(); ++i) {
if (matchedProperties[i].properties->hasOneRef()) {
toRemove.append(it->key);
break;
}
}
}
for (size_t i = 0; i < toRemove.size(); ++i)
m_matchedPropertiesCache.remove(toRemove[i]);
m_matchedPropertiesCacheAdditionsSinceLastSweep = 0;
}
StyleResolver::State::State(const Element& element, const RenderStyle* parentStyle, const RenderStyle* documentElementStyle, const SelectorFilter* selectorFilter)
: m_element(&element)
, m_parentStyle(parentStyle)
, m_elementLinkState(element.document().visitedLinkState().determineLinkState(element))
, m_selectorFilter(selectorFilter)
{
bool resetStyleInheritance = hasShadowRootParent(element) && downcast<ShadowRoot>(element.parentNode())->resetStyleInheritance();
if (resetStyleInheritance)
m_parentStyle = nullptr;
auto& document = element.document();
auto* documentElement = document.documentElement();
if (!documentElement || documentElement == &element)
m_rootElementStyle = document.renderStyle();
else
m_rootElementStyle = documentElementStyle ? documentElementStyle : documentElement->renderStyle();
updateConversionData();
}
inline void StyleResolver::State::updateConversionData()
{
m_cssToLengthConversionData = CSSToLengthConversionData(m_style.get(), m_rootElementStyle, m_element ? m_element->document().renderView() : nullptr);
}
inline void StyleResolver::State::setStyle(std::unique_ptr<RenderStyle> style)
{
m_style = WTFMove(style);
updateConversionData();
}
void StyleResolver::State::setParentStyle(std::unique_ptr<RenderStyle> parentStyle)
{
m_ownedParentStyle = WTFMove(parentStyle);
m_parentStyle = m_ownedParentStyle.get();
}
static inline bool isAtShadowBoundary(const Element& element)
{
auto* parentNode = element.parentNode();
return parentNode && parentNode->isShadowRoot();
}
ElementStyle StyleResolver::styleForElement(const Element& element, const RenderStyle* parentStyle, const RenderStyle* parentBoxStyle, RuleMatchingBehavior matchingBehavior, const SelectorFilter* selectorFilter)
{
RELEASE_ASSERT(!m_isDeleted);
m_state = State(element, parentStyle, m_overrideDocumentElementStyle, selectorFilter);
State& state = m_state;
if (state.parentStyle()) {
state.setStyle(RenderStyle::createPtr());
state.style()->inheritFrom(*state.parentStyle());
} else {
state.setStyle(defaultStyleForElement());
state.setParentStyle(RenderStyle::clonePtr(*state.style()));
}
auto& style = *state.style();
if (element.isLink()) {
style.setIsLink(true);
EInsideLink linkState = state.elementLinkState();
if (linkState != NotInsideLink) {
bool forceVisited = InspectorInstrumentation::forcePseudoState(element, CSSSelector::PseudoClassVisited);
if (forceVisited)
linkState = InsideVisitedLink;
}
style.setInsideLink(linkState);
}
CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(element);
ElementRuleCollector collector(element, m_ruleSets, m_state.selectorFilter());
collector.setMedium(&m_mediaQueryEvaluator);
if (matchingBehavior == MatchOnlyUserAgentRules)
collector.matchUARules();
else
collector.matchAllRules(m_matchAuthorAndUserStyles, matchingBehavior != MatchAllRulesExcludingSMIL);
if (collector.matchedPseudoElementIds())
style.setHasPseudoStyles(collector.matchedPseudoElementIds());
if (collector.didMatchUncommonAttributeSelector())
style.setUnique();
auto elementStyleRelations = Style::commitRelationsToRenderStyle(style, element, collector.styleRelations());
applyMatchedProperties(collector.matchedResult(), element);
adjustRenderStyle(*state.style(), *state.parentStyle(), parentBoxStyle, &element);
if (state.style()->hasViewportUnits())
document().setHasStyleWithViewportUnits();
state.clear();
return { state.takeStyle(), WTFMove(elementStyleRelations) };
}
std::unique_ptr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* elementStyle, const StyleRuleKeyframe* keyframe, KeyframeValue& keyframeValue)
{
RELEASE_ASSERT(!m_isDeleted);
MatchResult result;
result.addMatchedProperties(keyframe->properties());
ASSERT(!m_state.style());
State& state = m_state;
state.setStyle(RenderStyle::clonePtr(*elementStyle));
state.setParentStyle(RenderStyle::clonePtr(*elementStyle));
TextDirection direction;
WritingMode writingMode;
extractDirectionAndWritingMode(*state.style(), result, direction, writingMode);
CascadedProperties cascade(direction, writingMode);
cascade.addNormalMatches(result, 0, result.matchedProperties().size() - 1);
applyCascadedProperties(cascade, CSSPropertyCustom, CSSPropertyCustom, &result);
applyCascadedProperties(cascade, firstCSSProperty, lastHighPriorityProperty, &result);
updateFont();
applyCascadedProperties(cascade, firstLowPriorityProperty, lastCSSProperty, &result);
updateFont();
cascade.applyDeferredProperties(*this, &result);
adjustRenderStyle(*state.style(), *state.parentStyle(), nullptr, nullptr);
unsigned propertyCount = keyframe->properties().propertyCount();
for (unsigned i = 0; i < propertyCount; ++i) {
CSSPropertyID property = keyframe->properties().propertyAt(i).id();
if (property != CSSPropertyAnimationTimingFunction)
keyframeValue.addProperty(property);
}
return state.takeStyle();
}
void StyleResolver::keyframeStylesForAnimation(const Element& element, const RenderStyle* elementStyle, KeyframeList& list)
{
list.clear();
if (list.animationName().isEmpty())
return;
m_keyframesRuleMap.checkConsistency();
KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(list.animationName().impl());
if (it == m_keyframesRuleMap.end())
return;
const StyleRuleKeyframes* keyframesRule = it->value.get();
auto* keyframes = &keyframesRule->keyframes();
Vector<Ref<StyleRuleKeyframe>> newKeyframesIfNecessary;
bool hasDuplicateKeys = false;
HashSet<double> keyframeKeys;
for (auto& keyframe : *keyframes) {
for (auto key : keyframe->keys()) {
if (!keyframeKeys.add(key)) {
hasDuplicateKeys = true;
break;
}
}
if (hasDuplicateKeys)
break;
}
if (hasDuplicateKeys) {
HashMap<double, RefPtr<StyleRuleKeyframe>> keyframesMap;
for (auto& originalKeyframe : keyframesRule->keyframes()) {
for (auto key : originalKeyframe->keys()) {
if (auto keyframe = keyframesMap.get(key))
keyframe->mutableProperties().mergeAndOverrideOnConflict(originalKeyframe->properties());
else {
auto StyleRuleKeyframe = StyleRuleKeyframe::create(MutableStyleProperties::create());
StyleRuleKeyframe.ptr()->setKey(key);
StyleRuleKeyframe.ptr()->mutableProperties().mergeAndOverrideOnConflict(originalKeyframe->properties());
keyframesMap.set(key, StyleRuleKeyframe.ptr());
}
}
}
for (auto& keyframe : keyframesMap.values())
newKeyframesIfNecessary.append(*keyframe.get());
keyframes = &newKeyframesIfNecessary;
}
for (auto& keyframe : *keyframes) {
m_state = State(element, nullptr);
for (auto key : keyframe->keys()) {
KeyframeValue keyframeValue(0, nullptr);
keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe.ptr(), keyframeValue));
keyframeValue.setKey(key);
list.insert(WTFMove(keyframeValue));
}
}
int initialListSize = list.size();
if (initialListSize > 0 && list[0].key()) {
static StyleRuleKeyframe* zeroPercentKeyframe;
if (!zeroPercentKeyframe) {
zeroPercentKeyframe = &StyleRuleKeyframe::create(MutableStyleProperties::create()).leakRef();
zeroPercentKeyframe->setKey(0);
}
KeyframeValue keyframeValue(0, nullptr);
keyframeValue.setStyle(styleForKeyframe(elementStyle, zeroPercentKeyframe, keyframeValue));
list.insert(WTFMove(keyframeValue));
}
if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) {
static StyleRuleKeyframe* hundredPercentKeyframe;
if (!hundredPercentKeyframe) {
hundredPercentKeyframe = &StyleRuleKeyframe::create(MutableStyleProperties::create()).leakRef();
hundredPercentKeyframe->setKey(1);
}
KeyframeValue keyframeValue(1, nullptr);
keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyframe, keyframeValue));
list.insert(WTFMove(keyframeValue));
}
}
std::unique_ptr<RenderStyle> StyleResolver::pseudoStyleForElement(const Element& element, const PseudoStyleRequest& pseudoStyleRequest, const RenderStyle& parentStyle, const SelectorFilter* selectorFilter)
{
m_state = State(element, &parentStyle, m_overrideDocumentElementStyle, selectorFilter);
State& state = m_state;
if (m_state.parentStyle()) {
state.setStyle(RenderStyle::createPtr());
state.style()->inheritFrom(*m_state.parentStyle());
} else {
state.setStyle(defaultStyleForElement());
state.setParentStyle(RenderStyle::clonePtr(*state.style()));
}
ElementRuleCollector collector(element, m_ruleSets, m_state.selectorFilter());
collector.setPseudoStyleRequest(pseudoStyleRequest);
collector.setMedium(&m_mediaQueryEvaluator);
collector.matchUARules();
if (m_matchAuthorAndUserStyles) {
collector.matchUserRules(false);
collector.matchAuthorRules(false);
}
ASSERT(!collector.matchedPseudoElementIds());
if (collector.matchedResult().matchedProperties().isEmpty())
return nullptr;
state.style()->setStyleType(pseudoStyleRequest.pseudoId);
applyMatchedProperties(collector.matchedResult(), element);
adjustRenderStyle(*state.style(), *m_state.parentStyle(), nullptr, nullptr);
if (state.style()->hasViewportUnits())
document().setHasStyleWithViewportUnits();
return state.takeStyle();
}
std::unique_ptr<RenderStyle> StyleResolver::styleForPage(int pageIndex)
{
RELEASE_ASSERT(!m_isDeleted);
auto* documentElement = m_document.documentElement();
if (!documentElement)
return RenderStyle::createPtr();
m_state = State(*documentElement, m_document.renderStyle());
m_state.setStyle(RenderStyle::createPtr());
m_state.style()->inheritFrom(*m_state.rootElementStyle());
PageRuleCollector collector(m_state, m_ruleSets);
collector.matchAllPageRules(pageIndex);
MatchResult& result = collector.matchedResult();
TextDirection direction;
WritingMode writingMode;
extractDirectionAndWritingMode(*m_state.style(), result, direction, writingMode);
CascadedProperties cascade(direction, writingMode);
cascade.addNormalMatches(result, 0, result.matchedProperties().size() - 1);
applyCascadedProperties(cascade, CSSPropertyCustom, CSSPropertyCustom, &result);
applyCascadedProperties(cascade, firstCSSProperty, lastHighPriorityProperty, &result);
updateFont();
applyCascadedProperties(cascade, firstLowPriorityProperty, lastCSSProperty, &result);
cascade.applyDeferredProperties(*this, &result);
return m_state.takeStyle();
}
std::unique_ptr<RenderStyle> StyleResolver::defaultStyleForElement()
{
m_state.setStyle(RenderStyle::createPtr());
initializeFontStyle();
m_state.style()->fontCascade().update(&document().fontSelector());
return m_state.takeStyle();
}
static void addIntrinsicMargins(RenderStyle& style)
{
const int intrinsicMargin = clampToInteger(2 * style.effectiveZoom());
if (style.width().isIntrinsicOrAuto()) {
if (style.marginLeft().hasQuirk())
style.setMarginLeft(Length(intrinsicMargin, Fixed));
if (style.marginRight().hasQuirk())
style.setMarginRight(Length(intrinsicMargin, Fixed));
}
if (style.height().isAuto()) {
if (style.marginTop().hasQuirk())
style.setMarginTop(Length(intrinsicMargin, Fixed));
if (style.marginBottom().hasQuirk())
style.setMarginBottom(Length(intrinsicMargin, Fixed));
}
}
static EDisplay equivalentBlockDisplay(const RenderStyle& style, const Document& document)
{
switch (auto display = style.display()) {
case BLOCK:
case TABLE:
case BOX:
case FLEX:
case WEBKIT_FLEX:
case GRID:
return display;
case LIST_ITEM:
if (document.inQuirksMode() && style.isFloating())
return BLOCK;
return display;
case INLINE_TABLE:
return TABLE;
case INLINE_BOX:
return BOX;
case INLINE_FLEX:
case WEBKIT_INLINE_FLEX:
return FLEX;
case INLINE_GRID:
return GRID;
case INLINE:
case COMPACT:
case INLINE_BLOCK:
case TABLE_ROW_GROUP:
case TABLE_HEADER_GROUP:
case TABLE_FOOTER_GROUP:
case TABLE_ROW:
case TABLE_COLUMN_GROUP:
case TABLE_COLUMN:
case TABLE_CELL:
case TABLE_CAPTION:
return BLOCK;
case CONTENTS:
ASSERT_NOT_REACHED();
return CONTENTS;
case NONE:
ASSERT_NOT_REACHED();
return NONE;
}
ASSERT_NOT_REACHED();
return BLOCK;
}
static bool doesNotInheritTextDecoration(const RenderStyle& style, const Element* element)
{
return style.display() == TABLE || style.display() == INLINE_TABLE
|| style.display() == INLINE_BLOCK || style.display() == INLINE_BOX || (element && isAtShadowBoundary(*element))
|| style.isFloating() || style.hasOutOfFlowPosition();
}
#if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
static bool isScrollableOverflow(EOverflow overflow)
{
return overflow == OSCROLL || overflow == OAUTO || overflow == OOVERLAY;
}
#endif
void StyleResolver::adjustStyleForInterCharacterRuby()
{
RenderStyle* style = m_state.style();
if (style->rubyPosition() != RubyPositionInterCharacter || !m_state.element() || !m_state.element()->hasTagName(rtTag))
return;
style->setTextAlign(CENTER);
if (style->isHorizontalWritingMode())
style->setWritingMode(LeftToRightWritingMode);
}
static bool hasEffectiveDisplayNoneForDisplayContents(const Element& element)
{
static NeverDestroyed<HashSet<AtomicString>> tagNames = [] {
static const HTMLQualifiedName* const tagList[] = {
&brTag.get(),
&wbrTag.get(),
&meterTag.get(),
&appletTag.get(),
&progressTag.get(),
&canvasTag.get(),
&embedTag.get(),
&objectTag.get(),
&audioTag.get(),
&iframeTag.get(),
&imgTag.get(),
&videoTag.get(),
&frameTag.get(),
&framesetTag.get(),
&inputTag.get(),
&textareaTag.get(),
&selectTag.get(),
};
HashSet<AtomicString> set;
for (auto& name : tagList)
set.add(name->localName());
return set;
}();
if (is<SVGElement>(element))
return true;
#if ENABLE(MATHML)
if (is<MathMLElement>(element))
return true;
#endif // ENABLE(MATHML)
if (!is<HTMLElement>(element))
return false;
return tagNames.get().contains(element.localName());
}
static void adjustDisplayContentsStyle(RenderStyle& style, const Element* element)
{
bool displayContentsEnabled = is<HTMLSlotElement>(element) || RuntimeEnabledFeatures::sharedFeatures().displayContentsEnabled();
if (!displayContentsEnabled) {
style.setDisplay(INLINE);
return;
}
if (!element) {
if (style.styleType() != BEFORE && style.styleType() != AFTER)
style.setDisplay(NONE);
return;
}
if (element->document().documentElement() == element) {
style.setDisplay(BLOCK);
return;
}
if (hasEffectiveDisplayNoneForDisplayContents(*element))
style.setDisplay(NONE);
}
void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element* element)
{
if (!parentBoxStyle)
parentBoxStyle = &parentStyle;
style.setOriginalDisplay(style.display());
if (style.display() == CONTENTS)
adjustDisplayContentsStyle(style, element);
if (style.display() != NONE && style.display() != CONTENTS) {
if (element) {
if (document().inQuirksMode()) {
if (element->hasTagName(tdTag)) {
style.setDisplay(TABLE_CELL);
style.setFloating(NoFloat);
} else if (is<HTMLTableElement>(*element))
style.setDisplay(style.isDisplayInlineType() ? INLINE_TABLE : TABLE);
}
if (element->hasTagName(tdTag) || element->hasTagName(thTag)) {
if (style.whiteSpace() == KHTML_NOWRAP) {
if (style.width().isFixed())
style.setWhiteSpace(NORMAL);
else
style.setWhiteSpace(NOWRAP);
}
}
if (is<HTMLTableElement>(*element) && (style.textAlign() == WEBKIT_LEFT || style.textAlign() == WEBKIT_CENTER || style.textAlign() == WEBKIT_RIGHT))
style.setTextAlign(TASTART);
if (element->hasTagName(frameTag) || element->hasTagName(framesetTag)) {
style.setPosition(StaticPosition);
style.setDisplay(BLOCK);
}
if (element->hasTagName(rtTag)) {
style.setPosition(StaticPosition);
style.setFloating(NoFloat);
}
if (element->hasTagName(thTag) && !style.hasExplicitlySetTextAlign() && parentStyle.textAlign() == RenderStyle::initialTextAlign())
style.setTextAlign(CENTER);
if (element->hasTagName(legendTag))
style.setDisplay(BLOCK);
}
if (style.hasOutOfFlowPosition() || style.isFloating() || (element && element->document().documentElement() == element))
style.setDisplay(equivalentBlockDisplay(style, document()));
if (style.display() == INLINE && style.styleType() == NOPSEUDO && style.writingMode() != parentStyle.writingMode())
style.setDisplay(INLINE_BLOCK);
if ((style.display() == TABLE_HEADER_GROUP || style.display() == TABLE_ROW_GROUP
|| style.display() == TABLE_FOOTER_GROUP || style.display() == TABLE_ROW)
&& style.position() == RelativePosition)
style.setPosition(StaticPosition);
if (style.display() == TABLE_COLUMN || style.display() == TABLE_COLUMN_GROUP || style.display() == TABLE_FOOTER_GROUP
|| style.display() == TABLE_HEADER_GROUP || style.display() == TABLE_ROW || style.display() == TABLE_ROW_GROUP
|| style.display() == TABLE_CELL)
style.setWritingMode(parentStyle.writingMode());
if (style.writingMode() != TopToBottomWritingMode && (style.display() == BOX || style.display() == INLINE_BOX))
style.setWritingMode(TopToBottomWritingMode);
if (parentBoxStyle->isDisplayFlexibleOrGridBox()) {
style.setFloating(NoFloat);
style.setDisplay(equivalentBlockDisplay(style, document()));
}
}
if (style.position() == StaticPosition && !parentBoxStyle->isDisplayFlexibleOrGridBox())
style.setHasAutoZIndex();
if (style.hasAutoZIndex()) {
if ((element && element->document().documentElement() == element)
|| style.opacity() < 1.0f
|| style.hasTransformRelatedProperty()
|| style.hasMask()
|| style.clipPath()
|| style.boxReflect()
|| style.hasFilter()
#if ENABLE(FILTERS_LEVEL_2)
|| style.hasBackdropFilter()
#endif
|| style.hasBlendMode()
|| style.hasIsolation()
|| style.position() == StickyPosition
|| style.position() == FixedPosition
|| style.willChangeCreatesStackingContext())
style.setZIndex(0);
}
if (element) {
if (is<HTMLTextAreaElement>(*element)) {
style.setOverflowX(style.overflowX() == OVISIBLE ? OAUTO : style.overflowX());
style.setOverflowY(style.overflowY() == OVISIBLE ? OAUTO : style.overflowY());
}
if (!element->shadowPseudoId().isNull())
style.setUserModify(READ_ONLY);
if (is<HTMLMarqueeElement>(*element)) {
style.setOverflowX(OHIDDEN);
style.setOverflowY(OHIDDEN);
bool isVertical = style.marqueeDirection() == MUP || style.marqueeDirection() == MDOWN;
if (!isVertical) {
style.setWhiteSpace(NOWRAP);
style.setTextAlign(TASTART);
}
if (isVertical && style.height().isAuto())
style.setHeight(Length(200, Fixed));
}
}
if (doesNotInheritTextDecoration(style, element))
style.setTextDecorationsInEffect(style.textDecoration());
else
style.addToTextDecorationsInEffect(style.textDecoration());
if (style.overflowX() == OVISIBLE && style.overflowY() != OVISIBLE) {
style.setOverflowX(OAUTO);
} else if (style.overflowY() == OVISIBLE && style.overflowX() != OVISIBLE)
style.setOverflowY(OAUTO);
if ((style.overflowY() == OPAGEDX || style.overflowY() == OPAGEDY) && !(element && (element->hasTagName(htmlTag) || element->hasTagName(bodyTag))))
style.setColumnStylesFromPaginationMode(WebCore::paginationModeForRenderStyle(style));
if (style.display() == TABLE || style.display() == INLINE_TABLE
|| style.display() == TABLE_ROW_GROUP || style.display() == TABLE_ROW) {
if (style.overflowX() != OVISIBLE && style.overflowX() != OHIDDEN)
style.setOverflowX(OVISIBLE);
if (style.overflowY() != OVISIBLE && style.overflowY() != OHIDDEN)
style.setOverflowY(OVISIBLE);
}
if (style.appearance() == MenulistPart) {
style.setOverflowX(OVISIBLE);
style.setOverflowY(OVISIBLE);
}
#if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
if (style.hasAutoZIndex() && style.useTouchOverflowScrolling() && (isScrollableOverflow(style.overflowX()) || isScrollableOverflow(style.overflowY())))
style.setZIndex(0);
#endif
style.adjustBackgroundLayers();
style.adjustMaskLayers();
style.adjustAnimations();
style.adjustTransitions();
if (is<HTMLFormControlElement>(element) && style.computedFontPixelSize() >= 11) {
if (!is<HTMLInputElement>(*element) || !downcast<HTMLInputElement>(*element).isImageButton())
addIntrinsicMargins(style);
}
if (style.hasAppearance())
RenderTheme::singleton().adjustStyle(*this, style, element, m_state.hasUAAppearance(), m_state.borderData(), m_state.backgroundData(), m_state.backgroundColor());
if (style.hasPseudoStyle(FIRST_LETTER))
style.setUnique();
if (style.preserves3D() && (style.overflowX() != OVISIBLE
|| style.overflowY() != OVISIBLE
|| style.hasClip()
|| style.clipPath()
|| style.hasFilter()
#if ENABLE(FILTERS_LEVEL_2)
|| style.hasBackdropFilter()
#endif
|| style.hasBlendMode()))
style.setTransformStyle3D(TransformStyle3DFlat);
if (is<SVGElement>(element)) {
if (!(element->hasTagName(SVGNames::svgTag) && element->parentNode() && !element->parentNode()->isSVGElement()))
style.setPosition(RenderStyle::initialPosition());
if (element->hasTagName(SVGNames::foreignObjectTag))
style.setEffectiveZoom(RenderStyle::initialZoom());
if ((element->hasTagName(SVGNames::foreignObjectTag) || element->hasTagName(SVGNames::textTag)) && style.isDisplayInlineType())
style.setDisplay(BLOCK);
}
if (style.justifyItems().position() == ItemPositionAuto) {
if (parentBoxStyle->justifyItems().positionType() == LegacyPosition)
style.setJustifyItems(parentBoxStyle->justifyItems());
}
}
static void checkForOrientationChange(RenderStyle* style)
{
FontOrientation fontOrientation;
NonCJKGlyphOrientation glyphOrientation;
std::tie(fontOrientation, glyphOrientation) = style->fontAndGlyphOrientation();
const auto& fontDescription = style->fontDescription();
if (fontDescription.orientation() == fontOrientation && fontDescription.nonCJKGlyphOrientation() == glyphOrientation)
return;
auto newFontDescription = fontDescription;
newFontDescription.setNonCJKGlyphOrientation(glyphOrientation);
newFontDescription.setOrientation(fontOrientation);
style->setFontDescription(newFontDescription);
}
void StyleResolver::updateFont()
{
if (!m_state.fontDirty())
return;
RenderStyle* style = m_state.style();
#if ENABLE(TEXT_AUTOSIZING)
checkForTextSizeAdjust(style);
#endif
checkForGenericFamilyChange(style, m_state.parentStyle());
checkForZoomChange(style, m_state.parentStyle());
checkForOrientationChange(style);
style->fontCascade().update(&document().fontSelector());
if (m_state.fontSizeHasViewportUnits())
style->setHasViewportUnits(true);
m_state.setFontDirty(false);
}
Vector<RefPtr<StyleRule>> StyleResolver::styleRulesForElement(const Element* element, unsigned rulesToInclude)
{
return pseudoStyleRulesForElement(element, NOPSEUDO, rulesToInclude);
}
Vector<RefPtr<StyleRule>> StyleResolver::pseudoStyleRulesForElement(const Element* element, PseudoId pseudoId, unsigned rulesToInclude)
{
if (!element)
return { };
m_state = State(*element, nullptr);
ElementRuleCollector collector(*element, m_ruleSets, m_state.selectorFilter());
collector.setMode(SelectorChecker::Mode::CollectingRules);
collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
collector.setMedium(&m_mediaQueryEvaluator);
if (rulesToInclude & UAAndUserCSSRules) {
collector.matchUARules();
if (m_matchAuthorAndUserStyles)
collector.matchUserRules(rulesToInclude & EmptyCSSRules);
}
if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules))
collector.matchAuthorRules(rulesToInclude & EmptyCSSRules);
return collector.matchedRuleList();
}
static bool shouldApplyPropertyInParseOrder(CSSPropertyID propertyID)
{
switch (propertyID) {
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyBackgroundClip:
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyBackgroundOrigin:
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyBackgroundSize:
case CSSPropertyWebkitBorderImage:
case CSSPropertyBorderImage:
case CSSPropertyBorderImageSlice:
case CSSPropertyBorderImageSource:
case CSSPropertyBorderImageOutset:
case CSSPropertyBorderImageRepeat:
case CSSPropertyBorderImageWidth:
case CSSPropertyWebkitBoxShadow:
case CSSPropertyBoxShadow:
case CSSPropertyWebkitTextDecoration:
case CSSPropertyWebkitTextDecorationLine:
case CSSPropertyWebkitTextDecorationStyle:
case CSSPropertyWebkitTextDecorationColor:
case CSSPropertyWebkitTextDecorationSkip:
case CSSPropertyWebkitTextUnderlinePosition:
case CSSPropertyTextDecoration:
return true;
default:
return false;
}
}
static bool elementTypeHasAppearanceFromUAStyle(const Element& element)
{
const auto& localName = element.localName();
return localName == HTMLNames::inputTag
|| localName == HTMLNames::textareaTag
|| localName == HTMLNames::buttonTag
|| localName == HTMLNames::progressTag
|| localName == HTMLNames::selectTag
|| localName == HTMLNames::meterTag;
}
unsigned StyleResolver::computeMatchedPropertiesHash(const MatchedProperties* properties, unsigned size)
{
return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size);
}
bool operator==(const StyleResolver::MatchRanges& a, const StyleResolver::MatchRanges& b)
{
return a.firstUARule == b.firstUARule
&& a.lastUARule == b.lastUARule
&& a.firstAuthorRule == b.firstAuthorRule
&& a.lastAuthorRule == b.lastAuthorRule
&& a.firstUserRule == b.firstUserRule
&& a.lastUserRule == b.lastUserRule;
}
bool operator!=(const StyleResolver::MatchRanges& a, const StyleResolver::MatchRanges& b)
{
return !(a == b);
}
bool operator==(const StyleResolver::MatchedProperties& a, const StyleResolver::MatchedProperties& b)
{
return a.properties == b.properties && a.linkMatchType == b.linkMatchType;
}
bool operator!=(const StyleResolver::MatchedProperties& a, const StyleResolver::MatchedProperties& b)
{
return !(a == b);
}
const StyleResolver::MatchedPropertiesCacheItem* StyleResolver::findFromMatchedPropertiesCache(unsigned hash, const MatchResult& matchResult)
{
ASSERT(hash);
MatchedPropertiesCache::iterator it = m_matchedPropertiesCache.find(hash);
if (it == m_matchedPropertiesCache.end())
return nullptr;
MatchedPropertiesCacheItem& cacheItem = it->value;
size_t size = matchResult.matchedProperties().size();
if (size != cacheItem.matchedProperties.size())
return nullptr;
for (size_t i = 0; i < size; ++i) {
if (matchResult.matchedProperties()[i] != cacheItem.matchedProperties[i])
return nullptr;
}
if (cacheItem.ranges != matchResult.ranges)
return nullptr;
return &cacheItem;
}
void StyleResolver::addToMatchedPropertiesCache(const RenderStyle* style, const RenderStyle* parentStyle, unsigned hash, const MatchResult& matchResult)
{
static const unsigned matchedDeclarationCacheAdditionsBetweenSweeps = 100;
if (++m_matchedPropertiesCacheAdditionsSinceLastSweep >= matchedDeclarationCacheAdditionsBetweenSweeps
&& !m_matchedPropertiesCacheSweepTimer.isActive()) {
static const Seconds matchedDeclarationCacheSweepTime { 1_min };
m_matchedPropertiesCacheSweepTimer.startOneShot(matchedDeclarationCacheSweepTime);
}
ASSERT(hash);
MatchedPropertiesCacheItem cacheItem;
cacheItem.matchedProperties.appendVector(matchResult.matchedProperties());
cacheItem.ranges = matchResult.ranges;
cacheItem.renderStyle = RenderStyle::clonePtr(*style);
cacheItem.parentRenderStyle = RenderStyle::clonePtr(*parentStyle);
m_matchedPropertiesCache.add(hash, WTFMove(cacheItem));
}
void StyleResolver::invalidateMatchedPropertiesCache()
{
m_matchedPropertiesCache.clear();
}
void StyleResolver::clearCachedPropertiesAffectedByViewportUnits()
{
Vector<unsigned, 16> toRemove;
for (auto& cacheKeyValue : m_matchedPropertiesCache) {
if (cacheKeyValue.value.renderStyle->hasViewportUnits())
toRemove.append(cacheKeyValue.key);
}
for (auto key : toRemove)
m_matchedPropertiesCache.remove(key);
}
static bool isCacheableInMatchedPropertiesCache(const Element& element, const RenderStyle* style, const RenderStyle* parentStyle)
{
if (&element == element.document().documentElement())
return false;
if (style->hasAttrContent() || (style->styleType() != NOPSEUDO && parentStyle->hasAttrContent()))
return false;
if (style->hasAppearance())
return false;
if (style->zoom() != RenderStyle::initialZoom())
return false;
if (style->writingMode() != RenderStyle::initialWritingMode() || style->direction() != RenderStyle::initialDirection())
return false;
if (style->hasExplicitlyInheritedProperties())
return false;
return true;
}
void extractDirectionAndWritingMode(const RenderStyle& style, const StyleResolver::MatchResult& matchResult, TextDirection& direction, WritingMode& writingMode)
{
direction = style.direction();
writingMode = style.writingMode();
bool hadImportantWritingMode = false;
bool hadImportantDirection = false;
for (const auto& matchedProperties : matchResult.matchedProperties()) {
for (unsigned i = 0, count = matchedProperties.properties->propertyCount(); i < count; ++i) {
auto property = matchedProperties.properties->propertyAt(i);
if (!property.value()->isPrimitiveValue())
continue;
switch (property.id()) {
case CSSPropertyWritingMode:
if (!hadImportantWritingMode || property.isImportant()) {
writingMode = downcast<CSSPrimitiveValue>(*property.value());
hadImportantWritingMode = property.isImportant();
}
break;
case CSSPropertyDirection:
if (!hadImportantDirection || property.isImportant()) {
direction = downcast<CSSPrimitiveValue>(*property.value());
hadImportantDirection = property.isImportant();
}
break;
default:
break;
}
}
}
}
void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element& element, ShouldUseMatchedPropertiesCache shouldUseMatchedPropertiesCache)
{
State& state = m_state;
unsigned cacheHash = shouldUseMatchedPropertiesCache && matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult.matchedProperties().data(), matchResult.matchedProperties().size()) : 0;
bool applyInheritedOnly = false;
const MatchedPropertiesCacheItem* cacheItem = nullptr;
if (cacheHash && (cacheItem = findFromMatchedPropertiesCache(cacheHash, matchResult))
&& isCacheableInMatchedPropertiesCache(element, state.style(), state.parentStyle())) {
state.style()->copyNonInheritedFrom(*cacheItem->renderStyle);
if (state.parentStyle()->inheritedDataShared(cacheItem->parentRenderStyle.get()) && !isAtShadowBoundary(element)) {
EInsideLink linkStatus = state.style()->insideLink();
state.style()->inheritFrom(*cacheItem->renderStyle);
state.style()->setInsideLink(linkStatus);
return;
}
applyInheritedOnly = true;
}
TextDirection direction;
WritingMode writingMode;
extractDirectionAndWritingMode(*state.style(), matchResult, direction, writingMode);
if (elementTypeHasAppearanceFromUAStyle(*state.element())) {
CascadedProperties cascade(direction, writingMode);
cascade.addNormalMatches(matchResult, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
cascade.addImportantMatches(matchResult, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
applyCascadedProperties(cascade, CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition, &matchResult);
adjustStyleForInterCharacterRuby();
applyCascadedProperties(cascade, CSSPropertyCustom, CSSPropertyCustom, &matchResult);
applyCascadedProperties(cascade, firstCSSProperty, lastHighPriorityProperty, &matchResult);
updateFont();
applyCascadedProperties(cascade, firstLowPriorityProperty, lastCSSProperty, &matchResult);
state.cacheBorderAndBackground();
}
CascadedProperties cascade(direction, writingMode);
cascade.addNormalMatches(matchResult, 0, matchResult.matchedProperties().size() - 1, applyInheritedOnly);
cascade.addImportantMatches(matchResult, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
cascade.addImportantMatches(matchResult, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
cascade.addImportantMatches(matchResult, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
applyCascadedProperties(cascade, CSSPropertyCustom, CSSPropertyCustom, &matchResult);
applyCascadedProperties(cascade, CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition, &matchResult);
adjustStyleForInterCharacterRuby();
applyCascadedProperties(cascade, firstCSSProperty, lastHighPriorityProperty, &matchResult);
if (cacheItem && cacheItem->renderStyle->effectiveZoom() != state.style()->effectiveZoom())
return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache);
updateFont();
if (cacheItem && cacheItem->renderStyle->fontDescription() != state.style()->fontDescription())
return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache);
applyCascadedProperties(cascade, firstLowPriorityProperty, lastCSSProperty, &matchResult);
cascade.applyDeferredProperties(*this, &matchResult);
ASSERT(!state.fontDirty());
if (cacheItem || !cacheHash)
return;
if (!isCacheableInMatchedPropertiesCache(*state.element(), state.style(), state.parentStyle()))
return;
addToMatchedPropertiesCache(state.style(), state.parentStyle(), cacheHash, matchResult);
}
void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, std::unique_ptr<RenderStyle> style)
{
m_state = State();
m_state.setParentStyle(RenderStyle::clonePtr(*style));
m_state.setStyle(WTFMove(style));
applyPropertyToCurrentStyle(id, value);
}
void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* value)
{
if (value)
applyProperty(id, value);
}
inline bool isValidVisitedLinkProperty(CSSPropertyID id)
{
switch (id) {
case CSSPropertyBackgroundColor:
case CSSPropertyBorderLeftColor:
case CSSPropertyBorderRightColor:
case CSSPropertyBorderTopColor:
case CSSPropertyBorderBottomColor:
case CSSPropertyCaretColor:
case CSSPropertyColor:
case CSSPropertyOutlineColor:
case CSSPropertyColumnRuleColor:
case CSSPropertyWebkitTextDecorationColor:
case CSSPropertyWebkitTextEmphasisColor:
case CSSPropertyWebkitTextFillColor:
case CSSPropertyWebkitTextStrokeColor:
case CSSPropertyFill:
case CSSPropertyStroke:
case CSSPropertyStrokeColor:
return true;
default:
break;
}
return false;
}
static inline bool isValidMarkerStyleProperty(CSSPropertyID id)
{
switch (id) {
case CSSPropertyColor:
case CSSPropertyFontFamily:
case CSSPropertyFontFeatureSettings:
case CSSPropertyFontSize:
case CSSPropertyFontStretch:
case CSSPropertyFontStyle:
case CSSPropertyFontSynthesis:
case CSSPropertyFontVariantAlternates:
case CSSPropertyFontVariantCaps:
case CSSPropertyFontVariantEastAsian:
case CSSPropertyFontVariantLigatures:
case CSSPropertyFontVariantNumeric:
case CSSPropertyFontVariantPosition:
case CSSPropertyFontWeight:
#if ENABLE(VARIATION_FONTS)
case CSSPropertyFontOpticalSizing:
case CSSPropertyFontVariationSettings:
#endif
return true;
default:
break;
}
return false;
}
#if ENABLE(VIDEO_TRACK)
static inline bool isValidCueStyleProperty(CSSPropertyID id)
{
switch (id) {
case CSSPropertyBackground:
case CSSPropertyBackgroundAttachment:
case CSSPropertyBackgroundClip:
case CSSPropertyBackgroundColor:
case CSSPropertyBackgroundImage:
case CSSPropertyBackgroundOrigin:
case CSSPropertyBackgroundPosition:
case CSSPropertyBackgroundPositionX:
case CSSPropertyBackgroundPositionY:
case CSSPropertyBackgroundRepeat:
case CSSPropertyBackgroundSize:
case CSSPropertyColor:
case CSSPropertyFont:
case CSSPropertyFontFamily:
case CSSPropertyFontSize:
case CSSPropertyFontStyle:
case CSSPropertyFontVariantCaps:
case CSSPropertyFontWeight:
case CSSPropertyLineHeight:
case CSSPropertyOpacity:
case CSSPropertyOutline:
case CSSPropertyOutlineColor:
case CSSPropertyOutlineOffset:
case CSSPropertyOutlineStyle:
case CSSPropertyOutlineWidth:
case CSSPropertyVisibility:
case CSSPropertyWhiteSpace:
case CSSPropertyTextDecoration:
case CSSPropertyTextShadow:
case CSSPropertyBorderStyle:
case CSSPropertyPaintOrder:
case CSSPropertyStrokeLinejoin:
case CSSPropertyStrokeLinecap:
case CSSPropertyStrokeColor:
case CSSPropertyStrokeWidth:
return true;
default:
break;
}
return false;
}
#endif
bool StyleResolver::useSVGZoomRules()
{
return m_state.element() && m_state.element()->isSVGElement();
}
bool StyleResolver::useSVGZoomRulesForLength()
{
return is<SVGElement>(m_state.element()) && !(is<SVGSVGElement>(*m_state.element()) && m_state.element()->parentNode());
}
StyleResolver::CascadedProperties* StyleResolver::cascadedPropertiesForRollback(const MatchResult& matchResult)
{
ASSERT(cascadeLevel() != UserAgentLevel);
TextDirection direction;
WritingMode writingMode;
extractDirectionAndWritingMode(*state().style(), matchResult, direction, writingMode);
if (cascadeLevel() == AuthorLevel) {
CascadedProperties* authorRollback = state().authorRollback();
if (authorRollback)
return authorRollback;
auto newAuthorRollback(std::make_unique<CascadedProperties>(direction, writingMode));
newAuthorRollback->addNormalMatches(matchResult, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, false);
newAuthorRollback->addNormalMatches(matchResult, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, false);
newAuthorRollback->addImportantMatches(matchResult, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, false);
newAuthorRollback->addImportantMatches(matchResult, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, false);
state().setAuthorRollback(newAuthorRollback);
return state().authorRollback();
}
if (cascadeLevel() == UserLevel) {
CascadedProperties* userRollback = state().userRollback();
if (userRollback)
return userRollback;
auto newUserRollback(std::make_unique<CascadedProperties>(direction, writingMode));
newUserRollback->addNormalMatches(matchResult, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, false);
newUserRollback->addImportantMatches(matchResult, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, false);
state().setUserRollback(newUserRollback);
return state().userRollback();
}
return nullptr;
}
void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value, SelectorChecker::LinkMatchMask linkMatchMask, const MatchResult* matchResult)
{
ASSERT_WITH_MESSAGE(!isShorthandCSSProperty(id), "Shorthand property id = %d wasn't expanded at parsing time", id);
State& state = m_state;
RefPtr<CSSValue> valueToApply = value;
if (value->hasVariableReferences()) {
valueToApply = resolvedVariableValue(id, *value);
if (!valueToApply) {
if (CSSProperty::isInheritedProperty(id))
valueToApply = CSSValuePool::singleton().createInheritedValue();
else
valueToApply = CSSValuePool::singleton().createExplicitInitialValue();
}
}
if (CSSProperty::isDirectionAwareProperty(id)) {
CSSPropertyID newId = CSSProperty::resolveDirectionAwareProperty(id, state.style()->direction(), state.style()->writingMode());
ASSERT(newId != id);
return applyProperty(newId, valueToApply.get(), linkMatchMask, matchResult);
}
CSSValue* valueToCheckForInheritInitial = valueToApply.get();
CSSCustomPropertyValue* customPropertyValue = nullptr;
CSSValueID customPropertyValueID = CSSValueInvalid;
if (id == CSSPropertyCustom) {
customPropertyValue = &downcast<CSSCustomPropertyValue>(*valueToApply);
customPropertyValueID = customPropertyValue->valueID();
}
bool isInherit = state.parentStyle() ? valueToCheckForInheritInitial->isInheritedValue() || customPropertyValueID == CSSValueInherit : false;
bool isInitial = valueToCheckForInheritInitial->isInitialValue() || customPropertyValueID == CSSValueInitial || (!state.parentStyle() && (valueToCheckForInheritInitial->isInheritedValue() || customPropertyValueID == CSSValueInherit));
bool isUnset = valueToCheckForInheritInitial->isUnsetValue() || customPropertyValueID == CSSValueUnset;
bool isRevert = valueToCheckForInheritInitial->isRevertValue() || customPropertyValueID == CSSValueRevert;
if (isRevert) {
if (cascadeLevel() == UserAgentLevel || !matchResult)
isUnset = true;
else {
auto* rollback = cascadedPropertiesForRollback(*matchResult);
ASSERT(rollback);
if (customPropertyValue) {
if (rollback->hasCustomProperty(customPropertyValue->name())) {
auto property = rollback->customProperty(customPropertyValue->name());
if (property.cssValue[linkMatchMask])
applyProperty(property.id, property.cssValue[linkMatchMask], linkMatchMask, matchResult);
return;
}
} else if (rollback->hasProperty(id)) {
auto& property = rollback->property(id);
if (property.cssValue[linkMatchMask])
applyProperty(property.id, property.cssValue[linkMatchMask], linkMatchMask, matchResult);
return;
}
isUnset = true;
}
}
if (isUnset) {
if (CSSProperty::isInheritedProperty(id))
isInherit = true;
else
isInitial = true;
}
ASSERT(!isInherit || !isInitial);
if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLinkStyle() || !isValidVisitedLinkProperty(id))) {
return;
}
if (isInherit && !CSSProperty::isInheritedProperty(id))
state.style()->setHasExplicitlyInheritedProperties();
if (customPropertyValue) {
auto& name = customPropertyValue->name();
auto* value = isInitial ? nullptr : isInherit ? state.parentStyle()->customProperties().get(name) : customPropertyValue;
state.style()->setCustomPropertyValue(name, value ? makeRef(*value) : CSSCustomPropertyValue::createInvalid());
return;
}
StyleBuilder::applyProperty(id, *this, *valueToApply, isInitial, isInherit);
}
RefPtr<CSSValue> StyleResolver::resolvedVariableValue(CSSPropertyID propID, const CSSValue& value)
{
CSSParser parser(document());
return parser.parseValueWithVariableReferences(propID, value, m_state.style()->customProperties(), m_state.style()->direction(), m_state.style()->writingMode());
}
RefPtr<StyleImage> StyleResolver::styleImage(CSSValue& value)
{
if (is<CSSImageGeneratorValue>(value)) {
if (is<CSSGradientValue>(value))
return StyleGeneratedImage::create(downcast<CSSGradientValue>(value).gradientWithStylesResolved(*this));
if (is<CSSFilterImageValue>(value)) {
downcast<CSSFilterImageValue>(value).createFilterOperations(this);
}
return StyleGeneratedImage::create(downcast<CSSImageGeneratorValue>(value));
}
if (is<CSSImageValue>(value) || is<CSSImageSetValue>(value) || is<CSSCursorImageValue>(value))
return StyleCachedImage::create(value);
return nullptr;
}
#if ENABLE(TEXT_AUTOSIZING)
void StyleResolver::checkForTextSizeAdjust(RenderStyle* style)
{
if (style->textSizeAdjust().isAuto())
return;
auto newFontDescription = style->fontDescription();
if (!style->textSizeAdjust().isNone())
newFontDescription.setComputedSize(newFontDescription.specifiedSize() * style->textSizeAdjust().multiplier());
else
newFontDescription.setComputedSize(newFontDescription.specifiedSize());
style->setFontDescription(newFontDescription);
}
#endif
void StyleResolver::checkForZoomChange(RenderStyle* style, const RenderStyle* parentStyle)
{
if (!parentStyle)
return;
if (style->effectiveZoom() == parentStyle->effectiveZoom() && style->textZoom() == parentStyle->textZoom())
return;
const auto& childFont = style->fontDescription();
auto newFontDescription = childFont;
setFontSize(newFontDescription, childFont.specifiedSize());
style->setFontDescription(newFontDescription);
}
void StyleResolver::checkForGenericFamilyChange(RenderStyle* style, const RenderStyle* parentStyle)
{
const auto& childFont = style->fontDescription();
if (childFont.isAbsoluteSize() || !parentStyle)
return;
const auto& parentFont = parentStyle->fontDescription();
if (childFont.useFixedDefaultSize() == parentFont.useFixedDefaultSize())
return;
float size;
if (CSSValueID sizeIdentifier = childFont.keywordSizeAsIdentifier())
size = Style::fontSizeForKeyword(sizeIdentifier, childFont.useFixedDefaultSize(), document());
else {
float fixedScaleFactor = (settings().defaultFixedFontSize() && settings().defaultFontSize())
? static_cast<float>(settings().defaultFixedFontSize()) / settings().defaultFontSize()
: 1;
size = parentFont.useFixedDefaultSize() ?
childFont.specifiedSize() / fixedScaleFactor :
childFont.specifiedSize() * fixedScaleFactor;
}
auto newFontDescription = childFont;
setFontSize(newFontDescription, size);
style->setFontDescription(newFontDescription);
}
void StyleResolver::initializeFontStyle()
{
FontCascadeDescription fontDescription;
fontDescription.setRenderingMode(settings().fontRenderingMode());
fontDescription.setOneFamily(standardFamily);
fontDescription.setKeywordSizeFromIdentifier(CSSValueMedium);
setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueMedium, false, document()));
fontDescription.setShouldAllowUserInstalledFonts(settings().shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No);
setFontDescription(fontDescription);
}
void StyleResolver::setFontSize(FontCascadeDescription& fontDescription, float size)
{
fontDescription.setSpecifiedSize(size);
fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), useSVGZoomRules(), m_state.style(), document()));
}
bool StyleResolver::colorFromPrimitiveValueIsDerivedFromElement(const CSSPrimitiveValue& value)
{
switch (value.valueID()) {
case CSSValueWebkitText:
case CSSValueWebkitLink:
case CSSValueWebkitActivelink:
case CSSValueCurrentcolor:
return true;
default:
return false;
}
}
Color StyleResolver::colorFromPrimitiveValue(const CSSPrimitiveValue& value, bool forVisitedLink) const
{
if (value.isRGBColor())
return value.color();
auto identifier = value.valueID();
switch (identifier) {
case CSSValueWebkitText:
return document().textColor();
case CSSValueWebkitLink:
return (m_state.element()->isLink() && forVisitedLink) ? document().visitedLinkColor() : document().linkColor();
case CSSValueWebkitActivelink:
return document().activeLinkColor();
case CSSValueWebkitFocusRingColor:
return RenderTheme::focusRingColor();
case CSSValueCurrentcolor:
m_state.style()->setHasExplicitlyInheritedProperties();
return m_state.style()->color();
default:
return StyleColor::colorFromKeyword(identifier);
}
}
void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExpression& expression, bool result)
{
m_viewportDependentMediaQueryResults.append(MediaQueryResult { expression, result });
}
bool StyleResolver::hasMediaQueriesAffectedByViewportChange() const
{
LOG(MediaQueries, "StyleResolver::hasMediaQueriesAffectedByViewportChange evaluating queries");
for (auto& result : m_viewportDependentMediaQueryResults) {
if (m_mediaQueryEvaluator.evaluate(result.expression) != result.result)
return true;
}
return false;
}
void StyleResolver::addAccessibilitySettingsDependentMediaQueryResult(const MediaQueryExpression& expression, bool result)
{
m_accessibilitySettingsDependentMediaQueryResults.append(MediaQueryResult { expression, result });
}
bool StyleResolver::hasMediaQueriesAffectedByAccessibilitySettingsChange() const
{
LOG(MediaQueries, "StyleResolver::hasMediaQueriesAffectedByAccessibilitySettingsChange evaluating queries");
for (auto& result : m_accessibilitySettingsDependentMediaQueryResults) {
if (m_mediaQueryEvaluator.evaluate(result.expression) != result.result)
return true;
}
return false;
}
static FilterOperation::OperationType filterOperationForType(CSSValueID type)
{
switch (type) {
case CSSValueUrl:
return FilterOperation::REFERENCE;
case CSSValueGrayscale:
return FilterOperation::GRAYSCALE;
case CSSValueSepia:
return FilterOperation::SEPIA;
case CSSValueSaturate:
return FilterOperation::SATURATE;
case CSSValueHueRotate:
return FilterOperation::HUE_ROTATE;
case CSSValueInvert:
return FilterOperation::INVERT;
case CSSValueOpacity:
return FilterOperation::OPACITY;
case CSSValueBrightness:
return FilterOperation::BRIGHTNESS;
case CSSValueContrast:
return FilterOperation::CONTRAST;
case CSSValueBlur:
return FilterOperation::BLUR;
case CSSValueDropShadow:
return FilterOperation::DROP_SHADOW;
default:
break;
}
ASSERT_NOT_REACHED();
return FilterOperation::NONE;
}
bool StyleResolver::createFilterOperations(const CSSValue& inValue, FilterOperations& outOperations)
{
State& state = m_state;
ASSERT(outOperations.isEmpty());
if (is<CSSPrimitiveValue>(inValue)) {
auto& primitiveValue = downcast<CSSPrimitiveValue>(inValue);
if (primitiveValue.valueID() == CSSValueNone)
return true;
}
if (!is<CSSValueList>(inValue))
return false;
FilterOperations operations;
for (auto& currentValue : downcast<CSSValueList>(inValue)) {
if (is<CSSPrimitiveValue>(currentValue)) {
auto& primitiveValue = downcast<CSSPrimitiveValue>(currentValue.get());
if (!primitiveValue.isURI())
continue;
String cssUrl = primitiveValue.stringValue();
URL url = document().completeURL(cssUrl);
RefPtr<ReferenceFilterOperation> operation = ReferenceFilterOperation::create(cssUrl, url.fragmentIdentifier());
operations.operations().append(operation);
continue;
}
if (!is<CSSFunctionValue>(currentValue))
continue;
auto& filterValue = downcast<CSSFunctionValue>(currentValue.get());
FilterOperation::OperationType operationType = filterOperationForType(filterValue.name());
const CSSPrimitiveValue* firstValue = nullptr;
if (operationType != FilterOperation::DROP_SHADOW) {
bool haveNonPrimitiveValue = false;
for (unsigned j = 0; j < filterValue.length(); ++j) {
if (!is<CSSPrimitiveValue>(*filterValue.itemWithoutBoundsCheck(j))) {
haveNonPrimitiveValue = true;
break;
}
}
if (haveNonPrimitiveValue)
continue;
if (filterValue.length())
firstValue = downcast<CSSPrimitiveValue>(filterValue.itemWithoutBoundsCheck(0));
}
switch (operationType) {
case FilterOperation::GRAYSCALE:
case FilterOperation::SEPIA:
case FilterOperation::SATURATE: {
double amount = 1;
if (filterValue.length() == 1) {
amount = firstValue->doubleValue();
if (firstValue->isPercentage())
amount /= 100;
}
operations.operations().append(BasicColorMatrixFilterOperation::create(amount, operationType));
break;
}
case FilterOperation::HUE_ROTATE: {
double angle = 0;
if (filterValue.length() == 1)
angle = firstValue->computeDegrees();
operations.operations().append(BasicColorMatrixFilterOperation::create(angle, operationType));
break;
}
case FilterOperation::INVERT:
case FilterOperation::BRIGHTNESS:
case FilterOperation::CONTRAST:
case FilterOperation::OPACITY: {
double amount = (operationType == FilterOperation::BRIGHTNESS) ? 0 : 1;
if (filterValue.length() == 1) {
amount = firstValue->doubleValue();
if (firstValue->isPercentage())
amount /= 100;
}
operations.operations().append(BasicComponentTransferFilterOperation::create(amount, operationType));
break;
}
case FilterOperation::BLUR: {
Length stdDeviation = Length(0, Fixed);
if (filterValue.length() >= 1)
stdDeviation = convertToFloatLength(firstValue, state.cssToLengthConversionData());
if (stdDeviation.isUndefined())
return false;
operations.operations().append(BlurFilterOperation::create(stdDeviation));
break;
}
case FilterOperation::DROP_SHADOW: {
if (filterValue.length() != 1)
return false;
const auto* cssValue = filterValue.itemWithoutBoundsCheck(0);
if (!is<CSSShadowValue>(cssValue))
continue;
const auto& item = downcast<CSSShadowValue>(*cssValue);
int x = item.x->computeLength<int>(state.cssToLengthConversionData());
int y = item.y->computeLength<int>(state.cssToLengthConversionData());
IntPoint location(x, y);
int blur = item.blur ? item.blur->computeLength<int>(state.cssToLengthConversionData()) : 0;
Color color;
if (item.color)
color = colorFromPrimitiveValue(*item.color);
operations.operations().append(DropShadowFilterOperation::create(location, blur, color.isValid() ? color : Color::transparent));
break;
}
default:
ASSERT_NOT_REACHED();
break;
}
}
outOperations = operations;
return true;
}
inline StyleResolver::MatchedProperties::MatchedProperties() = default;
StyleResolver::MatchedProperties::~MatchedProperties() = default;
StyleResolver::CascadedProperties::CascadedProperties(TextDirection direction, WritingMode writingMode)
: m_direction(direction)
, m_writingMode(writingMode)
{
}
inline bool StyleResolver::CascadedProperties::hasProperty(CSSPropertyID id) const
{
ASSERT(id < m_propertyIsPresent.size());
return m_propertyIsPresent[id];
}
inline StyleResolver::CascadedProperties::Property& StyleResolver::CascadedProperties::property(CSSPropertyID id)
{
return m_properties[id];
}
inline bool StyleResolver::CascadedProperties::hasCustomProperty(const String& name) const
{
return m_customProperties.contains(name);
}
inline StyleResolver::CascadedProperties::Property StyleResolver::CascadedProperties::customProperty(const String& name) const
{
return m_customProperties.get(name);
}
void StyleResolver::CascadedProperties::setPropertyInternal(Property& property, CSSPropertyID id, CSSValue& cssValue, unsigned linkMatchType, CascadeLevel cascadeLevel, Style::ScopeOrdinal styleScopeOrdinal)
{
ASSERT(linkMatchType <= SelectorChecker::MatchAll);
property.id = id;
property.level = cascadeLevel;
property.styleScopeOrdinal = styleScopeOrdinal;
if (linkMatchType == SelectorChecker::MatchAll) {
property.cssValue[0] = &cssValue;
property.cssValue[SelectorChecker::MatchLink] = &cssValue;
property.cssValue[SelectorChecker::MatchVisited] = &cssValue;
} else
property.cssValue[linkMatchType] = &cssValue;
}
void StyleResolver::CascadedProperties::set(CSSPropertyID id, CSSValue& cssValue, unsigned linkMatchType, CascadeLevel cascadeLevel, Style::ScopeOrdinal styleScopeOrdinal)
{
if (CSSProperty::isDirectionAwareProperty(id))
id = CSSProperty::resolveDirectionAwareProperty(id, m_direction, m_writingMode);
ASSERT(!shouldApplyPropertyInParseOrder(id));
auto& property = m_properties[id];
ASSERT(id < m_propertyIsPresent.size());
if (id == CSSPropertyCustom) {
m_propertyIsPresent.set(id);
const auto& customValue = downcast<CSSCustomPropertyValue>(cssValue);
bool hasValue = customProperties().contains(customValue.name());
if (!hasValue) {
Property property;
property.id = id;
memset(property.cssValue, 0, sizeof(property.cssValue));
setPropertyInternal(property, id, cssValue, linkMatchType, cascadeLevel, styleScopeOrdinal);
customProperties().set(customValue.name(), property);
} else {
Property property = customProperties().get(customValue.name());
setPropertyInternal(property, id, cssValue, linkMatchType, cascadeLevel, styleScopeOrdinal);
customProperties().set(customValue.name(), property);
}
return;
}
if (!m_propertyIsPresent[id])
memset(property.cssValue, 0, sizeof(property.cssValue));
m_propertyIsPresent.set(id);
setPropertyInternal(property, id, cssValue, linkMatchType, cascadeLevel, styleScopeOrdinal);
}
void StyleResolver::CascadedProperties::setDeferred(CSSPropertyID id, CSSValue& cssValue, unsigned linkMatchType, CascadeLevel cascadeLevel, Style::ScopeOrdinal styleScopeOrdinal)
{
ASSERT(!CSSProperty::isDirectionAwareProperty(id));
ASSERT(shouldApplyPropertyInParseOrder(id));
Property property;
memset(property.cssValue, 0, sizeof(property.cssValue));
setPropertyInternal(property, id, cssValue, linkMatchType, cascadeLevel, styleScopeOrdinal);
m_deferredProperties.append(property);
}
static CascadeLevel cascadeLevelForIndex(const StyleResolver::MatchResult& matchResult, int index)
{
if (index >= matchResult.ranges.firstUARule && index <= matchResult.ranges.lastUARule)
return UserAgentLevel;
if (index >= matchResult.ranges.firstUserRule && index <= matchResult.ranges.lastUserRule)
return UserLevel;
return AuthorLevel;
}
void StyleResolver::CascadedProperties::addMatch(const MatchResult& matchResult, unsigned index, bool isImportant, bool inheritedOnly)
{
auto& matchedProperties = matchResult.matchedProperties()[index];
auto& styleProperties = *matchedProperties.properties;
auto propertyWhitelistType = static_cast<PropertyWhitelistType>(matchedProperties.whitelistType);
auto cascadeLevel = cascadeLevelForIndex(matchResult, index);
for (unsigned i = 0, count = styleProperties.propertyCount(); i < count; ++i) {
auto current = styleProperties.propertyAt(i);
if (isImportant != current.isImportant())
continue;
if (inheritedOnly && !current.isInherited()) {
ASSERT(!current.value()->isInheritedValue());
continue;
}
CSSPropertyID propertyID = current.id();
#if ENABLE(VIDEO_TRACK)
if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStyleProperty(propertyID))
continue;
#endif
if (propertyWhitelistType == PropertyWhitelistMarker && !isValidMarkerStyleProperty(propertyID))
continue;
if (shouldApplyPropertyInParseOrder(propertyID))
setDeferred(propertyID, *current.value(), matchedProperties.linkMatchType, cascadeLevel, matchedProperties.styleScopeOrdinal);
else
set(propertyID, *current.value(), matchedProperties.linkMatchType, cascadeLevel, matchedProperties.styleScopeOrdinal);
}
}
void StyleResolver::CascadedProperties::addNormalMatches(const MatchResult& matchResult, int startIndex, int endIndex, bool inheritedOnly)
{
if (startIndex == -1)
return;
for (int i = startIndex; i <= endIndex; ++i)
addMatch(matchResult, i, false, inheritedOnly);
}
static bool hasImportantProperties(const StyleProperties& properties)
{
for (unsigned i = 0, count = properties.propertyCount(); i < count; ++i) {
if (properties.propertyAt(i).isImportant())
return true;
}
return false;
}
void StyleResolver::CascadedProperties::addImportantMatches(const MatchResult& matchResult, int startIndex, int endIndex, bool inheritedOnly)
{
if (startIndex == -1)
return;
struct IndexAndOrdinal {
int index;
Style::ScopeOrdinal ordinal;
};
Vector<IndexAndOrdinal> shadowTreeMatches;
for (int i = startIndex; i <= endIndex; ++i) {
const MatchedProperties& matchedProperties = matchResult.matchedProperties()[i];
if (!hasImportantProperties(*matchedProperties.properties))
continue;
if (matchedProperties.styleScopeOrdinal != Style::ScopeOrdinal::Element) {
shadowTreeMatches.append({ i, matchedProperties.styleScopeOrdinal });
continue;
}
addMatch(matchResult, i, true, inheritedOnly);
}
if (shadowTreeMatches.isEmpty())
return;
std::stable_sort(shadowTreeMatches.begin(), shadowTreeMatches.end(), [] (const IndexAndOrdinal& a, const IndexAndOrdinal& b) {
return a.ordinal < b.ordinal;
});
for (auto& match : shadowTreeMatches)
addMatch(matchResult, match.index, true, inheritedOnly);
}
void StyleResolver::CascadedProperties::applyDeferredProperties(StyleResolver& resolver, const MatchResult* matchResult)
{
for (auto& property : m_deferredProperties)
property.apply(resolver, matchResult);
}
void StyleResolver::CascadedProperties::Property::apply(StyleResolver& resolver, const MatchResult* matchResult)
{
State& state = resolver.state();
state.setCascadeLevel(level);
state.setStyleScopeOrdinal(styleScopeOrdinal);
if (cssValue[SelectorChecker::MatchDefault]) {
state.setApplyPropertyToRegularStyle(true);
state.setApplyPropertyToVisitedLinkStyle(false);
resolver.applyProperty(id, cssValue[SelectorChecker::MatchDefault], SelectorChecker::MatchDefault, matchResult);
}
if (state.style()->insideLink() == NotInsideLink)
return;
if (cssValue[SelectorChecker::MatchLink]) {
state.setApplyPropertyToRegularStyle(true);
state.setApplyPropertyToVisitedLinkStyle(false);
resolver.applyProperty(id, cssValue[SelectorChecker::MatchLink], SelectorChecker::MatchLink, matchResult);
}
if (cssValue[SelectorChecker::MatchVisited]) {
state.setApplyPropertyToRegularStyle(false);
state.setApplyPropertyToVisitedLinkStyle(true);
resolver.applyProperty(id, cssValue[SelectorChecker::MatchVisited], SelectorChecker::MatchVisited, matchResult);
}
state.setApplyPropertyToRegularStyle(true);
state.setApplyPropertyToVisitedLinkStyle(false);
}
void StyleResolver::applyCascadedProperties(CascadedProperties& cascade, int firstProperty, int lastProperty, const MatchResult* matchResult)
{
for (int id = firstProperty; id <= lastProperty; ++id) {
CSSPropertyID propertyID = static_cast<CSSPropertyID>(id);
if (!cascade.hasProperty(propertyID))
continue;
if (propertyID == CSSPropertyCustom) {
HashMap<AtomicString, CascadedProperties::Property>::iterator end = cascade.customProperties().end();
for (HashMap<AtomicString, CascadedProperties::Property>::iterator it = cascade.customProperties().begin(); it != end; ++it)
it->value.apply(*this, matchResult);
continue;
}
auto& property = cascade.property(propertyID);
ASSERT(!shouldApplyPropertyInParseOrder(propertyID));
property.apply(*this, matchResult);
}
if (firstProperty == CSSPropertyCustom)
m_state.style()->checkVariablesInCustomProperties();
}
}