#ifndef ShadowRoot_h
#define ShadowRoot_h
#include "ContainerNode.h"
#include "Document.h"
#include "DocumentFragment.h"
#include "Element.h"
#include "ExceptionCode.h"
#include "TreeScope.h"
namespace WebCore {
class AuthorStyleSheets;
class HTMLSlotElement;
class SlotAssignment;
class ShadowRoot final : public DocumentFragment, public TreeScope {
public:
enum class Type : uint8_t {
UserAgent = 0,
Closed,
Open,
};
static Ref<ShadowRoot> create(Document& document, Type 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();
using TreeScope::rootNode;
StyleResolver& styleResolver();
AuthorStyleSheets& authorStyleSheets();
void updateStyle();
void resetStyleResolver();
bool resetStyleInheritance() const { return m_resetStyleInheritance; }
void setResetStyleInheritance(bool);
Element* host() const { return m_host; }
void setHost(Element* host) { m_host = host; }
String innerHTML() const;
void setInnerHTML(const String&, ExceptionCode&);
Element* activeElement() const;
Type type() const { return m_type; }
void removeAllEventListeners() override;
HTMLSlotElement* findAssignedSlot(const Node&);
void addSlotElementByName(const AtomicString&, HTMLSlotElement&);
void removeSlotElementByName(const AtomicString&, HTMLSlotElement&);
void didRemoveAllChildrenOfShadowHost();
void didChangeDefaultSlot();
void hostChildElementDidChange(const Element&);
void hostChildElementDidChangeSlotAttribute(const AtomicString& oldValue, const AtomicString& newValue);
void innerSlotDidChange(const AtomicString&);
const Vector<Node*>* assignedNodesForSlot(const HTMLSlotElement&);
protected:
ShadowRoot(Document&, Type);
ShadowRoot(Document&, std::unique_ptr<SlotAssignment>&&);
bool isOrphan() const { return !m_host; }
private:
bool childTypeAllowed(NodeType) const override;
Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
bool m_resetStyleInheritance { false };
Type m_type { Type::UserAgent };
Element* m_host { nullptr };
std::unique_ptr<StyleResolver> m_styleResolver;
std::unique_ptr<AuthorStyleSheets> m_authorStyleSheets;
std::unique_ptr<SlotAssignment> m_slotAssignment;
};
inline Element* ShadowRoot::activeElement() const
{
return treeScope().focusedElement();
}
inline ShadowRoot* Node::shadowRoot() const
{
if (!is<Element>(*this))
return nullptr;
return downcast<Element>(*this).shadowRoot();
}
inline ContainerNode* Node::parentOrShadowHostNode() const
{
ASSERT(isMainThreadOrGCThread());
if (is<ShadowRoot>(*this))
return downcast<ShadowRoot>(*this).host();
return parentNode();
}
inline bool hasShadowRootParent(const Node& node)
{
return node.parentNode() && node.parentNode()->isShadowRoot();
}
}
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ShadowRoot)
static bool isType(const WebCore::Node& node) { return node.isShadowRoot(); }
SPECIALIZE_TYPE_TRAITS_END()
#endif