Commit 22a3c20d authored by shinyak@chromium.org's avatar shinyak@chromium.org

[Refactoring] Node::shadowHost() and Node::setShadowHost() can be moved to ShadowRoot.

https://bugs.webkit.org/show_bug.cgi?id=86585

Reviewed by Hajime Morita.

Since Node::shadowHost() and Node::setShadowHost() are valid only if Node is ShadowRoot,
they should be moved to ShadowRoot.

However, Node::setParent cannot be called from ShadowRoot, we add Node::setParentOrHostNode
to call it as Node::parentOrHostNode() calls Node::parent(). Node::setParent() is now private.
We also add SVGElementInstance::setParentOrHostNode() to share ContainerNodeAlgorithm.

No new tests, no change in behavior.

* dom/Attr.cpp:
(WebCore::Attr::createTextChild):
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::insertBeforeCommon):
(WebCore::ContainerNode::removeBetween):
(WebCore::ContainerNode::removeChildren):
* dom/ContainerNodeAlgorithms.h:
(WebCore::appendChildToContainer):
(WebCore::Private::addChildNodesToDeletionQueue):
* dom/ElementShadow.cpp:
(WebCore::validateShadowRoot):
(WebCore::ElementShadow::addShadowRoot):
(WebCore::ElementShadow::removeAllShadowRoots):
* dom/EventDispatcher.cpp:
(WebCore::eventTargetRespectingSVGTargetRules):
(WebCore::EventDispatcher::ensureEventAncestors):
(WebCore::EventDispatcher::determineDispatchBehavior):
* dom/EventDispatcher.h:
(WebCore):
(EventDispatcher):
* dom/Node.cpp:
(WebCore::Node::parentOrHostElement):
* dom/Node.h:
(Node):
(WebCore::Node::setParentOrHostNode):
(WebCore):
* dom/NodeRenderingContext.cpp:
(WebCore::NodeRenderingContext::NodeRenderingContext):
* dom/ShadowRoot.h:
(WebCore::ShadowRoot::host):
(WebCore):
(WebCore::ShadowRoot::setHost):
* dom/TreeScope.cpp:
(WebCore::TreeScope::focusedNode):
* html/shadow/ContentSelectorQuery.cpp:
(WebCore::ContentSelectorQuery::matches):
* page/DragController.cpp:
(WebCore::asFileInput):
* page/EventHandler.cpp:
(WebCore::EventHandler::handleMousePressEvent):
(WebCore::instanceAssociatedWithShadowTreeElement):
(WebCore::EventHandler::dispatchMouseEvent):
* page/FocusController.cpp:
(WebCore::FocusScope::owner):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::hasLineIfEmpty):
* svg/SVGElementInstance.h:
(WebCore::SVGElementInstance::setParentOrHostNode):
(SVGElementInstance):
* svg/SVGStyledElement.cpp:
(WebCore::SVGStyledElement::title):
* svg/SVGTRefElement.cpp:
(WebCore::SVGShadowText::willRecalcTextStyle):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@117723 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c084e1fd
2012-05-20 Shinya Kawanaka <shinyak@chromium.org>
[Refactoring] Node::shadowHost() and Node::setShadowHost() can be moved to ShadowRoot.
https://bugs.webkit.org/show_bug.cgi?id=86585
Reviewed by Hajime Morita.
Since Node::shadowHost() and Node::setShadowHost() are valid only if Node is ShadowRoot,
they should be moved to ShadowRoot.
However, Node::setParent cannot be called from ShadowRoot, we add Node::setParentOrHostNode
to call it as Node::parentOrHostNode() calls Node::parent(). Node::setParent() is now private.
We also add SVGElementInstance::setParentOrHostNode() to share ContainerNodeAlgorithm.
No new tests, no change in behavior.
* dom/Attr.cpp:
(WebCore::Attr::createTextChild):
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::insertBeforeCommon):
(WebCore::ContainerNode::removeBetween):
(WebCore::ContainerNode::removeChildren):
* dom/ContainerNodeAlgorithms.h:
(WebCore::appendChildToContainer):
(WebCore::Private::addChildNodesToDeletionQueue):
* dom/ElementShadow.cpp:
(WebCore::validateShadowRoot):
(WebCore::ElementShadow::addShadowRoot):
(WebCore::ElementShadow::removeAllShadowRoots):
* dom/EventDispatcher.cpp:
(WebCore::eventTargetRespectingSVGTargetRules):
(WebCore::EventDispatcher::ensureEventAncestors):
(WebCore::EventDispatcher::determineDispatchBehavior):
* dom/EventDispatcher.h:
(WebCore):
(EventDispatcher):
* dom/Node.cpp:
(WebCore::Node::parentOrHostElement):
* dom/Node.h:
(Node):
(WebCore::Node::setParentOrHostNode):
(WebCore):
* dom/NodeRenderingContext.cpp:
(WebCore::NodeRenderingContext::NodeRenderingContext):
* dom/ShadowRoot.h:
(WebCore::ShadowRoot::host):
(WebCore):
(WebCore::ShadowRoot::setHost):
* dom/TreeScope.cpp:
(WebCore::TreeScope::focusedNode):
* html/shadow/ContentSelectorQuery.cpp:
(WebCore::ContentSelectorQuery::matches):
* page/DragController.cpp:
(WebCore::asFileInput):
* page/EventHandler.cpp:
(WebCore::EventHandler::handleMousePressEvent):
(WebCore::instanceAssociatedWithShadowTreeElement):
(WebCore::EventHandler::dispatchMouseEvent):
* page/FocusController.cpp:
(WebCore::FocusScope::owner):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::hasLineIfEmpty):
* svg/SVGElementInstance.h:
(WebCore::SVGElementInstance::setParentOrHostNode):
(SVGElementInstance):
* svg/SVGStyledElement.cpp:
(WebCore::SVGStyledElement::title):
* svg/SVGTRefElement.cpp:
(WebCore::SVGShadowText::willRecalcTextStyle):
2012-05-20 Joe Thomas <joethomas@motorola.com>
Unsupported commands should have queryCommandValue() = "", not false
......@@ -81,7 +81,7 @@ void Attr::createTextChild()
// This does everything appendChild() would do in this situation (assuming m_ignoreChildrenChanged was set),
// but much more efficiently.
textNode->setParent(this);
textNode->setParentOrHostNode(this);
setFirstChild(textNode.get());
setLastChild(textNode.get());
}
......
......@@ -186,6 +186,7 @@ void ContainerNode::insertBeforeCommon(Node* nextChild, Node* newChild)
ASSERT(!newChild->parentNode()); // Use insertBefore if you need to handle reparenting (and want DOM mutation events).
ASSERT(!newChild->nextSibling());
ASSERT(!newChild->previousSibling());
ASSERT(!newChild->isShadowRoot());
forbidEventDispatch();
Node* prev = nextChild->previousSibling();
......@@ -199,7 +200,7 @@ void ContainerNode::insertBeforeCommon(Node* nextChild, Node* newChild)
ASSERT(m_firstChild == nextChild);
m_firstChild = newChild;
}
newChild->setParent(this);
newChild->setParentOrHostNode(this);
newChild->setPreviousSibling(prev);
newChild->setNextSibling(nextChild);
allowEventDispatch();
......@@ -428,7 +429,7 @@ void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node* ol
oldChild->setPreviousSibling(0);
oldChild->setNextSibling(0);
oldChild->setParent(0);
oldChild->setParentOrHostNode(0);
document()->adoptIfNeeded(oldChild);
......@@ -481,7 +482,7 @@ void ContainerNode::removeChildren()
// this discrepancy between removeChild() and its optimized version removeChildren().
n->setPreviousSibling(0);
n->setNextSibling(0);
n->setParent(0);
n->setParentOrHostNode(0);
document()->adoptIfNeeded(n.get());
m_firstChild = next;
......
......@@ -105,7 +105,7 @@ inline void removeAllChildrenInContainer(GenericNodeContainer* container)
template<class GenericNode, class GenericNodeContainer>
inline void appendChildToContainer(GenericNode* child, GenericNodeContainer* container)
{
child->setParent(container);
child->setParentOrHostNode(container);
GenericNode* lastChild = container->lastChild();
if (lastChild) {
......@@ -161,7 +161,7 @@ namespace Private {
next = n->nextSibling();
n->setPreviousSibling(0);
n->setNextSibling(0);
n->setParent(0);
n->setParentOrHostNode(0);
if (!n->refCount()) {
#ifndef NDEBUG
......
......@@ -53,7 +53,7 @@ static bool validateShadowRoot(Document* document, ShadowRoot* shadowRoot, Excep
if (!shadowRoot)
return true;
if (shadowRoot->shadowHost()) {
if (shadowRoot->host()) {
ec = HIERARCHY_REQUEST_ERR;
return false;
}
......@@ -74,7 +74,7 @@ void ElementShadow::addShadowRoot(Element* shadowHost, PassRefPtr<ShadowRoot> sh
if (!validateShadowRoot(shadowHost->document(), shadowRoot.get(), ec))
return;
shadowRoot->setShadowHost(shadowHost);
shadowRoot->setHost(shadowHost);
ChildNodeInsertionNotifier(shadowHost).notify(shadowRoot.get());
if (shadowHost->attached()) {
......@@ -99,7 +99,7 @@ void ElementShadow::removeAllShadowRoots()
if (oldRoot->attached())
oldRoot->detach();
oldRoot->setShadowHost(0);
oldRoot->setHost(0);
oldRoot->setPrev(0);
oldRoot->setNext(0);
shadowHost->document()->adoptIfNeeded(oldRoot.get());
......
......@@ -36,6 +36,7 @@
#include "InspectorInstrumentation.h"
#include "MouseEvent.h"
#include "ScopedEventQueue.h"
#include "ShadowRoot.h"
#include "WindowEventContext.h"
#include <wtf/RefPtr.h>
#include <wtf/UnusedParam.h>
......@@ -125,7 +126,7 @@ inline static EventTarget* eventTargetRespectingSVGTargetRules(Node* referenceNo
// Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
// as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects
Element* shadowHostElement = referenceNode->treeScope()->rootNode()->shadowHost();
Element* shadowHostElement = toShadowRoot(referenceNode->treeScope()->rootNode())->host();
// At this time, SVG nodes are not allowed in non-<use> shadow trees, so any shadow root we do
// have should be a use. The assert and following test is here to catch future shadow DOM changes
// that do enable SVG in a shadow tree.
......@@ -176,7 +177,6 @@ void EventDispatcher::dispatchSimulatedClick(Node* node, PassRefPtr<Event> under
gNodesDispatchingSimulatedClicks->remove(node);
}
void EventDispatcher::adjustRelatedTarget(Event* event, PassRefPtr<EventTarget> prpRelatedTarget)
{
if (!prpRelatedTarget)
......@@ -216,7 +216,7 @@ void EventDispatcher::ensureEventAncestors(Event* event)
targetStack.append(originalTarget);
while (true) {
if (ancestorWalker.get()->isShadowRoot()) {
if (determineDispatchBehavior(event, ancestorWalker.get()) == StayInsideShadowDOM)
if (determineDispatchBehavior(event, toShadowRoot(ancestorWalker.get())) == StayInsideShadowDOM)
return;
ancestorWalker.parentIncludingInsertionPointAndShadowRoot();
if (!ancestorWalker.get())
......@@ -347,7 +347,7 @@ const EventContext* EventDispatcher::topEventContext()
return m_ancestors.isEmpty() ? 0 : &m_ancestors.last();
}
EventDispatchBehavior EventDispatcher::determineDispatchBehavior(Event* event, Node* shadowRoot)
EventDispatchBehavior EventDispatcher::determineDispatchBehavior(Event* event, ShadowRoot* shadowRoot)
{
#if ENABLE(FULLSCREEN_API) && ENABLE(VIDEO)
// Video-only full screen is a mode where we use the shadow DOM as an implementation
......@@ -355,7 +355,7 @@ EventDispatchBehavior EventDispatcher::determineDispatchBehavior(Event* event, N
if (Element* element = m_node->document()->webkitCurrentFullScreenElement()) {
// FIXME: We assume that if the full screen element is a media element that it's
// the video-only full screen. Both here and elsewhere. But that is probably wrong.
if (element->isMediaElement() && shadowRoot && shadowRoot->shadowHost() == element)
if (element->isMediaElement() && shadowRoot && shadowRoot->host() == element)
return StayInsideShadowDOM;
}
#else
......
......@@ -40,7 +40,7 @@ class FrameView;
class Node;
class PlatformKeyboardEvent;
class PlatformMouseEvent;
class PlatformWheelEvent;
class ShadowRoot;
class TreeScope;
enum EventDispatchBehavior {
......@@ -75,7 +75,8 @@ public:
private:
EventDispatcher(Node*);
EventDispatchBehavior determineDispatchBehavior(Event*, Node* shadowRoot);
EventDispatchBehavior determineDispatchBehavior(Event*, ShadowRoot*);
void ensureEventAncestors(Event*);
const EventContext* topEventContext();
......
......@@ -497,17 +497,6 @@ void Node::clearRareData()
clearFlag(HasRareDataFlag);
}
Element* Node::shadowHost() const
{
return toElement(isShadowRoot() ? parent() : 0);
}
void Node::setShadowHost(Element* host)
{
ASSERT(!parentNode() && isShadowRoot());
setParent(host);
}
Node* Node::toNode()
{
return this;
......@@ -1552,7 +1541,7 @@ Element* Node::parentOrHostElement() const
return 0;
if (parent->isShadowRoot())
return parent->shadowHost();
return toShadowRoot(parent)->host();
if (!parent->isElementNode())
return 0;
......
......@@ -229,6 +229,7 @@ public:
// Node's parent, shadow tree host.
ContainerNode* parentOrHostNode() const;
Element* parentOrHostElement() const;
void setParentOrHostNode(ContainerNode*);
Node* highestAncestor() const;
// Use when it's guaranteed to that shadowHost is 0.
......@@ -236,9 +237,6 @@ public:
// Returns the parent node, but 0 if the parent node is a ShadowRoot.
ContainerNode* nonShadowBoundaryParentNode() const;
Element* shadowHost() const;
void setShadowHost(Element*);
bool selfOrAncestorHasDirAutoAttribute() const { return getFlag(SelfOrAncestorHasDirAutoFlag); }
void setSelfOrAncestorHasDirAutoAttribute(bool flag) { setFlag(flag, SelfOrAncestorHasDirAutoFlag); }
......@@ -776,6 +774,7 @@ private:
// This method is made private to ensure a compiler error on call sites that
// don't follow this rule.
using TreeShared<ContainerNode>::parent;
using TreeShared<ContainerNode>::setParent;
void trackForDebugging();
......@@ -833,6 +832,11 @@ inline ContainerNode* Node::parentNode() const
return getFlag(IsShadowRootFlag) ? 0 : parent();
}
inline void Node::setParentOrHostNode(ContainerNode* parent)
{
setParent(parent);
}
inline ContainerNode* Node::parentOrHostNode() const
{
return parent();
......
......@@ -66,7 +66,7 @@ NodeRenderingContext::NodeRenderingContext(Node* node)
if (parent->isShadowRoot() && toShadowRoot(parent)->isYoungest()) {
m_phase = AttachingShadowChild;
m_parentNodeForRenderingAndStyle = parent->shadowHost();
m_parentNodeForRenderingAndStyle = toShadowRoot(parent)->host();
return;
}
......
......@@ -27,6 +27,7 @@
#ifndef ShadowRoot_h
#define ShadowRoot_h
#include "ContainerNode.h"
#include "Document.h"
#include "DocumentFragment.h"
#include "Element.h"
......@@ -68,7 +69,8 @@ public:
virtual bool applyAuthorStyles() const OVERRIDE;
void setApplyAuthorStyles(bool);
Element* host() const { return shadowHost(); }
Element* host() const;
void setHost(Element*);
ElementShadow* owner() const;
String innerHTML() const;
......@@ -104,6 +106,16 @@ private:
InsertionPoint* m_insertionPointAssignedTo;
};
inline Element* ShadowRoot::host() const
{
return toElement(parentOrHostNode());
}
inline void ShadowRoot::setHost(Element* host)
{
setParentOrHostNode(host);
}
inline InsertionPoint* ShadowRoot::assignedTo() const
{
return m_insertionPointAssignedTo;
......
......@@ -39,6 +39,7 @@
#include "HTMLNames.h"
#include "Page.h"
#include "RuntimeEnabledFeatures.h"
#include "ShadowRoot.h"
#include "TreeScopeAdopter.h"
#include <wtf/text/AtomicString.h>
#include <wtf/text/CString.h>
......@@ -221,7 +222,7 @@ Node* TreeScope::focusedNode()
TreeScope* treeScope = node->treeScope();
while (treeScope != this && treeScope != document) {
node = treeScope->rootNode()->shadowHost();
node = toShadowRoot(treeScope->rootNode())->host();
treeScope = node->treeScope();
}
if (this != treeScope)
......
......@@ -64,7 +64,7 @@ bool ContentSelectorQuery::matches(Node* node) const
if (!node)
return false;
ASSERT(node->parentNode() == m_insertionPoint->shadowRoot()->shadowHost());
ASSERT(node->parentNode() == m_insertionPoint->shadowRoot()->host());
if (m_insertionPoint->select().isNull() || m_insertionPoint->select().isEmpty())
return true;
......
......@@ -63,6 +63,7 @@
#include "ResourceRequest.h"
#include "SecurityOrigin.h"
#include "Settings.h"
#include "ShadowRoot.h"
#include "StylePropertySet.h"
#include "Text.h"
#include "TextEvent.h"
......@@ -276,7 +277,7 @@ static HTMLInputElement* asFileInput(Node* node)
// If this is a button inside of the a file input, move up to the file input.
if (inputElement && inputElement->isTextButton() && inputElement->treeScope()->rootNode()->isShadowRoot())
inputElement = inputElement->treeScope()->rootNode()->shadowHost()->toInputElement();
inputElement = toShadowRoot(inputElement->treeScope()->rootNode())->host()->toInputElement();
return inputElement && inputElement->isFileUpload() ? inputElement : 0;
}
......
......@@ -1599,7 +1599,7 @@ bool EventHandler::handleMousePressEvent(const PlatformMouseEvent& mouseEvent)
// If a mouse event handler changes the input element type to one that has a widget associated,
// we'd like to EventHandler::handleMousePressEvent to pass the event to the widget and thus the
// event target node can't still be the shadow node.
if (targetNode(mev)->isShadowRoot() && targetNode(mev)->shadowHost()->hasTagName(inputTag)) {
if (targetNode(mev)->isShadowRoot() && toShadowRoot(targetNode(mev))->host()->hasTagName(inputTag)) {
HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mouseEvent);
}
......@@ -2092,11 +2092,11 @@ static inline SVGElementInstance* instanceAssociatedWithShadowTreeElement(Node*
if (!referenceNode || !referenceNode->isSVGElement())
return 0;
Node* shadowTreeElement = referenceNode->shadowRoot();
if (!shadowTreeElement)
ShadowRoot* shadowRoot = referenceNode->shadowRoot();
if (!shadowRoot)
return 0;
Element* shadowTreeParentElement = shadowTreeElement->shadowHost();
Element* shadowTreeParentElement = shadowRoot->host();
if (!shadowTreeParentElement)
return 0;
......@@ -2250,7 +2250,7 @@ bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targe
// focused if the user does a mouseup over it, however, because the mouseup
// will set a selection inside it, which will call setFocuseNodeIfNeeded.
ExceptionCode ec = 0;
Node* n = node->isShadowRoot() ? node->shadowHost() : node;
Node* n = node->isShadowRoot() ? toShadowRoot(node)->host() : node;
if (m_frame->selection()->isRange()
&& m_frame->selection()->toNormalizedRange()->compareNode(n, ec) == Range::NODE_INSIDE
&& n->isDescendantOf(m_frame->document()->focusedNode()))
......
......@@ -110,7 +110,7 @@ Element* FocusScope::owner() const
{
Node* root = rootNode();
if (root->isShadowRoot())
return root->shadowHost();
return toShadowRoot(root)->host();
if (Frame* frame = root->document()->frame())
return frame->ownerElement();
return 0;
......
......@@ -58,6 +58,7 @@
#include "RenderView.h"
#include "Settings.h"
#include "SVGTextRunRenderingContext.h"
#include "ShadowRoot.h"
#include "TransformState.h"
#include <wtf/StdLibExtras.h>
......@@ -5773,7 +5774,7 @@ bool RenderBlock::hasLineIfEmpty() const
if (node()->isRootEditableElement())
return true;
if (node()->isShadowRoot() && (node()->shadowHost()->hasTagName(inputTag)))
if (node()->isShadowRoot() && toShadowRoot(node())->host()->hasTagName(inputTag))
return true;
return false;
......
......@@ -48,6 +48,8 @@ public:
virtual ~SVGElementInstance();
void setParentOrHostNode(SVGElementInstance* instance) { setParent(instance); }
virtual const AtomicString& interfaceName() const;
virtual ScriptExecutionContext* scriptExecutionContext() const;
......@@ -143,6 +145,8 @@ public:
private:
friend class SVGUseElement;
using TreeShared<SVGElementInstance>::parent;
using TreeShared<SVGElementInstance>::setParent;
SVGElementInstance(SVGUseElement*, SVGUseElement*, PassRefPtr<SVGElement> originalElement);
......
......@@ -42,6 +42,7 @@
#include "SVGRenderSupport.h"
#include "SVGSVGElement.h"
#include "SVGUseElement.h"
#include "ShadowRoot.h"
#include <wtf/Assertions.h>
#include <wtf/HashMap.h>
#include <wtf/StdLibExtras.h>
......@@ -90,7 +91,7 @@ String SVGStyledElement::title() const
// Walk up the tree, to find out whether we're inside a <use> shadow tree, to find the right title.
if (isInShadowTree()) {
Element* shadowHostElement = treeScope()->rootNode()->shadowHost();
Element* shadowHostElement = toShadowRoot(treeScope()->rootNode())->host();
// At this time, SVG nodes are not allowed in non-<use> shadow trees, so any shadow root we do
// have should be a use. The assert and following test is here to catch future shadow DOM changes
// that do enable SVG in a shadow tree.
......
......@@ -142,9 +142,9 @@ RenderObject* SVGShadowText::createRenderer(RenderArena* arena, RenderStyle*)
void SVGShadowText::willRecalcTextStyle(StyleChange change)
{
if (change != NoChange && parentNode()->shadowHost()) {
if (change != NoChange && parentNode()->isShadowRoot()) {
if (renderer())
renderer()->setStyle(parentNode()->shadowHost()->renderer()->style());
renderer()->setStyle(toShadowRoot(parentNode())->host()->renderer()->style());
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment