Bug 461199 (Part 13) - mozilla::dom::Link::SetLinkState should inform the document about changes to its state when it is called.

Make Link::SetLinkState notify the document about changes in state, plus a
whole bunch of assertions for sanity checking.
r=sicking
r=bz
This commit is contained in:
Shawn Wilsher 2009-12-15 16:04:07 -08:00
parent f284f552ef
commit 2d89f25390

View File

@ -46,6 +46,7 @@
#include "nsEscape.h"
#include "nsGkAtoms.h"
#include "nsString.h"
#include "mozAutoDocUpdate.h"
#include "mozilla/IHistory.h"
@ -78,10 +79,29 @@ Link::SetLinkState(nsLinkState aState)
{
NS_ASSERTION(mRegistered,
"Setting the link state of an unregistered Link!");
NS_ASSERTION(mLinkState != aState,
"Setting state to the currently set state!");
// Remember our old link state for when we notify.
PRInt32 oldLinkState = LinkState();
// Set our current state as appropriate.
mLinkState = aState;
// Per IHistory interface documentation, we are no longer registered.
mRegistered = false;
// Notify the document that our visited state has changed.
nsCOMPtr<nsIContent> content(do_QueryInterface(this));
NS_ASSERTION(content, "Why isn't this an nsIContent node?!");
nsIDocument *doc = content->GetCurrentDoc();
NS_ASSERTION(doc, "Registered but we have no document?!");
PRInt32 newLinkState = LinkState();
NS_ASSERTION(newLinkState == NS_EVENT_STATE_VISITED ||
newLinkState == NS_EVENT_STATE_UNVISITED,
"Unexpected state obtained from LinkState()!");
mozAutoDocUpdate update(doc, UPDATE_CONTENT_STATE, PR_TRUE);
doc->ContentStatesChanged(content, nsnull, oldLinkState ^ newLinkState);
}
PRInt32