Skip to content

Commit

Permalink
[Refactoring] Make m_selectorChecker in StyleResolver an on-stack obj…
Browse files Browse the repository at this point in the history
…ect.

https://bugs.webkit.org/show_bug.cgi?id=108595

Reviewed by Eric Seidel.

StyleResolver uses SelectorChecker's mode to change its resolving mode.
However it is a state of StyleResolver. StyleResolver should have the
mode and make SelectorChecker instance on a stack while required.

No new tests, just refactoring.

* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::fastCheckRightmostSelector):
(WebCore::SelectorChecker::fastCheck):
(WebCore::SelectorChecker::commonPseudoClassSelectorMatches):
(WebCore::SelectorChecker::matchesFocusPseudoClass):
Changed to static class function, because these methods never use
"this".
(WebCore):
* css/SelectorChecker.h:
(SelectorChecker):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::collectMatchingRules):
Now, matchesFocusPseudoClass is not a static method of
SelectorChecker, so replaced "m_selectorChecker." with
"SelectorChecker::".
(WebCore::StyleResolver::sortAndTransferMatchedRules):
(WebCore::StyleResolver::collectMatchingRulesForList):
(WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):
(WebCore::StyleResolver::matchUARules):
(WebCore::StyleResolver::adjustRenderStyle):
(WebCore::StyleResolver::pseudoStyleRulesForElement):
Use m_mode instead of m_selectorChecker.mode().
Also use document()->inQuirksMode() instead of
m_selectoChecker.strictParsing().
(WebCore::StyleResolver::ruleMatches):
(WebCore::StyleResolver::checkRegionSelector):
Created an on-stack SelectorChecker object and used it to check
selectors.
* css/StyleResolver.h:
(WebCore::StyleResolver::State::State):
Added m_mode, this keeps m_selectorChecker's mode.
(State):
(StyleResolver):
Removed m_selectorChecker.


Canonical link: https://commits.webkit.org/127830@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142591 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
tasak committed Feb 12, 2013
1 parent 3d338e2 commit 8712a4b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 35 deletions.
49 changes: 49 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,52 @@
2013-02-12 Takashi Sakamoto <tasak@google.com>

[Refactoring] Make m_selectorChecker in StyleResolver an on-stack object.
https://bugs.webkit.org/show_bug.cgi?id=108595

Reviewed by Eric Seidel.

StyleResolver uses SelectorChecker's mode to change its resolving mode.
However it is a state of StyleResolver. StyleResolver should have the
mode and make SelectorChecker instance on a stack while required.

No new tests, just refactoring.

* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::fastCheckRightmostSelector):
(WebCore::SelectorChecker::fastCheck):
(WebCore::SelectorChecker::commonPseudoClassSelectorMatches):
(WebCore::SelectorChecker::matchesFocusPseudoClass):
Changed to static class function, because these methods never use
"this".
(WebCore):
* css/SelectorChecker.h:
(SelectorChecker):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::collectMatchingRules):
Now, matchesFocusPseudoClass is not a static method of
SelectorChecker, so replaced "m_selectorChecker." with
"SelectorChecker::".
(WebCore::StyleResolver::sortAndTransferMatchedRules):
(WebCore::StyleResolver::collectMatchingRulesForList):
(WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):
(WebCore::StyleResolver::matchUARules):
(WebCore::StyleResolver::adjustRenderStyle):
(WebCore::StyleResolver::pseudoStyleRulesForElement):
Use m_mode instead of m_selectorChecker.mode().
Also use document()->inQuirksMode() instead of
m_selectoChecker.strictParsing().
(WebCore::StyleResolver::ruleMatches):
(WebCore::StyleResolver::checkRegionSelector):
Created an on-stack SelectorChecker object and used it to check
selectors.
* css/StyleResolver.h:
(WebCore::StyleResolver::State::State):
Added m_mode, this keeps m_selectorChecker's mode.
(State):
(StyleResolver):
Removed m_selectorChecker.

2013-02-11 Viatcheslav Ostapenko <sl.ostapenko@samsung.com>

[Qt][EFL][WebGL] Minor refactoring of GraphicsSurface/GraphicsSurfaceGLX
Expand Down
15 changes: 11 additions & 4 deletions Source/WebCore/css/SelectorChecker.cpp
Expand Up @@ -139,9 +139,9 @@ inline bool checkTagValue(const Element* element, const CSSSelector* selector)

}

