| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 if (selectorListMatches<SelectorQueryTrait>(rootNode, element, output) && | 387 if (selectorListMatches<SelectorQueryTrait>(rootNode, element, output) && |
| 388 SelectorQueryTrait::shouldOnlyMatchFirstElement) | 388 SelectorQueryTrait::shouldOnlyMatchFirstElement) |
| 389 return; | 389 return; |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 | 392 |
| 393 // FIXME: Move the following helper functions, authorShadowRootOf, | 393 // FIXME: Move the following helper functions, authorShadowRootOf, |
| 394 // firstWithinTraversingShadowTree, nextTraversingShadowTree to the best place, | 394 // firstWithinTraversingShadowTree, nextTraversingShadowTree to the best place, |
| 395 // e.g. NodeTraversal. | 395 // e.g. NodeTraversal. |
| 396 static ShadowRoot* authorShadowRootOf(const ContainerNode& node) { | 396 static ShadowRoot* authorShadowRootOf(const ContainerNode& node) { |
| 397 if (!node.isElementNode() || !isShadowHost(&node)) | 397 if (!node.isElementNode()) |
| 398 return nullptr; |
| 399 ElementShadow* shadow = toElement(node).shadow(); |
| 400 if (!shadow) |
| 398 return nullptr; | 401 return nullptr; |
| 399 | 402 |
| 400 ElementShadow* shadow = toElement(node).shadow(); | |
| 401 DCHECK(shadow); | |
| 402 for (ShadowRoot* shadowRoot = &shadow->oldestShadowRoot(); shadowRoot; | 403 for (ShadowRoot* shadowRoot = &shadow->oldestShadowRoot(); shadowRoot; |
| 403 shadowRoot = shadowRoot->youngerShadowRoot()) { | 404 shadowRoot = shadowRoot->youngerShadowRoot()) { |
| 404 if (shadowRoot->type() == ShadowRootType::V0 || | 405 if (shadowRoot->isOpenOrV0()) |
| 405 shadowRoot->type() == ShadowRootType::Open) | |
| 406 return shadowRoot; | 406 return shadowRoot; |
| 407 } | 407 } |
| 408 return nullptr; | 408 return nullptr; |
| 409 } | 409 } |
| 410 | 410 |
| 411 static ContainerNode* firstWithinTraversingShadowTree( | |
| 412 const ContainerNode& rootNode) { | |
| 413 if (ShadowRoot* shadowRoot = authorShadowRootOf(rootNode)) | |
| 414 return shadowRoot; | |
| 415 return ElementTraversal::firstWithin(rootNode); | |
| 416 } | |
| 417 | |
| 418 static ContainerNode* nextTraversingShadowTree(const ContainerNode& node, | 411 static ContainerNode* nextTraversingShadowTree(const ContainerNode& node, |
| 419 const ContainerNode* rootNode) { | 412 const ContainerNode* rootNode) { |
| 420 if (ShadowRoot* shadowRoot = authorShadowRootOf(node)) | 413 if (ShadowRoot* shadowRoot = authorShadowRootOf(node)) |
| 421 return shadowRoot; | 414 return shadowRoot; |
| 422 | 415 |
| 423 const ContainerNode* current = &node; | 416 const ContainerNode* current = &node; |
| 424 while (current) { | 417 while (current) { |
| 425 if (Element* next = ElementTraversal::next(*current, rootNode)) | 418 if (Element* next = ElementTraversal::next(*current, rootNode)) |
| 426 return next; | 419 return next; |
| 427 | 420 |
| 428 if (!current->isInShadowTree()) | 421 if (!current->isInShadowTree()) |
| 429 return nullptr; | 422 return nullptr; |
| 430 | 423 |
| 431 ShadowRoot* shadowRoot = current->containingShadowRoot(); | 424 ShadowRoot* shadowRoot = current->containingShadowRoot(); |
| 432 if (shadowRoot == rootNode) | 425 if (shadowRoot == rootNode) |
| 433 return nullptr; | 426 return nullptr; |
| 434 if (ShadowRoot* youngerShadowRoot = shadowRoot->youngerShadowRoot()) { | 427 if (ShadowRoot* youngerShadowRoot = shadowRoot->youngerShadowRoot()) { |
| 435 // Should not obtain any elements in closed or user-agent shadow root. | 428 DCHECK(youngerShadowRoot->isOpenOrV0()); |
| 436 DCHECK(youngerShadowRoot->type() == ShadowRootType::V0 || | |
| 437 youngerShadowRoot->type() == ShadowRootType::Open); | |
| 438 return youngerShadowRoot; | 429 return youngerShadowRoot; |
| 439 } | 430 } |
| 440 | 431 |
| 441 current = &shadowRoot->host(); | 432 current = &shadowRoot->host(); |
| 442 } | 433 } |
| 443 return nullptr; | 434 return nullptr; |
| 444 } | 435 } |
| 445 | 436 |
| 446 template <typename SelectorQueryTrait> | 437 template <typename SelectorQueryTrait> |
| 447 void SelectorQuery::executeSlowTraversingShadowTree( | 438 void SelectorQuery::executeSlowTraversingShadowTree( |
| 448 ContainerNode& rootNode, | 439 ContainerNode& rootNode, |
| 449 typename SelectorQueryTrait::OutputType& output) const { | 440 typename SelectorQueryTrait::OutputType& output) const { |
| 450 for (ContainerNode* node = firstWithinTraversingShadowTree(rootNode); node; | 441 for (ContainerNode* node = nextTraversingShadowTree(rootNode, &rootNode); |
| 451 node = nextTraversingShadowTree(*node, &rootNode)) { | 442 node; node = nextTraversingShadowTree(*node, &rootNode)) { |
| 452 if (!node->isElementNode()) | 443 if (!node->isElementNode()) |
| 453 continue; | 444 continue; |
| 454 Element* element = toElement(node); | 445 Element* element = toElement(node); |
| 455 if (selectorListMatches<SelectorQueryTrait>(rootNode, *element, output) && | 446 if (selectorListMatches<SelectorQueryTrait>(rootNode, *element, output) && |
| 456 SelectorQueryTrait::shouldOnlyMatchFirstElement) | 447 SelectorQueryTrait::shouldOnlyMatchFirstElement) |
| 457 return; | 448 return; |
| 458 } | 449 } |
| 459 } | 450 } |
| 460 | 451 |
| 461 static const CSSSelector* selectorForIdLookup( | 452 static const CSSSelector* selectorForIdLookup( |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 return m_entries | 599 return m_entries |
| 609 .insert(selectors, SelectorQuery::adopt(std::move(selectorList))) | 600 .insert(selectors, SelectorQuery::adopt(std::move(selectorList))) |
| 610 .storedValue->value.get(); | 601 .storedValue->value.get(); |
| 611 } | 602 } |
| 612 | 603 |
| 613 void SelectorQueryCache::invalidate() { | 604 void SelectorQueryCache::invalidate() { |
| 614 m_entries.clear(); | 605 m_entries.clear(); |
| 615 } | 606 } |
| 616 | 607 |
| 617 } // namespace blink | 608 } // namespace blink |
| OLD | NEW |