| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 return nullptr; | 71 return nullptr; |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool SelectorQuery::selectorMatches(ContainerNode& rootNode, Element& element) c
onst | 74 bool SelectorQuery::selectorMatches(ContainerNode& rootNode, Element& element) c
onst |
| 75 { | 75 { |
| 76 SelectorChecker checker(element.document(), SelectorChecker::QueryingRules); | 76 SelectorChecker checker(element.document(), SelectorChecker::QueryingRules); |
| 77 for (const CSSSelector* selector = m_selectors.first(); selector; selector =
CSSSelectorList::next(*selector)) { | 77 for (const CSSSelector* selector = m_selectors.first(); selector; selector =
CSSSelectorList::next(*selector)) { |
| 78 SelectorChecker::SelectorCheckingContext context(*selector, &element); | 78 SelectorChecker::SelectorCheckingContext context(*selector, &element); |
| 79 context.scope = !rootNode.isDocumentNode() ? &rootNode : 0; | 79 context.scope = !rootNode.isDocumentNode() ? &rootNode : 0; |
| 80 if (context.scope) | |
| 81 context.contextFlags = SelectorChecker::ScopeContainsLastMatchedElem
ent; | |
| 82 if (checker.match(context)) | 80 if (checker.match(context)) |
| 83 return true; | 81 return true; |
| 84 } | 82 } |
| 85 return false; | 83 return false; |
| 86 } | 84 } |
| 87 | 85 |
| 88 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) | 86 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) |
| 89 { | 87 { |
| 90 HashMap<AtomicString, OwnPtr<SelectorQuery> >::iterator it = m_entries.find(
selectors); | 88 HashMap<AtomicString, OwnPtr<SelectorQuery> >::iterator it = m_entries.find(
selectors); |
| 91 if (it != m_entries.end()) | 89 if (it != m_entries.end()) |
| 92 return it->value.get(); | 90 return it->value.get(); |
| 93 | 91 |
| 94 BisonCSSParser parser(CSSParserContext(document, 0)); | 92 BisonCSSParser parser(CSSParserContext(document, 0)); |
| 95 CSSSelectorList selectorList; | 93 CSSSelectorList selectorList; |
| 96 parser.parseSelector(selectors, selectorList); | 94 parser.parseSelector(selectors, selectorList); |
| 97 | 95 |
| 98 if (!selectorList.first()) { | 96 if (!selectorList.first()) { |
| 99 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); | 97 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); |
| 100 return 0; | 98 return 0; |
| 101 } | 99 } |
| 102 | 100 |
| 103 const unsigned maximumSelectorQueryCacheSize = 256; | 101 const unsigned maximumSelectorQueryCacheSize = 256; |
| 104 if (m_entries.size() == maximumSelectorQueryCacheSize) | 102 if (m_entries.size() == maximumSelectorQueryCacheSize) |
| 105 m_entries.remove(m_entries.begin()); | 103 m_entries.remove(m_entries.begin()); |
| 106 | 104 |
| 107 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa
lue->value.get(); | 105 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa
lue->value.get(); |
| 108 } | 106 } |
| 109 | 107 |
| 110 } | 108 } |
| OLD | NEW |