Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: sky/engine/core/dom/SelectorQuery.cpp

Issue 840163003: Make SelectorChecker a const operation over element. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 { 66 {
67 for (Element* element = ElementTraversal::firstWithin(rootNode); element; el ement = ElementTraversal::next(*element, &rootNode)) { 67 for (Element* element = ElementTraversal::firstWithin(rootNode); element; el ement = ElementTraversal::next(*element, &rootNode)) {
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.document(), SelectorChecker::QueryingRules); 76 SelectorChecker checker;
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 (checker.match(context)) 80 if (checker.match(context))
81 return true; 81 return true;
82 } 82 }
83 return false; 83 return false;
84 } 84 }
85 85
86 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)
(...skipping 12 matching lines...) Expand all
99 } 99 }
100 100
101 const unsigned maximumSelectorQueryCacheSize = 256; 101 const unsigned maximumSelectorQueryCacheSize = 256;
102 if (m_entries.size() == maximumSelectorQueryCacheSize) 102 if (m_entries.size() == maximumSelectorQueryCacheSize)
103 m_entries.remove(m_entries.begin()); 103 m_entries.remove(m_entries.begin());
104 104
105 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();
106 } 106 }
107 107
108 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698