void Link::ResetLinkState(bool aNotify, bool aHasHref) { nsLinkState defaultState; // The default state for links with an href is unvisited. if (aHasHref) { defaultState = eLinkState_Unvisited; } else { defaultState = eLinkState_NotLink; } // If !mNeedsRegstration, then either we've never registered, or we're // currently registered; in either case, we should remove ourself // from the doc and the history. if (!mNeedsRegistration && mLinkState != eLinkState_NotLink) { nsIDocument *doc = mElement->GetCurrentDoc(); if (doc && (mRegistered || mLinkState == eLinkState_Visited)) { // Tell the document to forget about this link if we've registered // with it before. doc->ForgetLink(this); } UnregisterFromHistory(); } // If we have an href, we should register with the history. mNeedsRegistration = aHasHref; // If we've cached the URI, reset always invalidates it. mCachedURI = nullptr; if (mSearchParams) { mSearchParams->Invalidate(); } // Update our state back to the default. mLinkState = defaultState; // We have to be very careful here: if aNotify is false we do NOT // want to call UpdateState, because that will call into LinkState() // and try to start off loads, etc. But ResetLinkState is called // with aNotify false when things are in inconsistent states, so // we'll get confused in that situation. Instead, just silently // update the link state on mElement. Since we might have set the // link state to unvisited, make sure to update with that state if // required. if (aNotify) { mElement->UpdateState(aNotify); } else { if (mLinkState == eLinkState_Unvisited) { mElement->UpdateLinkState(NS_EVENT_STATE_UNVISITED); } else { mElement->UpdateLinkState(nsEventStates()); } } }
void Link::ResetLinkState(bool aNotify) { // If we are in our default state, bail early. if (mLinkState == defaultState) { return; } Element *element = mElement; // Tell the document to forget about this link if we were a link before. nsIDocument *doc = element->GetCurrentDoc(); if (doc && mLinkState != eLinkState_NotLink) { doc->ForgetLink(this); } UnregisterFromHistory(); // Update our state back to the default. mLinkState = defaultState; // Get rid of our cached URI. mCachedURI = nullptr; // We have to be very careful here: if aNotify is false we do NOT // want to call UpdateState, because that will call into LinkState() // and try to start off loads, etc. But ResetLinkState is called // with aNotify false when things are in inconsistent states, so // we'll get confused in that situation. Instead, just silently // update the link state on mElement. if (aNotify) { mElement->UpdateState(aNotify); } else { mElement->UpdateLinkState(nsEventStates()); } }
Link::~Link() { UnregisterFromHistory(); }