| 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 10 matching lines...) Expand all Loading... |
| 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/dom/SelectorQuery.h" | 28 #include "core/dom/SelectorQuery.h" |
| 29 | 29 |
| 30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
| 31 #include "core/css/parser/BisonCSSParser.h" | |
| 32 #include "core/css/SelectorChecker.h" | 31 #include "core/css/SelectorChecker.h" |
| 33 #include "core/css/SiblingTraversalStrategies.h" | 32 #include "core/css/SiblingTraversalStrategies.h" |
| 33 #include "core/css/parser/CSSParser.h" |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/ElementTraversal.h" | 35 #include "core/dom/ElementTraversal.h" |
| 36 #include "core/dom/Node.h" | 36 #include "core/dom/Node.h" |
| 37 #include "core/dom/StaticNodeList.h" | 37 #include "core/dom/StaticNodeList.h" |
| 38 #include "core/dom/shadow/ElementShadow.h" | 38 #include "core/dom/shadow/ElementShadow.h" |
| 39 #include "core/dom/shadow/ShadowRoot.h" | 39 #include "core/dom/shadow/ShadowRoot.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 struct SingleElementSelectorQueryTrait { | 43 struct SingleElementSelectorQueryTrait { |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 { | 491 { |
| 492 return m_selectors.queryFirst(rootNode); | 492 return m_selectors.queryFirst(rootNode); |
| 493 } | 493 } |
| 494 | 494 |
| 495 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) | 495 SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, const Docu
ment& document, ExceptionState& exceptionState) |
| 496 { | 496 { |
| 497 HashMap<AtomicString, OwnPtr<SelectorQuery> >::iterator it = m_entries.find(
selectors); | 497 HashMap<AtomicString, OwnPtr<SelectorQuery> >::iterator it = m_entries.find(
selectors); |
| 498 if (it != m_entries.end()) | 498 if (it != m_entries.end()) |
| 499 return it->value.get(); | 499 return it->value.get(); |
| 500 | 500 |
| 501 BisonCSSParser parser(CSSParserContext(document, 0)); | 501 CSSParser parser(CSSParserContext(document, 0)); |
| 502 CSSSelectorList selectorList; | 502 CSSSelectorList selectorList; |
| 503 parser.parseSelector(selectors, selectorList); | 503 parser.parseSelector(selectors, selectorList); |
| 504 | 504 |
| 505 if (!selectorList.first()) { | 505 if (!selectorList.first()) { |
| 506 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); | 506 exceptionState.throwDOMException(SyntaxError, "'" + selectors + "' is no
t a valid selector."); |
| 507 return 0; | 507 return 0; |
| 508 } | 508 } |
| 509 | 509 |
| 510 // throw a NamespaceError if the selector includes any namespace prefixes. | 510 // throw a NamespaceError if the selector includes any namespace prefixes. |
| 511 if (selectorList.selectorsNeedNamespaceResolution()) { | 511 if (selectorList.selectorsNeedNamespaceResolution()) { |
| 512 exceptionState.throwDOMException(NamespaceError, "'" + selectors + "' co
ntains namespaces, which are not supported."); | 512 exceptionState.throwDOMException(NamespaceError, "'" + selectors + "' co
ntains namespaces, which are not supported."); |
| 513 return 0; | 513 return 0; |
| 514 } | 514 } |
| 515 | 515 |
| 516 const unsigned maximumSelectorQueryCacheSize = 256; | 516 const unsigned maximumSelectorQueryCacheSize = 256; |
| 517 if (m_entries.size() == maximumSelectorQueryCacheSize) | 517 if (m_entries.size() == maximumSelectorQueryCacheSize) |
| 518 m_entries.remove(m_entries.begin()); | 518 m_entries.remove(m_entries.begin()); |
| 519 | 519 |
| 520 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa
lue->value.get(); | 520 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa
lue->value.get(); |
| 521 } | 521 } |
| 522 | 522 |
| 523 void SelectorQueryCache::invalidate() | 523 void SelectorQueryCache::invalidate() |
| 524 { | 524 { |
| 525 m_entries.clear(); | 525 m_entries.clear(); |
| 526 } | 526 } |
| 527 | 527 |
| 528 } | 528 } |
| OLD | NEW |