2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef InsertionPoint_h
32 #define InsertionPoint_h
34 #include "core/css/CSSSelectorList.h"
35 #include "core/dom/shadow/ContentDistribution.h"
36 #include "core/dom/shadow/ShadowRoot.h"
37 #include "core/html/HTMLElement.h"
41 class InsertionPoint : public HTMLElement {
43 virtual ~InsertionPoint();
45 bool hasDistribution() const { return !m_distribution.isEmpty(); }
46 void setDistribution(ContentDistribution&);
47 void clearDistribution() { m_distribution.clear(); }
48 bool isActive() const;
49 bool canBeActive() const;
51 bool isShadowInsertionPoint() const;
52 bool isContentInsertionPoint() const;
54 PassRefPtrWillBeRawPtr<StaticNodeList> getDistributedNodes();
56 virtual bool canAffectSelector() const { return false; }
58 virtual void attach(const AttachContext& = AttachContext()) override;
59 virtual void detach(const AttachContext& = AttachContext()) override;
61 bool shouldUseFallbackElements() const;
63 size_t size() const { return m_distribution.size(); }
64 Node* at(size_t index) const { return m_distribution.at(index).get(); }
65 Node* first() const { return m_distribution.isEmpty() ? 0 : m_distribution.first().get(); }
66 Node* last() const { return m_distribution.isEmpty() ? 0 : m_distribution.last().get(); }
67 Node* nextTo(const Node* node) const { return m_distribution.nextTo(node); }
68 Node* previousTo(const Node* node) const { return m_distribution.previousTo(node); }
70 virtual void trace(Visitor*) override;
73 InsertionPoint(const QualifiedName&, Document&);
74 virtual bool rendererIsNeeded(const RenderStyle&) override;
75 virtual void childrenChanged(const ChildrenChange&) override;
76 virtual InsertionNotificationRequest insertedInto(ContainerNode*) override;
77 virtual void removedFrom(ContainerNode*) override;
78 virtual void willRecalcStyle(StyleRecalcChange) override;
81 bool isInsertionPoint() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
83 ContentDistribution m_distribution;
84 bool m_registeredWithShadowRoot;
87 typedef WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> > DestinationInsertionPoints;
89 DEFINE_ELEMENT_TYPE_CASTS(InsertionPoint, isInsertionPoint());
91 inline bool isActiveInsertionPoint(const Node& node)
93 return node.isInsertionPoint() && toInsertionPoint(node).isActive();
96 inline bool isActiveShadowInsertionPoint(const Node& node)
98 return node.isInsertionPoint() && toInsertionPoint(node).isShadowInsertionPoint();
101 inline ElementShadow* shadowWhereNodeCanBeDistributed(const Node& node)
103 Node* parent = node.parentNode();
106 if (parent->isShadowRoot() && !toShadowRoot(parent)->isYoungest())
107 return node.shadowHost()->shadow();
108 if (isActiveInsertionPoint(*parent))
109 return node.shadowHost()->shadow();
110 if (parent->isElementNode())
111 return toElement(parent)->shadow();
115 const InsertionPoint* resolveReprojection(const Node*);
117 void collectDestinationInsertionPoints(const Node&, WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8>& results);
121 #endif // InsertionPoint_h