inline bool SelectorChecker::fastCheckRightmostSelector(const CSSSelector* selector, const Element* element, VisitedMatchType visitedMatchType) const
bool SelectorChecker::fastCheckRightmostSelector(const CSSSelector* selector, const Element* element, SelectorChecker::VisitedMatchType visitedMatchType)
{
ASSERT(isFastCheckableSelector(selector));
ASSERT(SelectorChecker::isFastCheckableSelector(selector));

switch (selector->m_match) {
case CSSSelector::Tag:
Expand All @@ -161,7 +161,7 @@ inline bool SelectorChecker::fastCheckRightmostSelector(const CSSSelector* selec
return false;
}

bool SelectorChecker::fastCheck(const CSSSelector* selector, const Element* element) const
bool SelectorChecker::fastCheck(const CSSSelector* selector, const Element* element)
{
ASSERT(fastCheckRightmostSelector(selector, element, VisitedMatchEnabled));

Expand Down Expand Up @@ -999,7 +999,7 @@ bool SelectorChecker::checkScrollbarPseudoClass(Document* document, const CSSSel
}
}

bool SelectorChecker::commonPseudoClassSelectorMatches(const Element* element, const CSSSelector* selector, VisitedMatchType visitedMatchType) const
bool SelectorChecker::commonPseudoClassSelectorMatches(const Element* element, const CSSSelector* selector, VisitedMatchType visitedMatchType)
{
ASSERT(isCommonPseudoClassSelector(selector));
switch (selector->pseudoType()) {
Expand Down Expand Up @@ -1066,6 +1066,13 @@ bool SelectorChecker::isFrameFocused(const Element* element)
return element->document()->frame() && element->document()->frame()->selection()->isFocusedAndActive();
}

bool SelectorChecker::matchesFocusPseudoClass(const Element* element)
{
if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(element), CSSSelector::PseudoFocus))
return true;
return element->focused() && isFrameFocused(element);
}

template
SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, PseudoId&, const DOMSiblingTraversalStrategy&) const;

Expand Down
16 changes: 5 additions & 11 deletions Source/WebCore/css/SelectorChecker.h
Expand Up @@ -82,7 +82,7 @@ class SelectorChecker {
bool checkOne(const SelectorCheckingContext&, const SiblingTraversalStrategy&) const;

static bool isFastCheckableSelector(const CSSSelector*);
bool fastCheck(const CSSSelector*, const Element*) const;
static bool fastCheck(const CSSSelector*, const Element*);

bool strictParsing() const { return m_strictParsing; }

Expand All @@ -91,7 +91,7 @@ class SelectorChecker {

static bool tagMatches(const Element*, const QualifiedName&);
static bool isCommonPseudoClassSelector(const CSSSelector*);
bool matchesFocusPseudoClass(const Element*) const;
static bool matchesFocusPseudoClass(const Element*);
static bool fastCheckRightmostAttributeSelector(const Element*, const CSSSelector*);
static bool checkExactAttribute(const Element*, const QualifiedName& selectorAttributeName, const AtomicStringImpl* value);

Expand All @@ -100,10 +100,11 @@ class SelectorChecker {

private:
bool checkScrollbarPseudoClass(Document*, const CSSSelector*) const;

static bool isFrameFocused(const Element*);

bool fastCheckRightmostSelector(const CSSSelector*, const Element*, VisitedMatchType) const;
bool commonPseudoClassSelectorMatches(const Element*, const CSSSelector*, VisitedMatchType) const;
static bool fastCheckRightmostSelector(const CSSSelector*, const Element*, VisitedMatchType);
static bool commonPseudoClassSelectorMatches(const Element*, const CSSSelector*, VisitedMatchType);

bool m_strictParsing;
bool m_documentIsHTML;
Expand All @@ -121,13 +122,6 @@ inline bool SelectorChecker::isCommonPseudoClassSelector(const CSSSelector* sele
|| pseudoType == CSSSelector::PseudoFocus;
}

inline bool SelectorChecker::matchesFocusPseudoClass(const Element* element) const
{
if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(element), CSSSelector::PseudoFocus))
return true;
return element->focused() && isFrameFocused(element);
}

inline bool SelectorChecker::tagMatches(const Element* element, const QualifiedName& tagQName)
{
if (tagQName == anyQName())
Expand Down
32 changes: 17 additions & 15 deletions Source/WebCore/css/StyleResolver.cpp
Expand Up @@ -228,7 +228,6 @@ StyleResolver::StyleResolver(Document* document, bool matchAuthorAndUserStyles)
: m_matchedPropertiesCacheAdditionsSinceLastSweep(0)
, m_matchedPropertiesCacheSweepTimer(this, &StyleResolver::sweepMatchedPropertiesCache)
, m_document(document)
, m_selectorChecker(document)
, m_matchAuthorAndUserStyles(matchAuthorAndUserStyles)
, m_fontSelector(CSSFontSelector::create(document))
#if ENABLE(CSS_DEVICE_ADAPTATION)
Expand Down Expand Up @@ -458,7 +457,7 @@ void StyleResolver::collectMatchingRules(const MatchRequest& matchRequest, RuleR

if (element->isLink())
collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, ruleRange);
if (m_selectorChecker.matchesFocusPseudoClass(element))
if (SelectorChecker::matchesFocusPseudoClass(element))
collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, ruleRange);
collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element->localName().impl()), matchRequest, ruleRange);
collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), matchRequest, ruleRange);
Expand Down Expand Up @@ -488,7 +487,7 @@ void StyleResolver::sortAndTransferMatchedRules(MatchResult& result)

