| 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 |
| 11 * contributors may be used to endorse or promote products derived from | 11 * contributors may be used to endorse or promote products derived from |
| 12 * this software without specific prior written permission. | 12 * this software without specific prior written permission. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 ElementShadowV0_h |
| 28 #define ElementShadow_h | 28 #define ElementShadowV0_h |
| 29 | 29 |
| 30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 31 #include "core/dom/shadow/InsertionPoint.h" | 31 #include "core/dom/shadow/InsertionPoint.h" |
| 32 #include "core/dom/shadow/SelectRuleFeatureSet.h" | 32 #include "core/dom/shadow/SelectRuleFeatureSet.h" |
| 33 #include "core/dom/shadow/ShadowRoot.h" | |
| 34 #include "platform/heap/Handle.h" | 33 #include "platform/heap/Handle.h" |
| 35 #include "wtf/HashMap.h" | |
| 36 #include "wtf/Noncopyable.h" | 34 #include "wtf/Noncopyable.h" |
| 37 | 35 |
| 38 namespace blink { | 36 namespace blink { |
| 39 | 37 |
| 40 class CORE_EXPORT ElementShadow final : public GarbageCollectedFinalized<Element
Shadow> { | 38 class CORE_EXPORT ElementShadowV0 final : public GarbageCollectedFinalized<Eleme
ntShadowV0> { |
| 41 WTF_MAKE_NONCOPYABLE(ElementShadow); | 39 WTF_MAKE_NONCOPYABLE(ElementShadowV0); |
| 42 public: | 40 public: |
| 43 static ElementShadow* create(); | 41 static ElementShadowV0* create(ElementShadow&); |
| 44 ~ElementShadow(); | 42 ~ElementShadowV0(); |
| 45 | 43 |
| 46 Element& host() const; | |
| 47 ShadowRoot& youngestShadowRoot() const; | |
| 48 ShadowRoot& oldestShadowRoot() const { DCHECK(m_shadowRoot); return *m_shado
wRoot; } | |
| 49 ElementShadow* containingShadow() const; | |
| 50 | |
| 51 ShadowRoot& addShadowRoot(Element& shadowHost, ShadowRootType); | |
| 52 | |
| 53 bool hasSameStyles(const ElementShadow*) const; | |
| 54 | |
| 55 void attach(const Node::AttachContext&); | |
| 56 void detach(const Node::AttachContext&); | |
| 57 | |
| 58 void distributeIfNeeded(); | |
| 59 void setNeedsDistributionRecalc(); | |
| 60 bool needsDistributionRecalc() const { return m_needsDistributionRecalc; } | |
| 61 | |
| 62 bool isV1() const { return youngestShadowRoot().isV1(); }; | |
| 63 bool isOpenOrV0() const { return youngestShadowRoot().isOpenOrV0(); }; | |
| 64 | |
| 65 // For only v0 | |
| 66 void willAffectSelector(); | 44 void willAffectSelector(); |
| 67 const SelectRuleFeatureSet& ensureSelectFeatureSet(); | 45 const SelectRuleFeatureSet& ensureSelectFeatureSet(); |
| 68 | 46 |
| 69 const InsertionPoint* finalDestinationInsertionPointFor(const Node*) const; | 47 const InsertionPoint* finalDestinationInsertionPointFor(const Node*) const; |
| 70 const DestinationInsertionPoints* destinationInsertionPointsFor(const Node*)
const; | 48 const DestinationInsertionPoints* destinationInsertionPointsFor(const Node*)
const; |
| 71 | 49 |
| 50 void distribute(); |
| 72 void didDistributeNode(const Node*, InsertionPoint*); | 51 void didDistributeNode(const Node*, InsertionPoint*); |
| 52 void clearDistribution(); |
| 73 | 53 |
| 74 DECLARE_TRACE(); | 54 DECLARE_TRACE(); |
| 75 DECLARE_TRACE_WRAPPERS(); | 55 DECLARE_TRACE_WRAPPERS(); |
| 76 | 56 |
| 77 private: | 57 private: |
| 78 ElementShadow(); | 58 explicit ElementShadowV0(ElementShadow&); |
| 79 | 59 |
| 80 void appendShadowRoot(ShadowRoot&); | 60 ShadowRoot& youngestShadowRoot() const; |
| 61 ShadowRoot& oldestShadowRoot() const; |
| 81 | 62 |
| 82 void distribute(); | |
| 83 void clearDistributionV0(); | |
| 84 | |
| 85 void distributeV0(); | |
| 86 void distributeV1(); | |
| 87 | |
| 88 void collectSelectFeatureSetFrom(ShadowRoot&); | |
| 89 void distributeNodeChildrenTo(InsertionPoint*, ContainerNode*); | 63 void distributeNodeChildrenTo(InsertionPoint*, ContainerNode*); |
| 90 | 64 |
| 65 void collectSelectFeatureSetFrom(const ShadowRoot&); |
| 91 bool needsSelectFeatureSet() const { return m_needsSelectFeatureSet; } | 66 bool needsSelectFeatureSet() const { return m_needsSelectFeatureSet; } |
| 92 void setNeedsSelectFeatureSet() { m_needsSelectFeatureSet = true; } | 67 void setNeedsSelectFeatureSet() { m_needsSelectFeatureSet = true; } |
| 93 | 68 |
| 94 Member<ShadowRoot> m_shadowRoot; | 69 Member<ElementShadow> m_elementShadow; |
| 95 bool m_needsDistributionRecalc; | |
| 96 | |
| 97 // For only v0 | |
| 98 using NodeToDestinationInsertionPoints = HeapHashMap<Member<const Node>, Mem
ber<DestinationInsertionPoints>>; | 70 using NodeToDestinationInsertionPoints = HeapHashMap<Member<const Node>, Mem
ber<DestinationInsertionPoints>>; |
| 99 NodeToDestinationInsertionPoints m_nodeToInsertionPoints; | 71 NodeToDestinationInsertionPoints m_nodeToInsertionPoints; |
| 100 SelectRuleFeatureSet m_selectFeatures; | 72 SelectRuleFeatureSet m_selectFeatures; |
| 101 bool m_needsSelectFeatureSet; | 73 bool m_needsSelectFeatureSet; |
| 102 }; | 74 }; |
| 103 | 75 |
| 104 inline Element& ElementShadow::host() const | |
| 105 { | |
| 106 DCHECK(m_shadowRoot); | |
| 107 return m_shadowRoot->host(); | |
| 108 } | |
| 109 | |
| 110 inline ShadowRoot* Node::youngestShadowRoot() const | |
| 111 { | |
| 112 if (!isElementNode()) | |
| 113 return 0; | |
| 114 return toElement(this)->youngestShadowRoot(); | |
| 115 } | |
| 116 | |
| 117 inline ShadowRoot* Element::youngestShadowRoot() const | |
| 118 { | |
| 119 if (ElementShadow* shadow = this->shadow()) | |
| 120 return &shadow->youngestShadowRoot(); | |
| 121 return 0; | |
| 122 } | |
| 123 | |
| 124 inline ElementShadow* ElementShadow::containingShadow() const | |
| 125 { | |
| 126 if (ShadowRoot* parentRoot = host().containingShadowRoot()) | |
| 127 return parentRoot->owner(); | |
| 128 return 0; | |
| 129 } | |
| 130 | |
| 131 inline void ElementShadow::distributeIfNeeded() | |
| 132 { | |
| 133 if (m_needsDistributionRecalc) | |
| 134 distribute(); | |
| 135 m_needsDistributionRecalc = false; | |
| 136 } | |
| 137 | |
| 138 } // namespace blink | 76 } // namespace blink |
| 139 | 77 |
| 140 #endif | 78 #endif |
| OLD | NEW |