Changeset 137731 in webkit


Ignore:
Timestamp:
Dec 14, 2012, 1:23:22 AM (13 years ago)
Author:
shinyak@chromium.org
Message:

[Shadow DOM] ShadowRoot.getElementById() should work outside document.
https://bugs.webkit.org/show_bug.cgi?id=87815

Reviewed by Hajime Morita.

Source/WebCore:

ShadowRoot.getElementById() didn't work if ShadowRoot is outside document. We need to update id when an element
is in ShadowTree event if it is not in document.

For performance reason, we introduce IsInShadowTree flag, which enables us to check isInTreeScope() fast.
This is maintained in Element::insertedInto and removedFrom. Here, we're anxious about performance regression,
however our benchmark result shows this doesn't regress the performance.

I've measured Dromaeo/dom-modify.html and Parser/html5-full-render.html 2 times.

Dromaeo/dom-modify.html

35.21, 35.27 [runs/s] ---> 35.76, 35.56 [runs/s]

Parser/html5-full-render.html

4328.51, 4254.94 [ms] ---> 4277.14, 4222.43 [ms]

Test: fast/dom/shadow/getelementbyid-in-orphan.html

  • dom/Element.cpp:

(WebCore::Element::insertedInto):

  • dom/Element.h:

(WebCore::Element::updateId):

  • dom/Node.cpp:

(WebCore::Node::insertedInto): If the parent node is in shadow tree, this node should be also in the same shadow tree.
Since this node is inserted, parentOrHostNode() will not be null.
(WebCore::Node::removedFrom): When node is removed from ShadowTree, its treeScope() should not be ShadowRoot.

  • dom/Node.h:

(Node):
(WebCore::Node::isInShadowTree):
(WebCore::Node::isInTreeScope):

