mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 461199 (Part 7) - mozilla::dom::Link should have a method to obtain a cached URI
Add mozilla::dom::Link::GetURI method used to cache the URI for this element. r=bz
This commit is contained in:
parent
7e6a8b2fd8
commit
3501faf702
@ -75,17 +75,47 @@ Link::LinkState() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
already_AddRefed<nsIURI>
|
||||||
|
Link::GetURI() const
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIURI> uri(mCachedURI);
|
||||||
|
|
||||||
|
// If we have this URI cached, use it.
|
||||||
|
if (uri) {
|
||||||
|
return uri.forget();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise obtain it.
|
||||||
|
Link *self = const_cast<Link *>(this);
|
||||||
|
nsCOMPtr<nsIContent> content(do_QueryInterface(self));
|
||||||
|
NS_ASSERTION(content, "Why isn't this an nsIContent node?!");
|
||||||
|
uri = content->GetHrefURI();
|
||||||
|
|
||||||
|
// We want to cache the URI if the node is in the document.
|
||||||
|
if (uri && content->IsInDoc()) {
|
||||||
|
mCachedURI = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
return uri.forget();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Link::ResetLinkState()
|
Link::ResetLinkState()
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIContent> content(do_QueryInterface(this));
|
nsCOMPtr<nsIContent> content(do_QueryInterface(this));
|
||||||
NS_ASSERTION(content, "Why isn't this an nsIContent node?!");
|
NS_ASSERTION(content, "Why isn't this an nsIContent node?!");
|
||||||
|
|
||||||
|
// Tell the document to forget about this link.
|
||||||
nsIDocument *doc = content->GetCurrentDoc();
|
nsIDocument *doc = content->GetCurrentDoc();
|
||||||
if (doc) {
|
if (doc) {
|
||||||
doc->ForgetLink(content);
|
doc->ForgetLink(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update our state back to the default.
|
||||||
mLinkState = defaultState;
|
mLinkState = defaultState;
|
||||||
|
|
||||||
|
// Get rid of our cached URI.
|
||||||
|
mCachedURI = nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
@ -64,6 +64,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
PRInt32 LinkState() const;
|
PRInt32 LinkState() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the URI this link is for, if available.
|
||||||
|
*/
|
||||||
|
already_AddRefed<nsIURI> GetURI() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Invalidates any link caching, and resets the state to the default.
|
* Invalidates any link caching, and resets the state to the default.
|
||||||
@ -71,6 +76,9 @@ protected:
|
|||||||
virtual void ResetLinkState();
|
virtual void ResetLinkState();
|
||||||
|
|
||||||
nsLinkState mLinkState;
|
nsLinkState mLinkState;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable nsCOMPtr<nsIURI> mCachedURI;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
Loading…
Reference in New Issue
Block a user