Source/WebCore/ChangeLog

 12012-09-28 Dimitri Glazkov <dglazkov@chromium.org>
 2
 3 Kill transitive effects of SelectorChecker::checkOneSelector.
 4 https://bugs.webkit.org/show_bug.cgi?id=97953
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 The dynamicPseudo/hasUnknownPseudoelements by-ref parameters that are passed into checkOneSelector make the logic harder to understand and aren't needed. Refactor the code to rid of them, replacing them instead with two flags in SelectorCheckingContext.
 9
 10 No change in behavior, covered by existing tests.
 11
 12 * css/SelectorChecker.cpp:
 13 (WebCore::SelectorChecker::checkSelector): Rolled pseudo-element-checking code out of checkOneSelector into here, since that is where t
 14 (WebCore::SelectorChecker::checkOneSelector): Changed to use SelectorCheckingContext rather than transitive params.
 15 * css/SelectorChecker.h:
 16 (WebCore::SelectorChecker::SelectorCheckingContext::SelectorCheckingContext): Added two new flags.
 17 (SelectorCheckingContext): Ditto.
 18
 19
1202012-10-01 Arpita Bahuguna <arpitabahuguna@gmail.com>
221
322 RenderBlock incorrectly calculates pref width when a replaced object follows a RenderInline with width

Source/WebCore/css/SelectorChecker.cpp

@@bool SelectorChecker::checkSelector(CSSSelector* sel, Element* element, bool isF
266266 return fastCheckSelector(sel, element);
267267 }
268268
269  PseudoId dynamicPseudo = NOPSEUDO;
 269 PseudoId ignoreDynamicPseudo = NOPSEUDO;
270270 bool hasUnknownPseudoElements = false;
271  return checkSelector(SelectorCheckingContext(sel, element, SelectorChecker::VisitedMatchDisabled), dynamicPseudo, hasUnknownPseudoElements) == SelectorMatches;
 271 return checkSelector(SelectorCheckingContext(sel, element, SelectorChecker::VisitedMatchDisabled), ignoreDynamicPseudo, hasUnknownPseudoElements) == SelectorMatches;
