Fix picker popup layout
[framework/web/webkit-efl.git] / Source / WebCore / dom / ShadowRoot.h
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  *     * 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
27 #ifndef ShadowRoot_h
28 #define ShadowRoot_h
29
30 #include "ContainerNode.h"
31 #include "Document.h"
32 #include "DocumentFragment.h"
33 #include "Element.h"
34 #include "ExceptionCode.h"
35 #include "TreeScope.h"
36 #include <wtf/DoublyLinkedList.h>
37
38 namespace WebCore {
39
40 class Document;
41 class DOMSelection;
42 class InsertionPoint;
43 class ElementShadow;
44
45 class ShadowRoot : public DocumentFragment, public TreeScope, public DoublyLinkedListNode<ShadowRoot> {
46     friend class WTF::DoublyLinkedListNode<ShadowRoot>;
47 public:
48     static PassRefPtr<ShadowRoot> create(Element*, ExceptionCode&);
49
50     // FIXME: We will support multiple shadow subtrees, however current implementation does not work well
51     // if a shadow root is dynamically created. So we prohibit multiple shadow subtrees
52     // in several elements for a while.
53     // See https://bugs.webkit.org/show_bug.cgi?id=77503 and related bugs.
54     enum ShadowRootType {
55         UserAgentShadowRoot,
56         AuthorShadowRoot
57     };
58     static PassRefPtr<ShadowRoot> create(Element*, ShadowRootType, ExceptionCode& = ASSERT_NO_EXCEPTION);
59
60     void recalcShadowTreeStyle(StyleChange);
61
62     InsertionPoint* insertionPointFor(Node*) const;
63
64     virtual bool applyAuthorStyles() const OVERRIDE;
65     void setApplyAuthorStyles(bool);
66     virtual bool resetStyleInheritance() const OVERRIDE;
67     void setResetStyleInheritance(bool);
68
69     Element* host() const;
70     void setHost(Element*);
71     ElementShadow* owner() const;
72
73     String innerHTML() const;
74     void setInnerHTML(const String&, ExceptionCode&);
75
76     Element* activeElement() const;
77
78     ShadowRoot* youngerShadowRoot() const { return prev(); }
79     ShadowRoot* olderShadowRoot() const { return next(); }
80
81     bool isYoungest() const { return !youngerShadowRoot(); }
82     bool isOldest() const { return !olderShadowRoot(); }
83
84     bool hasInsertionPoint() const;
85
86     virtual void attach();
87
88     bool isUsedForRendering() const;
89     InsertionPoint* assignedTo() const;
90     void setAssignedTo(InsertionPoint*);
91
92 #ifndef NDEBUG
93     ShadowRootType type() const { return m_type; }
94 #endif
95
96 private:
97     explicit ShadowRoot(Document*);
98     virtual ~ShadowRoot();
99     virtual String nodeName() const;
100     virtual PassRefPtr<Node> cloneNode(bool deep);
101     virtual bool childTypeAllowed(NodeType) const;
102     virtual void childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) OVERRIDE;
103
104     ShadowRoot* m_prev;
105     ShadowRoot* m_next;
106     bool m_applyAuthorStyles : 1;
107     bool m_resetStyleInheritance : 1;
108     InsertionPoint* m_insertionPointAssignedTo;
109
110 #ifndef NDEBUG
111     ShadowRootType m_type;
112 #endif
113 };
114
115 inline Element* ShadowRoot::host() const
116 {
117     return toElement(parentOrHostNode());
118 }
119
120 inline void ShadowRoot::setHost(Element* host)
121 {
122     setParentOrHostNode(host);
123 }
124
125 inline InsertionPoint* ShadowRoot::assignedTo() const
126 {
127     return m_insertionPointAssignedTo;
128 }
129
130 inline void ShadowRoot::setAssignedTo(InsertionPoint* insertionPoint)
131 {
132     ASSERT(!m_insertionPointAssignedTo || !insertionPoint);
133     m_insertionPointAssignedTo = insertionPoint;
134 }
135
136 inline bool ShadowRoot::isUsedForRendering() const
137 {
138     return isYoungest() || assignedTo();
139 }
140
141 inline Element* ShadowRoot::activeElement() const
142 {
143     if (Node* node = treeScope()->focusedNode())
144         return node->isElementNode() ? toElement(node) : 0;
145     return 0;
146 }
147
148 inline const ShadowRoot* toShadowRoot(const Node* node)
149 {
150     ASSERT(!node || node->isShadowRoot());
151     return static_cast<const ShadowRoot*>(node);
152 }
153
154 inline ShadowRoot* toShadowRoot(Node* node)
155 {
156     return const_cast<ShadowRoot*>(toShadowRoot(static_cast<const Node*>(node)));
157 }
158
159 } // namespace
160
161 #endif