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 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.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public License
23 * along with this library; see the file COPYING.LIB. If not, write to
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
28 #ifndef SelectorChecker_h
29 #define SelectorChecker_h
31 #include "core/css/CSSSelector.h"
32 #include "core/dom/Element.h"
33 #include "platform/scroll/ScrollTypes.h"
40 class LayoutScrollbar
;
43 class SelectorChecker
{
44 WTF_MAKE_NONCOPYABLE(SelectorChecker
);
47 enum VisitedMatchType
{ VisitedMatchDisabled
, VisitedMatchEnabled
};
48 enum Mode
{ ResolvingStyle
= 0, CollectingStyleRules
, CollectingCSSRules
, QueryingRules
, SharingRules
};
50 explicit SelectorChecker(Mode
);
52 struct SelectorCheckingContext
{
55 // Initial selector constructor
56 SelectorCheckingContext(Element
* element
, VisitedMatchType visitedMatchType
)
59 , previousElement(nullptr)
61 , visitedMatchType(visitedMatchType
)
63 , elementStyle(nullptr)
65 , scrollbarPart(NoPart
)
66 , isSubSelector(false)
67 , inRightmostCompound(true)
68 , hasScrollbarPseudo(false)
69 , hasSelectionPseudo(false)
71 , scopeContainsLastMatchedElement(false)
72 , treatShadowHostAsNormalScope(false)
76 const CSSSelector
* selector
;
77 RawPtrWillBeMember
<Element
> element
;
78 RawPtrWillBeMember
<Element
> previousElement
;
79 RawPtrWillBeMember
<const ContainerNode
> scope
;
80 VisitedMatchType visitedMatchType
;
82 ComputedStyle
* elementStyle
;
83 RawPtrWillBeMember
<LayoutScrollbar
> scrollbar
;
84 ScrollbarPart scrollbarPart
;
86 bool inRightmostCompound
;
87 bool hasScrollbarPseudo
;
88 bool hasSelectionPseudo
;
90 bool scopeContainsLastMatchedElement
;
91 bool treatShadowHostAsNormalScope
;
97 : dynamicPseudo(NOPSEUDO
)
100 PseudoId dynamicPseudo
;
101 unsigned specificity
;
104 bool match(const SelectorCheckingContext
&, MatchResult
&) const;
105 bool match(const SelectorCheckingContext
&) const;
107 static bool matchesFocusPseudoClass(const Element
&);
110 bool checkOne(const SelectorCheckingContext
&, MatchResult
&) const;
112 enum Match
{ SelectorMatches
, SelectorFailsLocally
, SelectorFailsAllSiblings
, SelectorFailsCompletely
};
114 Match
matchSelector(const SelectorCheckingContext
&, MatchResult
&) const;
115 Match
matchForSubSelector(const SelectorCheckingContext
&, MatchResult
&) const;
116 Match
matchForRelation(const SelectorCheckingContext
&, MatchResult
&) const;
117 Match
matchForShadowDistributed(const SelectorCheckingContext
&, const Element
&, MatchResult
&) const;
118 Match
matchForPseudoShadow(const SelectorCheckingContext
&, const ContainerNode
*, MatchResult
&) const;
119 bool checkPseudoClass(const SelectorCheckingContext
&, MatchResult
&) const;
120 bool checkPseudoElement(const SelectorCheckingContext
&, MatchResult
&) const;
121 bool checkScrollbarPseudoClass(const SelectorCheckingContext
&, MatchResult
&) const;
122 bool checkPseudoHost(const SelectorCheckingContext
&, MatchResult
&) const;
123 bool checkPseudoNot(const SelectorCheckingContext
&, MatchResult
&) const;