Bug 467144 - nsIMutationObserver::AttributeChanged should provide old attribute value; r=bzbarsky, r+sr=sicking

This commit is contained in:
David Bolter 2009-06-29 14:36:25 -04:00
parent f090c43a7f
commit 047c8ca2a3
15 changed files with 120 additions and 42 deletions

View File

@ -1054,6 +1054,17 @@ NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(nsDocAccessible)
NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(nsDocAccessible)
NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(nsDocAccessible)
void
nsDocAccessible::AttributeWillChange(nsIDocument *aDocument,
nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute, PRInt32 aModType)
{
// XXX TODO: bugs 381599 467143 472142 472143
// Here we will want to cache whatever state we are potentially interested in,
// such as the existence of aria-pressed for button (so we know if we need to
// newly expose it as a toggle button) etc.
}
void
nsDocAccessible::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent,
PRInt32 aNameSpaceID, nsIAtom* aAttribute,

View File

@ -105,8 +105,8 @@ class nsIBoxObject;
// IID for the nsIDocument interface
#define NS_IDOCUMENT_IID \
{ 0x9abf0b96, 0xc9e2, 0x4d49, \
{ 0x9c, 0x0a, 0x37, 0xc1, 0x22, 0x39, 0x83, 0x50 } }
{0x282f1cd0, 0x6dfb, 0x4cff, \
{0x83, 0x3e, 0x05, 0x98, 0x52, 0xe6, 0xd8, 0x59 } }
// Flag for AddStyleSheet().
#define NS_STYLESHEET_FROM_CATALOG (1 << 0)
@ -652,13 +652,6 @@ public:
virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) = 0;
/**
* Notify document of pending attribute change
*/
virtual void AttributeWillChange(nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute) = 0;
/**
* Flush notifications for this document and its parent documents
* (since those may affect the layout of this one).

View File

@ -45,8 +45,8 @@ class nsIDocument;
class nsINode;
#define NS_IMUTATION_OBSERVER_IID \
{ 0x32e68316, 0x67d4, 0x44a5, \
{ 0x8d, 0x35, 0xd, 0x39, 0xf, 0xa9, 0xdf, 0x11 } }
{0x365d600b, 0x868a, 0x452a, \
{0x8d, 0xe8, 0xf4, 0x6f, 0xad, 0x8f, 0xee, 0x53 } }
/**
* Information details about a characterdata change. Basically, we
@ -138,6 +138,23 @@ public:
nsIContent* aContent,
CharacterDataChangeInfo* aInfo) = 0;
/**
* Notification that an attribute of an element will change.
*
* @param aDocument The owner-document of aContent. Can be null.
* @param aContent The element whose attribute will change
* @param aNameSpaceID The namespace id of the changing attribute
* @param aAttribute The name of the changing attribute
* @param aModType Whether or not the attribute will be added, changed, or
* removed. The constants are defined in
* nsIDOMMutationEvent.h.
*/
virtual void AttributeWillChange(nsIDocument* aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType) = 0;
/**
* Notification that an attribute of an element has changed.
*
@ -251,6 +268,13 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIMutationObserver, NS_IMUTATION_OBSERVER_IID)
nsIContent* aContent, \
CharacterDataChangeInfo* aInfo);
#define NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE \
virtual void AttributeWillChange(nsIDocument* aDocument, \
nsIContent* aContent, \
PRInt32 aNameSpaceID, \
nsIAtom* aAttribute, \
PRInt32 aModType);
#define NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED \
virtual void AttributeChanged(nsIDocument* aDocument, \
nsIContent* aContent, \
@ -285,6 +309,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIMutationObserver, NS_IMUTATION_OBSERVER_IID)
#define NS_DECL_NSIMUTATIONOBSERVER \
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE \
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED \
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE \
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED \
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED \
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED \
@ -312,6 +337,14 @@ _class::CharacterDataChanged(nsIDocument* aDocument, \
{ \
} \
void \
_class::AttributeWillChange(nsIDocument* aDocument, \
nsIContent* aContent, \
PRInt32 aNameSpaceID, \
nsIAtom* aAttribute, \
PRInt32 aModType) \
{ \
} \
void \
_class::AttributeChanged(nsIDocument* aDocument, \
nsIContent* aContent, \
PRInt32 aNameSpaceID, \

View File

@ -2397,8 +2397,9 @@ nsDocument::ContentRemoved(nsIDocument* aDocument,
}
void
nsDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute)
nsDocument::AttributeWillChange(nsIDocument* aDocument,
nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute, PRInt32 aModType)
{
NS_ABORT_IF_FALSE(aContent, "Null content!");
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");

View File

@ -773,10 +773,6 @@ public:
nsIContent* aContent2,
PRInt32 aStateMask);
virtual void AttributeWillChange(nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute);
virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aOldStyleRule,
nsIStyleRule* aNewStyleRule);
@ -914,6 +910,7 @@ public:
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
// nsIScriptObjectPrincipal
virtual nsIPrincipal* GetPrincipal();

View File

@ -4255,9 +4255,7 @@ nsGenericElement::SetAttrAndNotify(PRInt32 aNamespaceID,
if (aNotify) {
stateMask = PRUint32(IntrinsicState());
if (document) {
document->AttributeWillChange(this, aNamespaceID, aName);
}
nsNodeUtils::AttributeWillChange(this, aNamespaceID, aName, modType);
}
if (aNamespaceID == kNameSpaceID_None) {
@ -4495,15 +4493,16 @@ nsGenericElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIDocument *document = GetCurrentDoc();
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
if (document) {
if (kNameSpaceID_XLink == aNameSpaceID && nsGkAtoms::href == aName) {
// XLink URI might be changing.
document->ForgetLink(this);
}
if (aNotify) {
document->AttributeWillChange(this, aNameSpaceID, aName);
}
if (aNotify) {
nsNodeUtils::AttributeWillChange(this, aNameSpaceID, aName,
nsIDOMMutationEvent::REMOVAL);
}
if (document && kNameSpaceID_XLink == aNameSpaceID &&
nsGkAtoms::href == aName) {
// XLink URI might be changing.
document->ForgetLink(this);
}
// When notifying, make sure to keep track of states whose value

View File

@ -97,6 +97,18 @@ nsNodeUtils::CharacterDataChanged(nsIContent* aContent,
(doc, aContent, aInfo));
}
void
nsNodeUtils::AttributeWillChange(nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType)
{
nsIDocument* doc = aContent->GetOwnerDoc();
IMPL_MUTATION_NOTIFICATION(AttributeWillChange, aContent,
(doc, aContent, aNameSpaceID, aAttribute,
aModType));
}
void
nsNodeUtils::AttributeChanged(nsIContent* aContent,
PRInt32 aNameSpaceID,

View File

@ -73,6 +73,19 @@ public:
static void CharacterDataChanged(nsIContent* aContent,
CharacterDataChangeInfo* aInfo);
/**
* Send AttributeWillChange notifications to nsIMutationObservers.
* @param aContent Node whose data will change
* @param aNameSpaceID Namespace of changing attribute
* @param aAttribute Local-name of changing attribute
* @param aModType Type of change (add/change/removal)
* @see nsIMutationObserver::AttributeWillChange
*/
static void AttributeWillChange(nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType);
/**
* Send AttributeChanged notifications to nsIMutationObservers.
* @param aContent Node whose data changed

View File

@ -356,6 +356,12 @@ nsXMLEventsManager::CharacterDataChanged(nsIDocument* aDocument,
nsIContent* aContent,
CharacterDataChangeInfo* aInfo) {}
void
nsXMLEventsManager::AttributeWillChange(nsIDocument* aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType) {}
void
nsXMLEventsManager::AttributeChanged(nsIDocument* aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,

View File

@ -1317,10 +1317,9 @@ nsXULElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, PRBool aNotify)
PRUint32 stateMask;
if (aNotify) {
stateMask = PRUint32(IntrinsicState());
if (doc) {
doc->AttributeWillChange(this, aNameSpaceID, aName);
}
nsNodeUtils::AttributeWillChange(this, aNameSpaceID, aName,
nsIDOMMutationEvent::REMOVAL);
}
PRBool hasMutationListeners = aNotify &&

View File

@ -960,8 +960,9 @@ nsXULDocument::ExecuteOnBroadcastHandlerFor(nsIContent* aBroadcaster,
}
void
nsXULDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute)
nsXULDocument::AttributeWillChange(nsIDocument* aDocument,
nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute, PRInt32 aModType)
{
NS_ABORT_IF_FALSE(aContent, "Null content!");
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
@ -973,7 +974,8 @@ nsXULDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
RemoveElementFromRefMap(aContent);
}
nsXMLDocument::AttributeWillChange(aContent, aNameSpaceID, aAttribute);
nsXMLDocument::AttributeWillChange(aDocument, aContent, aNameSpaceID,
aAttribute, aModType);
}
void

View File

@ -145,10 +145,7 @@ public:
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
virtual void AttributeWillChange(nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute);
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
// nsIXULDocument interface
NS_IMETHOD AddElementForID(nsIContent* aElement);

View File

@ -751,6 +751,15 @@ nsSHEntry::CharacterDataChanged(nsIDocument* aDocument,
DocumentMutated();
}
void
nsSHEntry::AttributeWillChange(nsIDocument* aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType)
{
}
void
nsSHEntry::AttributeChanged(nsIDocument* aDocument,
nsIContent* aContent,

View File

@ -267,9 +267,9 @@ nsHTMLFramesetFrame::FrameResizePrefCallback(const char* aPref, void* aClosure)
nsIDocument* doc = frame->mContent->GetDocument();
mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, PR_TRUE);
if (doc) {
doc->AttributeWillChange(frame->mContent,
kNameSpaceID_None,
nsGkAtoms::frameborder);
nsNodeUtils::AttributeWillChange(frame->mContent, kNameSpaceID_None,
nsGkAtoms::frameborder,
nsIDOMMutationEvent::MODIFICATION);
}
frame->mForceFrameResizability =

View File

@ -697,6 +697,12 @@ void nsMenuBarX::NodeWillBeDestroyed(const nsINode * aNode)
}
void nsMenuBarX::AttributeWillChange(nsIDocument* aDocument,
nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute, PRInt32 aModType)
{
}
void nsMenuBarX::AttributeChanged(nsIDocument * aDocument, nsIContent * aContent,
PRInt32 aNameSpaceID, nsIAtom * aAttribute,
PRInt32 aModType, PRUint32 aStateMask)