Commit e2511942 authored by eric@webkit.org's avatar eric@webkit.org

2010-03-04 Antoine Quint <ml@graougraou.com>

        Reviewed by Darin Adler.

        DOM insertion mutation events should dispatch after a node is attached to the render tree
        https://bugs.webkit.org/show_bug.cgi?id=35590

        * fast/events/domnodeinsertedintodocument-dispatched-post-rendering-expected.txt: Added.
        * fast/events/domnodeinsertedintodocument-dispatched-post-rendering.html: Added.
2010-03-04  Antoine Quint  <ml@graougraou.com>

        Reviewed by Darin Adler.

        DOM insertion mutation events should dispatch after a node is attached to the render tree
        https://bugs.webkit.org/show_bug.cgi?id=35590

        Test: fast/events/domnodeinsertedintodocument-dispatched-post-rendering.html

        Split off the internal-to-WebCore node insertion notification code from the DOM mutation
        event dispatching, originally in dispatchChildInsertionEvents(), to a new static function
        called notifyChildInserted(). This allows us to dispatch the mutation events at a later
        time upon insertion of a child into to the tree, specifically _after_ attachment to the render
        tree.

        * dom/ContainerNode.cpp:
        (WebCore::ContainerNode::insertBefore):
        (WebCore::ContainerNode::replaceChild):
        (WebCore::ContainerNode::appendChild):
        (WebCore::notifyChildInserted):
        (WebCore::dispatchChildInsertionEvents):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55532 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ba67b54b
2010-03-04 Antoine Quint <ml@graougraou.com>
Reviewed by Darin Adler.
DOM insertion mutation events should dispatch after a node is attached to the render tree
https://bugs.webkit.org/show_bug.cgi?id=35590
* fast/events/domnodeinsertedintodocument-dispatched-post-rendering-expected.txt: Added.
* fast/events/domnodeinsertedintodocument-dispatched-post-rendering.html: Added.
2010-03-04 Csaba Osztrogonác <ossy@webkit.org>
Unreviewed.
......
<!doctype html>
<html class="a">
<head>
<title>DOMNodeInsertedIntoDocument: dispatch after appending to the render tree</title>
<style type="text/css">
.appended {
width: 100px;
}
.inserted {
width: 200px;
}
.replaced {
width: 300px;
}
</style>
</head>
<body>
<p id="original-message">FAIL (script did not run)</p>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
var body = document.body;
function log (msg) {
var original_message = document.getElementById('original-message');
if (original_message) {
body.removeChild(original_message);
}
body.appendChild(document.createElement('p')).textContent = msg;
};
function test (element, expected_width, methodName) {
var width = window.getComputedStyle(element, null).width;
log((width == expected_width) ? 'PASS' : 'FAIL: got width = "' + width + '" for element added to the tree with ' + methodName + '()');
};
var appended_element = document.createElement('div');
appended_element.className = 'appended';
appended_element.addEventListener('DOMNodeInsertedIntoDocument', function (event) {
test(appended_element, '100px', 'appendChild');
}, false);
body.appendChild(appended_element);
var inserted_element = document.createElement('div');
inserted_element.className = 'inserted';
inserted_element.addEventListener('DOMNodeInsertedIntoDocument', function (event) {
test(inserted_element, '200px', 'insertBefore');
}, false);
body.insertBefore(inserted_element, appended_element);
var replaced_element = document.createElement('div');
replaced_element.className = 'replaced';
replaced_element.addEventListener('DOMNodeInsertedIntoDocument', function (event) {
test(replaced_element, '300px', 'replaceChild');
}, false);
body.replaceChild(replaced_element, inserted_element);
</script>
</body>
</html>
2010-03-04 Antoine Quint <ml@graougraou.com>
Reviewed by Darin Adler.
DOM insertion mutation events should dispatch after a node is attached to the render tree
https://bugs.webkit.org/show_bug.cgi?id=35590
Test: fast/events/domnodeinsertedintodocument-dispatched-post-rendering.html
Split off the internal-to-WebCore node insertion notification code from the DOM mutation
event dispatching, originally in dispatchChildInsertionEvents(), to a new static function
called notifyChildInserted(). This allows us to dispatch the mutation events at a later
time upon insertion of a child into to the tree, specifically _after_ attachment to the render
tree.
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::insertBefore):
(WebCore::ContainerNode::replaceChild):
(WebCore::ContainerNode::appendChild):
(WebCore::notifyChildInserted):
(WebCore::dispatchChildInsertionEvents):
2010-03-04 Fridrich Strba <fridrich.strba@bluewin.ch>
Reviewed by Holger Freyther.
......
......@@ -43,6 +43,7 @@
namespace WebCore {
static void notifyChildInserted(Node*);
static void dispatchChildInsertionEvents(Node*);
static void dispatchChildRemovalEvents(Node*);
......@@ -144,9 +145,9 @@ bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
child->setNextSibling(next.get());
allowEventDispatch();
// Dispatch the mutation events.
// Send notification about the children change.
childrenChanged(false, refChildPreviousSibling.get(), next.get(), 1);
dispatchChildInsertionEvents(child.get());
notifyChildInserted(child.get());
// Add child to the rendering tree.
if (attached() && !child->attached() && child->parent() == this) {
......@@ -156,6 +157,10 @@ bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
child->attach();
}
// Now that the child is attached to the render tree, dispatch
// the relevant mutation events.
dispatchChildInsertionEvents(child.get());
child = nextChild.release();
}
......@@ -256,8 +261,7 @@ bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
child->setNextSibling(next);
allowEventDispatch();
// Dispatch the mutation events
dispatchChildInsertionEvents(child.get());
notifyChildInserted(child.get());
// Add child to the rendering tree
if (attached() && !child->attached() && child->parent() == this) {
......@@ -267,6 +271,10 @@ bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
child->attach();
}
// Now that the child is attached to the render tree, dispatch
// the relevant mutation events.
dispatchChildInsertionEvents(child.get());
prev = child;
child = nextChild.release();
}
......@@ -490,9 +498,9 @@ bool ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, bo
m_lastChild = child.get();
allowEventDispatch();
// Dispatch the mutation events
// Send notification about the children change.
childrenChanged(false, prev.get(), 0, 1);
dispatchChildInsertionEvents(child.get());
notifyChildInserted(child.get());
// Add child to the rendering tree
if (attached() && !child->attached() && child->parent() == this) {
......@@ -501,6 +509,10 @@ bool ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, bo
else
child->attach();
}
// Now that the child is attached to the render tree, dispatch
// the relevant mutation events.
dispatchChildInsertionEvents(child.get());
child = nextChild.release();
}
......@@ -876,7 +888,7 @@ Node *ContainerNode::childNode(unsigned index) const
return n;
}
static void dispatchChildInsertionEvents(Node* child)
static void notifyChildInserted(Node* child)
{
ASSERT(!eventDispatchForbidden());
......@@ -896,6 +908,14 @@ static void dispatchChildInsertionEvents(Node* child)
c->insertedIntoTree(true);
document->incDOMTreeVersion();
}
static void dispatchChildInsertionEvents(Node* child)
{
ASSERT(!eventDispatchForbidden());
RefPtr<Node> c = child;
RefPtr<Document> document = child->document();
if (c->parentNode() && document->hasListenerType(Document::DOMNODEINSERTED_LISTENER))
c->dispatchEvent(MutationEvent::create(eventNames().DOMNodeInsertedEvent, true, c->parentNode()));
......
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