sortMatchedRules();

if (m_selectorChecker.mode() == SelectorChecker::CollectingRules) {
if (state.mode == SelectorChecker::CollectingRules) {
if (!state.ruleList)
state.ruleList = StaticCSSRuleList::create();
for (unsigned i = 0; i < state.matchedRules.size(); ++i)
Expand Down Expand Up @@ -655,7 +654,7 @@ void StyleResolver::collectMatchingRulesForList(const Vector<RuleData>* rules, c
// If we're matching normal rules, set a pseudo bit if
// we really just matched a pseudo-element.
if (state.dynamicPseudo != NOPSEUDO && state.pseudoStyle == NOPSEUDO) {
if (m_selectorChecker.mode() == SelectorChecker::CollectingRules) {
if (state.mode == SelectorChecker::CollectingRules) {
InspectorInstrumentation::didMatchRule(cookie, false);
continue;
}
Expand Down Expand Up @@ -851,11 +850,11 @@ bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet)
return false;
m_state.matchedRules.clear();

m_selectorChecker.setMode(SelectorChecker::SharingRules);
m_state.mode = SelectorChecker::SharingRules;
int firstRuleIndex = -1, lastRuleIndex = -1;
RuleRange ruleRange(firstRuleIndex, lastRuleIndex);
collectMatchingRules(MatchRequest(ruleSet), ruleRange);
m_selectorChecker.setMode(SelectorChecker::ResolvingStyle);
m_state.mode = SelectorChecker::ResolvingStyle;
if (m_state.matchedRules.isEmpty())
return false;
m_state.matchedRules.clear();
Expand Down Expand Up @@ -1137,7 +1136,7 @@ void StyleResolver::matchUARules(MatchResult& result)
matchUARules(result, userAgentStyleSheet);

// In quirks mode, we match rules from the quirks user agent sheet.
if (!m_selectorChecker.strictParsing())
if (document()->inQuirksMode())
matchUARules(result, CSSDefaultStyleSheets::defaultQuirksStyle);

// If document uses view source styles (in view source mode or in xml viewer mode), then we match rules from the view source style sheet.
Expand Down Expand Up @@ -1729,7 +1728,7 @@ void StyleResolver::adjustRenderStyle(RenderStyle* style, RenderStyle* parentSty
// property.
// Sites also commonly use display:inline/block on <td>s and <table>s. In quirks mode we force
// these tags to retain their display types.
if (!m_selectorChecker.strictParsing() && e) {
if (document()->inQuirksMode() && e) {
if (e->hasTagName(tdTag)) {
style->setDisplay(TABLE_CELL);
style->setFloating(NoFloat);
Expand Down Expand Up @@ -1776,7 +1775,7 @@ void StyleResolver::adjustRenderStyle(RenderStyle* style, RenderStyle* parentSty

// Absolute/fixed positioned elements, floating elements and the document element need block-like outside display.
if (style->hasOutOfFlowPosition() || style->isFloating() || (e && e->document()->documentElement() == e))
style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), m_selectorChecker.strictParsing()));
style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), !document()->inQuirksMode()));

// FIXME: Don't support this mutation for pseudo styles like first-letter or first-line, since it's not completely
// clear how that should work.
Expand Down Expand Up @@ -1806,7 +1805,7 @@ void StyleResolver::adjustRenderStyle(RenderStyle* style, RenderStyle* parentSty

if (isDisplayFlexibleBox(parentStyle->display())) {
style->setFloating(NoFloat);
style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), m_selectorChecker.strictParsing()));
style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), !document()->inQuirksMode()));
}

