Skip to content

Commit

Permalink
Bug 509672 - Make HTML5 parser not fire mutation events when adding a…
Browse files Browse the repository at this point in the history
…ttributes to root or body elements. r=jonas
  • Loading branch information
hsivonen committed Aug 13, 2009
1 parent ec18dfc commit 2b3ede7
Show file tree
Hide file tree
Showing 9 changed files with 1,362 additions and 864 deletions.
41 changes: 39 additions & 2 deletions parser/html/nsHtml5TreeOperation.cpp
Expand Up @@ -39,9 +39,14 @@
* ***** END LICENSE BLOCK ***** */

#include "nsHtml5TreeOperation.h"
#include "nsContentUtils.h"
#include "nsNodeUtils.h"
#include "nsAttrName.h"
#include "nsHtml5TreeBuilder.h"
#include "nsIDOMMutationEvent.h"
#include "mozAutoDocUpdate.h"
#include "nsBindingManager.h"
#include "nsXBLBinding.h"

nsHtml5TreeOperation::nsHtml5TreeOperation()
: mOpCode(eTreeOpAppend)
Expand Down Expand Up @@ -117,6 +122,8 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeBuilder* aBuilder)
}
case eTreeOpAddAttributes: {
// mNode holds the new attributes and mParent is the target
nsIDocument* document = mParent->GetCurrentDoc();

PRUint32 len = mNode->GetAttrCount();
for (PRUint32 i = 0; i < len; ++i) {
const nsAttrName* attrName = mNode->GetAttrNameAt(i);
Expand All @@ -125,8 +132,38 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeBuilder* aBuilder)
if (!mParent->HasAttr(nsuri, localName)) {
nsAutoString value;
mNode->GetAttr(nsuri, localName, value);
mParent->SetAttr(nsuri, localName, attrName->GetPrefix(), value, PR_TRUE);
// XXX should not fire mutation event here

// the manual notification code is based on nsGenericElement

PRUint32 stateMask = PRUint32(mParent->IntrinsicState());
nsNodeUtils::AttributeWillChange(mParent,
nsuri,
localName,
static_cast<PRUint8>(nsIDOMMutationEvent::ADDITION));

mParent->SetAttr(nsuri, localName, attrName->GetPrefix(), value, PR_FALSE);

if (document || mParent->HasFlag(NODE_FORCE_XBL_BINDINGS)) {
nsIDocument* ownerDoc = mParent->GetOwnerDoc();
if (ownerDoc) {
nsRefPtr<nsXBLBinding> binding =
ownerDoc->BindingManager()->GetBinding(mParent);
if (binding) {
binding->AttributeChanged(localName, nsuri, PR_FALSE, PR_FALSE);
}
}
}

stateMask = stateMask ^ PRUint32(mParent->IntrinsicState());
if (stateMask && document) {
MOZ_AUTO_DOC_UPDATE(document, UPDATE_CONTENT_STATE, PR_TRUE);
document->ContentStatesChanged(mParent, nsnull, stateMask);
}
nsNodeUtils::AttributeChanged(mParent,
nsuri,
localName,
static_cast<PRUint8>(nsIDOMMutationEvent::ADDITION),
stateMask);
}
}
return rv;
Expand Down
28 changes: 28 additions & 0 deletions parser/htmlparser/tests/mochitest/Makefile.in
Expand Up @@ -46,11 +46,39 @@ include $(topsrcdir)/config/rules.mk

_TEST_FILES = parser_datreader.js \
parser_web_testrunner.js \
tokenizer_file_server.sjs \
html5lib_tokenizer_entities.test \
html5lib_tokenizer_numeric_entities.test \
html5lib_tokenizer_unicode_chars.test \
html5lib_tokenizer_test1.test \
html5lib_tokenizer_test2.test \
html5lib_tokenizer_test3.test \
html5lib_tokenizer_test4.test \
html5lib_tokenizer_test5.test \
html5lib_tree_dat1.txt \
html5lib_tree_dat2.txt \
html5lib_tree_dat3.txt \
html5lib_tree_dat5.txt \
html5lib_tree_dat6.txt \
html5lib_tree_dat7.txt \
html5lib_tree_dat8.txt \
html5lib_tree_dat9.txt \
html5lib_tree_dat10.txt \
html5lib_tree_dat11.txt \
html5lib_tree_dat12.txt \
html5lib_tree_dat14.txt \
html5_tree_construction_exceptions.js \
nu.validator.htmlparser.HtmlParser.nocache.js \
test_html5_tokenizer_entities.html \
test_html5_tokenizer_numeric_entities.html \
test_html5_tokenizer_test1.html \
test_html5_tokenizer_test2.html \
test_html5_tokenizer_test3.html \
test_html5_tokenizer_test4.html \
test_html5_tokenizer_test5.html \
test_html5_tokenizer_unicode_chars.html \
test_html5_tree_construction.html \
test_html5_tree_construction_js_compare.html \
test_bug174351.html \
test_bug339350.xhtml \
test_bug358797.html \
Expand Down

0 comments on commit 2b3ede7

Please sign in to comment.