⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 184034 in webkit


Ignore:
Timestamp:
May 8, 2015, 6:14:17 PM (11 years ago)
Author:
weinig@apple.com
Message:

Element Traversal is not just Elements anymore
https://bugs.webkit.org/show_bug.cgi?id=144822

Reviewed by Simon Fraser.

Source/WebCore:

Match other browsers and the new DOM spec at https://dom.spec.whatwg.org by
exposing the element traversal methods on non-Elements.

  • Makes firstElementChild, lastElementChild and childElementCount available on Document and DocumentFragment in addition to Element.
  • Makes nextElementSibling and previousElementSibling available on CharacterData in addition to Element.

Tests: fast/dom/element-traversal-on-character-data.html

fast/dom/element-traversal-on-document-fragment.html
fast/dom/element-traversal-on-document.html

  • dom/CharacterData.idl:

Expose nextElementSibling and previousElementSibling.

  • dom/ContainerNode.cpp:

(WebCore::ContainerNode::firstElementChild):
(WebCore::ContainerNode::lastElementChild):
(WebCore::ContainerNode::childElementCount):

  • dom/ContainerNode.h:

Move implementations of firstElementChild, lastElementChild and childElementCount here
from Element to make them shareable.

  • dom/Document.idl:
  • dom/DocumentFragment.idl:

Expose firstElementChild, lastElementChild and childElementCount.

  • dom/Element.cpp:

(WebCore::Element::firstElementChild): Deleted.
(WebCore::Element::lastElementChild): Deleted.
(WebCore::Element::previousElementSibling): Deleted.
(WebCore::Element::nextElementSibling): Deleted.
(WebCore::Element::childElementCount): Deleted.

  • dom/Element.h:

Move element traversal functions down to Node and ContainerNode.

  • dom/Element.idl:

Update comments to indicate where these functions are defined now.

  • dom/Node.cpp:

(WebCore::Node::previousElementSibling):
(WebCore::Node::nextElementSibling):

  • dom/Node.h:

Move implementations of nextElementSibling and previousElementSibling here
from Element to make them shareable.

LayoutTests:

Add new tests for element traversal functions on Document, DocumentFragment and CharacterData.

  • fast/dom/element-traversal-on-character-data-expected.txt: Added.
  • fast/dom/element-traversal-on-character-data.html: Added.
  • fast/dom/element-traversal-on-document-expected.txt: Added.
  • fast/dom/element-traversal-on-document-fragment-expected.txt: Added.
  • fast/dom/element-traversal-on-document-fragment.html: Added.
  • fast/dom/element-traversal-on-document.html: Added.