#if ENABLE(DIALOG_ELEMENT)
Expand Down Expand Up @@ -2025,7 +2024,7 @@ PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps
if (!e || !e->document()->haveStylesheetsLoaded())
return 0;

m_selectorChecker.setMode(SelectorChecker::CollectingRules);
m_state.mode = SelectorChecker::CollectingRules;

initElement(e);
initForStyleResolve(e, 0, pseudoId);
Expand All @@ -2049,7 +2048,7 @@ PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps
m_state.sameOriginOnly = false;
}

m_selectorChecker.setMode(SelectorChecker::ResolvingStyle);
m_state.mode = SelectorChecker::ResolvingStyle;

return m_state.ruleList.release();
}
Expand All @@ -2074,15 +2073,17 @@ inline bool StyleResolver::ruleMatches(const RuleData& ruleData, const Container
if (!SelectorChecker::fastCheckRightmostAttributeSelector(state.element, ruleData.selector()))
return false;

return m_selectorChecker.fastCheck(ruleData.selector(), state.element);
return SelectorChecker::fastCheck(ruleData.selector(), state.element);
}

// Slow path.
SelectorChecker selectorChecker(document());
selectorChecker.setMode(state.mode);
SelectorChecker::SelectorCheckingContext context(ruleData.selector(), state.element, SelectorChecker::VisitedMatchEnabled);
context.elementStyle = state.style.get();
context.scope = scope;
context.pseudoStyle = state.pseudoStyle;
SelectorChecker::Match match = m_selectorChecker.match(context, state.dynamicPseudo, DOMSiblingTraversalStrategy());
SelectorChecker::Match match = selectorChecker.match(context, state.dynamicPseudo, DOMSiblingTraversalStrategy());
if (match != SelectorChecker::SelectorMatches)
return false;
if (state.pseudoStyle != NOPSEUDO && state.pseudoStyle != state.dynamicPseudo)
Expand All @@ -2097,8 +2098,9 @@ bool StyleResolver::checkRegionSelector(const CSSSelector* regionSelector, Eleme

m_state.pseudoStyle = NOPSEUDO;

SelectorChecker selectorChecker(document());
for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s))
if (m_selectorChecker.matches(s, regionElement))
if (selectorChecker.matches(s, regionElement))
return true;

return false;
Expand Down
8 changes: 3 additions & 5 deletions Source/WebCore/css/StyleResolver.h
Expand Up @@ -443,6 +443,7 @@ class StyleResolver {
, elementLinkState(NotInsideLink)
, distributedToInsertionPoint(false)
, elementAffectedByClassRules(false)
, mode(SelectorChecker::ResolvingStyle)
, applyPropertyToRegularStyle(true)
, applyPropertyToVisitedLinkStyle(false)
#if ENABLE(CSS_SHADERS)
Expand Down Expand Up @@ -476,6 +477,8 @@ class StyleResolver {

PseudoId dynamicPseudo;

SelectorChecker::Mode mode;

// A buffer used to hold the set of matched rules for an element,
// and a temporary buffer used for merge sorting.
Vector<const RuleData*, 32> matchedRules;
Expand Down Expand Up @@ -567,11 +570,6 @@ class StyleResolver {
RefPtr<RenderStyle> m_rootDefaultStyle;

Document* m_document;
// FIXME: Make SelectorChecker an on-stack object and
// move selectorChecker.mode() to State.
// selectorChecker.stringParsing() can be replaced with
// !document.inQuirksMode().
SelectorChecker m_selectorChecker;
SelectorFilter m_selectorFilter;

bool m_matchAuthorAndUserStyles;
Expand Down

0 comments on commit 8712a4b

Please sign in to comment.