Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: Source/core/dom/shadow/ElementShadow.h

Issue 23133006: Merge ContentDistributor into ElementShadow (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Don't find git copies Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/shadow/ContentDistributor.cpp ('k') | Source/core/dom/shadow/ElementShadow.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ElementShadow_h
28 #define ElementShadow_h 28 #define ElementShadow_h
29 29
30 #include "core/dom/shadow/ContentDistributor.h" 30 #include "core/dom/shadow/SelectRuleFeatureSet.h"
31 #include "core/dom/shadow/ShadowRoot.h" 31 #include "core/dom/shadow/ShadowRoot.h"
32 #include "wtf/DoublyLinkedList.h" 32 #include "wtf/DoublyLinkedList.h"
33 #include "wtf/Forward.h"
34 #include "wtf/HashMap.h"
33 #include "wtf/Noncopyable.h" 35 #include "wtf/Noncopyable.h"
34 #include "wtf/PassOwnPtr.h" 36 #include "wtf/PassOwnPtr.h"
35 #include "wtf/Vector.h" 37 #include "wtf/Vector.h"
36 38
37 namespace WebCore { 39 namespace WebCore {
38 40
41 class InsertionPoint;
42
39 class ElementShadow { 43 class ElementShadow {
40 WTF_MAKE_NONCOPYABLE(ElementShadow); WTF_MAKE_FAST_ALLOCATED; 44 WTF_MAKE_NONCOPYABLE(ElementShadow); WTF_MAKE_FAST_ALLOCATED;
41 public: 45 public:
42 static PassOwnPtr<ElementShadow> create() 46 static PassOwnPtr<ElementShadow> create();
43 { 47 ~ElementShadow();
44 return adoptPtr(new ElementShadow());
45 }
46
47 ~ElementShadow()
48 {
49 removeAllShadowRoots();
50 }
51 48
52 Element* host() const; 49 Element* host() const;
53 ShadowRoot* youngestShadowRoot() const { return m_shadowRoots.head(); } 50 ShadowRoot* youngestShadowRoot() const { return m_shadowRoots.head(); }
54 ShadowRoot* oldestShadowRoot() const { return m_shadowRoots.tail(); } 51 ShadowRoot* oldestShadowRoot() const { return m_shadowRoots.tail(); }
55 ElementShadow* containingShadow() const; 52 ElementShadow* containingShadow() const;
56 53
57 ShadowRoot* addShadowRoot(Element* shadowHost, ShadowRoot::ShadowRootType); 54 ShadowRoot* addShadowRoot(Element* shadowHost, ShadowRoot::ShadowRootType);
55
58 bool applyAuthorStyles() const { return m_applyAuthorStyles; } 56 bool applyAuthorStyles() const { return m_applyAuthorStyles; }
57 bool didAffectApplyAuthorStyles();
58 bool containsActiveStyles() const;
59 59
60 void attach(const Node::AttachContext&); 60 void attach(const Node::AttachContext&);
61 void detach(const Node::AttachContext&); 61 void detach(const Node::AttachContext&);
62 62
63 void removeAllEventListeners(); 63 void removeAllEventListeners();
64 64
65 void didAffectSelector(AffectedSelectorMask mask) { m_distributor.didAffectS elector(host(), mask); } 65 void didAffectSelector(AffectedSelectorMask);
66 void willAffectSelector() { m_distributor.willAffectSelector(host()); } 66 void willAffectSelector();
67 const SelectRuleFeatureSet& ensureSelectFeatureSet() { return m_distributor. ensureSelectFeatureSet(this); } 67 const SelectRuleFeatureSet& ensureSelectFeatureSet();
68 68
69 // FIXME: Move all callers of this to APIs on ElementShadow and remove it. 69 void distributeIfNeeded();
70 ContentDistributor& distributor() { return m_distributor; }
71 const ContentDistributor& distributor() const { return m_distributor; }
72
73 void distributeIfNeeded()
74 {
75 if (m_needsDistributionRecalc)
76 m_distributor.distribute(host());
77 m_needsDistributionRecalc = false;
78 }
79 void clearDistribution() { m_distributor.clearDistribution(host()); }
80
81 void setNeedsDistributionRecalc(); 70 void setNeedsDistributionRecalc();
82 71
83 bool didAffectApplyAuthorStyles(); 72 InsertionPoint* findInsertionPointFor(const Node*) const;
84 bool containsActiveStyles() const;
85 73
86 private: 74 private:
87 ElementShadow() 75 ElementShadow();
88 : m_needsDistributionRecalc(false)
89 , m_applyAuthorStyles(false)
90 { }
91 76
92 void removeAllShadowRoots(); 77 void removeAllShadowRoots();
93 bool resolveApplyAuthorStyles() const; 78 bool resolveApplyAuthorStyles() const;
94 79
80 void distribute();
81 void clearDistribution();
82 void populate(Node*, Vector<Node*>&);
83 void collectSelectFeatureSetFrom(ShadowRoot*);
84 void distributeSelectionsTo(InsertionPoint*, const Vector<Node*>& pool, Vect or<bool>& distributed);
85 void distributeNodeChildrenTo(InsertionPoint*, ContainerNode*);
86
87 bool needsSelectFeatureSet() const { return m_needsSelectFeatureSet; }
88 void setNeedsSelectFeatureSet() { m_needsSelectFeatureSet = true; }
89
90 HashMap<const Node*, RefPtr<InsertionPoint> > m_nodeToInsertionPoint;
91 SelectRuleFeatureSet m_selectFeatures;
95 DoublyLinkedList<ShadowRoot> m_shadowRoots; 92 DoublyLinkedList<ShadowRoot> m_shadowRoots;
96 ContentDistributor m_distributor;
97 bool m_needsDistributionRecalc; 93 bool m_needsDistributionRecalc;
98 bool m_applyAuthorStyles; 94 bool m_applyAuthorStyles;
95 bool m_needsSelectFeatureSet;
gmorrita 2013/08/16 05:26:01 It's time to switch bitfields!
99 }; 96 };
100 97
101 inline Element* ElementShadow::host() const 98 inline Element* ElementShadow::host() const
102 { 99 {
103 ASSERT(!m_shadowRoots.isEmpty()); 100 ASSERT(!m_shadowRoots.isEmpty());
104 return youngestShadowRoot()->host(); 101 return youngestShadowRoot()->host();
105 } 102 }
106 103
107 inline ShadowRoot* Node::youngestShadowRoot() const 104 inline ShadowRoot* Node::youngestShadowRoot() const
108 { 105 {
109 if (!this->isElementNode()) 106 if (!this->isElementNode())
110 return 0; 107 return 0;
111 if (ElementShadow* shadow = toElement(this)->shadow()) 108 if (ElementShadow* shadow = toElement(this)->shadow())
112 return shadow->youngestShadowRoot(); 109 return shadow->youngestShadowRoot();
113 return 0; 110 return 0;
114 } 111 }
115 112
116 inline ElementShadow* ElementShadow::containingShadow() const 113 inline ElementShadow* ElementShadow::containingShadow() const
117 { 114 {
118 if (ShadowRoot* parentRoot = host()->containingShadowRoot()) 115 if (ShadowRoot* parentRoot = host()->containingShadowRoot())
119 return parentRoot->owner(); 116 return parentRoot->owner();
120 return 0; 117 return 0;
121 } 118 }
122 119
123 class ShadowRootVector : public Vector<RefPtr<ShadowRoot> > { 120 inline void ElementShadow::distributeIfNeeded()
124 public: 121 {
125 explicit ShadowRootVector(ElementShadow* tree) 122 if (m_needsDistributionRecalc)
126 { 123 distribute();
127 for (ShadowRoot* root = tree->youngestShadowRoot(); root; root = root->o lderShadowRoot()) 124 m_needsDistributionRecalc = false;
128 append(root); 125 }
129 }
130 };
131 126
132 inline ElementShadow* shadowOfParent(const Node* node) 127 inline ElementShadow* shadowOfParent(const Node* node)
133 { 128 {
134 if (!node) 129 if (!node)
135 return 0; 130 return 0;
136 if (Node* parent = node->parentNode()) 131 if (Node* parent = node->parentNode())
137 if (parent->isElementNode()) 132 if (parent->isElementNode())
138 return toElement(parent)->shadow(); 133 return toElement(parent)->shadow();
139 return 0; 134 return 0;
140 } 135 }
141 136
142
143 } // namespace 137 } // namespace
144 138
145 #endif 139 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/shadow/ContentDistributor.cpp ('k') | Source/core/dom/shadow/ElementShadow.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698