Changeset 117723 in webkit


Ignore:
Timestamp:
May 20, 2012 7:41:58 PM (12 years ago)
Author:
shinyak@chromium.org
Message:

[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):

Location:
trunk/Source/WebCore
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117721 r117723  
     12012-05-20  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        [Refactoring] Node::shadowHost() and Node::setShadowHost() can be moved to ShadowRoot.
     4        https://bugs.webkit.org/show_bug.cgi?id=86585
     5
     6        Reviewed by Hajime Morita.
     7
     8        Since Node::shadowHost() and Node::setShadowHost() are valid only if Node is ShadowRoot,
     9        they should be moved to ShadowRoot.
     10
     11        However, Node::setParent cannot be called from ShadowRoot, we add Node::setParentOrHostNode
     12        to call it as Node::parentOrHostNode() calls Node::parent(). Node::setParent() is now private.
     13        We also add SVGElementInstance::setParentOrHostNode() to share ContainerNodeAlgorithm.
     14
     15        No new tests, no change in behavior.
     16
     17        * dom/Attr.cpp:
     18        (WebCore::Attr::createTextChild):
     19        * dom/ContainerNode.cpp:
     20        (WebCore::ContainerNode::insertBeforeCommon):
     21        (WebCore::ContainerNode::removeBetween):
     22        (WebCore::ContainerNode::removeChildren):
     23        * dom/ContainerNodeAlgorithms.h:
     24        (WebCore::appendChildToContainer):
     25        (WebCore::Private::addChildNodesToDeletionQueue):
     26        * dom/ElementShadow.cpp:
     27        (WebCore::validateShadowRoot):
     28        (WebCore::ElementShadow::addShadowRoot):
     29        (WebCore::ElementShadow::removeAllShadowRoots):
     30        * dom/EventDispatcher.cpp:
     31        (WebCore::eventTargetRespectingSVGTargetRules):
     32        (WebCore::EventDispatcher::ensureEventAncestors):
     33        (WebCore::EventDispatcher::determineDispatchBehavior):
     34        * dom/EventDispatcher.h:
     35        (WebCore):
     36        (EventDispatcher):
     37        * dom/Node.cpp:
     38        (WebCore::Node::parentOrHostElement):
     39        * dom/Node.h:
     40        (Node):
     41        (WebCore::Node::setParentOrHostNode):
     42        (WebCore):
     43        * dom/NodeRenderingContext.cpp:
     44        (WebCore::NodeRenderingContext::NodeRenderingContext):
     45        * dom/ShadowRoot.h:
     46        (WebCore::ShadowRoot::host):
     47        (WebCore):
     48        (WebCore::ShadowRoot::setHost):
     49        * dom/TreeScope.cpp:
     50        (WebCore::TreeScope::focusedNode):
     51        * html/shadow/ContentSelectorQuery.cpp:
     52        (WebCore::ContentSelectorQuery::matches):
     53        * page/DragController.cpp:
     54        (WebCore::asFileInput):
     55        * page/EventHandler.cpp:
     56        (WebCore::EventHandler::handleMousePressEvent):
     57        (WebCore::instanceAssociatedWithShadowTreeElement):
     58        (WebCore::EventHandler::dispatchMouseEvent):
     59        * page/FocusController.cpp:
     60        (WebCore::FocusScope::owner):
     61        * rendering/RenderBlock.cpp:
     62        (WebCore::RenderBlock::hasLineIfEmpty):
     63        * svg/SVGElementInstance.h:
     64        (WebCore::SVGElementInstance::setParentOrHostNode):
     65        (SVGElementInstance):
     66        * svg/SVGStyledElement.cpp:
     67        (WebCore::SVGStyledElement::title):
     68        * svg/SVGTRefElement.cpp:
     69        (WebCore::SVGShadowText::willRecalcTextStyle):
     70
    1712012-05-20  Joe Thomas  <joethomas@motorola.com>
    272
  • trunk/Source/WebCore/dom/Attr.cpp

    r117353 r117723  
    8282        // This does everything appendChild() would do in this situation (assuming m_ignoreChildrenChanged was set),
    8383        // but much more efficiently.
    84         textNode->setParent(this);
     84        textNode->setParentOrHostNode(this);
    8585        setFirstChild(textNode.get());
    8686        setLastChild(textNode.get());
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r117224 r117723  
    187187    ASSERT(!newChild->nextSibling());
    188188    ASSERT(!newChild->previousSibling());
     189    ASSERT(!newChild->isShadowRoot());
    189190
    190191    forbidEventDispatch();
     
    200201        m_firstChild = newChild;
    201202    }
    202     newChild->setParent(this);
     203    newChild->setParentOrHostNode(this);
    203204    newChild->setPreviousSibling(prev);
    204205    newChild->setNextSibling(nextChild);
     
    429430    oldChild->setPreviousSibling(0);
    430431    oldChild->setNextSibling(0);
    431     oldChild->setParent(0);
     432    oldChild->setParentOrHostNode(0);
    432433
    433434    document()->adoptIfNeeded(oldChild);
     
    482483        n->setPreviousSibling(0);
    483484        n->setNextSibling(0);
    484         n->setParent(0);
     485        n->setParentOrHostNode(0);
    485486        document()->adoptIfNeeded(n.get());
    486487
  • trunk/Source/WebCore/dom/ContainerNodeAlgorithms.h

    r117242 r117723  
    106106inline void appendChildToContainer(GenericNode* child, GenericNodeContainer* container)
    107107{
    108     child->setParent(container);
     108    child->setParentOrHostNode(container);
    109109
    110110    GenericNode* lastChild = container->lastChild();
     
    162162            n->setPreviousSibling(0);
    163163            n->setNextSibling(0);
    164             n->setParent(0);
     164            n->setParentOrHostNode(0);
    165165
    166166            if (!n->refCount()) {
  • trunk/Source/WebCore/dom/ElementShadow.cpp

    r117044 r117723  
    5454        return true;
    5555
    56     if (shadowRoot->shadowHost()) {
     56    if (shadowRoot->host()) {
    5757        ec = HIERARCHY_REQUEST_ERR;
    5858        return false;
     
    7575        return;
    7676
    77     shadowRoot->setShadowHost(shadowHost);
     77    shadowRoot->setHost(shadowHost);
    7878    ChildNodeInsertionNotifier(shadowHost).notify(shadowRoot.get());
    7979
     
    100100            oldRoot->detach();
    101101
    102         oldRoot->setShadowHost(0);
     102        oldRoot->setHost(0);
    103103        oldRoot->setPrev(0);
    104104        oldRoot->setNext(0);
  • trunk/Source/WebCore/dom/EventDispatcher.cpp

    r117394 r117723  
    3737#include "MouseEvent.h"
    3838#include "ScopedEventQueue.h"
     39#include "ShadowRoot.h"
    3940#include "WindowEventContext.h"
    4041#include <wtf/RefPtr.h>
     
    126127    // Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
    127128    // as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects
    128     Element* shadowHostElement = referenceNode->treeScope()->rootNode()->shadowHost();
     129    Element* shadowHostElement = toShadowRoot(referenceNode->treeScope()->rootNode())->host();
    129130    // At this time, SVG nodes are not allowed in non-<use> shadow trees, so any shadow root we do
    130131    // have should be a use. The assert and following test is here to catch future shadow DOM changes
     
    177178}
    178179
    179 
    180180void EventDispatcher::adjustRelatedTarget(Event* event, PassRefPtr<EventTarget> prpRelatedTarget)
    181181{
     
    217217    while (true) {
    218218        if (ancestorWalker.get()->isShadowRoot()) {
    219             if (determineDispatchBehavior(event, ancestorWalker.get()) == StayInsideShadowDOM)
     219            if (determineDispatchBehavior(event, toShadowRoot(ancestorWalker.get())) == StayInsideShadowDOM)
    220220                return;
    221221            ancestorWalker.parentIncludingInsertionPointAndShadowRoot();
     
    348348}
    349349
    350 EventDispatchBehavior EventDispatcher::determineDispatchBehavior(Event* event, Node* shadowRoot)
     350EventDispatchBehavior EventDispatcher::determineDispatchBehavior(Event* event, ShadowRoot* shadowRoot)
    351351{
    352352#if ENABLE(FULLSCREEN_API) && ENABLE(VIDEO)
     
    356356        // FIXME: We assume that if the full screen element is a media element that it's
    357357        // the video-only full screen. Both here and elsewhere. But that is probably wrong.
    358         if (element->isMediaElement() && shadowRoot && shadowRoot->shadowHost() == element)
     358        if (element->isMediaElement() && shadowRoot && shadowRoot->host() == element)
    359359            return StayInsideShadowDOM;
    360360    }
  • trunk/Source/WebCore/dom/EventDispatcher.h

    r117394 r117723  
    4141class PlatformKeyboardEvent;
    4242class PlatformMouseEvent;
    43 class PlatformWheelEvent;
     43class ShadowRoot;
    4444class TreeScope;
    4545
     
    7676    EventDispatcher(Node*);
    7777
    78     EventDispatchBehavior determineDispatchBehavior(Event*, Node* shadowRoot);
     78    EventDispatchBehavior determineDispatchBehavior(Event*, ShadowRoot*);
     79
    7980    void ensureEventAncestors(Event*);
    8081    const EventContext* topEventContext();
  • trunk/Source/WebCore/dom/Node.cpp

    r117417 r117723  
    498498}
    499499
    500 Element* Node::shadowHost() const
    501 {
    502     return toElement(isShadowRoot() ? parent() : 0);
    503 }
    504 
    505 void Node::setShadowHost(Element* host)
    506 {
    507     ASSERT(!parentNode() && isShadowRoot());
    508     setParent(host);
    509 }
    510 
    511500Node* Node::toNode()
    512501{
     
    15531542
    15541543    if (parent->isShadowRoot())
    1555         return parent->shadowHost();
     1544        return toShadowRoot(parent)->host();
    15561545
    15571546    if (!parent->isElementNode())
  • trunk/Source/WebCore/dom/Node.h

    r117417 r117723  
    230230    ContainerNode* parentOrHostNode() const;
    231231    Element* parentOrHostElement() const;
     232    void setParentOrHostNode(ContainerNode*);
    232233    Node* highestAncestor() const;
    233234
     
    236237    // Returns the parent node, but 0 if the parent node is a ShadowRoot.
    237238    ContainerNode* nonShadowBoundaryParentNode() const;
    238 
    239     Element* shadowHost() const;
    240     void setShadowHost(Element*);
    241239
    242240    bool selfOrAncestorHasDirAutoAttribute() const { return getFlag(SelfOrAncestorHasDirAutoFlag); }
     
    777775    // don't follow this rule.
    778776    using TreeShared<ContainerNode>::parent;
     777    using TreeShared<ContainerNode>::setParent;
    779778
    780779    void trackForDebugging();
     
    834833}
    835834
     835inline void Node::setParentOrHostNode(ContainerNode* parent)
     836{
     837    setParent(parent);
     838}
     839
    836840inline ContainerNode* Node::parentOrHostNode() const
    837841{
  • trunk/Source/WebCore/dom/NodeRenderingContext.cpp

    r117210 r117723  
    6767    if (parent->isShadowRoot() && toShadowRoot(parent)->isYoungest()) {
    6868        m_phase = AttachingShadowChild;
    69         m_parentNodeForRenderingAndStyle = parent->shadowHost();
     69        m_parentNodeForRenderingAndStyle = toShadowRoot(parent)->host();
    7070        return;
    7171    }
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r117421 r117723  
    2828#define ShadowRoot_h
    2929
     30#include "ContainerNode.h"
    3031#include "Document.h"
    3132#include "DocumentFragment.h"
     
    6970    void setApplyAuthorStyles(bool);
    7071
    71     Element* host() const { return shadowHost(); }
     72    Element* host() const;
     73    void setHost(Element*);
    7274    ElementShadow* owner() const;
    7375
     
    104106    InsertionPoint* m_insertionPointAssignedTo;
    105107};
     108
     109inline Element* ShadowRoot::host() const
     110{
     111    return toElement(parentOrHostNode());
     112}
     113
     114inline void ShadowRoot::setHost(Element* host)
     115{
     116    setParentOrHostNode(host);
     117}
    106118
    107119inline InsertionPoint* ShadowRoot::assignedTo() const
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r117420 r117723  
    4040#include "Page.h"
    4141#include "RuntimeEnabledFeatures.h"
     42#include "ShadowRoot.h"
    4243#include "TreeScopeAdopter.h"
    4344#include <wtf/text/AtomicString.h>
     
    222223
    223224    while (treeScope != this && treeScope != document) {
    224         node = treeScope->rootNode()->shadowHost();
     225        node = toShadowRoot(treeScope->rootNode())->host();
    225226        treeScope = node->treeScope();
    226227    }
  • trunk/Source/WebCore/html/shadow/ContentSelectorQuery.cpp

    r117210 r117723  
    6565        return false;
    6666
    67     ASSERT(node->parentNode() == m_insertionPoint->shadowRoot()->shadowHost());
     67    ASSERT(node->parentNode() == m_insertionPoint->shadowRoot()->host());
    6868
    6969    if (m_insertionPoint->select().isNull() || m_insertionPoint->select().isEmpty())
  • trunk/Source/WebCore/page/DragController.cpp

    r117327 r117723  
    6464#include "SecurityOrigin.h"
    6565#include "Settings.h"
     66#include "ShadowRoot.h"
    6667#include "StylePropertySet.h"
    6768#include "Text.h"
     
    277278    // If this is a button inside of the a file input, move up to the file input.
    278279    if (inputElement && inputElement->isTextButton() && inputElement->treeScope()->rootNode()->isShadowRoot())
    279         inputElement = inputElement->treeScope()->rootNode()->shadowHost()->toInputElement();
     280        inputElement = toShadowRoot(inputElement->treeScope()->rootNode())->host()->toInputElement();
    280281
    281282    return inputElement && inputElement->isFileUpload() ? inputElement : 0;
  • trunk/Source/WebCore/page/EventHandler.cpp

    r117210 r117723  
    16001600        // we'd like to EventHandler::handleMousePressEvent to pass the event to the widget and thus the
    16011601        // event target node can't still be the shadow node.
    1602         if (targetNode(mev)->isShadowRoot() && targetNode(mev)->shadowHost()->hasTagName(inputTag)) {
     1602        if (targetNode(mev)->isShadowRoot() && toShadowRoot(targetNode(mev))->host()->hasTagName(inputTag)) {
    16031603            HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
    16041604            mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mouseEvent);
     
    20932093        return 0;
    20942094
    2095     Node* shadowTreeElement = referenceNode->shadowRoot();
    2096     if (!shadowTreeElement)
     2095    ShadowRoot* shadowRoot = referenceNode->shadowRoot();
     2096    if (!shadowRoot)
    20972097        return 0;
    20982098
    2099     Element* shadowTreeParentElement = shadowTreeElement->shadowHost();
     2099    Element* shadowTreeParentElement = shadowRoot->host();
    21002100    if (!shadowTreeParentElement)
    21012101        return 0;
     
    22512251                // will set a selection inside it, which will call setFocuseNodeIfNeeded.
    22522252                ExceptionCode ec = 0;
    2253                 Node* n = node->isShadowRoot() ? node->shadowHost() : node;
     2253                Node* n = node->isShadowRoot() ? toShadowRoot(node)->host() : node;
    22542254                if (m_frame->selection()->isRange()
    22552255                    && m_frame->selection()->toNormalizedRange()->compareNode(n, ec) == Range::NODE_INSIDE
  • trunk/Source/WebCore/page/FocusController.cpp

    r116798 r117723  
    111111    Node* root = rootNode();
    112112    if (root->isShadowRoot())
    113         return root->shadowHost();
     113        return toShadowRoot(root)->host();
    114114    if (Frame* frame = root->document()->frame())
    115115        return frame->ownerElement();
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r117659 r117723  
    5959#include "Settings.h"
    6060#include "SVGTextRunRenderingContext.h"
     61#include "ShadowRoot.h"
    6162#include "TransformState.h"
    6263#include <wtf/StdLibExtras.h>
     
    57745775        return true;
    57755776   
    5776     if (node()->isShadowRoot() && (node()->shadowHost()->hasTagName(inputTag)))
     5777    if (node()->isShadowRoot() && toShadowRoot(node())->host()->hasTagName(inputTag))
    57775778        return true;
    57785779   
  • trunk/Source/WebCore/svg/SVGElementInstance.h

    r111380 r117723  
    4848
    4949    virtual ~SVGElementInstance();
     50
     51    void setParentOrHostNode(SVGElementInstance* instance) { setParent(instance); }
    5052
    5153    virtual const AtomicString& interfaceName() const;
     
    144146private:
    145147    friend class SVGUseElement;
     148    using TreeShared<SVGElementInstance>::parent;
     149    using TreeShared<SVGElementInstance>::setParent;
    146150
    147151    SVGElementInstance(SVGUseElement*, SVGUseElement*, PassRefPtr<SVGElement> originalElement);
  • trunk/Source/WebCore/svg/SVGStyledElement.cpp

    r117195 r117723  
    4343#include "SVGSVGElement.h"
    4444#include "SVGUseElement.h"
     45#include "ShadowRoot.h"
    4546#include <wtf/Assertions.h>
    4647#include <wtf/HashMap.h>
     
    9192    // Walk up the tree, to find out whether we're inside a <use> shadow tree, to find the right title.
    9293    if (isInShadowTree()) {
    93         Element* shadowHostElement = treeScope()->rootNode()->shadowHost();
     94        Element* shadowHostElement = toShadowRoot(treeScope()->rootNode())->host();
    9495        // At this time, SVG nodes are not allowed in non-<use> shadow trees, so any shadow root we do
    9596        // have should be a use. The assert and following test is here to catch future shadow DOM changes
  • trunk/Source/WebCore/svg/SVGTRefElement.cpp

    r117242 r117723  
    143143void SVGShadowText::willRecalcTextStyle(StyleChange change)
    144144{
    145     if (change != NoChange && parentNode()->shadowHost()) {
     145    if (change != NoChange && parentNode()->isShadowRoot()) {
    146146        if (renderer())
    147             renderer()->setStyle(parentNode()->shadowHost()->renderer()->style());
     147            renderer()->setStyle(toShadowRoot(parentNode())->host()->renderer()->style());
    148148    }
    149149}
Note: See TracChangeset for help on using the changeset viewer.