Bug 598833 part 8. Create an explicit API to request link state updates. r=smaug,sdwilsh

This is a bit of a hack to make sure that we update link state sometime when doing style resolution, pending a better setup in bug 660959 for determining when to resolve the link URI.
This commit is contained in:
Boris Zbarsky 2011-05-31 21:46:57 -04:00
parent 7867f56859
commit e0320797e3
8 changed files with 64 additions and 0 deletions

View File

@ -100,6 +100,17 @@ public:
return IntrinsicState() | mState;
}
/**
* Request an update of the link state for this element. This will
* make sure that if the element is a link at all then either
* NS_EVENT_STATE_VISITED or NS_EVENT_STATE_UNVISITED is set in
* mState, and a history lookup kicked off if needed to find out
* whether the link is really visited. This method will NOT send any
* state change notifications. If you want them to happen for this
* call, you need to handle them yourself.
*/
virtual void RequestLinkStateUpdate();
protected:
/**
* Method to get the _intrinsic_ content state of this element. This is the
@ -109,6 +120,11 @@ protected:
*/
virtual nsEventStates IntrinsicState() const;
/**
* Method to update mState with link state information. This does not notify.
*/
void UpdateLinkState(nsEventStates aState);
private:
// Need to allow the ESM, nsGlobalWindow, and the focus manager to
// set our state

View File

@ -802,6 +802,22 @@ Element::NotifyStateChange(nsEventStates aStates)
}
}
void
Element::RequestLinkStateUpdate()
{
}
void
Element::UpdateLinkState(nsEventStates aState)
{
NS_ABORT_IF_FALSE(!aState.HasAtLeastOneOfStates(~(NS_EVENT_STATE_VISITED |
NS_EVENT_STATE_UNVISITED)),
"Unexpected link state bits");
mState =
(mState & ~(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED)) |
aState;
}
void
nsIContent::UpdateEditableState()
{

View File

@ -99,6 +99,7 @@ public:
virtual PRBool IsLink(nsIURI** aURI) const;
virtual void GetLinkTarget(nsAString& aTarget);
virtual nsLinkState GetLinkState() const;
virtual void RequestLinkStateUpdate();
virtual already_AddRefed<nsIURI> GetHrefURI() const;
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
@ -368,6 +369,12 @@ nsHTMLAnchorElement::GetLinkState() const
return Link::GetLinkState();
}
void
nsHTMLAnchorElement::RequestLinkStateUpdate()
{
UpdateLinkState(Link::LinkState());
}
already_AddRefed<nsIURI>
nsHTMLAnchorElement::GetHrefURI() const
{

View File

@ -82,6 +82,7 @@ public:
virtual PRBool IsLink(nsIURI** aURI) const;
virtual void GetLinkTarget(nsAString& aTarget);
virtual nsLinkState GetLinkState() const;
virtual void RequestLinkStateUpdate();
virtual already_AddRefed<nsIURI> GetHrefURI() const;
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
@ -295,6 +296,12 @@ nsHTMLAreaElement::GetLinkState() const
return Link::GetLinkState();
}
void
nsHTMLAreaElement::RequestLinkStateUpdate()
{
UpdateLinkState(Link::LinkState());
}
already_AddRefed<nsIURI>
nsHTMLAreaElement::GetHrefURI() const
{

View File

@ -112,6 +112,7 @@ public:
virtual PRBool IsLink(nsIURI** aURI) const;
virtual void GetLinkTarget(nsAString& aTarget);
virtual nsLinkState GetLinkState() const;
virtual void RequestLinkStateUpdate();
virtual already_AddRefed<nsIURI> GetHrefURI() const;
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
@ -378,6 +379,12 @@ nsHTMLLinkElement::GetLinkState() const
return Link::GetLinkState();
}
void
nsHTMLLinkElement::RequestLinkStateUpdate()
{
UpdateLinkState(Link::LinkState());
}
already_AddRefed<nsIURI>
nsHTMLLinkElement::GetHrefURI() const
{

View File

@ -160,6 +160,12 @@ nsSVGAElement::GetLinkState() const
return Link::GetLinkState();
}
void
nsSVGAElement::RequestLinkStateUpdate()
{
UpdateLinkState(Link::LinkState());
}
already_AddRefed<nsIURI>
nsSVGAElement::GetHrefURI() const
{

View File

@ -91,6 +91,7 @@ public:
virtual PRBool IsLink(nsIURI** aURI) const;
virtual void GetLinkTarget(nsAString& aTarget);
virtual nsLinkState GetLinkState() const;
virtual void RequestLinkStateUpdate();
virtual already_AddRefed<nsIURI> GetHrefURI() const;
virtual nsEventStates IntrinsicState() const;
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,

View File

@ -1149,6 +1149,8 @@ static void GetLang(nsIContent* aContent, nsString& aLang)
nsEventStates
nsCSSRuleProcessor::GetContentState(Element* aElement)
{
// FIXME: RequestLinkStateUpdate is a hack; see bug 660959.
aElement->RequestLinkStateUpdate();
nsEventStates state = aElement->State();
// If we are not supposed to mark visited links as such, be sure to
@ -1168,6 +1170,8 @@ nsCSSRuleProcessor::GetContentState(Element* aElement)
PRBool
nsCSSRuleProcessor::IsLink(Element* aElement)
{
// FIXME: RequestLinkStateUpdate is a hack; see bug 660959.
aElement->RequestLinkStateUpdate();
nsEventStates state = aElement->State();
return state.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED);
}