LayoutTests:

  • fast/dom/shadow/getelementbyid-in-orphan-expected.txt: Added.
  • fast/dom/shadow/getelementbyid-in-orphan.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r137727 r137731  
     12012-12-14  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        [Shadow DOM] ShadowRoot.getElementById() should work outside document.
     4        https://bugs.webkit.org/show_bug.cgi?id=87815
     5
     6        Reviewed by Hajime Morita.
     7
     8        * fast/dom/shadow/getelementbyid-in-orphan-expected.txt: Added.
     9        * fast/dom/shadow/getelementbyid-in-orphan.html: Added.
     10
    1112012-12-14  Eugene Klyuchnikov  <eustas@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r137730 r137731  
     12012-12-14  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        [Shadow DOM] ShadowRoot.getElementById() should work outside document.
     4        https://bugs.webkit.org/show_bug.cgi?id=87815
     5
     6        Reviewed by Hajime Morita.
     7
     8        ShadowRoot.getElementById() didn't work if ShadowRoot is outside document. We need to update id when an element
     9        is in ShadowTree event if it is not in document.
     10
     11        For performance reason, we introduce IsInShadowTree flag, which enables us to check isInTreeScope() fast.
     12        This is maintained in Element::insertedInto and removedFrom. Here, we're anxious about performance regression,
     13        however our benchmark result shows this doesn't regress the performance.
     14
     15        I've measured Dromaeo/dom-modify.html and Parser/html5-full-render.html 2 times.
     16
     17        Dromaeo/dom-modify.html
     18             35.21,   35.27 [runs/s] --->   35.76,   35.56 [runs/s]
     19        Parser/html5-full-render.html
     20           4328.51, 4254.94 [ms]     ---> 4277.14, 4222.43 [ms]
     21
     22        Test: fast/dom/shadow/getelementbyid-in-orphan.html
     23
     24        * dom/Element.cpp:
     25        (WebCore::Element::insertedInto):
     26        * dom/Element.h:
     27        (WebCore::Element::updateId):
     28        * dom/Node.cpp:
     29        (WebCore::Node::insertedInto): If the parent node is in shadow tree, this node should be also in the same shadow tree.
     30        Since this node is inserted, parentOrHostNode() will not be null.
     31        (WebCore::Node::removedFrom): When node is removed from ShadowTree, its treeScope() should not be ShadowRoot.
     32        * dom/Node.h:
     33        (Node):
     34        (WebCore::Node::isInShadowTree):
     35        (WebCore::Node::isInTreeScope):
     36
    1372012-12-14  Antoine Quint  <graouts@apple.com>
    238
  • trunk/Source/WebCore/dom/Element.cpp

    r137715 r137731  
    10991099#endif
    11001100
    1101     if (!insertionPoint->inDocument())
     1101    if (!insertionPoint->isInTreeScope())
    11021102        return InsertionDone;
    11031103
  • trunk/Source/WebCore/dom/Element.h

    r137715 r137731  
    680680inline void Element::updateId(const AtomicString& oldId, const AtomicString& newId)
    681681{
    682     if (!inDocument())
     682    if (!isInTreeScope())
    683683        return;
    684684
     
    691691inline void Element::updateId(TreeScope* scope, const AtomicString& oldId, const AtomicString& newId)
    692692{
    693     ASSERT(inDocument());
     693    ASSERT(isInTreeScope());
    694694    ASSERT(oldId != newId);
    695695
  • trunk/Source/WebCore/dom/Node.cpp

    r137715 r137731  
    12711271}
    12721272
    1273 bool Node::isInShadowTree() const
    1274 {
    1275     return treeScope() != document();
    1276 }
    1277 
    12781273Element* Node::parentOrHostElement() const
    12791274{
     
    21012096    if (insertionPoint->inDocument())
    21022097        setFlag(InDocumentFlag);
     2098    if (parentOrHostNode()->isInShadowTree())
     2099        setFlag(IsInShadowTreeFlag);
    21032100    return InsertionDone;
    21042101}
     
    21092106    if (insertionPoint->inDocument())
    21102107        clearFlag(InDocumentFlag);
     2108    if (isInShadowTree() && !treeScope()->rootNode()->isShadowRoot())
     2109        clearFlag(IsInShadowTreeFlag);
    21112110}
    21122111
  • trunk/Source/WebCore/dom/Node.h

    r137715 r137731  
    276276    // Returns 0, a child of ShadowRoot, or a legacy shadow root.
    277277    Node* nonBoundaryShadowTreeRootNode();
    278     bool isInShadowTree() const;
     278
    279279    // Node's parent, shadow tree host.
    280280    ContainerNode* parentOrHostNode() const;
     
    477477        return getFlag(InDocumentFlag);
    478478    }
     479    bool isInShadowTree() const { return getFlag(IsInShadowTreeFlag); }
     480    bool isInTreeScope() const { return getFlag(static_cast<NodeFlags>(InDocumentFlag | IsInShadowTreeFlag)); }
    479481
    480482    bool isReadOnlyNode() const { return nodeType() == ENTITY_REFERENCE_NODE; }
     
    713715        V8CollectableDuringMinorGCFlag = 1 << 24,
    714716        NeedsShadowTreeWalkerFlag = 1 << 25,
     717        IsInShadowTreeFlag = 1 << 26,
    715718
    716719        DefaultNodeFlags = IsParsingChildrenFinishedFlag
    717720    };
    718721
    719     // 6 bits remaining
     722    // 5 bits remaining
    720723
    721724    bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
     
    731734        CreateElement = CreateContainer | IsElementFlag,
    732735        CreatePseudoElement =  CreateElement | InDocumentFlag | NeedsShadowTreeWalkerFlag,
    733         CreateShadowRoot = CreateContainer | IsDocumentFragmentFlag | NeedsShadowTreeWalkerFlag,
     736        CreateShadowRoot = CreateContainer | IsDocumentFragmentFlag | NeedsShadowTreeWalkerFlag | IsInShadowTreeFlag,
    734737        CreateDocumentFragment = CreateContainer | IsDocumentFragmentFlag,
    735738        CreateStyledElement = CreateElement | IsStyledElementFlag,
Note: See TracChangeset for help on using the changeset viewer.