#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 ElementShadow;
class ShadowRoot FINAL : public DocumentFragment, public TreeScope {
public:
enum ShadowRootType {
UserAgentShadowRoot = 0,
AuthorShadowRoot
};
static PassRefPtr<ShadowRoot> create(Document* document, ShadowRootType type)
{
return adoptRef(new ShadowRoot(document, type));
}
virtual ~ShadowRoot();
void recalcStyle(StyleChange);
virtual bool applyAuthorStyles() const OVERRIDE { return m_applyAuthorStyles; }
void setApplyAuthorStyles(bool);
virtual bool resetStyleInheritance() const OVERRIDE { return m_resetStyleInheritance; }
void setResetStyleInheritance(bool);
Element* host() const { return toElement(parentOrShadowHostNode()); }
ElementShadow* owner() const { return host() ? host()->shadow() : 0; }
String innerHTML() const;
void setInnerHTML(const String&, ExceptionCode&);
Element* activeElement() const;
virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
virtual void registerScopedHTMLStyleChild() OVERRIDE;
virtual void unregisterScopedHTMLStyleChild() OVERRIDE;
ShadowRootType type() const { return static_cast<ShadowRootType>(m_type); }
PassRefPtr<Node> cloneNode(bool, ExceptionCode&);
private:
ShadowRoot(Document*, ShadowRootType);
virtual void dispose() OVERRIDE;
virtual bool childTypeAllowed(NodeType) const OVERRIDE;
virtual void childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) OVERRIDE;
virtual PassRefPtr<Node> cloneNode(bool) OVERRIDE { return 0; }
bool isOrphan() const { return !host(); }
unsigned m_numberOfStyles : 28;
unsigned m_applyAuthorStyles : 1;
unsigned m_resetStyleInheritance : 1;
unsigned m_type : 1;
};
inline Element* ShadowRoot::activeElement() const
{
return treeScope()->focusedElement();
}
inline const ShadowRoot* toShadowRoot(const Node* node)
{
ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isShadowRoot());
return static_cast<const ShadowRoot*>(node);
}
inline ShadowRoot* toShadowRoot(Node* node)
{
return const_cast<ShadowRoot*>(toShadowRoot(static_cast<const Node*>(node)));
}
}
#endif