OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.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. | 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> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@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.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 static bool isFirstOfType(Element& element, const QualifiedName& type) | 173 static bool isFirstOfType(Element& element, const QualifiedName& type) |
174 { | 174 { |
175 return !ElementTraversal::previousSibling(element, HasTagName(type)); | 175 return !ElementTraversal::previousSibling(element, HasTagName(type)); |
176 } | 176 } |
177 | 177 |
178 static bool isLastOfType(Element& element, const QualifiedName& type) | 178 static bool isLastOfType(Element& element, const QualifiedName& type) |
179 { | 179 { |
180 return !ElementTraversal::nextSibling(element, HasTagName(type)); | 180 return !ElementTraversal::nextSibling(element, HasTagName(type)); |
181 } | 181 } |
182 | 182 |
183 static int nthChildIndex(Element& element) | |
184 { | |
185 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) | |
186 return nthIndexCache->nthChildIndex(element); | |
187 | |
188 int index = 1; | |
189 for (const Element* sibling = ElementTraversal::previousSibling(element); si
bling; sibling = ElementTraversal::previousSibling(*sibling)) | |
190 index++; | |
191 | |
192 return index; | |
193 } | |
194 | |
195 static int nthOfTypeIndex(Element& element, const QualifiedName& type) | |
196 { | |
197 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) | |
198 return nthIndexCache->nthChildIndexOfType(element, type); | |
199 int index = 1; | |
200 for (const Element* sibling = ElementTraversal::previousSibling(element, Has
TagName(type)); sibling; sibling = ElementTraversal::previousSibling(*sibling, H
asTagName(type))) | |
201 ++index; | |
202 return index; | |
203 } | |
204 | |
205 static int nthLastChildIndex(Element& element) | |
206 { | |
207 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) | |
208 return nthIndexCache->nthLastChildIndex(element); | |
209 | |
210 int index = 1; | |
211 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin
g; sibling = ElementTraversal::nextSibling(*sibling)) | |
212 ++index; | |
213 return index; | |
214 } | |
215 | |
216 static int nthLastOfTypeIndex(Element& element, const QualifiedName& type) | |
217 { | |
218 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) | |
219 return nthIndexCache->nthLastChildIndexOfType(element, type); | |
220 | |
221 int index = 1; | |
222 for (const Element* sibling = ElementTraversal::nextSibling(element, HasTagN
ame(type)); sibling; sibling = ElementTraversal::nextSibling(*sibling, HasTagNam
e(type))) | |
223 ++index; | |
224 return index; | |
225 } | |
226 | |
227 // Recursive check of selectors and combinators | 183 // Recursive check of selectors and combinators |
228 // It can return 4 different values: | 184 // It can return 4 different values: |
229 // * SelectorMatches - the selector matches the element e | 185 // * SelectorMatches - the selector matches the element e |
230 // * SelectorFailsLocally - the selector fails for the element e | 186 // * SelectorFailsLocally - the selector fails for the element e |
231 // * SelectorFailsAllSiblings - the selector fails for e and any sibling of e | 187 // * SelectorFailsAllSiblings - the selector fails for e and any sibling of e |
232 // * SelectorFailsCompletely - the selector fails for e and any sibling or ance
stor of e | 188 // * SelectorFailsCompletely - the selector fails for e and any sibling or ance
stor of e |
233 SelectorChecker::Match SelectorChecker::matchSelector(const SelectorCheckingCont
ext& context, MatchResult& result) const | 189 SelectorChecker::Match SelectorChecker::matchSelector(const SelectorCheckingCont
ext& context, MatchResult& result) const |
234 { | 190 { |
235 MatchResult subResult; | 191 MatchResult subResult; |
236 if (!checkOne(context, subResult)) | 192 if (!checkOne(context, subResult)) |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 } | 719 } |
764 break; | 720 break; |
765 case CSSSelector::PseudoPlaceholderShown: | 721 case CSSSelector::PseudoPlaceholderShown: |
766 if (isHTMLTextFormControlElement(element)) | 722 if (isHTMLTextFormControlElement(element)) |
767 return toHTMLTextFormControlElement(element).isPlaceholderVisible(); | 723 return toHTMLTextFormControlElement(element).isPlaceholderVisible(); |
768 break; | 724 break; |
769 case CSSSelector::PseudoNthChild: | 725 case CSSSelector::PseudoNthChild: |
770 if (ContainerNode* parent = element.parentElementOrDocumentFragment()) { | 726 if (ContainerNode* parent = element.parentElementOrDocumentFragment()) { |
771 if (m_mode == ResolvingStyle) | 727 if (m_mode == ResolvingStyle) |
772 parent->setChildrenAffectedByForwardPositionalRules(); | 728 parent->setChildrenAffectedByForwardPositionalRules(); |
773 return selector.matchNth(nthChildIndex(element)); | 729 return selector.matchNth(NthIndexCache::nthChildIndex(element)); |
774 } | 730 } |
775 break; | 731 break; |
776 case CSSSelector::PseudoNthOfType: | 732 case CSSSelector::PseudoNthOfType: |
777 if (ContainerNode* parent = element.parentElementOrDocumentFragment()) { | 733 if (ContainerNode* parent = element.parentElementOrDocumentFragment()) { |
778 if (m_mode == ResolvingStyle) | 734 if (m_mode == ResolvingStyle) |
779 parent->setChildrenAffectedByForwardPositionalRules(); | 735 parent->setChildrenAffectedByForwardPositionalRules(); |
780 return selector.matchNth(nthOfTypeIndex(element, element.tagQName())
); | 736 return selector.matchNth(NthIndexCache::nthOfTypeIndex(element)); |
781 } | 737 } |
782 break; | 738 break; |
783 case CSSSelector::PseudoNthLastChild: | 739 case CSSSelector::PseudoNthLastChild: |
784 if (ContainerNode* parent = element.parentElementOrDocumentFragment()) { | 740 if (ContainerNode* parent = element.parentElementOrDocumentFragment()) { |
785 if (m_mode == ResolvingStyle) | 741 if (m_mode == ResolvingStyle) |
786 parent->setChildrenAffectedByBackwardPositionalRules(); | 742 parent->setChildrenAffectedByBackwardPositionalRules(); |
787 if (!parent->isFinishedParsingChildren()) | 743 if (!parent->isFinishedParsingChildren()) |
788 return false; | 744 return false; |
789 return selector.matchNth(nthLastChildIndex(element)); | 745 return selector.matchNth(NthIndexCache::nthLastChildIndex(element)); |
790 } | 746 } |
791 break; | 747 break; |
792 case CSSSelector::PseudoNthLastOfType: | 748 case CSSSelector::PseudoNthLastOfType: |
793 if (ContainerNode* parent = element.parentElementOrDocumentFragment()) { | 749 if (ContainerNode* parent = element.parentElementOrDocumentFragment()) { |
794 if (m_mode == ResolvingStyle) | 750 if (m_mode == ResolvingStyle) |
795 parent->setChildrenAffectedByBackwardPositionalRules(); | 751 parent->setChildrenAffectedByBackwardPositionalRules(); |
796 if (!parent->isFinishedParsingChildren()) | 752 if (!parent->isFinishedParsingChildren()) |
797 return false; | 753 return false; |
798 return selector.matchNth(nthLastOfTypeIndex(element, element.tagQNam
e())); | 754 return selector.matchNth(NthIndexCache::nthLastOfTypeIndex(element))
; |
799 } | 755 } |
800 break; | 756 break; |
801 case CSSSelector::PseudoTarget: | 757 case CSSSelector::PseudoTarget: |
802 return element == element.document().cssTarget(); | 758 return element == element.document().cssTarget(); |
803 case CSSSelector::PseudoAny: | 759 case CSSSelector::PseudoAny: |
804 { | 760 { |
805 SelectorCheckingContext subContext(context); | 761 SelectorCheckingContext subContext(context); |
806 subContext.isSubSelector = true; | 762 subContext.isSubSelector = true; |
807 ASSERT(selector.selectorList()); | 763 ASSERT(selector.selectorList()); |
808 for (subContext.selector = selector.selectorList()->first(); subCont
ext.selector; subContext.selector = CSSSelectorList::next(*subContext.selector))
{ | 764 for (subContext.selector = selector.selectorList()->first(); subCont
ext.selector; subContext.selector = CSSSelectorList::next(*subContext.selector))
{ |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 } | 1143 } |
1188 | 1144 |
1189 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) | 1145 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) |
1190 { | 1146 { |
1191 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element
), CSSSelector::PseudoFocus)) | 1147 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element
), CSSSelector::PseudoFocus)) |
1192 return true; | 1148 return true; |
1193 return element.focused() && isFrameFocused(element); | 1149 return element.focused() && isFrameFocused(element); |
1194 } | 1150 } |
1195 | 1151 |
1196 } // namespace blink | 1152 } // namespace blink |
OLD | NEW |