| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef ContentDistributor_h | |
| 32 #define ContentDistributor_h | |
| 33 | |
| 34 #include "core/dom/shadow/SelectRuleFeatureSet.h" | |
| 35 #include "wtf/Forward.h" | |
| 36 #include "wtf/HashMap.h" | |
| 37 #include "wtf/Vector.h" | |
| 38 | |
| 39 namespace WebCore { | |
| 40 | |
| 41 class ContainerNode; | |
| 42 class Element; | |
| 43 class InsertionPoint; | |
| 44 class Node; | |
| 45 class ShadowRoot; | |
| 46 | |
| 47 class ContentDistribution { | |
| 48 public: | |
| 49 PassRefPtr<Node> first() const { return m_nodes.first(); } | |
| 50 PassRefPtr<Node> last() const { return m_nodes.last(); } | |
| 51 PassRefPtr<Node> at(size_t index) const { return m_nodes.at(index); } | |
| 52 | |
| 53 size_t size() const { return m_nodes.size(); } | |
| 54 bool isEmpty() const { return m_nodes.isEmpty(); } | |
| 55 | |
| 56 void append(PassRefPtr<Node>); | |
| 57 void clear() { m_nodes.clear(); m_indices.clear(); } | |
| 58 | |
| 59 bool contains(const Node* node) const { return m_indices.contains(node); } | |
| 60 size_t find(const Node*) const; | |
| 61 Node* nextTo(const Node*) const; | |
| 62 Node* previousTo(const Node*) const; | |
| 63 | |
| 64 void swap(ContentDistribution& other); | |
| 65 | |
| 66 const Vector<RefPtr<Node> >& nodes() const { return m_nodes; } | |
| 67 | |
| 68 private: | |
| 69 Vector<RefPtr<Node> > m_nodes; | |
| 70 HashMap<const Node*, size_t> m_indices; | |
| 71 }; | |
| 72 | |
| 73 class ScopeContentDistribution { | |
| 74 public: | |
| 75 ScopeContentDistribution(); | |
| 76 | |
| 77 InsertionPoint* insertionPointAssignedTo() const { return m_insertionPointAs
signedTo.get(); } | |
| 78 void setInsertionPointAssignedTo(PassRefPtr<InsertionPoint>); | |
| 79 | |
| 80 void registerInsertionPoint(InsertionPoint*); | |
| 81 void unregisterInsertionPoint(InsertionPoint*); | |
| 82 bool hasShadowElementChildren() const { return m_numberOfShadowElementChildr
en > 0; } | |
| 83 bool hasContentElementChildren() const { return m_numberOfContentElementChil
dren > 0; } | |
| 84 | |
| 85 void registerElementShadow() { ++m_numberOfElementShadowChildren; } | |
| 86 void unregisterElementShadow() { ASSERT(m_numberOfElementShadowChildren > 0)
; --m_numberOfElementShadowChildren; } | |
| 87 unsigned numberOfElementShadowChildren() const { return m_numberOfElementSha
dowChildren; } | |
| 88 bool hasElementShadowChildren() const { return m_numberOfElementShadowChildr
en > 0; } | |
| 89 | |
| 90 void invalidateInsertionPointList(); | |
| 91 const Vector<RefPtr<InsertionPoint> >& ensureInsertionPointList(ShadowRoot*)
; | |
| 92 | |
| 93 private: | |
| 94 RefPtr<InsertionPoint> m_insertionPointAssignedTo; | |
| 95 unsigned m_numberOfShadowElementChildren; | |
| 96 unsigned m_numberOfContentElementChildren; | |
| 97 unsigned m_numberOfElementShadowChildren; | |
| 98 bool m_insertionPointListIsValid; | |
| 99 Vector<RefPtr<InsertionPoint> > m_insertionPointList; | |
| 100 }; | |
| 101 | |
| 102 class ContentDistributor { | |
| 103 WTF_MAKE_NONCOPYABLE(ContentDistributor); | |
| 104 public: | |
| 105 ContentDistributor(); | |
| 106 ~ContentDistributor(); | |
| 107 | |
| 108 InsertionPoint* findInsertionPointFor(const Node* key) const; | |
| 109 const SelectRuleFeatureSet& ensureSelectFeatureSet(ElementShadow*); | |
| 110 | |
| 111 void distributeSelectionsTo(InsertionPoint*, const Vector<Node*>& pool, Vect
or<bool>& distributed); | |
| 112 void distributeNodeChildrenTo(InsertionPoint*, ContainerNode*); | |
| 113 | |
| 114 void didAffectSelector(Element* host, AffectedSelectorMask); | |
| 115 void willAffectSelector(Element* host); | |
| 116 | |
| 117 void distribute(Element* host); | |
| 118 void clearDistribution(Element* host); | |
| 119 | |
| 120 private: | |
| 121 void populate(Node*, Vector<Node*>&); | |
| 122 | |
| 123 void collectSelectFeatureSetFrom(ShadowRoot*); | |
| 124 bool needsSelectFeatureSet() const { return m_needsSelectFeatureSet; } | |
| 125 void setNeedsSelectFeatureSet() { m_needsSelectFeatureSet = true; } | |
| 126 | |
| 127 typedef HashMap<const Node*, RefPtr<InsertionPoint> > NodeInsertionPointMap; | |
| 128 NodeInsertionPointMap m_nodeToInsertionPoint; | |
| 129 SelectRuleFeatureSet m_selectFeatures; | |
| 130 bool m_needsSelectFeatureSet; | |
| 131 }; | |
| 132 | |
| 133 } | |
| 134 | |
| 135 #endif | |
| OLD | NEW |