Commit fa4b1a10 authored by weinig@apple.com's avatar weinig@apple.com

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:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34543 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 166f2512
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:
2008-06-14 Darin Adler <darin@apple.com>
Reviewed by Maciej.
......@@ -520,7 +520,6 @@ window.Element.prototype.hasAttribute [function]
window.Element.prototype.hasAttributeNS [function]
window.Element.prototype.hasAttributes [function]
window.Element.prototype.hasChildNodes [function]
window.Element.prototype.insertAdjacentElement [function]
window.Element.prototype.insertBefore [function]
window.Element.prototype.isDefaultNamespace [function]
window.Element.prototype.isEqualNode [function]
......
......@@ -32,7 +32,7 @@ PASS resultArray[2].i is '2'
PASS resultArray[2].item is namedNodeMap.item(2)
[object HTMLFormElement]
PASS resultArray.length is 119
PASS resultArray.length is 121
PASS resultArray[0].i is '0'
PASS resultArray[0].item is document.getElementsByTagName('select')[0]
PASS resultArray[1].i is '1'
......@@ -41,7 +41,7 @@ PASS resultArray[2].i is '2'
PASS resultArray[2].item is document.getElementsByTagName('select')[2]
[object HTMLSelectElement]
PASS resultArray.length is 122
PASS resultArray.length is 124
PASS resultArray[0].i is '0'
PASS resultArray[0].item is document.getElementsByTagName('option')[0]
PASS resultArray[1].i is '1'
......
......@@ -130,7 +130,7 @@ shouldBe("resultArray[2].item", "namedNodeMap.item(2)");
// HTMLFormElement
var htmlFormElement = document.getElementsByTagName('form')[0];
resultArray = iterateList(htmlFormElement);
shouldBe("resultArray.length", "119");
shouldBe("resultArray.length", "121");
shouldBe("resultArray[0].i", "'0'");
shouldBe("resultArray[0].item", "document.getElementsByTagName('select')[0]");
shouldBe("resultArray[1].i", "'1'");
......@@ -141,7 +141,7 @@ shouldBe("resultArray[2].item", "document.getElementsByTagName('select')[2]");
// HTMLSelectElement
var htmlSelectElement = document.getElementsByTagName('select')[0];
resultArray = iterateList(htmlSelectElement);
shouldBe("resultArray.length", "122");
shouldBe("resultArray.length", "124");
shouldBe("resultArray[0].i", "'0'");
shouldBe("resultArray[0].item", "document.getElementsByTagName('option')[0]");
shouldBe("resultArray[1].i", "'1'");
......
<body>
<pre id="error-log"></pre>
<span id="container" style="color: green">
</span>
<div style="display: none">
......@@ -22,6 +21,9 @@
</span>
</body>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
// verify all standard cases
document.getElementById("container").insertAdjacentElement("beforeBegin", document.getElementById("1"));
document.getElementById("container").insertAdjacentElement("afterBegin", document.getElementById("2"));
......@@ -54,6 +56,6 @@
passes = passes & (elt.insertAdjacentElement("beforeBegin", document.createElement("p")) == null);
if (passes) {
document.getElementById("status").style.color = "green";
document.getElementById("status").innerHTML = "PASS";
document.getElementById("status").innerHTML = "<br><br>PASS";
}
</script>
Caught expected exception: Error: NOT_SUPPORTED_ERR: DOM Exception 9
1 (black) 2 (green) 3 (green) 4 (black)
PASS
<body>
<pre id="error-log"></pre>
<span id="container" style="color: green">
</span>
<span id="status" style="color: red">
FAILURE
</span>
</body>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
// verify all standard cases
document.getElementById("container").insertAdjacentHTML("beforeBegin", "<span id='1''> 1 (black)</span>");
document.getElementById("container").insertAdjacentHTML("afterBegin", "<span id='2''> 2 (green)</span>");
document.getElementById("container").insertAdjacentHTML("beforeEnd", "<span id='3''> 3 (green)</span>");
document.getElementById("container").insertAdjacentHTML("afterEnd", "<span id='4''> 4 (black)</span>");
function assertThrows(func) {
var testPassed = false;
try {
func();
} catch (e) {
document.getElementById("error-log").innerHTML += "Caught expected exception: " + e + "\n";
testPassed = true;
}
return testPassed;
}
// check that exceptions are thrown as required
var passes = true;
passes = passes & assertThrows(function() {
// should throw TYPE_MISMATCH_ERR
document.getElementById("container").insertAdjacentHTML("blah", "<span>html</span>");
});
if (passes) {
document.getElementById("status").style.color = "green";
document.getElementById("status").innerHTML = "<br<br>PASS";
}
</script>
Caught expected exception: Error: NOT_SUPPORTED_ERR: DOM Exception 9
1 (black) 2 (green) 3 (green) 4 (black)
PASS
<body>
<pre id="error-log"></pre>
<span id="container" style="color: green">
</span>
<span id="status" style="color: red">
FAILURE
</span>
</body>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
// verify all standard cases
document.getElementById("container").insertAdjacentText("beforeBegin", " 1 (black)");
document.getElementById("container").insertAdjacentText("afterBegin", " 2 (green)");
document.getElementById("container").insertAdjacentText("beforeEnd", " 3 (green)");
document.getElementById("container").insertAdjacentText("afterEnd", " 4 (black)");
function assertThrows(func) {
var testPassed = false;
try {
func();
} catch (e) {
document.getElementById("error-log").innerHTML += "Caught expected exception: " + e + "\n";
testPassed = true;
}
return testPassed;
}
// check that exceptions are thrown as required
var passes = true;
passes = passes & assertThrows(function() {
// should throw TYPE_MISMATCH_ERR
document.getElementById("container").insertAdjacentText("blah", "text");
});
if (passes) {
document.getElementById("status").style.color = "green";
document.getElementById("status").innerHTML = "<br<br>PASS";
}
</script>
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {PRE} at (0,0) size 784x30
RenderText {#text} at (0,0) size 552x30
text run at (0,0) width 544: "Caught expected exception: Error: NOT_SUPPORTED_ERR: DOM Exception 9"
text run at (544,0) width 0: " "
text run at (0,15) width 552: "Caught expected exception: Error: TYPE_MISMATCH_ERR: DOM Exception 17"
text run at (552,15) width 0: " "
RenderBlock (anonymous) at (0,43) size 784x18
RenderInline {SPAN} at (0,0) size 60x18
RenderText {#text} at (0,0) size 60x18
text run at (0,0) width 60: "1 (black) "
RenderInline {SPAN} at (0,0) size 122x18 [color=#008000]
RenderInline {SPAN} at (0,0) size 61x18
RenderText {#text} at (60,0) size 61x18
text run at (60,0) width 61: "2 (green) "
RenderText {#text} at (0,0) size 0x0
RenderInline {SPAN} at (0,0) size 61x18
RenderText {#text} at (121,0) size 61x18
text run at (121,0) width 61: "3 (green) "
RenderInline {SPAN} at (0,0) size 60x18
RenderText {#text} at (182,0) size 60x18
text run at (182,0) width 60: "4 (black) "
RenderText {#text} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
RenderInline {SPAN} at (0,0) size 39x18 [color=#008000]
RenderText {#text} at (242,0) size 39x18
text run at (242,0) width 39: "PASS"
RenderText {#text} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
Caught expected exception: Error: NOT_SUPPORTED_ERR: DOM Exception 9
Caught expected exception: Error: TYPE_MISMATCH_ERR: DOM Exception 17
1 (black) 2 (green) 3 (green) 4 (black)
PASS
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:
2008-06-14 Darin Adler <darin@apple.com>
Reviewed by Maciej.
......@@ -617,38 +617,6 @@ KURL Element::baseURI() const
return KURL(parentBase, base.string());
}
Node* Element::insertAdjacentElement(const String& where, Node* newChild, int& exception)
{
if (!newChild) {
// IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative
exception = TYPE_MISMATCH_ERR;
return 0;
}
// In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd",
// a document fragment is created and the elements appended in the correct order. This document
// fragment isn't returned anywhere.
//
// This is impossible for us to implement as the DOM tree does not allow for such structures,
// Opera also appears to disallow such usage.
if (equalIgnoringCase(where, "beforeBegin")) {
if (Node* p = parent())
return p->insertBefore(newChild, this, exception) ? newChild : 0;
} else if (equalIgnoringCase(where, "afterBegin")) {
return insertBefore(newChild, firstChild(), exception) ? newChild : 0;
} else if (equalIgnoringCase(where, "beforeEnd")) {
return appendChild(newChild, exception) ? newChild : 0;
} else if (equalIgnoringCase(where, "afterEnd")) {
if (Node* p = parent())
return p->insertBefore(newChild, nextSibling(), exception) ? newChild : 0;
} else {
// IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative
exception = NOT_SUPPORTED_ERR;
}
return 0;
}
bool Element::contains(const Node* node) const
{
if (!node)
......
......@@ -168,7 +168,6 @@ public:
virtual void formatForDebugger(char* buffer, unsigned length) const;
#endif
Node* insertAdjacentElement(const String& where, Node* newChild, ExceptionCode&);
bool contains(const Node*) const;
String innerText() const;
......
......@@ -92,9 +92,6 @@ module core {
// IE extensions
Node insertAdjacentElement(in DOMString position,
in Node element)
raises(DOMException);
boolean contains(in Element element);
// WebKit extensions
......
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -492,6 +492,70 @@ void HTMLElement::setOuterText(const String &text, ExceptionCode& ec)
}
}
Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, ExceptionCode& ec)
{
// In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd",
// a document fragment is created and the elements appended in the correct order. This document
// fragment isn't returned anywhere.
//
// This is impossible for us to implement as the DOM tree does not allow for such structures,
// Opera also appears to disallow such usage.
if (equalIgnoringCase(where, "beforeBegin")) {
if (Node* p = parent())
return p->insertBefore(newChild, this, ec) ? newChild : 0;
return 0;
}
if (equalIgnoringCase(where, "afterBegin"))
return insertBefore(newChild, firstChild(), ec) ? newChild : 0;
if (equalIgnoringCase(where, "beforeEnd"))
return appendChild(newChild, ec) ? newChild : 0;
if (equalIgnoringCase(where, "afterEnd")) {
if (Node* p = parent())
return p->insertBefore(newChild, nextSibling(), ec) ? newChild : 0;
return 0;
}
// IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative
ec = NOT_SUPPORTED_ERR;
return 0;
}
Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChild, ExceptionCode& ec)
{
if (!newChild) {
// IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative
ec = TYPE_MISMATCH_ERR;
return 0;
}
Node* returnValue = insertAdjacent(where, newChild, ec);
ASSERT(!returnValue || returnValue->isElementNode());
return static_cast<Element*>(returnValue);
}
void HTMLElement::insertAdjacentHTML(const String& where, const String& html, ExceptionCode& ec)
{
// FIXME: perhaps this should use createFragmentFromMarkup() instead as
// createContextualFragment() has all sorts of odd rules in it.
RefPtr<DocumentFragment> fragment = createContextualFragment(html);
if (!fragment) {
ec = NO_MODIFICATION_ALLOWED_ERR;
return;
}
insertAdjacent(where, fragment.get(), ec);
}
void HTMLElement::insertAdjacentText(const String& where, const String& text, ExceptionCode& ec)
{
RefPtr<Text> textNode = document()->createTextNode(text);
insertAdjacent(where, textNode.get(), ec);
}
void HTMLElement::addHTMLAlignment(MappedAttribute* attr)
{
// vertical alignment with respect to the current baseline of the text
......
......@@ -69,7 +69,11 @@ public:
void setOuterHTML(const String&, ExceptionCode&);
void setInnerText(const String&, ExceptionCode&);
void setOuterText(const String&, ExceptionCode&);
Element* insertAdjacentElement(const String& where, Element* newChild, ExceptionCode&);
void insertAdjacentHTML(const String& where, const String& html, ExceptionCode&);
void insertAdjacentText(const String& where, const String& text, ExceptionCode&);
virtual bool isFocusable() const;
virtual bool isContentEditable() const;
virtual bool isContentRichlyEditable() const;
......@@ -107,8 +111,9 @@ protected:
private:
virtual HTMLFormElement* virtualForm() const;
Node* insertAdjacent(const String& where, Node* newChild, ExceptionCode&);
};
} //namespace
} // namespace WebCore
#endif
#endif // HTMLElement_h
......@@ -49,6 +49,16 @@ module html {
attribute [ConvertNullToNullString] DOMString outerText
setter raises(DOMException);
Element insertAdjacentElement(in DOMString where,
in Element element)
raises(DOMException);
void insertAdjacentHTML(in DOMString where,
in DOMString html)
raises(DOMException);
void insertAdjacentText(in DOMString where,
in DOMString text)
raises(DOMException);
readonly attribute HTMLCollection children;
attribute [ConvertNullToNullString] DOMString contentEditable;
......
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