| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef ElementShadow_h | 27 #ifndef ElementShadow_h |
| 28 #define ElementShadow_h | 28 #define ElementShadow_h |
| 29 | 29 |
| 30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 31 #include "core/dom/shadow/InsertionPoint.h" | |
| 32 #include "core/dom/shadow/SelectRuleFeatureSet.h" | |
| 33 #include "core/dom/shadow/ShadowRoot.h" | 31 #include "core/dom/shadow/ShadowRoot.h" |
| 34 #include "platform/heap/Handle.h" | 32 #include "platform/heap/Handle.h" |
| 35 #include "wtf/HashMap.h" | |
| 36 #include "wtf/Noncopyable.h" | 33 #include "wtf/Noncopyable.h" |
| 37 | 34 |
| 38 namespace blink { | 35 namespace blink { |
| 39 | 36 |
| 37 class ElementShadowV0; |
| 38 |
| 40 class CORE_EXPORT ElementShadow final : public GarbageCollectedFinalized<Element
Shadow> { | 39 class CORE_EXPORT ElementShadow final : public GarbageCollectedFinalized<Element
Shadow> { |
| 41 WTF_MAKE_NONCOPYABLE(ElementShadow); | 40 WTF_MAKE_NONCOPYABLE(ElementShadow); |
| 42 public: | 41 public: |
| 43 static ElementShadow* create(); | 42 static ElementShadow* create(); |
| 44 ~ElementShadow(); | 43 ~ElementShadow(); |
| 45 | 44 |
| 46 Element& host() const; | 45 Element& host() const { DCHECK(m_shadowRoot); return m_shadowRoot->host(); } |
| 46 |
| 47 // TODO(hayato): Remove youngestShadowRoot() and oldestShadowRoot() from Ele
mentShadow |
| 47 ShadowRoot& youngestShadowRoot() const; | 48 ShadowRoot& youngestShadowRoot() const; |
| 48 ShadowRoot& oldestShadowRoot() const { DCHECK(m_shadowRoot); return *m_shado
wRoot; } | 49 ShadowRoot& oldestShadowRoot() const { DCHECK(m_shadowRoot); return *m_shado
wRoot; } |
| 50 |
| 49 ElementShadow* containingShadow() const; | 51 ElementShadow* containingShadow() const; |
| 50 | 52 |
| 51 ShadowRoot& addShadowRoot(Element& shadowHost, ShadowRootType); | 53 ShadowRoot& addShadowRoot(Element& shadowHost, ShadowRootType); |
| 52 | 54 |
| 53 bool hasSameStyles(const ElementShadow*) const; | 55 bool hasSameStyles(const ElementShadow&) const; |
| 54 | 56 |
| 55 void attach(const Node::AttachContext&); | 57 void attach(const Node::AttachContext&); |
| 56 void detach(const Node::AttachContext&); | 58 void detach(const Node::AttachContext&); |
| 57 | 59 |
| 58 void distributeIfNeeded(); | 60 void distributeIfNeeded(); |
| 61 |
| 59 void setNeedsDistributionRecalc(); | 62 void setNeedsDistributionRecalc(); |
| 60 bool needsDistributionRecalc() const { return m_needsDistributionRecalc; } | 63 bool needsDistributionRecalc() const { return m_needsDistributionRecalc; } |
| 61 | 64 |
| 62 bool isV1() const { return youngestShadowRoot().isV1(); }; | 65 bool isV1() const { return youngestShadowRoot().isV1(); } |
| 63 bool isOpenOrV0() const { return youngestShadowRoot().isOpenOrV0(); }; | 66 bool isOpenOrV0() const { return youngestShadowRoot().isOpenOrV0(); } |
| 64 | 67 |
| 65 // For only v0 | 68 ElementShadowV0& v0() const { DCHECK(m_elementShadowV0); return *m_elementSh
adowV0; } |
| 66 void willAffectSelector(); | |
| 67 const SelectRuleFeatureSet& ensureSelectFeatureSet(); | |
| 68 | |
| 69 const InsertionPoint* finalDestinationInsertionPointFor(const Node*) const; | |
| 70 const DestinationInsertionPoints* destinationInsertionPointsFor(const Node*)
const; | |
| 71 | |
| 72 void didDistributeNode(const Node*, InsertionPoint*); | |
| 73 | 69 |
| 74 DECLARE_TRACE(); | 70 DECLARE_TRACE(); |
| 75 DECLARE_TRACE_WRAPPERS(); | 71 DECLARE_TRACE_WRAPPERS(); |
| 76 | 72 |
| 77 private: | 73 private: |
| 78 ElementShadow(); | 74 ElementShadow(); |
| 79 | 75 |
| 80 void appendShadowRoot(ShadowRoot&); | 76 void appendShadowRoot(ShadowRoot&); |
| 77 void distribute(); |
| 81 | 78 |
| 82 void distribute(); | 79 Member<ElementShadowV0> m_elementShadowV0; |
| 83 void clearDistributionV0(); | |
| 84 | |
| 85 void distributeV0(); | |
| 86 void distributeV1(); | |
| 87 | |
| 88 void collectSelectFeatureSetFrom(ShadowRoot&); | |
| 89 void distributeNodeChildrenTo(InsertionPoint*, ContainerNode*); | |
| 90 | |
| 91 bool needsSelectFeatureSet() const { return m_needsSelectFeatureSet; } | |
| 92 void setNeedsSelectFeatureSet() { m_needsSelectFeatureSet = true; } | |
| 93 | |
| 94 Member<ShadowRoot> m_shadowRoot; | 80 Member<ShadowRoot> m_shadowRoot; |
| 95 bool m_needsDistributionRecalc; | 81 bool m_needsDistributionRecalc; |
| 96 | |
| 97 // For only v0 | |
| 98 using NodeToDestinationInsertionPoints = HeapHashMap<Member<const Node>, Mem
ber<DestinationInsertionPoints>>; | |
| 99 NodeToDestinationInsertionPoints m_nodeToInsertionPoints; | |
| 100 SelectRuleFeatureSet m_selectFeatures; | |
| 101 bool m_needsSelectFeatureSet; | |
| 102 }; | 82 }; |
| 103 | 83 |
| 104 inline Element& ElementShadow::host() const | |
| 105 { | |
| 106 DCHECK(m_shadowRoot); | |
| 107 return m_shadowRoot->host(); | |
| 108 } | |
| 109 | |
| 110 inline ShadowRoot* Node::youngestShadowRoot() const | 84 inline ShadowRoot* Node::youngestShadowRoot() const |
| 111 { | 85 { |
| 112 if (!isElementNode()) | 86 if (!isElementNode()) |
| 113 return 0; | 87 return nullptr; |
| 114 return toElement(this)->youngestShadowRoot(); | 88 return toElement(this)->youngestShadowRoot(); |
| 115 } | 89 } |
| 116 | 90 |
| 117 inline ShadowRoot* Element::youngestShadowRoot() const | 91 inline ShadowRoot* Element::youngestShadowRoot() const |
| 118 { | 92 { |
| 119 if (ElementShadow* shadow = this->shadow()) | 93 if (ElementShadow* shadow = this->shadow()) |
| 120 return &shadow->youngestShadowRoot(); | 94 return &shadow->youngestShadowRoot(); |
| 121 return 0; | 95 return nullptr; |
| 122 } | 96 } |
| 123 | 97 |
| 124 inline ElementShadow* ElementShadow::containingShadow() const | 98 inline ElementShadow* ElementShadow::containingShadow() const |
| 125 { | 99 { |
| 126 if (ShadowRoot* parentRoot = host().containingShadowRoot()) | 100 if (ShadowRoot* parentRoot = host().containingShadowRoot()) |
| 127 return parentRoot->owner(); | 101 return parentRoot->owner(); |
| 128 return 0; | 102 return nullptr; |
| 129 } | 103 } |
| 130 | 104 |
| 131 inline void ElementShadow::distributeIfNeeded() | 105 inline void ElementShadow::distributeIfNeeded() |
| 132 { | 106 { |
| 133 if (m_needsDistributionRecalc) | 107 if (m_needsDistributionRecalc) |
| 134 distribute(); | 108 distribute(); |
| 135 m_needsDistributionRecalc = false; | 109 m_needsDistributionRecalc = false; |
| 136 } | 110 } |
| 137 | 111 |
| 138 } // namespace blink | 112 } // namespace blink |
| 139 | 113 |
| 140 #endif | 114 #endif |
| OLD | NEW |