Move :placeholder-shown out of experimental
[WebKit-https.git] / Source / WebCore / css / SelectorChecker.cpp
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4  * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5  * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Apple Inc. All rights reserved.
6  * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7  * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
9  * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
11  * Copyright (C) 2014 Yusuke Suzuki <utatane.tea@gmail.com>
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Library General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Library General Public License for more details.
22  *
23  * You should have received a copy of the GNU Library General Public License
24  * along with this library; see the file COPYING.LIB.  If not, write to
25  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26  * Boston, MA 02110-1301, USA.
27  */
28
29 #include "config.h"
30 #include "SelectorChecker.h"
31
32 #include "CSSSelector.h"
33 #include "CSSSelectorList.h"
34 #include "Document.h"
35 #include "ElementTraversal.h"
36 #include "Frame.h"
37 #include "FrameSelection.h"
38 #include "HTMLAnchorElement.h"
39 #include "HTMLDocument.h"
40 #include "HTMLFrameElementBase.h"
41 #include "HTMLInputElement.h"
42 #include "HTMLNames.h"
43 #include "HTMLOptGroupElement.h"
44 #include "HTMLOptionElement.h"
45 #include "HTMLParserIdioms.h"
46 #include "HTMLProgressElement.h"
47 #include "HTMLStyleElement.h"
48 #include "InsertionPoint.h"
49 #include "InspectorInstrumentation.h"
50 #include "NodeRenderStyle.h"
51 #include "Page.h"
52 #include "RenderElement.h"
53 #include "RenderStyle.h"
54 #include "SelectorCheckerTestFunctions.h"
55 #include "ShadowRoot.h"
56 #include "StyledElement.h"
57 #include "Text.h"
58
59 namespace WebCore {
60
61 using namespace HTMLNames;
62
63 enum class VisitedMatchType : unsigned char {
64     Disabled, Enabled
65 };
66
67 struct SelectorChecker::CheckingContextWithStatus : public SelectorChecker::CheckingContext {
68     CheckingContextWithStatus(const SelectorChecker::CheckingContext& checkingContext, const CSSSelector* selector, Element* element)
69         : SelectorChecker::CheckingContext(checkingContext)
70         , selector(selector)
71         , element(element)
72         , visitedMatchType(resolvingMode == SelectorChecker::Mode::QueryingRules ? VisitedMatchType::Disabled : VisitedMatchType::Enabled)
73         , firstSelectorOfTheFragment(selector)
74         , inFunctionalPseudoClass(false)
75         , pseudoElementEffective(true)
76         , hasScrollbarPseudo(false)
77         , hasSelectionPseudo(false)
78     { }
79
80     const CSSSelector* selector;
81     Element* element;
82     VisitedMatchType visitedMatchType;
83     const CSSSelector* firstSelectorOfTheFragment;
84     bool inFunctionalPseudoClass;
85     bool pseudoElementEffective;
86     bool hasScrollbarPseudo;
87     bool hasSelectionPseudo;
88 };
89
90 static inline bool isFirstChildElement(const Element* element)
91 {
92     return !ElementTraversal::previousSibling(element);
93 }
94
95 static inline bool isLastChildElement(const Element* element)
96 {
97     return !ElementTraversal::nextSibling(element);
98 }
99
100 static inline bool isFirstOfType(Element* element, const QualifiedName& type, bool isResolvingStyle)
101 {
102     for (Element* sibling = ElementTraversal::previousSibling(element); sibling; sibling = ElementTraversal::previousSibling(sibling)) {
103         if (isResolvingStyle)
104             sibling->setAffectsNextSiblingElementStyle();
105         if (sibling->hasTagName(type))
106             return false;
107     }
108     return true;
109 }
110
111 static inline bool isLastOfType(const Element* element, const QualifiedName& type)
112 {
113     for (const Element* sibling = ElementTraversal::nextSibling(element); sibling; sibling = ElementTraversal::nextSibling(sibling)) {
114         if (sibling->hasTagName(type))
115             return false;
116     }
117     return true;
118 }
119
120 static inline int countElementsBefore(Element* element, bool isResolvingStyle)
121 {
122     int count = 0;
123     for (Element* sibling = ElementTraversal::previousSibling(element); sibling; sibling = ElementTraversal::previousSibling(sibling)) {
124         if (isResolvingStyle)
125             sibling->setAffectsNextSiblingElementStyle();
126
127         unsigned index = sibling->childIndex();
128         if (index) {
129             count += index;
130             break;
131         }
132         count++;
133     }
134     return count;
135 }
136
137 static inline int countElementsOfTypeBefore(Element* element, const QualifiedName& type, bool isResolvingStyle)
138 {
139     int count = 0;
140     for (Element* sibling = ElementTraversal::previousSibling(element); sibling; sibling = ElementTraversal::previousSibling(sibling)) {
141         if (isResolvingStyle)
142             sibling->setAffectsNextSiblingElementStyle();
143
144         if (sibling->hasTagName(type))
145             ++count;
146     }
147     return count;
148 }
149
150 static inline int countElementsAfter(const Element* element)
151 {
152     int count = 0;
153     for (const Element* sibling = ElementTraversal::nextSibling(element); sibling; sibling = ElementTraversal::nextSibling(sibling))
154         ++count;
155     return count;
156 }
157
158 static inline int countElementsOfTypeAfter(const Element* element, const QualifiedName& type)
159 {
160     int count = 0;
161     for (const Element* sibling = ElementTraversal::nextSibling(element); sibling; sibling = ElementTraversal::nextSibling(sibling)) {
162         if (sibling->hasTagName(type))
163             ++count;
164     }
165     return count;
166 }
167
168 SelectorChecker::SelectorChecker(Document& document)
169     : m_strictParsing(!document.inQuirksMode())
170     , m_documentIsHTML(document.isHTMLDocument())
171 {
172 }
173
174 bool SelectorChecker::match(const CSSSelector* selector, Element* element, const CheckingContext& providedContext, unsigned& specificity) const
175 {
176     specificity = 0;
177
178     CheckingContextWithStatus context(providedContext, selector, element);
179     PseudoIdSet pseudoIdSet;
180     MatchResult result = matchRecursively(context, pseudoIdSet, specificity);
181     if (result.match != Match::SelectorMatches)
182         return false;
183     if (context.pseudoId != NOPSEUDO && !pseudoIdSet.has(context.pseudoId))
184         return false;
185
186     if (context.pseudoId == NOPSEUDO && pseudoIdSet) {
187         PseudoIdSet publicPseudoIdSet = pseudoIdSet & PseudoIdSet::fromMask(PUBLIC_PSEUDOID_MASK);
188         if (context.resolvingMode == Mode::ResolvingStyle && publicPseudoIdSet)
189             context.elementStyle->setHasPseudoStyles(publicPseudoIdSet);
190
191         // When ignoring virtual pseudo elements, the context's pseudo should also be NOPSEUDO but that does
192         // not cause a failure.
193         return context.resolvingMode == Mode::CollectingRulesIgnoringVirtualPseudoElements || result.matchType == MatchType::Element;
194     }
195     return true;
196 }
197
198 inline static bool hasScrollbarPseudoElement(const PseudoIdSet& dynamicPseudoIdSet)
199 {
200     PseudoIdSet scrollbarIdSet = { SCROLLBAR, SCROLLBAR_THUMB, SCROLLBAR_BUTTON, SCROLLBAR_TRACK, SCROLLBAR_TRACK_PIECE, SCROLLBAR_CORNER };
201     if (dynamicPseudoIdSet & scrollbarIdSet)
202         return true;
203
204     // RESIZER does not always have a scrollbar but it is a scrollbar-like pseudo element
205     // because it can have more than one pseudo element.
206     return dynamicPseudoIdSet.has(RESIZER);
207 }
208
209 static SelectorChecker::CheckingContextWithStatus checkingContextForParent(const SelectorChecker::CheckingContextWithStatus& context)
210 {
211     SelectorChecker::CheckingContextWithStatus updatedContext(context);
212     // Disable :visited matching when we see the first link.
213     if (context.element->isLink())
214         updatedContext.visitedMatchType = VisitedMatchType::Disabled;
215     updatedContext.element = context.element->parentElement();
216     return updatedContext;
217 }
218
219 // Recursive check of selectors and combinators
220 // It can return 4 different values:
221 // * SelectorMatches          - the selector matches the element e
222 // * SelectorFailsLocally     - the selector fails for the element e
223 // * SelectorFailsAllSiblings - the selector fails for e and any sibling of e
224 // * SelectorFailsCompletely  - the selector fails for e and any sibling or ancestor of e
225 SelectorChecker::MatchResult SelectorChecker::matchRecursively(const CheckingContextWithStatus& context, PseudoIdSet& dynamicPseudoIdSet, unsigned& specificity) const
226 {
227     MatchType matchType = MatchType::Element;
228
229     // The first selector has to match.
230     if (!checkOne(context, dynamicPseudoIdSet, matchType, specificity))
231         return MatchResult::fails(Match::SelectorFailsLocally);
232
233     if (context.selector->match() == CSSSelector::PseudoElement) {
234         if (context.selector->isCustomPseudoElement()) {
235             // In functional pseudo class, custom pseudo elements are always disabled.
236             // FIXME: We should accept custom pseudo elements inside :matches().
237             if (context.inFunctionalPseudoClass)
238                 return MatchResult::fails(Match::SelectorFailsCompletely);
239             if (ShadowRoot* root = context.element->containingShadowRoot()) {
240                 if (context.element->shadowPseudoId() != context.selector->value())
241                     return MatchResult::fails(Match::SelectorFailsLocally);
242
243                 if (context.selector->pseudoElementType() == CSSSelector::PseudoElementWebKitCustom && root->type() != ShadowRoot::UserAgentShadowRoot)
244                     return MatchResult::fails(Match::SelectorFailsLocally);
245             } else
246                 return MatchResult::fails(Match::SelectorFailsLocally);
247         } else {
248             if (!context.pseudoElementEffective)
249                 return MatchResult::fails(Match::SelectorFailsCompletely);
250
251             if (context.resolvingMode == Mode::QueryingRules)
252                 return MatchResult::fails(Match::SelectorFailsCompletely);
253
254             PseudoId pseudoId = CSSSelector::pseudoId(context.selector->pseudoElementType());
255             if (pseudoId != NOPSEUDO)
256                 dynamicPseudoIdSet.add(pseudoId);
257             matchType = MatchType::VirtualPseudoElementOnly;
258         }
259     }
260
261     // The rest of the selectors has to match
262     CSSSelector::Relation relation = context.selector->relation();
263
264     // Prepare next selector
265     const CSSSelector* historySelector = context.selector->tagHistory();
266     if (!historySelector)
267         return MatchResult::matches(matchType);
268
269     CheckingContextWithStatus nextContext(context);
270     nextContext.selector = historySelector;
271
272     if (relation != CSSSelector::SubSelector) {
273         // Bail-out if this selector is irrelevant for the pseudoId
274         if (context.pseudoId != NOPSEUDO && !dynamicPseudoIdSet.has(context.pseudoId))
275             return MatchResult::fails(Match::SelectorFailsCompletely);
276
277         // Disable :visited matching when we try to match anything else than an ancestors.
278         if (relation != CSSSelector::Descendant && relation != CSSSelector::Child)
279             nextContext.visitedMatchType = VisitedMatchType::Disabled;
280
281         nextContext.pseudoId = NOPSEUDO;
282         // Virtual pseudo element is only effective in the rightmost fragment.
283         nextContext.pseudoElementEffective = false;
284     }
285
286     switch (relation) {
287     case CSSSelector::Descendant:
288         nextContext = checkingContextForParent(nextContext);
289         nextContext.firstSelectorOfTheFragment = nextContext.selector;
290         nextContext.elementStyle = nullptr;
291         for (; nextContext.element; nextContext = checkingContextForParent(nextContext)) {
292             PseudoIdSet ignoreDynamicPseudo;
293             unsigned descendantsSpecificity = 0;
294             MatchResult result = matchRecursively(nextContext, ignoreDynamicPseudo, descendantsSpecificity);
295             ASSERT(!nextContext.pseudoElementEffective && !ignoreDynamicPseudo);
296
297             if (result.match == Match::SelectorMatches)
298                 specificity = CSSSelector::addSpecificities(specificity, descendantsSpecificity);
299
300             if (result.match == Match::SelectorMatches || result.match == Match::SelectorFailsCompletely)
301                 return MatchResult::updateWithMatchType(result, matchType);
302         }
303         return MatchResult::fails(Match::SelectorFailsCompletely);
304
305     case CSSSelector::Child:
306         {
307             nextContext = checkingContextForParent(nextContext);
308             if (!nextContext.element)
309                 return MatchResult::fails(Match::SelectorFailsCompletely);
310             nextContext.firstSelectorOfTheFragment = nextContext.selector;
311             nextContext.elementStyle = nullptr;
312             PseudoIdSet ignoreDynamicPseudo;
313             unsigned childSpecificity = 0;
314             MatchResult result = matchRecursively(nextContext, ignoreDynamicPseudo, childSpecificity);
315             ASSERT(!nextContext.pseudoElementEffective && !ignoreDynamicPseudo);
316
317             if (result.match == Match::SelectorMatches)
318                 specificity = CSSSelector::addSpecificities(specificity, childSpecificity);
319
320             if (result.match == Match::SelectorMatches || result.match == Match::SelectorFailsCompletely)
321                 return MatchResult::updateWithMatchType(result, matchType);
322             return MatchResult::fails(Match::SelectorFailsAllSiblings);
323         }
324
325     case CSSSelector::DirectAdjacent:
326         {
327             if (context.resolvingMode == Mode::ResolvingStyle)
328                 context.element->setStyleIsAffectedByPreviousSibling();
329
330             Element* previousElement = context.element->previousElementSibling();
331             if (!previousElement)
332                 return MatchResult::fails(Match::SelectorFailsAllSiblings);
333             if (context.resolvingMode == Mode::ResolvingStyle)
334                 previousElement->setAffectsNextSiblingElementStyle();
335             nextContext.element = previousElement;
336             nextContext.firstSelectorOfTheFragment = nextContext.selector;
337             nextContext.elementStyle = nullptr;
338             PseudoIdSet ignoreDynamicPseudo;
339             unsigned adjacentSpecificity = 0;
340             MatchResult result = matchRecursively(nextContext, ignoreDynamicPseudo, adjacentSpecificity);
341             ASSERT(!nextContext.pseudoElementEffective && !ignoreDynamicPseudo);
342
343             if (result.match == Match::SelectorMatches)
344                 specificity = CSSSelector::addSpecificities(specificity, adjacentSpecificity);
345
346             return MatchResult::updateWithMatchType(result, matchType);
347         }
348     case CSSSelector::IndirectAdjacent:
349         if (context.resolvingMode == Mode::ResolvingStyle)
350             context.element->setStyleIsAffectedByPreviousSibling();
351         nextContext.element = context.element->previousElementSibling();
352         nextContext.firstSelectorOfTheFragment = nextContext.selector;
353         nextContext.elementStyle = nullptr;
354         for (; nextContext.element; nextContext.element = nextContext.element->previousElementSibling()) {
355             if (context.resolvingMode == Mode::ResolvingStyle)
356                 context.element->setAffectsNextSiblingElementStyle();
357
358             PseudoIdSet ignoreDynamicPseudo;
359             unsigned indirectAdjacentSpecificity = 0;
360             MatchResult result = matchRecursively(nextContext, ignoreDynamicPseudo, indirectAdjacentSpecificity);
361             ASSERT(!nextContext.pseudoElementEffective && !ignoreDynamicPseudo);
362
363             if (result.match == Match::SelectorMatches)
364                 specificity = CSSSelector::addSpecificities(specificity, indirectAdjacentSpecificity);
365
366             if (result.match == Match::SelectorMatches || result.match == Match::SelectorFailsAllSiblings || result.match == Match::SelectorFailsCompletely)
367                 return MatchResult::updateWithMatchType(result, matchType);
368         };
369         return MatchResult::fails(Match::SelectorFailsAllSiblings);
370
371     case CSSSelector::SubSelector:
372         {
373             // a selector is invalid if something follows a pseudo-element
374             // We make an exception for scrollbar pseudo elements and allow a set of pseudo classes (but nothing else)
375             // to follow the pseudo elements.
376             nextContext.hasScrollbarPseudo = hasScrollbarPseudoElement(dynamicPseudoIdSet);
377             nextContext.hasSelectionPseudo = dynamicPseudoIdSet.has(SELECTION);
378             if ((context.elementStyle || context.resolvingMode == Mode::CollectingRules) && dynamicPseudoIdSet
379                 && !nextContext.hasSelectionPseudo
380                 && !(nextContext.hasScrollbarPseudo && nextContext.selector->match() == CSSSelector::PseudoClass))
381                 return MatchResult::fails(Match::SelectorFailsCompletely);
382
383             unsigned subselectorSpecificity = 0;
384             MatchResult result = matchRecursively(nextContext, dynamicPseudoIdSet, subselectorSpecificity);
385
386             if (result.match == Match::SelectorMatches)
387                 specificity = CSSSelector::addSpecificities(specificity, subselectorSpecificity);
388
389             return MatchResult::updateWithMatchType(result, matchType);
390         }
391     case CSSSelector::ShadowDescendant:
392         {
393             Element* shadowHostNode = context.element->shadowHost();
394             if (!shadowHostNode)
395                 return MatchResult::fails(Match::SelectorFailsCompletely);
396             nextContext.element = shadowHostNode;
397             nextContext.firstSelectorOfTheFragment = nextContext.selector;
398             nextContext.elementStyle = nullptr;
399             PseudoIdSet ignoreDynamicPseudo;
400             unsigned shadowDescendantSpecificity = 0;
401             MatchResult result = matchRecursively(nextContext, ignoreDynamicPseudo, shadowDescendantSpecificity);
402
403             if (result.match == Match::SelectorMatches)
404                 specificity = CSSSelector::addSpecificities(specificity, shadowDescendantSpecificity);
405
406             return MatchResult::updateWithMatchType(result, matchType);
407         }
408     }
409
410     ASSERT_NOT_REACHED();
411     return MatchResult::fails(Match::SelectorFailsCompletely);
412 }
413
414 static bool attributeValueMatches(const Attribute& attribute, CSSSelector::Match match, const AtomicString& selectorValue, bool caseSensitive)
415 {
416     const AtomicString& value = attribute.value();
417     ASSERT(!value.isNull());
418
419     switch (match) {
420     case CSSSelector::Set:
421         break;
422     case CSSSelector::Exact:
423         if (caseSensitive ? selectorValue != value : !equalIgnoringCase(selectorValue, value))
424             return false;
425         break;
426     case CSSSelector::List:
427         {
428             // Ignore empty selectors or selectors containing spaces.
429             if (selectorValue.isEmpty() || selectorValue.find(isHTMLSpace<UChar>) != notFound)
430                 return false;
431
432             unsigned startSearchAt = 0;
433             while (true) {
434                 size_t foundPos = value.find(selectorValue, startSearchAt, caseSensitive);
435                 if (foundPos == notFound)
436                     return false;
437                 if (!foundPos || isHTMLSpace(value[foundPos - 1])) {
438                     unsigned endStr = foundPos + selectorValue.length();
439                     if (endStr == value.length() || isHTMLSpace(value[endStr]))
440                         break; // We found a match.
441                 }
442
443                 // No match. Keep looking.
444                 startSearchAt = foundPos + 1;
445             }
446             break;
447         }
448     case CSSSelector::Contain:
449         if (!value.contains(selectorValue, caseSensitive) || selectorValue.isEmpty())
450             return false;
451         break;
452     case CSSSelector::Begin:
453         if (!value.startsWith(selectorValue, caseSensitive) || selectorValue.isEmpty())
454             return false;
455         break;
456     case CSSSelector::End:
457         if (!value.endsWith(selectorValue, caseSensitive) || selectorValue.isEmpty())
458             return false;
459         break;
460     case CSSSelector::Hyphen:
461         if (value.length() < selectorValue.length())
462             return false;
463         if (!value.startsWith(selectorValue, caseSensitive))
464             return false;
465         // It they start the same, check for exact match or following '-':
466         if (value.length() != selectorValue.length() && value[selectorValue.length()] != '-')
467             return false;
468         break;
469     default:
470         ASSERT_NOT_REACHED();
471         return false;
472     }
473
474     return true;
475 }
476
477 static bool anyAttributeMatches(Element* element, const CSSSelector* selector, const QualifiedName& selectorAttr, bool caseSensitive)
478 {
479     ASSERT(element->hasAttributesWithoutUpdate());
480     for (const Attribute& attribute : element->attributesIterator()) {
481         if (!attribute.matches(selectorAttr.prefix(), element->isHTMLElement() ? selector->attributeCanonicalLocalName() : selectorAttr.localName(), selectorAttr.namespaceURI()))
482             continue;
483
484         if (attributeValueMatches(attribute, selector->match(), selector->value(), caseSensitive))
485             return true;
486     }
487
488     return false;
489 }
490
491 static bool canMatchHoverOrActiveInQuirksMode(const SelectorChecker::CheckingContextWithStatus& context)
492 {
493     // For quirks mode, follow this: http://quirks.spec.whatwg.org/#the-:active-and-:hover-quirk
494     // In quirks mode, a compound selector 'selector' that matches the following conditions must not match elements that would not also match the ':any-link' selector.
495     //
496     //    selector uses the ':active' or ':hover' pseudo-classes.
497     //    selector does not use a type selector.
498     //    selector does not use an attribute selector.
499     //    selector does not use an ID selector.
500     //    selector does not use a class selector.
501     //    selector does not use a pseudo-class selector other than ':active' and ':hover'.
502     //    selector does not use a pseudo-element selector.
503     //    selector is not part of an argument to a functional pseudo-class or pseudo-element.
504     if (context.inFunctionalPseudoClass)
505         return true;
506
507     for (const CSSSelector* selector = context.firstSelectorOfTheFragment; selector; selector = selector->tagHistory()) {
508         switch (selector->match()) {
509         case CSSSelector::Tag:
510             if (selector->tagQName() != anyQName())
511                 return true;
512             break;
513         case CSSSelector::PseudoClass: {
514             CSSSelector::PseudoClassType pseudoClassType = selector->pseudoClassType();
515             if (pseudoClassType != CSSSelector::PseudoClassHover && pseudoClassType != CSSSelector::PseudoClassActive)
516                 return true;
517             break;
518         }
519         case CSSSelector::Id:
520         case CSSSelector::Class:
521         case CSSSelector::Exact:
522         case CSSSelector::Set:
523         case CSSSelector::List:
524         case CSSSelector::Hyphen:
525         case CSSSelector::Contain:
526         case CSSSelector::Begin:
527         case CSSSelector::End:
528         case CSSSelector::PagePseudoClass:
529         case CSSSelector::PseudoElement:
530             return true;
531         case CSSSelector::Unknown:
532             ASSERT_NOT_REACHED();
533             break;
534         }
535
536         CSSSelector::Relation relation = selector->relation();
537         if (relation == CSSSelector::ShadowDescendant)
538             return true;
539
540         if (relation != CSSSelector::SubSelector)
541             return false;
542     }
543     return false;
544 }
545
546 bool SelectorChecker::checkOne(const CheckingContextWithStatus& context, PseudoIdSet& dynamicPseudoIdSet, MatchType& matchType, unsigned& specificity) const
547 {
548     Element* const & element = context.element;
549     const CSSSelector* const & selector = context.selector;
550     ASSERT(element);
551     ASSERT(selector);
552
553     specificity = CSSSelector::addSpecificities(specificity, selector->simpleSelectorSpecificity());
554
555     if (selector->match() == CSSSelector::Tag)
556         return SelectorChecker::tagMatches(element, selector->tagQName());
557
558     if (selector->match() == CSSSelector::Class)
559         return element->hasClass() && element->classNames().contains(selector->value());
560
561     if (selector->match() == CSSSelector::Id)
562         return element->hasID() && element->idForStyleResolution() == selector->value();
563
564     if (selector->isAttributeSelector()) {
565         if (!element->hasAttributes())
566             return false;
567
568         const QualifiedName& attr = selector->attribute();
569         bool caseSensitive = !(m_documentIsHTML && element->isHTMLElement()) || HTMLDocument::isCaseSensitiveAttribute(attr);
570
571         return anyAttributeMatches(element, selector, attr, caseSensitive);
572     }
573
574     if (selector->match() == CSSSelector::PseudoClass) {
575         // Handle :not up front.
576         if (selector->pseudoClassType() == CSSSelector::PseudoClassNot) {
577             const CSSSelectorList* selectorList = selector->selectorList();
578
579             for (const CSSSelector* subselector = selectorList->first(); subselector; subselector = CSSSelectorList::next(subselector)) {
580                 CheckingContextWithStatus subcontext(context);
581                 subcontext.inFunctionalPseudoClass = true;
582                 subcontext.pseudoElementEffective = false;
583                 subcontext.selector = subselector;
584                 subcontext.firstSelectorOfTheFragment = selectorList->first();
585                 PseudoIdSet ignoreDynamicPseudo;
586
587                 unsigned ignoredSpecificity;
588                 if (matchRecursively(subcontext, ignoreDynamicPseudo, ignoredSpecificity).match == Match::SelectorMatches) {
589                     ASSERT(!ignoreDynamicPseudo);
590                     return false;
591                 }
592             }
593             return true;
594         } else if (context.hasScrollbarPseudo) {
595             // CSS scrollbars match a specific subset of pseudo classes, and they have specialized rules for each
596             // (since there are no elements involved except with window-inactive).
597             return checkScrollbarPseudoClass(context, selector);
598         }
599
600         // Normal element pseudo class checking.
601         switch (selector->pseudoClassType()) {
602             // Pseudo classes:
603         case CSSSelector::PseudoClassNot:
604             break; // Already handled up above.
605         case CSSSelector::PseudoClassEmpty:
606             {
607                 bool result = true;
608                 for (Node* node = element->firstChild(); node; node = node->nextSibling()) {
609                     if (is<Element>(*node)) {
610                         result = false;
611                         break;
612                     }
613                     if (is<Text>(*node)) {
614                         Text& textNode = downcast<Text>(*node);
615                         if (!textNode.data().isEmpty()) {
616                             result = false;
617                             break;
618                         }
619                     }
620                 }
621                 if (context.resolvingMode == Mode::ResolvingStyle) {
622                     element->setStyleAffectedByEmpty();
623                     if (context.elementStyle)
624                         context.elementStyle->setEmptyState(result);
625                 }
626                 return result;
627             }
628         case CSSSelector::PseudoClassFirstChild:
629             // first-child matches the first child that is an element
630             if (Element* parentElement = element->parentElement()) {
631                 bool result = isFirstChildElement(element);
632                 if (context.resolvingMode == Mode::ResolvingStyle) {
633                     RenderStyle* childStyle = context.elementStyle ? context.elementStyle : element->renderStyle();
634                     parentElement->setChildrenAffectedByFirstChildRules();
635                     if (result && childStyle)
636                         childStyle->setFirstChildState();
637                 }
638                 return result;
639             }
640             break;
641         case CSSSelector::PseudoClassFirstOfType:
642             // first-of-type matches the first element of its type
643             if (element->parentElement()) {
644                 if (context.resolvingMode == Mode::ResolvingStyle)
645                     element->setStyleIsAffectedByPreviousSibling();
646
647                 return isFirstOfType(element, element->tagQName(), context.resolvingMode == Mode::ResolvingStyle);
648             }
649             break;
650         case CSSSelector::PseudoClassLastChild:
651             // last-child matches the last child that is an element
652             if (Element* parentElement = element->parentElement()) {
653                 bool result = parentElement->isFinishedParsingChildren() && isLastChildElement(element);
654                 if (context.resolvingMode == Mode::ResolvingStyle) {
655                     RenderStyle* childStyle = context.elementStyle ? context.elementStyle : element->renderStyle();
656                     parentElement->setChildrenAffectedByLastChildRules();
657                     if (result && childStyle)
658                         childStyle->setLastChildState();
659                 }
660                 return result;
661             }
662             break;
663         case CSSSelector::PseudoClassLastOfType:
664             // last-of-type matches the last element of its type
665             if (Element* parentElement = element->parentElement()) {
666                 if (context.resolvingMode == Mode::ResolvingStyle)
667                     parentElement->setChildrenAffectedByBackwardPositionalRules();
668                 if (!parentElement->isFinishedParsingChildren())
669                     return false;
670                 return isLastOfType(element, element->tagQName());
671             }
672             break;
673         case CSSSelector::PseudoClassOnlyChild:
674             if (Element* parentElement = element->parentElement()) {
675                 bool firstChild = isFirstChildElement(element);
676                 bool onlyChild = firstChild && parentElement->isFinishedParsingChildren() && isLastChildElement(element);
677                 if (context.resolvingMode == Mode::ResolvingStyle) {
678                     RenderStyle* childStyle = context.elementStyle ? context.elementStyle : element->renderStyle();
679                     parentElement->setChildrenAffectedByFirstChildRules();
680                     parentElement->setChildrenAffectedByLastChildRules();
681                     if (firstChild && childStyle)
682                         childStyle->setFirstChildState();
683                     if (onlyChild && childStyle)
684                         childStyle->setLastChildState();
685                 }
686                 return onlyChild;
687             }
688             break;
689         case CSSSelector::PseudoClassOnlyOfType:
690             // FIXME: This selector is very slow.
691             if (Element* parentElement = element->parentElement()) {
692                 if (context.resolvingMode == Mode::ResolvingStyle) {
693                     element->setStyleIsAffectedByPreviousSibling();
694                     parentElement->setChildrenAffectedByBackwardPositionalRules();
695                 }
696                 if (!parentElement->isFinishedParsingChildren())
697                     return false;
698                 return isFirstOfType(element, element->tagQName(), context.resolvingMode == Mode::ResolvingStyle) && isLastOfType(element, element->tagQName());
699             }
700             break;
701         case CSSSelector::PseudoClassMatches:
702             {
703                 bool hasMatchedAnything = false;
704                 unsigned maxSpecificity = 0;
705
706                 MatchType localMatchType = MatchType::VirtualPseudoElementOnly;
707                 for (const CSSSelector* subselector = selector->selectorList()->first(); subselector; subselector = CSSSelectorList::next(subselector)) {
708                     CheckingContextWithStatus subcontext(context);
709                     subcontext.inFunctionalPseudoClass = true;
710                     subcontext.pseudoElementEffective = context.pseudoElementEffective;
711                     subcontext.selector = subselector;
712                     subcontext.firstSelectorOfTheFragment = subselector;
713                     PseudoIdSet localDynamicPseudoIdSet;
714                     unsigned localSpecificity = 0;
715                     MatchResult result = matchRecursively(subcontext, localDynamicPseudoIdSet, localSpecificity);
716                     if (result.match == Match::SelectorMatches) {
717                         maxSpecificity = std::max(maxSpecificity, localSpecificity);
718
719                         if (result.matchType == MatchType::Element)
720                             localMatchType = MatchType::Element;
721
722                         dynamicPseudoIdSet.merge(localDynamicPseudoIdSet);
723                         hasMatchedAnything = true;
724                     }
725                 }
726                 if (hasMatchedAnything) {
727                     matchType = localMatchType;
728                     specificity = CSSSelector::addSpecificities(specificity, maxSpecificity);
729                 }
730                 return hasMatchedAnything;
731             }
732         case CSSSelector::PseudoClassPlaceholderShown:
733             if (is<HTMLTextFormControlElement>(*element)) {
734                 if (context.resolvingMode == Mode::ResolvingStyle) {
735                     if (RenderStyle* style = context.elementStyle ? context.elementStyle : element->renderStyle())
736                         style->setUnique();
737                 }
738                 return downcast<HTMLTextFormControlElement>(*element).isPlaceholderVisible();
739             }
740             return false;
741         case CSSSelector::PseudoClassNthChild:
742             if (!selector->parseNth())
743                 break;
744             if (element->parentElement()) {
745 #if ENABLE(CSS_SELECTORS_LEVEL4)
746                 if (const CSSSelectorList* selectorList = selector->selectorList()) {
747                     if (!matchSelectorList(context, *element, *selectorList))
748                         return false;
749                 }
750 #endif
751
752                 if (context.resolvingMode == Mode::ResolvingStyle)
753                     element->setStyleIsAffectedByPreviousSibling();
754
755                 int count = 1;
756 #if ENABLE(CSS_SELECTORS_LEVEL4)
757                 if (const CSSSelectorList* selectorList = selector->selectorList()) {
758                     for (Element* sibling = ElementTraversal::previousSibling(element); sibling; sibling = ElementTraversal::previousSibling(sibling)) {
759                         if (context.resolvingMode == Mode::ResolvingStyle)
760                             sibling->setAffectsNextSiblingElementStyle();
761
762                         if (matchSelectorList(context, *sibling, *selectorList))
763                             ++count;
764                     }
765                 } else
766 #endif
767                 {
768                     count += countElementsBefore(element, context.resolvingMode == Mode::ResolvingStyle);
769                     if (context.resolvingMode == Mode::ResolvingStyle)
770                         element->setChildIndex(count);
771                 }
772
773                 if (selector->matchNth(count))
774                     return true;
775             }
776             break;
777         case CSSSelector::PseudoClassNthOfType:
778             if (!selector->parseNth())
779                 break;
780
781             if (element->parentElement()) {
782                 if (context.resolvingMode == Mode::ResolvingStyle)
783                     element->setStyleIsAffectedByPreviousSibling();
784
785                 int count = 1 + countElementsOfTypeBefore(element, element->tagQName(), context.resolvingMode == Mode::ResolvingStyle);
786                 if (selector->matchNth(count))
787                     return true;
788             }
789             break;
790         case CSSSelector::PseudoClassNthLastChild:
791             if (!selector->parseNth())
792                 break;
793             if (Element* parentElement = element->parentElement()) {
794                 if (!parentElement->isFinishedParsingChildren())
795                     return false;
796
797 #if ENABLE(CSS_SELECTORS_LEVEL4)
798                 if (const CSSSelectorList* selectorList = selector->selectorList()) {
799                     if (!matchSelectorList(context, *element, *selectorList))
800                         return false;
801
802                     if (context.resolvingMode == Mode::ResolvingStyle) {
803                         parentElement->setChildrenAffectedByPropertyBasedBackwardPositionalRules();
804                         parentElement->setChildrenAffectedByBackwardPositionalRules();
805                     }
806                 } else
807 #endif
808                 if (context.resolvingMode == Mode::ResolvingStyle)
809                     parentElement->setChildrenAffectedByBackwardPositionalRules();
810
811                 int count = 1;
812 #if ENABLE(CSS_SELECTORS_LEVEL4)
813                 if (const CSSSelectorList* selectorList = selector->selectorList()) {
814                     for (Element* sibling = ElementTraversal::nextSibling(element); sibling; sibling = ElementTraversal::nextSibling(sibling)) {
815                         if (matchSelectorList(context, *sibling, *selectorList))
816                             ++count;
817                     }
818                 } else
819 #endif
820                 {
821                     count += countElementsAfter(element);
822                 }
823
824                 if (selector->matchNth(count))
825                     return true;
826             }
827             break;
828         case CSSSelector::PseudoClassNthLastOfType:
829             if (!selector->parseNth())
830                 break;
831             if (Element* parentElement = element->parentElement()) {
832                 if (context.resolvingMode == Mode::ResolvingStyle)
833                     parentElement->setChildrenAffectedByBackwardPositionalRules();
834                 if (!parentElement->isFinishedParsingChildren())
835                     return false;
836
837                 int count = 1 + countElementsOfTypeAfter(element, element->tagQName());
838                 if (selector->matchNth(count))
839                     return true;
840             }
841             break;
842         case CSSSelector::PseudoClassTarget:
843             if (element == element->document().cssTarget())
844                 return true;
845             break;
846         case CSSSelector::PseudoClassAny:
847             {
848                 CheckingContextWithStatus subContext(context);
849                 subContext.inFunctionalPseudoClass = true;
850                 subContext.pseudoElementEffective = false;
851                 for (subContext.selector = selector->selectorList()->first(); subContext.selector; subContext.selector = CSSSelectorList::next(subContext.selector)) {
852                     subContext.firstSelectorOfTheFragment = subContext.selector;
853                     PseudoIdSet ignoreDynamicPseudo;
854                     unsigned ingoredSpecificity = 0;
855                     if (matchRecursively(subContext, ignoreDynamicPseudo, ingoredSpecificity).match == Match::SelectorMatches)
856                         return true;
857                 }
858             }
859             break;
860         case CSSSelector::PseudoClassAutofill:
861             return isAutofilled(element);
862 #if ENABLE(CSS_SELECTORS_LEVEL4)
863         case CSSSelector::PseudoClassAnyLink:
864 #endif
865         case CSSSelector::PseudoClassAnyLinkDeprecated:
866         case CSSSelector::PseudoClassLink:
867             // :visited and :link matches are separated later when applying the style. Here both classes match all links...
868             return element->isLink();
869         case CSSSelector::PseudoClassVisited:
870             // ...except if :visited matching is disabled for ancestor/sibling matching.
871             // Inside functional pseudo class except for :not, :visited never matches.
872             if (context.inFunctionalPseudoClass)
873                 return false;
874             return element->isLink() && context.visitedMatchType == VisitedMatchType::Enabled;
875         case CSSSelector::PseudoClassDrag:
876             if (context.resolvingMode == Mode::ResolvingStyle) {
877                 if (context.elementStyle)
878                     context.elementStyle->setAffectedByDrag();
879                 else
880                     element->setChildrenAffectedByDrag();
881             }
882             if (element->renderer() && element->renderer()->isDragging())
883                 return true;
884             break;
885         case CSSSelector::PseudoClassFocus:
886             return matchesFocusPseudoClass(element);
887         case CSSSelector::PseudoClassHover:
888             if (m_strictParsing || element->isLink() || canMatchHoverOrActiveInQuirksMode(context)) {
889                 if (context.resolvingMode == Mode::ResolvingStyle) {
890                     if (context.elementStyle)
891                         context.elementStyle->setAffectedByHover();
892                     else
893                         element->setChildrenAffectedByHover();
894                 }
895                 if (element->hovered() || InspectorInstrumentation::forcePseudoState(element, CSSSelector::PseudoClassHover))
896                     return true;
897             }
898             break;
899         case CSSSelector::PseudoClassActive:
900             if (m_strictParsing || element->isLink() || canMatchHoverOrActiveInQuirksMode(context)) {
901                 if (context.resolvingMode == Mode::ResolvingStyle) {
902                     if (context.elementStyle)
903                         context.elementStyle->setAffectedByActive();
904                     else
905                         element->setChildrenAffectedByActive();
906                 }
907                 if (element->active() || InspectorInstrumentation::forcePseudoState(element, CSSSelector::PseudoClassActive))
908                     return true;
909             }
910             break;
911         case CSSSelector::PseudoClassEnabled:
912             return isEnabled(element);
913         case CSSSelector::PseudoClassFullPageMedia:
914             return isMediaDocument(element);
915         case CSSSelector::PseudoClassDefault:
916             return isDefaultButtonForForm(element);
917         case CSSSelector::PseudoClassDisabled:
918             return isDisabled(element);
919         case CSSSelector::PseudoClassReadOnly:
920             return matchesReadOnlyPseudoClass(element);
921         case CSSSelector::PseudoClassReadWrite:
922             return matchesReadWritePseudoClass(element);
923         case CSSSelector::PseudoClassOptional:
924             return isOptionalFormControl(element);
925         case CSSSelector::PseudoClassRequired:
926             return isRequiredFormControl(element);
927         case CSSSelector::PseudoClassValid:
928             return isValid(element);
929         case CSSSelector::PseudoClassInvalid:
930             return isInvalid(element);
931         case CSSSelector::PseudoClassChecked:
932             return isChecked(element);
933         case CSSSelector::PseudoClassIndeterminate:
934             return shouldAppearIndeterminate(element);
935         case CSSSelector::PseudoClassRoot:
936             if (element == element->document().documentElement())
937                 return true;
938             break;
939         case CSSSelector::PseudoClassLang:
940             {
941 #if ENABLE(CSS_SELECTORS_LEVEL4)
942                 ASSERT(selector->argumentList() && !selector->argumentList()->isEmpty());
943                 return matchesLangPseudoClass(element, *selector->argumentList());
944 #else
945                 const AtomicString& argument = selector->argument();      
946                 if (argument.isNull())
947                     return false;
948                 return matchesLangPseudoClassDeprecated(element, argument.impl());
949 #endif                          
950             }
951 #if ENABLE(FULLSCREEN_API)
952         case CSSSelector::PseudoClassFullScreen:
953             return matchesFullScreenPseudoClass(element);
954         case CSSSelector::PseudoClassAnimatingFullScreenTransition:
955             return matchesFullScreenAnimatingFullScreenTransitionPseudoClass(element);
956         case CSSSelector::PseudoClassFullScreenAncestor:
957             return matchesFullScreenAncestorPseudoClass(element);
958         case CSSSelector::PseudoClassFullScreenDocument:
959             return matchesFullScreenDocumentPseudoClass(element);
960 #endif
961         case CSSSelector::PseudoClassInRange:
962             return isInRange(element);
963         case CSSSelector::PseudoClassOutOfRange:
964             return isOutOfRange(element);
965 #if ENABLE(VIDEO_TRACK)
966         case CSSSelector::PseudoClassFuture:
967             return matchesFutureCuePseudoClass(element);
968         case CSSSelector::PseudoClassPast:
969             return matchesPastCuePseudoClass(element);
970 #endif
971
972         case CSSSelector::PseudoClassScope:
973             {
974                 const Node* contextualReferenceNode = !context.scope ? element->document().documentElement() : context.scope;
975                 if (element == contextualReferenceNode)
976                     return true;
977                 break;
978             }
979
980         case CSSSelector::PseudoClassWindowInactive:
981             return isWindowInactive(element);
982
983         case CSSSelector::PseudoClassHorizontal:
984         case CSSSelector::PseudoClassVertical:
985         case CSSSelector::PseudoClassDecrement:
986         case CSSSelector::PseudoClassIncrement:
987         case CSSSelector::PseudoClassStart:
988         case CSSSelector::PseudoClassEnd:
989         case CSSSelector::PseudoClassDoubleButton:
990         case CSSSelector::PseudoClassSingleButton:
991         case CSSSelector::PseudoClassNoButton:
992         case CSSSelector::PseudoClassCornerPresent:
993             return false;
994
995 #if ENABLE(CSS_SELECTORS_LEVEL4)
996         // FIXME: Implement :role() selector.
997         case CSSSelector::PseudoClassRole:
998             return false;
999 #endif
1000
1001         case CSSSelector::PseudoClassUnknown:
1002             ASSERT_NOT_REACHED();
1003             break;
1004         }
1005         return false;
1006     }
1007 #if ENABLE(VIDEO_TRACK)
1008     if (selector->match() == CSSSelector::PseudoElement && selector->pseudoElementType() == CSSSelector::PseudoElementCue) {
1009         CheckingContextWithStatus subContext(context);
1010
1011         const CSSSelector* const & selector = context.selector;
1012         for (subContext.selector = selector->selectorList()->first(); subContext.selector; subContext.selector = CSSSelectorList::next(subContext.selector)) {
1013             subContext.firstSelectorOfTheFragment = subContext.selector;
1014             subContext.inFunctionalPseudoClass = true;
1015             subContext.pseudoElementEffective = false;
1016             PseudoIdSet ignoredDynamicPseudo;
1017             unsigned ignoredSpecificity = 0;
1018             if (matchRecursively(subContext, ignoredDynamicPseudo, ignoredSpecificity).match == Match::SelectorMatches)
1019                 return true;
1020         }
1021         return false;
1022     }
1023 #endif
1024     // ### add the rest of the checks...
1025     return true;
1026 }
1027
1028 bool SelectorChecker::matchSelectorList(const CheckingContextWithStatus& baseContext, Element& element, const CSSSelectorList& selectorList) const
1029 {
1030     for (const CSSSelector* subselector = selectorList.first(); subselector; subselector = CSSSelectorList::next(subselector)) {
1031         CheckingContextWithStatus subcontext(baseContext);
1032         subcontext.element = &element;
1033         subcontext.selector = subselector;
1034         subcontext.inFunctionalPseudoClass = true;
1035         subcontext.pseudoElementEffective = false;
1036         subcontext.firstSelectorOfTheFragment = subselector;
1037         PseudoIdSet ignoreDynamicPseudo;
1038         unsigned localSpecificity = 0;
1039         if (matchRecursively(subcontext, ignoreDynamicPseudo, localSpecificity).match == Match::SelectorMatches) {
1040             ASSERT(!ignoreDynamicPseudo);
1041             return true;
1042         }
1043     }
1044     return false;
1045 }
1046
1047 bool SelectorChecker::checkScrollbarPseudoClass(const CheckingContextWithStatus& context, const CSSSelector* selector) const
1048 {
1049     ASSERT(selector->match() == CSSSelector::PseudoClass);
1050
1051     switch (selector->pseudoClassType()) {
1052     case CSSSelector::PseudoClassWindowInactive:
1053         return isWindowInactive(context.element);
1054     case CSSSelector::PseudoClassEnabled:
1055         return scrollbarMatchesEnabledPseudoClass(context);
1056     case CSSSelector::PseudoClassDisabled:
1057         return scrollbarMatchesDisabledPseudoClass(context);
1058     case CSSSelector::PseudoClassHover:
1059         return scrollbarMatchesHoverPseudoClass(context);
1060     case CSSSelector::PseudoClassActive:
1061         return scrollbarMatchesActivePseudoClass(context);
1062     case CSSSelector::PseudoClassHorizontal:
1063         return scrollbarMatchesHorizontalPseudoClass(context);
1064     case CSSSelector::PseudoClassVertical:
1065         return scrollbarMatchesVerticalPseudoClass(context);
1066     case CSSSelector::PseudoClassDecrement:
1067         return scrollbarMatchesDecrementPseudoClass(context);
1068     case CSSSelector::PseudoClassIncrement:
1069         return scrollbarMatchesIncrementPseudoClass(context);
1070     case CSSSelector::PseudoClassStart:
1071         return scrollbarMatchesStartPseudoClass(context);
1072     case CSSSelector::PseudoClassEnd:
1073         return scrollbarMatchesEndPseudoClass(context);
1074     case CSSSelector::PseudoClassDoubleButton:
1075         return scrollbarMatchesDoubleButtonPseudoClass(context);
1076     case CSSSelector::PseudoClassSingleButton:
1077         return scrollbarMatchesSingleButtonPseudoClass(context);
1078     case CSSSelector::PseudoClassNoButton:
1079         return scrollbarMatchesNoButtonPseudoClass(context);
1080     case CSSSelector::PseudoClassCornerPresent:
1081         return scrollbarMatchesCornerPresentPseudoClass(context);
1082     default:
1083         return false;
1084     }
1085 }
1086
1087 unsigned SelectorChecker::determineLinkMatchType(const CSSSelector* selector)
1088 {
1089     unsigned linkMatchType = MatchAll;
1090
1091     // Statically determine if this selector will match a link in visited, unvisited or any state, or never.
1092     // :visited never matches other elements than the innermost link element.
1093     for (; selector; selector = selector->tagHistory()) {
1094         if (selector->match() == CSSSelector::PseudoClass) {
1095             switch (selector->pseudoClassType()) {
1096             case CSSSelector::PseudoClassLink:
1097                 linkMatchType &= ~SelectorChecker::MatchVisited;
1098                 break;
1099             case CSSSelector::PseudoClassVisited:
1100                 linkMatchType &= ~SelectorChecker::MatchLink;
1101                 break;
1102             default:
1103                 // We don't support :link and :visited inside :-webkit-any.
1104                 break;
1105             }
1106         }
1107         CSSSelector::Relation relation = selector->relation();
1108         if (relation == CSSSelector::SubSelector)
1109             continue;
1110         if (relation != CSSSelector::Descendant && relation != CSSSelector::Child)
1111             return linkMatchType;
1112         if (linkMatchType != MatchAll)
1113             return linkMatchType;
1114     }
1115     return linkMatchType;
1116 }
1117
1118 static bool isFrameFocused(const Element* element)
1119 {
1120     return element->document().frame() && element->document().frame()->selection().isFocusedAndActive();
1121 }
1122
1123 bool SelectorChecker::matchesFocusPseudoClass(const Element* element)
1124 {
1125     if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(element), CSSSelector::PseudoClassFocus))
1126         return true;
1127     return element->focused() && isFrameFocused(element);
1128 }
1129
1130 }