Changeset 34543 in webkit


Ignore:
Timestamp:
Jun 14, 2008 7:03:24 PM (16 years ago)
Author:
weinig@apple.com
Message:

WebCore:

2008-06-14 Sam Weinig <sam@webkit.org>

Reviewed by Dan Bernstein.

Fix for <rdar://problem/5775192>
insertAdjacentHTML and insertAdjacentText are not implemented although insertAdjacentElement is.

  • Implements insertAdjacentHTML and insertAdjacentText for HTMLElement.
  • Moves the insertAdjacentElement implementation from Element to HTMLElement.

Tests: fast/dynamic/insertAdjacentHTML.html

fast/dynamic/insertAdjacentText.html

  • dom/Element.cpp:
  • dom/Element.h:
  • dom/Element.idl:
  • html/HTMLElement.cpp: (WebCore::HTMLElement::insertAdjacent): (WebCore::HTMLElement::insertAdjacentElement): (WebCore::HTMLElement::insertAdjacentHTML): (WebCore::HTMLElement::insertAdjacentText):
  • html/HTMLElement.h:
  • html/HTMLElement.idl:

LayoutTests:

2008-06-14 Sam Weinig <sam@webkit.org>

Reviewed by Dan Bernstein.

Tests for <rdar://problem/5775192>
insertAdjacentHTML and insertAdjacentText are not implemented although insertAdjacentElement is.

  • fast/dom/Window/window-properties-expected.txt:
  • fast/dom/domListEnumeration-expected.txt:
  • fast/dom/resources/domListEnumeration.js:
  • fast/dynamic/insertAdjacentElement.html:
  • fast/dynamic/insertAdjacentHTML-expected.txt: Added.
  • fast/dynamic/insertAdjacentHTML.html: Copied from fast/dynamic/insertAdjacentElement.html.
  • fast/dynamic/insertAdjacentText-expected.txt: Added.
  • fast/dynamic/insertAdjacentText.html: Copied from fast/dynamic/insertAdjacentElement.html.
  • platform/mac/fast/dynamic/insertAdjacentElement-expected.txt:
