Modified: trunk/Source/WebCore/ChangeLog (141312 => 141313)
--- trunk/Source/WebCore/ChangeLog 2013-01-30 22:30:29 UTC (rev 141312)
+++ trunk/Source/WebCore/ChangeLog 2013-01-30 22:30:54 UTC (rev 141313)
@@ -1,3 +1,33 @@
+2013-01-30 Elliott Sprehn <[email protected]>
+
+ Clean up interface to ShadowRoot
+ https://bugs.webkit.org/show_bug.cgi?id=108300
+
+ Reviewed by Dimitri Glazkov.
+
+ Lots of general clean up to ShadowRoot removing unused headers and forward
+ declarations, moving short inline methods into the class definition so it's
+ easier to understand what methods do what, and replacing macros with methods
+ with inline methods.
+
+ No new tests, just refactoring.
+
+ * dom/ElementShadow.cpp:
+ (WebCore::ElementShadow::addShadowRoot):
+ (WebCore::ElementShadow::removeAllShadowRoots):
+ * dom/ShadowRoot.cpp:
+ (WebCore::ShadowRoot::ShadowRoot):
+ (WebCore::ShadowRoot::setInnerHTML): Use isOrphan instead of macro.
+ (WebCore::ShadowRoot::setApplyAuthorStyles): Use isOrphan instead of macro.
+ (WebCore::ShadowRoot::setResetStyleInheritance): Use isOrphan instead of macro.
+ (WebCore::ShadowRoot::childrenChanged): Use isOrphan instead of macro.
+ * dom/ShadowRoot.h:
+ (WebCore::ShadowRoot::setHost): Removed.
+ (WebCore::ShadowRoot::host):
+ (WebCore::ShadowRoot::owner):
+ (ShadowRoot):
+ (WebCore::ShadowRoot::isOrphan): Replacement of GuardOrphanShadowRoot macro.
+
2013-01-30 Ryosuke Niwa <[email protected]>
Apple's internal PLT test suite doesn't finish after r141136
Modified: trunk/Source/WebCore/dom/ElementShadow.cpp (141312 => 141313)
--- trunk/Source/WebCore/dom/ElementShadow.cpp 2013-01-30 22:30:29 UTC (rev 141312)
+++ trunk/Source/WebCore/dom/ElementShadow.cpp 2013-01-30 22:30:54 UTC (rev 141313)
@@ -36,7 +36,8 @@
{
RefPtr<ShadowRoot> shadowRoot = ShadowRoot::create(shadowHost->document(), type);
- shadowRoot->setHost(shadowHost);
+ shadowRoot->setParentOrHostNode(shadowHost);
+ shadowRoot->setParentTreeScope(shadowHost->treeScope());
m_shadowRoots.push(shadowRoot.get());
m_distributor.didShadowBoundaryChange(shadowHost);
ChildNodeInsertionNotifier(shadowHost).notify(shadowRoot.get());
@@ -68,7 +69,7 @@
oldRoot->detach();
m_shadowRoots.removeHead();
- oldRoot->setHost(0);
+ oldRoot->setParentOrHostNode(0);
oldRoot->setParentTreeScope(shadowHost->document());
oldRoot->setPrev(0);
oldRoot->setNext(0);
Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (141312 => 141313)
--- trunk/Source/WebCore/dom/ShadowRoot.cpp 2013-01-30 22:30:29 UTC (rev 141312)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp 2013-01-30 22:30:54 UTC (rev 141313)
@@ -28,32 +28,14 @@
#include "ShadowRoot.h"
#include "ContentDistributor.h"
-#include "DOMSelection.h"
-#include "DOMWindow.h"
-#include "Document.h"
-#include "DocumentFragment.h"
-#include "Element.h"
#include "ElementShadow.h"
-#include "HTMLContentElement.h"
-#include "HTMLInputElement.h"
-#include "HTMLNames.h"
-#include "HTMLTextAreaElement.h"
#include "HistogramSupport.h"
#include "InsertionPoint.h"
-#include "NodeRareData.h"
#include "RuntimeEnabledFeatures.h"
-#include "SVGNames.h"
#include "StyleResolver.h"
#include "Text.h"
#include "markup.h"
-// FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=88834
-#define GuardOrphanShadowRoot(rejectStatement) \
- if (!this->host()) { \
- rejectStatement; \
- return; \
- }
-
namespace WebCore {
struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope, public DoublyLinkedListNode<ShadowRoot> {
@@ -66,20 +48,9 @@
enum ShadowRootUsageOriginType {
ShadowRootUsageOriginWeb = 0,
ShadowRootUsageOriginNotWeb,
- ShadowRootUsageOriginTypes
+ ShadowRootUsageOriginMax
};
-static inline ShadowRootUsageOriginType determineUsageType(Document* document)
-{
- // Enables only on CHROMIUM since this cost won't worth paying for platforms which don't collect this metrics.
-#if PLATFORM(CHROMIUM)
- return document->url().string().startsWith("http") ? ShadowRootUsageOriginWeb : ShadowRootUsageOriginNotWeb;
-#else
- UNUSED_PARAM(document);
- return ShadowRootUsageOriginWeb;
-#endif
-}
-
ShadowRoot::ShadowRoot(Document* document, ShadowRootType type)
: DocumentFragment(document, CreateShadowRoot)
, TreeScope(this, document)
@@ -94,8 +65,12 @@
ASSERT(document);
setTreeScope(this);
- if (type == ShadowRoot::AuthorShadowRoot)
- HistogramSupport::histogramEnumeration("WebCore.ShadowRoot.constructor", determineUsageType(document), ShadowRootUsageOriginTypes);
+#if PLATFORM(CHROMIUM)
+ if (type == ShadowRoot::AuthorShadowRoot) {
+ ShadowRootUsageOriginType usageType = document->url().protocolIsInHTTPFamily() ? ShadowRootUsageOriginWeb : ShadowRootUsageOriginNotWeb;
+ HistogramSupport::histogramEnumeration("WebCore.ShadowRoot.constructor", usageType, ShadowRootUsageOriginMax);
+ }
+#endif
}
ShadowRoot::~ShadowRoot()
@@ -114,12 +89,6 @@
clearRareData();
}
-PassRefPtr<Node> ShadowRoot::cloneNode(bool)
-{
- // ShadowRoot should not be arbitrarily cloned.
- return 0;
-}
-
PassRefPtr<Node> ShadowRoot::cloneNode(bool, ExceptionCode& ec)
{
ec = DATA_CLONE_ERR;
@@ -133,7 +102,10 @@
void ShadowRoot::setInnerHTML(const String& markup, ExceptionCode& ec)
{
- GuardOrphanShadowRoot(ec = INVALID_ACCESS_ERR);
+ if (isOrphan()) {
+ ec = INVALID_ACCESS_ERR;
+ return;
+ }
if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, host(), AllowScriptingContent, ec))
replaceChildrenWithFragment(this, fragment.release(), ec);
@@ -174,21 +146,10 @@
clearChildNeedsStyleRecalc();
}
-ElementShadow* ShadowRoot::owner() const
-{
- if (host())
- return host()->shadow();
- return 0;
-}
-
-bool ShadowRoot::applyAuthorStyles() const
-{
- return m_applyAuthorStyles;
-}
-
void ShadowRoot::setApplyAuthorStyles(bool value)
{
- GuardOrphanShadowRoot({ });
+ if (isOrphan())
+ return;
if (m_applyAuthorStyles != value) {
m_applyAuthorStyles = value;
@@ -196,14 +157,10 @@
}
}
-bool ShadowRoot::resetStyleInheritance() const
-{
- return m_resetStyleInheritance;
-}
-
void ShadowRoot::setResetStyleInheritance(bool value)
{
- GuardOrphanShadowRoot({ });
+ if (isOrphan())
+ return;
if (value != m_resetStyleInheritance) {
m_resetStyleInheritance = value;
@@ -258,7 +215,8 @@
void ShadowRoot::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
- GuardOrphanShadowRoot({ });
+ if (isOrphan())
+ return;
ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
owner()->invalidateDistribution();
Modified: trunk/Source/WebCore/dom/ShadowRoot.h (141312 => 141313)
--- trunk/Source/WebCore/dom/ShadowRoot.h 2013-01-30 22:30:29 UTC (rev 141312)
+++ trunk/Source/WebCore/dom/ShadowRoot.h 2013-01-30 22:30:54 UTC (rev 141313)
@@ -37,10 +37,7 @@
namespace WebCore {
-class Document;
-class DOMSelection;
class ElementShadow;
-class InsertionPoint;
class ScopeContentDistribution;
class ShadowRoot : public DocumentFragment, public TreeScope, public DoublyLinkedListNode<ShadowRoot> {
@@ -62,14 +59,13 @@
void recalcStyle(StyleChange);
- virtual bool applyAuthorStyles() const OVERRIDE;
+ virtual bool applyAuthorStyles() const OVERRIDE { return m_applyAuthorStyles; }
void setApplyAuthorStyles(bool);
- virtual bool resetStyleInheritance() const OVERRIDE;
+ virtual bool resetStyleInheritance() const OVERRIDE { return m_resetStyleInheritance; }
void setResetStyleInheritance(bool);
- Element* host() const;
- void setHost(Element*);
- ElementShadow* owner() const;
+ Element* host() const { return toElement(parentOrHostNode()); }
+ ElementShadow* owner() const { return host() ? host()->shadow() : 0; }
String innerHTML() const;
void setInnerHTML(const String&, ExceptionCode&);
@@ -103,10 +99,16 @@
private:
ShadowRoot(Document*, ShadowRootType);
virtual ~ShadowRoot();
- virtual PassRefPtr<Node> cloneNode(bool deep);
- virtual bool childTypeAllowed(NodeType) const;
+
+ virtual bool childTypeAllowed(NodeType) const OVERRIDE;
virtual void childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) OVERRIDE;
+ // ShadowRoots should never be cloned.
+ virtual PassRefPtr<Node> cloneNode(bool) OVERRIDE { return 0; }
+
+ // FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=88834
+ bool isOrphan() const { return !host(); }
+
ShadowRoot* m_prev;
ShadowRoot* m_next;
OwnPtr<ScopeContentDistribution> m_scopeDistribution;
@@ -117,18 +119,6 @@
unsigned m_registeredWithParentShadowRoot : 1;
};
-inline Element* ShadowRoot::host() const
-{
- return toElement(parentOrHostNode());
-}
-
-inline void ShadowRoot::setHost(Element* host)
-{
- setParentOrHostNode(host);
- if (host)
- setParentTreeScope(host->treeScope());
-}
-
inline Element* ShadowRoot::activeElement() const
{
if (Node* node = treeScope()->focusedNode())