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

Side by Side Diff: Source/core/dom/SelectorQuery.cpp

Issue 704733002: Adding Element.closest() API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « Source/core/dom/SelectorQuery.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 { 129 {
130 unsigned selectorCount = m_selectors.size(); 130 unsigned selectorCount = m_selectors.size();
131 for (unsigned i = 0; i < selectorCount; ++i) { 131 for (unsigned i = 0; i < selectorCount; ++i) {
132 if (selectorMatches(*m_selectors[i], targetElement, targetElement)) 132 if (selectorMatches(*m_selectors[i], targetElement, targetElement))
133 return true; 133 return true;
134 } 134 }
135 135
136 return false; 136 return false;
137 } 137 }
138 138
139 Element* SelectorDataList::closest(Element& targetElement) const
140 {
141 unsigned selectorCount = m_selectors.size();
142 for (Element* currentElement = &targetElement; currentElement; currentElemen t = currentElement->parentElement()) {
143 for (unsigned i = 0; i < selectorCount; ++i) {
144 if (selectorMatches(*m_selectors[i], *currentElement, targetElement) )
145 return currentElement;
146 }
147 }
148 return nullptr;
149 }
150
139 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo de& rootNode) const 151 PassRefPtrWillBeRawPtr<StaticElementList> SelectorDataList::queryAll(ContainerNo de& rootNode) const
140 { 152 {
141 WillBeHeapVector<RefPtrWillBeMember<Element> > result; 153 WillBeHeapVector<RefPtrWillBeMember<Element> > result;
142 execute<AllElementsSelectorQueryTrait>(rootNode, result); 154 execute<AllElementsSelectorQueryTrait>(rootNode, result);
143 return StaticElementList::adopt(result); 155 return StaticElementList::adopt(result);
144 } 156 }
145 157
146 PassRefPtrWillBeRawPtr<Element> SelectorDataList::queryFirst(ContainerNode& root Node) const 158 PassRefPtrWillBeRawPtr<Element> SelectorDataList::queryFirst(ContainerNode& root Node) const
147 { 159 {
148 Element* matchedElement = 0; 160 Element* matchedElement = 0;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 { 486 {
475 m_selectorList.adopt(selectorList); 487 m_selectorList.adopt(selectorList);
476 m_selectors.initialize(m_selectorList); 488 m_selectors.initialize(m_selectorList);
477 } 489 }
478 490
479 bool SelectorQuery::matches(Element& element) const 491 bool SelectorQuery::matches(Element& element) const
480 { 492 {
481 return m_selectors.matches(element); 493 return m_selectors.matches(element);
482 } 494 }
483 495
496 Element* SelectorQuery::closest(Element& element) const
497 {
498 return m_selectors.closest(element);
499 }
500
484 PassRefPtrWillBeRawPtr<StaticElementList> SelectorQuery::queryAll(ContainerNode& rootNode) const 501 PassRefPtrWillBeRawPtr<StaticElementList> SelectorQuery::queryAll(ContainerNode& rootNode) const
485 { 502 {
486 return m_selectors.queryAll(rootNode); 503 return m_selectors.queryAll(rootNode);
487 } 504 }
488 505
489 PassRefPtrWillBeRawPtr<Element> SelectorQuery::queryFirst(ContainerNode& rootNod e) const 506 PassRefPtrWillBeRawPtr<Element> SelectorQuery::queryFirst(ContainerNode& rootNod e) const
490 { 507 {
491 return m_selectors.queryFirst(rootNode); 508 return m_selectors.queryFirst(rootNode);
492 } 509 }
493 510
(...skipping 24 matching lines...) Expand all
518 535
519 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa lue->value.get(); 536 return m_entries.add(selectors, SelectorQuery::adopt(selectorList)).storedVa lue->value.get();
520 } 537 }
521 538
522 void SelectorQueryCache::invalidate() 539 void SelectorQueryCache::invalidate()
523 { 540 {
524 m_entries.clear(); 541 m_entries.clear();
525 } 542 }
526 543
527 } 544 }
OLDNEW
« no previous file with comments | « Source/core/dom/SelectorQuery.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698