Location:
trunk
Files:
2 added
13 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r34542 r34543  
     12008-06-14  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        Tests for <rdar://problem/5775192>
     6        insertAdjacentHTML and insertAdjacentText are not implemented although insertAdjacentElement is.
     7
     8        * fast/dom/Window/window-properties-expected.txt:
     9        * fast/dom/domListEnumeration-expected.txt:
     10        * fast/dom/resources/domListEnumeration.js:
     11        * fast/dynamic/insertAdjacentElement.html:
     12        * fast/dynamic/insertAdjacentHTML-expected.txt: Added.
     13        * fast/dynamic/insertAdjacentHTML.html: Copied from fast/dynamic/insertAdjacentElement.html.
     14        * fast/dynamic/insertAdjacentText-expected.txt: Added.
     15        * fast/dynamic/insertAdjacentText.html: Copied from fast/dynamic/insertAdjacentElement.html.
     16        * platform/mac/fast/dynamic/insertAdjacentElement-expected.txt:
     17
    1182008-06-14  Darin Adler  <darin@apple.com>
    219
  • trunk/LayoutTests/fast/dom/Window/window-properties-expected.txt

    r34010 r34543  
    521521window.Element.prototype.hasAttributes [function]
    522522window.Element.prototype.hasChildNodes [function]
    523 window.Element.prototype.insertAdjacentElement [function]
    524523window.Element.prototype.insertBefore [function]
    525524window.Element.prototype.isDefaultNamespace [function]
  • trunk/LayoutTests/fast/dom/domListEnumeration-expected.txt

    r34452 r34543  
    3333
    3434[object HTMLFormElement]
    35 PASS resultArray.length is 119
     35PASS resultArray.length is 121
    3636PASS resultArray[0].i is '0'
    3737PASS resultArray[0].item is document.getElementsByTagName('select')[0]
     
    4242
    4343[object HTMLSelectElement]
    44 PASS resultArray.length is 122
     44PASS resultArray.length is 124
    4545PASS resultArray[0].i is '0'
    4646PASS resultArray[0].item is document.getElementsByTagName('option')[0]
  • trunk/LayoutTests/fast/dom/resources/domListEnumeration.js

    r34452 r34543  
    131131var htmlFormElement = document.getElementsByTagName('form')[0];
    132132resultArray = iterateList(htmlFormElement);
    133 shouldBe("resultArray.length", "119");
     133shouldBe("resultArray.length", "121");
    134134shouldBe("resultArray[0].i", "'0'");
    135135shouldBe("resultArray[0].item", "document.getElementsByTagName('select')[0]");
     
    142142var htmlSelectElement = document.getElementsByTagName('select')[0];
    143143resultArray = iterateList(htmlSelectElement);
    144 shouldBe("resultArray.length", "122");
     144shouldBe("resultArray.length", "124");
    145145shouldBe("resultArray[0].i", "'0'");
    146146shouldBe("resultArray[0].item", "document.getElementsByTagName('option')[0]");
  • trunk/LayoutTests/fast/dynamic/insertAdjacentElement.html

    r13492 r34543  
    11<body>
    22   <pre id="error-log"></pre>
    3 
    43   <span id="container" style="color: green">
    54   </span>
     
    2322</body>
    2423<script>
     24    if (window.layoutTestController)
     25        layoutTestController.dumpAsText();
     26
    2527   // verify all standard cases
    2628   document.getElementById("container").insertAdjacentElement("beforeBegin", document.getElementById("1"));
     
    5557   if (passes) {
    5658      document.getElementById("status").style.color = "green";
    57       document.getElementById("status").innerHTML = "PASS";
     59      document.getElementById("status").innerHTML = "<br><br>PASS";
    5860   }
    5961</script>
  • trunk/LayoutTests/fast/dynamic/insertAdjacentHTML.html

    r34540 r34543  
    11<body>
    22   <pre id="error-log"></pre>
    3 
    43   <span id="container" style="color: green">
    54   </span>
    6    <div style="display: none">
    7       <span id="1">
    8          1 (black)
    9       </span>
    10       <span id="2">
    11          2 (green)
    12       </span>
    13       <span id="3">
    14          3 (green)
    15       </span>
    16       <span id="4">
    17          4 (black)
    18       </span>
    19    </div>
    205   <span id="status" style="color: red">
    216      FAILURE
     
    238</body>
    249<script>
     10if (window.layoutTestController)
     11    layoutTestController.dumpAsText();
     12
    2513   // verify all standard cases
    26    document.getElementById("container").insertAdjacentElement("beforeBegin", document.getElementById("1"));
    27    document.getElementById("container").insertAdjacentElement("afterBegin", document.getElementById("2"));
    28    document.getElementById("container").insertAdjacentElement("beforeEnd", document.getElementById("3"));
    29    document.getElementById("container").insertAdjacentElement("afterEnd", document.getElementById("4"));
     14   document.getElementById("container").insertAdjacentHTML("beforeBegin", "<span id='1''> 1 (black)</span>");
     15   document.getElementById("container").insertAdjacentHTML("afterBegin", "<span id='2''> 2 (green)</span>");
     16   document.getElementById("container").insertAdjacentHTML("beforeEnd", "<span id='3''> 3 (green)</span>");
     17   document.getElementById("container").insertAdjacentHTML("afterEnd", "<span id='4''> 4 (black)</span>");
    3018
    3119   function assertThrows(func) {
     
    4432   passes = passes & assertThrows(function() {
    4533      // should throw TYPE_MISMATCH_ERR
    46       document.getElementById("container").insertAdjacentElement("blah", document.getElementById("1"));
    47    });
    48    passes = passes & assertThrows(function() {
    49       // should throw NOT_SUPPORTED_ERR
    50       document.getElementById("container").insertAdjacentElement("beforeEnd", null);
     34      document.getElementById("container").insertAdjacentHTML("blah", "<span>html</span>");
    5135   });
    5236
    53    var elt = document.createElement("div");
    54    passes = passes & (elt.insertAdjacentElement("beforeBegin", document.createElement("p")) == null);
    5537   if (passes) {
    5638      document.getElementById("status").style.color = "green";
    57       document.getElementById("status").innerHTML = "PASS";
     39      document.getElementById("status").innerHTML = "<br<br>PASS";
    5840   }
    5941</script>
  • trunk/LayoutTests/fast/dynamic/insertAdjacentText.html

    r34540 r34543  
    11<body>
    22   <pre id="error-log"></pre>
    3 
    43   <span id="container" style="color: green">
    54   </span>
    6    <div style="display: none">
    7       <span id="1">
    8          1 (black)
    9       </span>
    10       <span id="2">
    11          2 (green)
    12       </span>
    13       <span id="3">
    14          3 (green)
    15       </span>
    16       <span id="4">
    17          4 (black)
    18       </span>
    19    </div>
    205   <span id="status" style="color: red">
    216      FAILURE
     
    238</body>
    249<script>
     10    if (window.layoutTestController)
     11        layoutTestController.dumpAsText();
     12
    2513   // verify all standard cases
    26    document.getElementById("container").insertAdjacentElement("beforeBegin", document.getElementById("1"));
    27    document.getElementById("container").insertAdjacentElement("afterBegin", document.getElementById("2"));
    28    document.getElementById("container").insertAdjacentElement("beforeEnd", document.getElementById("3"));
    29    document.getElementById("container").insertAdjacentElement("afterEnd", document.getElementById("4"));
     14   document.getElementById("container").insertAdjacentText("beforeBegin", " 1 (black)");
     15   document.getElementById("container").insertAdjacentText("afterBegin", " 2 (green)");
     16   document.getElementById("container").insertAdjacentText("beforeEnd", " 3 (green)");
     17   document.getElementById("container").insertAdjacentText("afterEnd", " 4 (black)");
    3018
    3119   function assertThrows(func) {
     
    4432   passes = passes & assertThrows(function() {
    4533      // should throw TYPE_MISMATCH_ERR
    46       document.getElementById("container").insertAdjacentElement("blah", document.getElementById("1"));
    47    });
    48    passes = passes & assertThrows(function() {
    49       // should throw NOT_SUPPORTED_ERR
    50       document.getElementById("container").insertAdjacentElement("beforeEnd", null);
     34      document.getElementById("container").insertAdjacentText("blah", "text");
    5135   });
    5236
    53    var elt = document.createElement("div");
    54    passes = passes & (elt.insertAdjacentElement("beforeBegin", document.createElement("p")) == null);
    5537   if (passes) {
    5638      document.getElementById("status").style.color = "green";
    57       document.getElementById("status").innerHTML = "PASS";
     39      document.getElementById("status").innerHTML = "<br<br>PASS";
    5840   }
    5941</script>
  • trunk/LayoutTests/platform/mac/fast/dynamic/insertAdjacentElement-expected.txt

    r30635 r34543  
    1 layer at (0,0) size 800x600
    2   RenderView at (0,0) size 800x600
    3 layer at (0,0) size 800x600
    4   RenderBlock {HTML} at (0,0) size 800x600
    5     RenderBody {BODY} at (8,8) size 784x584
    6       RenderBlock {PRE} at (0,0) size 784x30
    7         RenderText {#text} at (0,0) size 552x30
    8           text run at (0,0) width 544: "Caught expected exception: Error: NOT_SUPPORTED_ERR: DOM Exception 9"
    9           text run at (544,0) width 0: " "
    10           text run at (0,15) width 552: "Caught expected exception: Error: TYPE_MISMATCH_ERR: DOM Exception 17"
    11           text run at (552,15) width 0: " "
    12       RenderBlock (anonymous) at (0,43) size 784x18
    13         RenderInline {SPAN} at (0,0) size 60x18
    14           RenderText {#text} at (0,0) size 60x18
    15             text run at (0,0) width 60: "1 (black) "
    16         RenderInline {SPAN} at (0,0) size 122x18 [color=#008000]
    17           RenderInline {SPAN} at (0,0) size 61x18
    18             RenderText {#text} at (60,0) size 61x18
    19               text run at (60,0) width 61: "2 (green) "
    20           RenderText {#text} at (0,0) size 0x0
    21           RenderInline {SPAN} at (0,0) size 61x18
    22             RenderText {#text} at (121,0) size 61x18
    23               text run at (121,0) width 61: "3 (green) "
    24         RenderInline {SPAN} at (0,0) size 60x18
    25           RenderText {#text} at (182,0) size 60x18
    26             text run at (182,0) width 60: "4 (black) "
    27         RenderText {#text} at (0,0) size 0x0
    28         RenderText {#text} at (0,0) size 0x0
    29         RenderInline {SPAN} at (0,0) size 39x18 [color=#008000]
    30           RenderText {#text} at (242,0) size 39x18
    31             text run at (242,0) width 39: "PASS"
    32         RenderText {#text} at (0,0) size 0x0
    33         RenderText {#text} at (0,0) size 0x0
    34         RenderText {#text} at (0,0) size 0x0
     1Caught expected exception: Error: NOT_SUPPORTED_ERR: DOM Exception 9
     2Caught expected exception: Error: TYPE_MISMATCH_ERR: DOM Exception 17
     31 (black) 2 (green) 3 (green) 4 (black)
     4
     5PASS
  • trunk/WebCore/ChangeLog

    r34542 r34543  
     12008-06-14  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        Fix for <rdar://problem/5775192>
     6        insertAdjacentHTML and insertAdjacentText are not implemented although insertAdjacentElement is.
     7
     8        - Implements insertAdjacentHTML and insertAdjacentText for HTMLElement.
     9        - Moves the insertAdjacentElement implementation from Element to HTMLElement.
     10
     11        Tests: fast/dynamic/insertAdjacentHTML.html
     12               fast/dynamic/insertAdjacentText.html
     13
     14        * dom/Element.cpp:
     15        * dom/Element.h:
     16        * dom/Element.idl:
     17        * html/HTMLElement.cpp:
     18        (WebCore::HTMLElement::insertAdjacent):
     19        (WebCore::HTMLElement::insertAdjacentElement):
     20        (WebCore::HTMLElement::insertAdjacentHTML):
     21        (WebCore::HTMLElement::insertAdjacentText):
     22        * html/HTMLElement.h:
     23        * html/HTMLElement.idl:
     24
    1252008-06-14  Darin Adler  <darin@apple.com>
    226
  • trunk/WebCore/dom/Element.cpp

    r34536 r34543  
    618618}
    619619
    620 Node* Element::insertAdjacentElement(const String& where, Node* newChild, int& exception)
    621 {
    622     if (!newChild) {
    623         // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative
    624         exception = TYPE_MISMATCH_ERR;
    625         return 0;
    626     }
    627    
    628     // In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd",
    629     // a document fragment is created and the elements appended in the correct order. This document
    630     // fragment isn't returned anywhere.
    631     //
    632     // This is impossible for us to implement as the DOM tree does not allow for such structures,
    633     // Opera also appears to disallow such usage.
    634    
    635     if (equalIgnoringCase(where, "beforeBegin")) {
    636         if (Node* p = parent())
    637             return p->insertBefore(newChild, this, exception) ? newChild : 0;
    638     } else if (equalIgnoringCase(where, "afterBegin")) {
    639         return insertBefore(newChild, firstChild(), exception) ? newChild : 0;
    640     } else if (equalIgnoringCase(where, "beforeEnd")) {
    641         return appendChild(newChild, exception) ? newChild : 0;
    642     } else if (equalIgnoringCase(where, "afterEnd")) {
    643         if (Node* p = parent())
    644             return p->insertBefore(newChild, nextSibling(), exception) ? newChild : 0;
    645     } else {
    646         // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative
    647         exception = NOT_SUPPORTED_ERR;
    648     }
    649     return 0;
    650 }
    651 
    652620bool Element::contains(const Node* node) const
    653621{
  • trunk/WebCore/dom/Element.h

    r34536 r34543  
    169169#endif
    170170
    171     Node* insertAdjacentElement(const String& where, Node* newChild, ExceptionCode&);
    172171    bool contains(const Node*) const;
    173172
  • trunk/WebCore/dom/Element.idl

    r34515 r34543  
    9393        // IE extensions
    9494
    95         Node insertAdjacentElement(in DOMString position,
    96                                    in Node element)
    97             raises(DOMException);
    9895        boolean contains(in Element element);
    9996
  • trunk/WebCore/html/HTMLElement.cpp

    r34432 r34543  
    22 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    4  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
     4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
    55 *
    66 * This library is free software; you can redistribute it and/or
     
    493493}
    494494
     495Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, ExceptionCode& ec)
     496{
     497    // In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd",
     498    // a document fragment is created and the elements appended in the correct order. This document
     499    // fragment isn't returned anywhere.
     500    //
     501    // This is impossible for us to implement as the DOM tree does not allow for such structures,
     502    // Opera also appears to disallow such usage.
     503
     504    if (equalIgnoringCase(where, "beforeBegin")) {
     505        if (Node* p = parent())
     506            return p->insertBefore(newChild, this, ec) ? newChild : 0;
     507        return 0;
     508    }
     509
     510    if (equalIgnoringCase(where, "afterBegin"))
     511        return insertBefore(newChild, firstChild(), ec) ? newChild : 0;
     512
     513    if (equalIgnoringCase(where, "beforeEnd"))
     514        return appendChild(newChild, ec) ? newChild : 0;
     515
     516    if (equalIgnoringCase(where, "afterEnd")) {
     517        if (Node* p = parent())
     518            return p->insertBefore(newChild, nextSibling(), ec) ? newChild : 0;
     519        return 0;
     520    }
     521   
     522    // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative
     523    ec = NOT_SUPPORTED_ERR;
     524    return 0;
     525}
     526
     527Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChild, ExceptionCode& ec)
     528{
     529    if (!newChild) {
     530        // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative
     531        ec = TYPE_MISMATCH_ERR;
     532        return 0;
     533    }
     534
     535    Node* returnValue = insertAdjacent(where, newChild, ec);
     536    ASSERT(!returnValue || returnValue->isElementNode());
     537    return static_cast<Element*>(returnValue);
     538}
     539
     540void HTMLElement::insertAdjacentHTML(const String& where, const String& html, ExceptionCode& ec)
     541{
     542    // FIXME: perhaps this should use createFragmentFromMarkup() instead as
     543    // createContextualFragment() has all sorts of odd rules in it.
     544    RefPtr<DocumentFragment> fragment = createContextualFragment(html);
     545    if (!fragment) {
     546        ec = NO_MODIFICATION_ALLOWED_ERR;
     547        return;
     548    }
     549
     550    insertAdjacent(where, fragment.get(), ec);
     551}
     552
     553void HTMLElement::insertAdjacentText(const String& where, const String& text, ExceptionCode& ec)
     554{
     555    RefPtr<Text> textNode = document()->createTextNode(text);
     556    insertAdjacent(where, textNode.get(), ec);
     557}
     558
    495559void HTMLElement::addHTMLAlignment(MappedAttribute* attr)
    496560{
  • trunk/WebCore/html/HTMLElement.h

    r33577 r34543  
    7070    void setInnerText(const String&, ExceptionCode&);
    7171    void setOuterText(const String&, ExceptionCode&);
    72    
     72
     73    Element* insertAdjacentElement(const String& where, Element* newChild, ExceptionCode&);
     74    void insertAdjacentHTML(const String& where, const String& html, ExceptionCode&);
     75    void insertAdjacentText(const String& where, const String& text, ExceptionCode&);
     76
    7377    virtual bool isFocusable() const;
    7478    virtual bool isContentEditable() const;
     
    108112private:
    109113    virtual HTMLFormElement* virtualForm() const;
     114    Node* insertAdjacent(const String& where, Node* newChild, ExceptionCode&);
    110115};
    111116
    112 } //namespace
     117} // namespace WebCore
    113118
    114 #endif
     119#endif // HTMLElement_h
  • trunk/WebCore/html/HTMLElement.idl

    r32664 r34543  
    5050                     setter raises(DOMException);
    5151
     52        Element insertAdjacentElement(in DOMString where,
     53                                      in Element element)
     54            raises(DOMException);
     55        void insertAdjacentHTML(in DOMString where,
     56                                in DOMString html)
     57            raises(DOMException);
     58        void insertAdjacentText(in DOMString where,
     59                                in DOMString text)
     60            raises(DOMException);
     61
    5262        readonly attribute HTMLCollection children;
    5363
Note: See TracChangeset for help on using the changeset viewer.