| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (selectorMatches(rootNode, *element)) | 68 if (selectorMatches(rootNode, *element)) |
| 69 return element; | 69 return element; |
| 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); | 76 SelectorChecker checker(element); |
| 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 const ContainerNode* scope = !rootNode.isDocumentNode() ? &rootNode : 0; | 78 if (checker.match(*selector)) |
| 79 if (checker.match(*selector, scope)) | |
| 80 return true; | 79 return true; |
| 81 } | 80 } |
| 82 return false; | 81 return false; |
| 83 } | 82 } |
| 84 | 83 |
| 85 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) | 84 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) |
| 86 { | 85 { |
| 87 HashMap<AtomicString, OwnPtr<SelectorQuery> >::iterator it = m_entries.find(
selectors); | 86 HashMap<AtomicString, OwnPtr<SelectorQuery> >::iterator it = m_entries.find(
selectors); |
| 88 if (it != m_entries.end()) | 87 if (it != m_entries.end()) |
| 89 return it->value.get(); | 88 return it->value.get(); |
| 90 | 89 |
| 91 BisonCSSParser parser(CSSParserContext(document, 0)); | 90 BisonCSSParser parser(CSSParserContext(document, 0)); |
| 92 CSSSelectorList selectorList; | 91 CSSSelectorList selectorList; |
| 93 parser.parseSelector(selectors, selectorList); | 92 parser.parseSelector(selectors, selectorList); |
| 94 | 93 |
| 95 if (!selectorList.first()) { | 94 if (!selectorList.first()) { |
| 96 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); | 95 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); |
| 97 return 0; | 96 return 0; |
| 98 } | 97 } |
| 99 | 98 |
| 100 const unsigned maximumSelectorQueryCacheSize = 256; | 99 const unsigned maximumSelectorQueryCacheSize = 256; |
| 101 if (m_entries.size() == maximumSelectorQueryCacheSize) | 100 if (m_entries.size() == maximumSelectorQueryCacheSize) |
| 102 m_entries.remove(m_entries.begin()); | 101 m_entries.remove(m_entries.begin()); |
| 103 | 102 |
| 104 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa
lue->value.get(); | 103 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa
lue->value.get(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 } | 106 } |
| OLD | NEW |