Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / shadow / InsertionPoint.h
1 /*
2  * Copyright (C) 2012 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 InsertionPoint_h
32 #define InsertionPoint_h
33
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"
38
39 namespace blink {
40
41 class InsertionPoint : public HTMLElement {
42 public:
43     virtual ~InsertionPoint();
44
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;
50
51     bool isShadowInsertionPoint() const;
52     bool isContentInsertionPoint() const;
53
54     PassRefPtrWillBeRawPtr<StaticNodeList> getDistributedNodes();
55
56     virtual bool canAffectSelector() const { return false; }
57
58     virtual void attach(const AttachContext& = AttachContext()) override;
59     virtual void detach(const AttachContext& = AttachContext()) override;
60
61     bool shouldUseFallbackElements() const;
62
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); }
69
70     virtual void trace(Visitor*) override;
71
72 protected:
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;
79
80 private:
81     bool isInsertionPoint() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
82
83     ContentDistribution m_distribution;
84     bool m_registeredWithShadowRoot;
85 };
86
87 typedef WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> > DestinationInsertionPoints;
88
89 DEFINE_ELEMENT_TYPE_CASTS(InsertionPoint, isInsertionPoint());
90
91 inline bool isActiveInsertionPoint(const Node& node)
92 {
93     return node.isInsertionPoint() && toInsertionPoint(node).isActive();
94 }
95
96 inline bool isActiveShadowInsertionPoint(const Node& node)
97 {
98     return node.isInsertionPoint() && toInsertionPoint(node).isShadowInsertionPoint();
99 }
100
101 inline ElementShadow* shadowWhereNodeCanBeDistributed(const Node& node)
102 {
103     Node* parent = node.parentNode();
104     if (!parent)
105         return 0;
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();
112     return 0;
113 }
114
115 const InsertionPoint* resolveReprojection(const Node*);
116
117 void collectDestinationInsertionPoints(const Node&, WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8>& results);
118
119 } // namespace blink
120
121 #endif // InsertionPoint_h