summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/ShadowRoot.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/dom/ShadowRoot.h')
-rw-r--r--Source/WebCore/dom/ShadowRoot.h120
1 files changed, 61 insertions, 59 deletions
diff --git a/Source/WebCore/dom/ShadowRoot.h b/Source/WebCore/dom/ShadowRoot.h
index eb45ab8f3..86532e1bc 100644
--- a/Source/WebCore/dom/ShadowRoot.h
+++ b/Source/WebCore/dom/ShadowRoot.h
@@ -24,109 +24,107 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ShadowRoot_h
-#define ShadowRoot_h
+#pragma once
-#include "ContainerNode.h"
-#include "ContentDistributor.h"
#include "Document.h"
#include "DocumentFragment.h"
#include "Element.h"
-#include "ExceptionCode.h"
-#include "TreeScope.h"
+#include "ShadowRootMode.h"
namespace WebCore {
+class HTMLSlotElement;
+class SlotAssignment;
+
class ShadowRoot final : public DocumentFragment, public TreeScope {
public:
- // FIXME: We will support multiple shadow subtrees, however current implementation does not work well
- // if a shadow root is dynamically created. So we prohibit multiple shadow subtrees
- // in several elements for a while.
- // See https://bugs.webkit.org/show_bug.cgi?id=77503 and related bugs.
- enum ShadowRootType {
- UserAgentShadowRoot = 0,
- AuthorShadowRoot
- };
-
- static PassRefPtr<ShadowRoot> create(Document& document, ShadowRootType type)
+ static Ref<ShadowRoot> create(Document& document, ShadowRootMode type)
{
- return adoptRef(new ShadowRoot(document, type));
+ return adoptRef(*new ShadowRoot(document, type));
+ }
+
+ static Ref<ShadowRoot> create(Document& document, std::unique_ptr<SlotAssignment>&& assignment)
+ {
+ return adoptRef(*new ShadowRoot(document, WTFMove(assignment)));
}
virtual ~ShadowRoot();
- virtual bool applyAuthorStyles() const override { return m_applyAuthorStyles; }
- void setApplyAuthorStyles(bool);
+ using TreeScope::rootNode;
+
+ Style::Scope& styleScope();
+
bool resetStyleInheritance() const { return m_resetStyleInheritance; }
void setResetStyleInheritance(bool);
- Element* hostElement() const { return m_hostElement; }
- void setHostElement(Element* hostElement) { m_hostElement = hostElement; }
+ Element* host() const { return m_host; }
+ void setHost(Element* host) { m_host = host; }
String innerHTML() const;
- void setInnerHTML(const String&, ExceptionCode&);
+ ExceptionOr<void> setInnerHTML(const String&);
Element* activeElement() const;
- ShadowRootType type() const { return static_cast<ShadowRootType>(m_type); }
+ ShadowRootMode mode() const { return m_type; }
- PassRefPtr<Node> cloneNode(bool, ExceptionCode&);
+ void removeAllEventListeners() override;
- ContentDistributor& distributor() { return m_distributor; }
- void invalidateDistribution() { m_distributor.invalidateDistribution(hostElement()); }
+ HTMLSlotElement* findAssignedSlot(const Node&);
- virtual void removeAllEventListeners() override;
+ void addSlotElementByName(const AtomicString&, HTMLSlotElement&);
+ void removeSlotElementByName(const AtomicString&, HTMLSlotElement&);
-private:
- ShadowRoot(Document&, ShadowRootType);
+ void didRemoveAllChildrenOfShadowHost();
+ void didChangeDefaultSlot();
+ void hostChildElementDidChange(const Element&);
+ void hostChildElementDidChangeSlotAttribute(Element&, const AtomicString& oldValue, const AtomicString& newValue);
+
+ const Vector<Node*>* assignedNodesForSlot(const HTMLSlotElement&);
- virtual void dropChildren() override;
- virtual bool childTypeAllowed(NodeType) const override;
- virtual void childrenChanged(const ChildChange&) override;
+protected:
+ ShadowRoot(Document&, ShadowRootMode);
- // ShadowRoots should never be cloned.
- virtual PassRefPtr<Node> cloneNode(bool) override { return 0; }
+ ShadowRoot(Document&, std::unique_ptr<SlotAssignment>&&);
// FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=88834
- bool isOrphan() const { return !hostElement(); }
+ bool isOrphan() const { return !m_host; }
- unsigned m_applyAuthorStyles : 1;
- unsigned m_resetStyleInheritance : 1;
- unsigned m_type : 1;
+private:
+ bool childTypeAllowed(NodeType) const override;
- Element* m_hostElement;
+ Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
- ContentDistributor m_distributor;
-};
+ Node::InsertionNotificationRequest insertedInto(ContainerNode& insertionPoint) override;
+ void removedFrom(ContainerNode& insertionPoint) override;
+ void didMoveToNewDocument(Document& oldDocument) override;
-inline Element* ShadowRoot::activeElement() const
-{
- return treeScope().focusedElement();
-}
+ bool m_resetStyleInheritance { false };
+ ShadowRootMode m_type { ShadowRootMode::UserAgent };
-inline const ShadowRoot* toShadowRoot(const Node* node)
-{
- ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isShadowRoot());
- return static_cast<const ShadowRoot*>(node);
-}
+ Element* m_host { nullptr };
-inline ShadowRoot* toShadowRoot(Node* node)
+ std::unique_ptr<Style::Scope> m_styleScope;
+
+ std::unique_ptr<SlotAssignment> m_slotAssignment;
+};
+
+inline Element* ShadowRoot::activeElement() const
{
- return const_cast<ShadowRoot*>(toShadowRoot(static_cast<const Node*>(node)));
+ return treeScope().focusedElementInScope();
}
inline ShadowRoot* Node::shadowRoot() const
{
- if (!isElementNode())
- return 0;
- return toElement(this)->shadowRoot();
+ if (!is<Element>(*this))
+ return nullptr;
+ return downcast<Element>(*this).shadowRoot();
}
inline ContainerNode* Node::parentOrShadowHostNode() const
{
ASSERT(isMainThreadOrGCThread());
- if (isShadowRoot())
- return toShadowRoot(this)->hostElement();
+ if (is<ShadowRoot>(*this))
+ return downcast<ShadowRoot>(*this).host();
return parentNode();
}
@@ -135,6 +133,10 @@ inline bool hasShadowRootParent(const Node& node)
return node.parentNode() && node.parentNode()->isShadowRoot();
}
-} // namespace
+Vector<ShadowRoot*> assignedShadowRootsIfSlotted(const Node&);
+
+} // namespace WebCore
-#endif
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ShadowRoot)
+ static bool isType(const WebCore::Node& node) { return node.isShadowRoot(); }
+SPECIALIZE_TYPE_TRAITS_END()