Location:
trunk
Files:
6 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r184031 r184034  
     12015-05-08  Sam Weinig  <sam@webkit.org>
     2
     3        Element Traversal is not just Elements anymore
     4        https://bugs.webkit.org/show_bug.cgi?id=144822
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add new tests for element traversal functions on Document, DocumentFragment and CharacterData.
     9
     10        * fast/dom/element-traversal-on-character-data-expected.txt: Added.
     11        * fast/dom/element-traversal-on-character-data.html: Added.
     12        * fast/dom/element-traversal-on-document-expected.txt: Added.
     13        * fast/dom/element-traversal-on-document-fragment-expected.txt: Added.
     14        * fast/dom/element-traversal-on-document-fragment.html: Added.
     15        * fast/dom/element-traversal-on-document.html: Added.
     16
    1172015-05-08  Martin Robinson  <mrobinson@igalia.com>
    218
  • trunk/Source/WebCore/ChangeLog

    r184010 r184034  
     12015-05-08  Sam Weinig  <sam@webkit.org>
     2
     3        Element Traversal is not just Elements anymore
     4        https://bugs.webkit.org/show_bug.cgi?id=144822
     5
     6        Reviewed by Simon Fraser.
     7
     8        Match other browsers and the new DOM spec at https://dom.spec.whatwg.org by
     9        exposing the element traversal methods on non-Elements.
     10
     11        - Makes firstElementChild, lastElementChild and childElementCount available on
     12          Document and DocumentFragment in addition to Element.
     13        - Makes nextElementSibling and previousElementSibling available on CharacterData
     14          in addition to Element.
     15
     16        Tests: fast/dom/element-traversal-on-character-data.html
     17               fast/dom/element-traversal-on-document-fragment.html
     18               fast/dom/element-traversal-on-document.html
     19
     20        * dom/CharacterData.idl:
     21        Expose nextElementSibling and previousElementSibling.
     22
     23        * dom/ContainerNode.cpp:
     24        (WebCore::ContainerNode::firstElementChild):
     25        (WebCore::ContainerNode::lastElementChild):
     26        (WebCore::ContainerNode::childElementCount):
     27        * dom/ContainerNode.h:
     28        Move implementations of firstElementChild, lastElementChild and childElementCount here
     29        from Element to make them shareable.
     30
     31        * dom/Document.idl:
     32        * dom/DocumentFragment.idl:
     33        Expose firstElementChild, lastElementChild and childElementCount.
     34
     35        * dom/Element.cpp:
     36        (WebCore::Element::firstElementChild): Deleted.
     37        (WebCore::Element::lastElementChild): Deleted.
     38        (WebCore::Element::previousElementSibling): Deleted.
     39        (WebCore::Element::nextElementSibling): Deleted.
     40        (WebCore::Element::childElementCount): Deleted.
     41        * dom/Element.h:
     42        Move element traversal functions down to Node and ContainerNode.
     43
     44        * dom/Element.idl:
     45        Update comments to indicate where these functions are defined now.
     46
     47        * dom/Node.cpp:
     48        (WebCore::Node::previousElementSibling):
     49        (WebCore::Node::nextElementSibling):
     50        * dom/Node.h:
     51        Move implementations of nextElementSibling and previousElementSibling here
     52        from Element to make them shareable.
     53
    1542015-05-08  Michael Catanzaro  <mcatanzaro@igalia.com>, Martin Robinson <mrobinson@igalia.com>
    255
  • trunk/Source/WebCore/dom/CharacterData.idl

    r159061 r184034  
    3838                                    [IsIndex, Default=Undefined] optional unsigned long length,
    3939                                    [Default=Undefined] optional DOMString data);
     40
     41    // From the NonDocumentTypeChildNode interface - https://dom.spec.whatwg.org/#nondocumenttypechildnode
     42    // FIXME: Move this to a seperate NonDocumentTypeChildNode IDL file when one exists.
     43    readonly attribute Element previousElementSibling;
     44    readonly attribute Element nextElementSibling;
    4045};
    4146
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r183064 r184034  
    912912}
    913913
     914Element* ContainerNode::firstElementChild() const
     915{
     916    ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
     917
     918    return ElementTraversal::firstChild(*this);
     919}
     920
     921Element* ContainerNode::lastElementChild() const
     922{
     923    ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
     924
     925    return ElementTraversal::lastChild(*this);
     926}
     927
     928unsigned ContainerNode::childElementCount() const
     929{
     930    ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
     931
     932    unsigned count = 0;
     933    Node* n = firstChild();
     934    while (n) {
     935        count += n->isElementNode();
     936        n = n->nextSibling();
     937    }
     938    return count;
     939}
     940
    914941} // namespace WebCore
  • trunk/Source/WebCore/dom/ContainerNode.h

    r183169 r184034  
    146146    RefPtr<RadioNodeList> radioNodeList(const AtomicString&);
    147147
     148    // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
     149    Element* firstElementChild() const;
     150    Element* lastElementChild() const;
     151    unsigned childElementCount() const;
     152
    148153protected:
    149154    explicit ContainerNode(Document&, ConstructionType = CreateContainer);
  • trunk/Source/WebCore/dom/Document.idl

    r183967 r184034  
    11/*
    2  * Copyright (C) 2006, 2007, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007, 2011, 2015 Apple Inc. All rights reserved.
    33 * Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
    44 *
     
    343343    readonly attribute DOMString origin;
    344344
     345    // http://dev.w3.org/csswg/cssom-view/#dom-document-scrollingelement
    345346    readonly attribute Element scrollingElement;
     347
     348    // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
     349    // FIXME: Move this to a seperate ParentNode IDL file when one exists.
     350    readonly attribute Element firstElementChild;
     351    readonly attribute Element lastElementChild;
     352    readonly attribute unsigned long childElementCount;
    346353};
    347354
  • trunk/Source/WebCore/dom/DocumentFragment.idl

    r177864 r184034  
    11/*
    2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007, 2008, 2015 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    2525    [RaisesException] Element querySelector(DOMString selectors);
    2626    [RaisesException] NodeList querySelectorAll(DOMString selectors);
     27   
     28    // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
     29    // FIXME: Move this to a seperate ParentNode IDL file when one exists.
     30    readonly attribute Element firstElementChild;
     31    readonly attribute Element lastElementChild;
     32    readonly attribute unsigned long childElementCount;
    2733};
    2834
  • trunk/Source/WebCore/dom/Element.cpp

    r183706 r184034  
    26202620}
    26212621
    2622 // ElementTraversal API
    2623 Element* Element::firstElementChild() const
    2624 {
    2625     return ElementTraversal::firstChild(*this);
    2626 }
    2627 
    2628 Element* Element::lastElementChild() const
    2629 {
    2630     return ElementTraversal::lastChild(*this);
    2631 }
    2632 
    2633 Element* Element::previousElementSibling() const
    2634 {
    2635     return ElementTraversal::previousSibling(*this);
    2636 }
    2637 
    2638 Element* Element::nextElementSibling() const
    2639 {
    2640     return ElementTraversal::nextSibling(*this);
    2641 }
    2642 
    2643 unsigned Element::childElementCount() const
    2644 {
    2645     unsigned count = 0;
    2646     Node* n = firstChild();
    2647     while (n) {
    2648         count += n->isElementNode();
    2649         n = n->nextSibling();
    2650     }
    2651     return count;
    2652 }
    2653 
    26542622bool Element::matchesReadWritePseudoClass() const
    26552623{
  • trunk/Source/WebCore/dom/Element.h

    r183436 r184034  
    372372    void didShadowTreeAwareChildrenChange();
    373373
    374     // ElementTraversal API
    375     Element* firstElementChild() const;
    376     Element* lastElementChild() const;
    377     Element* previousElementSibling() const;
    378     Element* nextElementSibling() const;
    379     unsigned childElementCount() const;
    380 
    381374    virtual bool matchesReadWritePseudoClass() const;
    382375    bool matches(const String& selectors, ExceptionCode&);
  • trunk/Source/WebCore/dom/Element.idl

    r183021 r184034  
    128128    [ImplementedAs=matches, RaisesException] boolean webkitMatchesSelector(DOMString selectors);
    129129
    130     // ElementTraversal API
     130    // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
     131    // FIXME: Move this to a seperate ParentNode IDL file when one exists.
    131132    readonly attribute Element firstElementChild;
    132133    readonly attribute Element lastElementChild;
     134    readonly attribute unsigned long childElementCount;
     135
     136    // From the NonDocumentTypeChildNode interface - https://dom.spec.whatwg.org/#nondocumenttypechildnode
     137    // FIXME: Move this to a seperate NonDocumentTypeChildNode IDL file when one exists.
    133138    readonly attribute Element previousElementSibling;
    134139    readonly attribute Element nextElementSibling;
    135     readonly attribute unsigned long childElementCount;
    136140
    137141#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
  • trunk/Source/WebCore/dom/Node.cpp

    r183064 r184034  
    4444#include "ElementIterator.h"
    4545#include "ElementRareData.h"
     46#include "ElementTraversal.h"
    4647#include "EventDispatcher.h"
    4748#include "EventException.h"
     
    430431}
    431432
     433Element* Node::previousElementSibling() const
     434{
     435    ASSERT(is<CharacterData>(*this) || is<Element>(*this));
     436
     437    return ElementTraversal::previousSibling(*this);
     438}
     439
     440Element* Node::nextElementSibling() const
     441{
     442    ASSERT(is<CharacterData>(*this) || is<Element>(*this));
     443
     444    return ElementTraversal::nextSibling(*this);
     445}
     446
    432447bool Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec)
    433448{
  • trunk/Source/WebCore/dom/Node.h

    r183906 r184034  
    224224    Node* firstDescendant() const;
    225225
     226    // From the NonDocumentTypeChildNode - https://dom.spec.whatwg.org/#nondocumenttypechildnode
     227    Element* previousElementSibling() const;
     228    Element* nextElementSibling() const;
     229
    226230    // Other methods (not part of DOM)
    227231
Note: See TracChangeset for help on using the changeset viewer.