Bug 461199 (Part 13) - mozilla::dom::Link::SetLinkState should inform the document about changes to its state when it is called.
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Tue, 15 Dec 2009 16:04:07 -0800
changeset 38472 938cf5c0b16a79cbf7ddd59bbf7abad976552185
parent 38471 adc5d77e82f8845340198be614b576e29c5e7c70
child 38473 ddfb63f3bccdb12cf3b3af18649c4e9419a651a0
push idunknown
push userunknown
push dateunknown
bugs461199
milestone1.9.3a2pre
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
content/base/src/Link.cpp
--- a/content/base/src/Link.cpp
+++ b/content/base/src/Link.cpp
@@ -41,16 +41,17 @@
 
 #include "nsIEventStateManager.h"
 #include "nsIURL.h"
 
 #include "nsContentUtils.h"
 #include "nsEscape.h"
 #include "nsGkAtoms.h"
 #include "nsString.h"
+#include "mozAutoDocUpdate.h"
 
 #include "mozilla/IHistory.h"
 
 namespace mozilla {
 namespace dom {
 
 Link::Link()
   : mLinkState(defaultState)
@@ -73,20 +74,39 @@ Link::GetLinkState() const
   return mLinkState;
 }
 
 void
 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
 Link::LinkState() const
 {
   // We are a constant method, but we are just lazily doing things and have to
   // track that state.  Cast away that constness!
   Link *self = const_cast<Link *>(this);