OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 Google Inc. All Rights Reserved. |
3 * Copyright (C) 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2012 Apple Inc. 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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 using namespace HTMLNames; | 57 using namespace HTMLNames; |
58 | 58 |
59 TreeScope::TreeScope(ContainerNode& rootNode, Document& document) | 59 TreeScope::TreeScope(ContainerNode& rootNode, Document& document) |
60 : m_rootNode(&rootNode) | 60 : m_rootNode(&rootNode) |
61 , m_document(&document) | 61 , m_document(&document) |
62 , m_parentTreeScope(&document) | 62 , m_parentTreeScope(&document) |
63 #if !ENABLE(OILPAN) | 63 #if !ENABLE(OILPAN) |
64 , m_guardRefCount(0) | 64 , m_guardRefCount(0) |
65 #endif | 65 #endif |
66 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) | 66 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) |
67 , m_inActiveStyleSheetsTraversal(false) | |
67 { | 68 { |
68 ASSERT(rootNode != document); | 69 ASSERT(rootNode != document); |
69 #if !ENABLE(OILPAN) | 70 #if !ENABLE(OILPAN) |
70 m_parentTreeScope->guardRef(); | 71 m_parentTreeScope->guardRef(); |
71 #endif | 72 #endif |
72 m_rootNode->setTreeScope(this); | 73 m_rootNode->setTreeScope(this); |
73 } | 74 } |
74 | 75 |
75 TreeScope::TreeScope(Document& document) | 76 TreeScope::TreeScope(Document& document) |
76 : m_rootNode(document) | 77 : m_rootNode(document) |
77 , m_document(&document) | 78 , m_document(&document) |
78 , m_parentTreeScope(nullptr) | 79 , m_parentTreeScope(nullptr) |
79 #if !ENABLE(OILPAN) | 80 #if !ENABLE(OILPAN) |
80 , m_guardRefCount(0) | 81 , m_guardRefCount(0) |
81 #endif | 82 #endif |
82 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) | 83 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) |
84 , m_inActiveStyleSheetsTraversal(false) | |
83 { | 85 { |
84 m_rootNode->setTreeScope(this); | 86 m_rootNode->setTreeScope(this); |
85 } | 87 } |
86 | 88 |
87 TreeScope::~TreeScope() | 89 TreeScope::~TreeScope() |
88 { | 90 { |
89 #if !ENABLE(OILPAN) | 91 #if !ENABLE(OILPAN) |
90 ASSERT(!m_guardRefCount); | 92 ASSERT(!m_guardRefCount); |
91 m_rootNode->setTreeScope(0); | 93 m_rootNode->setTreeScope(0); |
92 | 94 |
93 if (m_selection) { | 95 if (m_selection) { |
94 m_selection->clearTreeScope(); | 96 m_selection->clearTreeScope(); |
95 m_selection = nullptr; | 97 m_selection = nullptr; |
96 } | 98 } |
97 | 99 |
100 if (m_inActiveStyleSheetsTraversal) | |
101 removeFromActiveStyleSheetsTraversal(); | |
102 | |
98 if (m_parentTreeScope) | 103 if (m_parentTreeScope) |
99 m_parentTreeScope->guardDeref(); | 104 m_parentTreeScope->guardDeref(); |
100 #endif | 105 #endif |
101 } | 106 } |
102 | 107 |
103 TreeScope* TreeScope::olderShadowRootOrParentTreeScope() const | 108 TreeScope* TreeScope::olderShadowRootOrParentTreeScope() const |
104 { | 109 { |
105 if (rootNode().isShadowRoot()) { | 110 if (rootNode().isShadowRoot()) { |
106 if (ShadowRoot* olderShadowRoot = toShadowRoot(rootNode()).olderShadowRo ot()) | 111 if (ShadowRoot* olderShadowRoot = toShadowRoot(rootNode()).olderShadowRo ot()) |
107 return olderShadowRoot; | 112 return olderShadowRoot; |
(...skipping 22 matching lines...) Expand all Loading... | |
130 m_imageMapsByName.clear(); | 135 m_imageMapsByName.clear(); |
131 m_labelsByForAttribute.clear(); | 136 m_labelsByForAttribute.clear(); |
132 } | 137 } |
133 #endif | 138 #endif |
134 | 139 |
135 void TreeScope::setParentTreeScope(TreeScope& newParentScope) | 140 void TreeScope::setParentTreeScope(TreeScope& newParentScope) |
136 { | 141 { |
137 // A document node cannot be re-parented. | 142 // A document node cannot be re-parented. |
138 ASSERT(!rootNode().isDocumentNode()); | 143 ASSERT(!rootNode().isDocumentNode()); |
139 | 144 |
145 if (m_inActiveStyleSheetsTraversal) | |
146 removeFromActiveStyleSheetsTraversal(); | |
140 #if !ENABLE(OILPAN) | 147 #if !ENABLE(OILPAN) |
141 newParentScope.guardRef(); | 148 newParentScope.guardRef(); |
142 if (m_parentTreeScope) | 149 if (m_parentTreeScope) |
143 m_parentTreeScope->guardDeref(); | 150 m_parentTreeScope->guardDeref(); |
144 #endif | 151 #endif |
145 m_parentTreeScope = &newParentScope; | 152 m_parentTreeScope = &newParentScope; |
146 setDocument(newParentScope.document()); | 153 setDocument(newParentScope.document()); |
147 } | 154 } |
148 | 155 |
149 ScopedStyleResolver& TreeScope::ensureScopedStyleResolver() | 156 ScopedStyleResolver& TreeScope::ensureScopedStyleResolver() |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 { | 568 { |
562 for (Element* element = ElementTraversal::firstWithin(rootNode()); element; element = ElementTraversal::nextIncludingPseudo(*element)) { | 569 for (Element* element = ElementTraversal::firstWithin(rootNode()); element; element = ElementTraversal::nextIncludingPseudo(*element)) { |
563 for (ShadowRoot* root = element->youngestShadowRoot(); root; root = root ->olderShadowRoot()) | 570 for (ShadowRoot* root = element->youngestShadowRoot(); root; root = root ->olderShadowRoot()) |
564 root->setNeedsStyleRecalcForViewportUnits(); | 571 root->setNeedsStyleRecalcForViewportUnits(); |
565 const ComputedStyle* style = element->computedStyle(); | 572 const ComputedStyle* style = element->computedStyle(); |
566 if (style && style->hasViewportUnits()) | 573 if (style && style->hasViewportUnits()) |
567 element->setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForT racing::create(StyleChangeReason::ViewportUnits)); | 574 element->setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForT racing::create(StyleChangeReason::ViewportUnits)); |
568 } | 575 } |
569 } | 576 } |
570 | 577 |
578 TreeScopeStyleSheetCollection* TreeScope::styleSheetCollection() | |
579 { | |
580 return document().styleEngine().styleSheetCollectionFor(*this); | |
581 } | |
582 | |
583 bool TreeScope::OrderedTreeScopeSet::insert(TreeScope* treeScope) | |
584 { | |
585 if (m_treeScopes.isEmpty()) { | |
586 m_treeScopes.append(treeScope); | |
587 m_hash.add(treeScope); | |
588 return true; | |
589 } | |
590 if (m_hash.contains(treeScope)) | |
591 return false; | |
592 | |
593 int end = m_treeScopes.size() - 1; | |
594 int start = 0; | |
595 int position = 0; | |
596 unsigned result = 0; | |
597 | |
598 while (start <= end) { | |
599 position = (start + end) / 2; | |
600 result = m_treeScopes[position]->comparePosition(*treeScope); | |
601 | |
602 if (result & Node::DOCUMENT_POSITION_PRECEDING) { | |
603 end = position - 1; | |
604 } else { | |
605 ASSERT(result & Node::DOCUMENT_POSITION_FOLLOWING); | |
606 start = position + 1; | |
607 } | |
608 } | |
609 | |
610 if (result & Node::DOCUMENT_POSITION_FOLLOWING) { | |
611 ++position; | |
612 ASSERT(static_cast<size_t>(position) == m_treeScopes.size() || (m_treeSc opes[position]->comparePosition(*treeScope) & Node::DOCUMENT_POSITION_PRECEDING) ); | |
613 } | |
614 m_treeScopes.insert(position, treeScope); | |
615 m_hash.add(treeScope); | |
616 | |
617 #if ENABLE(ASSERT) | |
618 // Check whether m_treeScopes is sorted in document order or not. | |
619 for (unsigned i = 0; i < m_treeScopes.size() - 1; ++i) { | |
620 unsigned result = m_treeScopes[i]->comparePosition(*m_treeScopes[i + 1]) ; | |
621 ASSERT(result & Node::DOCUMENT_POSITION_FOLLOWING); | |
622 } | |
623 #endif | |
624 return true; | |
625 } | |
626 | |
627 bool TreeScope::OrderedTreeScopeSet::remove(TreeScope* treeScope) | |
628 { | |
629 if (!m_hash.contains(treeScope)) | |
630 return false; | |
631 size_t position = m_treeScopes.find(treeScope); | |
632 m_treeScopes.remove(position); | |
633 m_hash.remove(treeScope); | |
634 return true; | |
635 } | |
636 | |
637 DEFINE_TRACE(TreeScope::OrderedTreeScopeSet) | |
638 { | |
639 #if ENABLE(OILPAN) | |
640 visitor->trace(m_treeScopes); | |
641 visitor->trace(m_hash); | |
642 #endif | |
643 } | |
644 | |
645 TreeScope::TreeScopesWithActiveStyleSheetsTraversal::TreeScopesWithActiveStyleSh eetsTraversal(TreeScope& treeScope) | |
646 : m_current(&treeScope), m_iterator(nullptr), m_end(nullptr) | |
647 { | |
648 skipIfNoStyleSheetCollection(); | |
649 } | |
650 | |
651 TreeScope::TreeScopesWithActiveStyleSheetsTraversal::TreeScopesWithActiveStyleSh eetsTraversal(OrderedTreeScopeSet& treeScopes) | |
652 : m_current(nullptr), m_iterator(treeScopes.begin()), m_end(treeScopes.end() ) | |
653 { | |
654 if (m_iterator != m_end) | |
655 m_current = *m_iterator; | |
656 skipIfNoStyleSheetCollection(); | |
657 } | |
658 | |
659 void TreeScope::TreeScopesWithActiveStyleSheetsTraversal::skipIfNoStyleSheetColl ection() | |
660 { | |
661 while (m_current && !m_current->styleSheetCollection()) | |
662 next(); | |
663 } | |
664 | |
665 void TreeScope::TreeScopesWithActiveStyleSheetsTraversal::nextWithStyleSheetColl ection() | |
666 { | |
667 do { | |
668 next(); | |
669 } while (m_current && !m_current->styleSheetCollection()); | |
670 } | |
671 | |
672 void TreeScope::TreeScopesWithActiveStyleSheetsTraversal::next() | |
673 { | |
674 if (!m_current) | |
675 return; | |
676 | |
677 OrderedTreeScopeSet& children = m_current->m_childTreeScopesWithActiveStyleS heets; | |
678 if (!children.isEmpty()) { | |
679 if (m_iterator) { | |
680 ++m_iterator; | |
681 if (m_iterator != m_end) | |
682 m_stack.append(std::make_pair(m_iterator, m_end)); | |
683 } | |
684 m_iterator = children.begin(); | |
685 m_end = children.end(); | |
686 ASSERT(m_iterator != m_end); | |
687 m_current = *m_iterator; | |
688 return; | |
689 } | |
690 | |
691 if (!m_iterator) { | |
692 m_current = nullptr; | |
693 return; | |
694 } | |
695 | |
696 ++m_iterator; | |
697 if (m_iterator != m_end) { | |
698 m_current = *m_iterator; | |
699 return; | |
700 } | |
701 | |
702 if (m_stack.isEmpty()) { | |
703 m_current = nullptr; | |
704 return; | |
705 } | |
706 | |
707 m_iterator = m_stack.last().first; | |
708 m_end = m_stack.last().second; | |
709 ASSERT(m_iterator != m_end); | |
710 m_stack.removeLast(); | |
711 m_current = *m_iterator; | |
712 } | |
713 | |
714 DEFINE_TRACE(TreeScope::TreeScopesWithActiveStyleSheetsTraversal) | |
715 { | |
716 #if ENABLE(OILPAN) | |
717 visitor->trace(m_current); | |
718 visitor->trace(m_iterator); | |
719 visitor->trace(m_end); | |
720 visitor->trace(m_stack); | |
721 #endif | |
722 } | |
723 | |
724 void TreeScope::insertToActiveStyleSheetsTraversal() | |
kochi
2015/05/26 01:52:34
nit: insertToActiveStyleSheetsTraversal() sounds a
kojii
2015/05/26 05:21:58
Changed to setSelfOrDescendantsHaveActiveStyleShee
| |
725 { | |
726 ASSERT(this != m_document); | |
727 for (TreeScope* treeScope = this;;) { | |
728 TreeScope* parent = treeScope->parentTreeScope(); | |
729 if (!parent) | |
730 break; | |
731 parent->m_childTreeScopesWithActiveStyleSheets.insert(treeScope); | |
732 treeScope->m_inActiveStyleSheetsTraversal = true; | |
kochi
2015/05/26 01:52:34
nit: maybe m_hasActiveStyleSheets? This also soun
kojii
2015/05/26 05:21:58
Changed to m_selfOrDescendantsHaveActiveStyleSheet
| |
733 | |
734 // Make sure to include parents so that we can traverse to this from the root treeScope. | |
735 treeScope = parent; | |
736 if (treeScope->m_inActiveStyleSheetsTraversal) | |
737 break; | |
738 } | |
739 } | |
740 | |
741 void TreeScope::removeFromActiveStyleSheetsTraversal() | |
kochi
2015/05/26 01:52:34
nit: ditto as insertToActiveStyleSheetsTraversal()
kojii
2015/05/26 05:21:58
Done.
| |
742 { | |
743 ASSERT(this != m_document); | |
744 ASSERT(parentTreeScope()); | |
745 ASSERT(m_inActiveStyleSheetsTraversal); | |
746 for (TreeScope* treeScope = this;;) { | |
747 TreeScope* parent = treeScope->parentTreeScope(); | |
748 if (!parent) | |
749 break; | |
750 parent->m_childTreeScopesWithActiveStyleSheets.remove(treeScope); | |
751 treeScope->m_inActiveStyleSheetsTraversal = false; | |
752 | |
753 // Remove parents if they were included only to traverse to this. | |
754 treeScope = parent; | |
755 if (!treeScope->m_inActiveStyleSheetsTraversal || !treeScope->m_childTre eScopesWithActiveStyleSheets.isEmpty()) | |
756 break; | |
757 } | |
758 } | |
759 | |
571 DEFINE_TRACE(TreeScope) | 760 DEFINE_TRACE(TreeScope) |
572 { | 761 { |
573 visitor->trace(m_rootNode); | 762 visitor->trace(m_rootNode); |
574 visitor->trace(m_document); | 763 visitor->trace(m_document); |
575 visitor->trace(m_parentTreeScope); | 764 visitor->trace(m_parentTreeScope); |
576 visitor->trace(m_idTargetObserverRegistry); | 765 visitor->trace(m_idTargetObserverRegistry); |
577 visitor->trace(m_selection); | 766 visitor->trace(m_selection); |
578 visitor->trace(m_elementsById); | 767 visitor->trace(m_elementsById); |
579 visitor->trace(m_imageMapsByName); | 768 visitor->trace(m_imageMapsByName); |
580 visitor->trace(m_labelsByForAttribute); | 769 visitor->trace(m_labelsByForAttribute); |
581 visitor->trace(m_scopedStyleResolver); | 770 visitor->trace(m_scopedStyleResolver); |
771 visitor->trace(m_childTreeScopesWithActiveStyleSheets); | |
582 } | 772 } |
583 | 773 |
584 } // namespace blink | 774 } // namespace blink |
OLD | NEW |