272272}
273273
274274namespace {

@@bool SelectorChecker::isFastCheckableSelector(const CSSSelector* selector)
442442SelectorChecker::SelectorMatch SelectorChecker::checkSelector(const SelectorCheckingContext& context, PseudoId& dynamicPseudo, bool& hasUnknownPseudoElements) const
443443{
444444 // first selector has to match
445  if (!checkOneSelector(context, dynamicPseudo, hasUnknownPseudoElements))
 445 if (!checkOneSelector(context))
446446 return SelectorFailsLocally;
447447
 448 if (context.selector->m_match == CSSSelector::PseudoElement) {
 449 if (context.selector->isUnknownPseudoElement()) {
 450 hasUnknownPseudoElements = true;
 451 if (context.element->shadowPseudoId() != context.selector->value())
 452 return SelectorFailsLocally;
 453 } else {
 454 if ((!context.elementStyle && m_mode == ResolvingStyle) || m_mode == QueryingRules)
 455 return SelectorFailsLocally;
 456
 457 PseudoId pseudoId = CSSSelector::pseudoId(context.selector->pseudoType());
 458 if (pseudoId == FIRST_LETTER) {
 459 if (Document* document = context.element->document())
 460 document->styleSheetCollection()->setUsesFirstLetterRules(true);
 461 }
 462 if (pseudoId != NOPSEUDO)
 463 dynamicPseudo = pseudoId;
 464 }
 465 }
 466
448467 // The rest of the selectors has to match
449468 CSSSelector::Relation relation = context.selector->relation();
450469

@@SelectorChecker::SelectorMatch SelectorChecker::checkSelector(const SelectorChec
532551 // a selector is invalid if something follows a pseudo-element
533552 // We make an exception for scrollbar pseudo elements and allow a set of pseudo classes (but nothing else)
534553 // to follow the pseudo elements.
535  if ((context.elementStyle || m_mode == CollectingRules || m_mode == QueryingRules) && dynamicPseudo != NOPSEUDO && dynamicPseudo != SELECTION
536  && !((RenderScrollbar::scrollbarForStyleResolve() || dynamicPseudo == SCROLLBAR_CORNER || dynamicPseudo == RESIZER) && nextContext.selector->m_match == CSSSelector::PseudoClass))
 554 nextContext.hasScrollbarPseudo = RenderScrollbar::scrollbarForStyleResolve() || dynamicPseudo == SCROLLBAR_CORNER || dynamicPseudo == RESIZER;
 555 nextContext.hasSelectionPseudo = dynamicPseudo == SELECTION;
 556 if ((context.elementStyle || m_mode == CollectingRules || m_mode == QueryingRules) && dynamicPseudo != NOPSEUDO
 557 && !nextContext.hasSelectionPseudo
 558 && !(nextContext.hasScrollbarPseudo && nextContext.selector->m_match == CSSSelector::PseudoClass))
537559 return SelectorFailsCompletely;
538560 nextContext.isSubSelector = true;
539561 return checkSelector(nextContext, dynamicPseudo, hasUnknownPseudoElements);

@@static bool anyAttributeMatches(Element* element, CSSSelector::Match match, cons
704726 return false;
705727}
706728
707 bool SelectorChecker::checkOneSelector(const SelectorCheckingContext& context, PseudoId& dynamicPseudo, bool& hasUnknownPseudoElements) const
 729bool SelectorChecker::checkOneSelector(const SelectorCheckingContext& context) const
708730{
709731 Element* const & element = context.element;
710732 CSSSelector* const & selector = context.selector;

@@bool SelectorChecker::checkOneSelector(const SelectorCheckingContext& context, P
751773 // We select between :visited and :link when applying. We don't know which one applied (or not) yet.
752774 if (subContext.selector->pseudoType() == CSSSelector::PseudoVisited || (subContext.selector->pseudoType() == CSSSelector::PseudoLink && subContext.visitedMatchType == VisitedMatchEnabled))
753775 return true;
754  if (!checkOneSelector(subContext, dynamicPseudo, hasUnknownPseudoElements))
 776 if (!checkOneSelector(subContext))
755777 return true;
756778 }
757  } else if (dynamicPseudo != NOPSEUDO && (RenderScrollbar::scrollbarForStyleResolve() || dynamicPseudo == SCROLLBAR_CORNER || dynamicPseudo == RESIZER)) {
 779 } else if (context.hasScrollbarPseudo) {
758780 // CSS scrollbars match a specific subset of pseudo classes, and they have specialized rules for each
759781 // (since there are no elements involved).
760782 return checkScrollbarPseudoClass(selector);
761  } else if (dynamicPseudo == SELECTION) {
 783 } else if (context.hasSelectionPseudo) {
762784 if (selector->pseudoType() == CSSSelector::PseudoWindowInactive)
763785 return !m_document->page()->focusController()->isActive();
764786 }

@@bool SelectorChecker::checkOneSelector(const SelectorCheckingContext& context, P
10001022 {
10011023 SelectorCheckingContext subContext(context);
10021024 subContext.isSubSelector = true;
 1025 bool hasUnknownPseudoElements = false;
 1026 PseudoId ignoreDynamicPseudo = NOPSEUDO;
10031027 for (subContext.selector = selector->selectorList()->first(); subContext.selector; subContext.selector = CSSSelectorList::next(subContext.selector)) {
1004  if (checkSelector(subContext, dynamicPseudo, hasUnknownPseudoElements) == SelectorMatches)
 1028 if (checkSelector(subContext, ignoreDynamicPseudo, hasUnknownPseudoElements) == SelectorMatches)
10051029 return true;
10061030 }
10071031 }

@@bool SelectorChecker::checkOneSelector(const SelectorCheckingContext& context, P
11751199 }
11761200 return false;
11771201 }
1178  if (selector->m_match == CSSSelector::PseudoElement) {
1179  if (selector->isUnknownPseudoElement()) {
1180  hasUnknownPseudoElements = true;
1181  return element->shadowPseudoId() == selector->value();
1182  }
1183 
1184  if ((!context.elementStyle && m_mode == ResolvingStyle) || m_mode == QueryingRules)
1185  return false;
1186 
1187  PseudoId pseudoId = CSSSelector::pseudoId(selector->pseudoType());
1188  if (pseudoId == FIRST_LETTER) {
1189  if (Document* document = element->document())
1190  document->styleSheetCollection()->setUsesFirstLetterRules(true);
1191  }
1192  if (pseudoId != NOPSEUDO)
1193  dynamicPseudo = pseudoId;
1194  }
11951202 // ### add the rest of the checks...
11961203 return true;
11971204}

Source/WebCore/css/SelectorChecker.h

@@public:
6565 , elementParentStyle(0)
6666 , isSubSelector(false)
6767 , pseudoStyle(NOPSEUDO)
 68 , hasScrollbarPseudo(false)
 69 , hasSelectionPseudo(false)
6870 { }
6971
7072 CSSSelector* selector;

@@public:
7577 RenderStyle* elementParentStyle;
7678 bool isSubSelector;
7779 PseudoId pseudoStyle;
 80 bool hasScrollbarPseudo;
 81 bool hasSelectionPseudo;
7882 };
7983
8084 bool checkSelector(CSSSelector*, Element*, bool isFastCheckableSelector = false) const;

@@public:
117121 static bool elementMatchesSelectorScopes(const StyledElement*, const HashSet<AtomicStringImpl*>& idScopes, const HashSet<AtomicStringImpl*>& classScopes);
118122
119123private:
120  bool checkOneSelector(const SelectorCheckingContext&, PseudoId&, bool& hasUnknownPseudoElements) const;
 124 bool checkOneSelector(const SelectorCheckingContext&) const;
121125 bool checkScrollbarPseudoClass(CSSSelector*) const;
122126 static bool isFrameFocused(const Element*);
123127