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

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

Issue 2322213002: Refactor ElementShadow by separating v0 related features as ElementShadowV0 (Closed)
Patch Set: minor Created 4 years, 3 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
OLDNEW
1 /* 1 // Copyright 2016 The Chromium Authors. All rights reserved.
tkent 2016/09/13 07:09:45 To me this file doesn't look a new file. Probably
hayato 2016/09/13 07:14:56 Sure. Done.
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be
3 * 3 // found in the LICENSE file.
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 * * Neither the name of Google Inc. nor the names of its
11 * contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
25 */
26 4
27 #ifndef ElementShadow_h 5 #ifndef ElementShadow_h
28 #define ElementShadow_h 6 #define ElementShadow_h
29 7
30 #include "core/CoreExport.h" 8 #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" 9 #include "core/dom/shadow/ShadowRoot.h"
34 #include "platform/heap/Handle.h" 10 #include "platform/heap/Handle.h"
35 #include "wtf/HashMap.h"
36 #include "wtf/Noncopyable.h" 11 #include "wtf/Noncopyable.h"
37 12
38 namespace blink { 13 namespace blink {
39 14
15 class ElementShadowV0;
16
40 class CORE_EXPORT ElementShadow final : public GarbageCollectedFinalized<Element Shadow> { 17 class CORE_EXPORT ElementShadow final : public GarbageCollectedFinalized<Element Shadow> {
41 WTF_MAKE_NONCOPYABLE(ElementShadow); 18 WTF_MAKE_NONCOPYABLE(ElementShadow);
42 public: 19 public:
43 static ElementShadow* create(); 20 static ElementShadow* create();
44 ~ElementShadow(); 21 ~ElementShadow();
45 22
46 Element& host() const; 23 Element& host() const { DCHECK(m_shadowRoot); return m_shadowRoot->host(); }
24
25 // TODO(hayato): Remove youngestShadowRoot() and oldestShadowRoot() from Ele mentShadow
47 ShadowRoot& youngestShadowRoot() const; 26 ShadowRoot& youngestShadowRoot() const;
48 ShadowRoot& oldestShadowRoot() const { DCHECK(m_shadowRoot); return *m_shado wRoot; } 27 ShadowRoot& oldestShadowRoot() const { DCHECK(m_shadowRoot); return *m_shado wRoot; }
28
49 ElementShadow* containingShadow() const; 29 ElementShadow* containingShadow() const;
50 30
51 ShadowRoot& addShadowRoot(Element& shadowHost, ShadowRootType); 31 ShadowRoot& addShadowRoot(Element& shadowHost, ShadowRootType);
52 32
53 bool hasSameStyles(const ElementShadow*) const; 33 bool hasSameStyles(const ElementShadow&) const;
54 34
55 void attach(const Node::AttachContext&); 35 void attach(const Node::AttachContext&);
56 void detach(const Node::AttachContext&); 36 void detach(const Node::AttachContext&);
57 37
58 void distributeIfNeeded(); 38 void distributeIfNeeded();
39
59 void setNeedsDistributionRecalc(); 40 void setNeedsDistributionRecalc();
60 bool needsDistributionRecalc() const { return m_needsDistributionRecalc; } 41 bool needsDistributionRecalc() const { return m_needsDistributionRecalc; }
61 42
62 bool isV1() const { return youngestShadowRoot().isV1(); }; 43 bool isV1() const { return youngestShadowRoot().isV1(); }
63 bool isOpenOrV0() const { return youngestShadowRoot().isOpenOrV0(); }; 44 bool isOpenOrV0() const { return youngestShadowRoot().isOpenOrV0(); }
64 45
65 // For only v0 46 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 47
74 DECLARE_TRACE(); 48 DECLARE_TRACE();
75 DECLARE_TRACE_WRAPPERS(); 49 DECLARE_TRACE_WRAPPERS();
76 50
77 private: 51 private:
78 ElementShadow(); 52 ElementShadow();
79 53
80 void appendShadowRoot(ShadowRoot&); 54 void appendShadowRoot(ShadowRoot&);
55 void distribute();
81 56
82 void distribute(); 57 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; 58 Member<ShadowRoot> m_shadowRoot;
95 bool m_needsDistributionRecalc; 59 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 }; 60 };
103 61
104 inline Element& ElementShadow::host() const
105 {
106 DCHECK(m_shadowRoot);
107 return m_shadowRoot->host();
108 }
109
110 inline ShadowRoot* Node::youngestShadowRoot() const 62 inline ShadowRoot* Node::youngestShadowRoot() const
111 { 63 {
112 if (!isElementNode()) 64 if (!isElementNode())
113 return 0; 65 return nullptr;
114 return toElement(this)->youngestShadowRoot(); 66 return toElement(this)->youngestShadowRoot();
115 } 67 }
116 68
117 inline ShadowRoot* Element::youngestShadowRoot() const 69 inline ShadowRoot* Element::youngestShadowRoot() const
118 { 70 {
119 if (ElementShadow* shadow = this->shadow()) 71 if (ElementShadow* shadow = this->shadow())
120 return &shadow->youngestShadowRoot(); 72 return &shadow->youngestShadowRoot();
121 return 0; 73 return nullptr;
122 } 74 }
123 75
124 inline ElementShadow* ElementShadow::containingShadow() const 76 inline ElementShadow* ElementShadow::containingShadow() const
125 { 77 {
126 if (ShadowRoot* parentRoot = host().containingShadowRoot()) 78 if (ShadowRoot* parentRoot = host().containingShadowRoot())
127 return parentRoot->owner(); 79 return parentRoot->owner();
128 return 0; 80 return nullptr;
129 } 81 }
130 82
131 inline void ElementShadow::distributeIfNeeded() 83 inline void ElementShadow::distributeIfNeeded()
132 { 84 {
133 if (m_needsDistributionRecalc) 85 if (m_needsDistributionRecalc)
134 distribute(); 86 distribute();
135 m_needsDistributionRecalc = false; 87 m_needsDistributionRecalc = false;
136 } 88 }
137 89
138 } // namespace blink 90 } // namespace blink
139 91
140 #endif 92 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698