From 581157178ee77a7f9a2aaaee78d1dfc562683433 Mon Sep 17 00:00:00 2001 From: "pkasting%google.com" Date: Fri, 25 Aug 2006 00:15:14 +0000 Subject: [PATCH] Bug 346373: Resync children when parent spellcheck attribute changes. r=bzbarsky sr=sicking --- .../html/content/src/nsGenericHTMLElement.cpp | 30 ++++++++++++++++--- .../html/content/src/nsGenericHTMLElement.h | 6 ++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 6e09bcd1e5e6..c813ccf5143f 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -1704,10 +1704,7 @@ nsGenericHTMLElement::AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, NS_ENSURE_SUCCESS(rv, rv); } else if (aNotify && aName == nsHTMLAtoms::spellcheck) { - nsCOMPtr editor = GetAssociatedEditor(); - if (editor) { - editor->SyncRealTimeSpell(); - } + SyncEditorsOnSubtree(this); } } @@ -4146,3 +4143,28 @@ nsGenericHTMLElement::IsCurrentBodyElement() htmlDocument->GetBody(getter_AddRefs(htmlElement)); return htmlElement == bodyElement; } + +// static +void +nsGenericHTMLElement::SyncEditorsOnSubtree(nsIContent* content) +{ + /* Sync this node */ + nsGenericHTMLElement* element = FromContent(content); + if (element) { + nsCOMPtr editor = element->GetAssociatedEditor(); + if (editor) { + editor->SyncRealTimeSpell(); + } + } + + /* Sync all children */ + PRUint32 childCount = content->GetChildCount(); + for (PRUint32 i = 0; i < childCount; ++i) { + nsIContent* childContent = content->GetChildAt(i); + NS_ASSERTION(childContent, + "DOM mutated unexpectedly while syncing editors!"); + if (childContent) { + SyncEditorsOnSubtree(childContent); + } + } +} diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 4f2ecf2cdf52..77a4589b835e 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -766,6 +766,12 @@ protected: * Returns true if this is the current document's body element */ PRBool IsCurrentBodyElement(); + + /** + * Ensures all editors associated with a subtree are synced, for purposes of + * spellchecking. + */ + static void SyncEditorsOnSubtree(nsIContent* content); };