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:
Shawn Wilsher 2009-11-09 10:00:54 -08:00
Родитель 8f089bb04c
Коммит 594cbb9453
2 изменённых файлов: 38 добавлений и 0 удалений

Просмотреть файл

@ -75,17 +75,47 @@ Link::LinkState() const
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
Link::ResetLinkState()
{
nsCOMPtr<nsIContent> content(do_QueryInterface(this));
NS_ASSERTION(content, "Why isn't this an nsIContent node?!");
// Tell the document to forget about this link.
nsIDocument *doc = content->GetCurrentDoc();
if (doc) {
doc->ForgetLink(content);
}
// Update our state back to the default.
mLinkState = defaultState;
// Get rid of our cached URI.
mCachedURI = nsnull;
}
} // namespace dom

Просмотреть файл

@ -64,6 +64,11 @@ public:
*/
PRInt32 LinkState() const;
/**
* @return the URI this link is for, if available.
*/
already_AddRefed<nsIURI> GetURI() const;
protected:
/**
* Invalidates any link caching, and resets the state to the default.
@ -71,6 +76,9 @@ protected:
virtual void ResetLinkState();
nsLinkState mLinkState;
private:
mutable nsCOMPtr<nsIURI> mCachedURI;
};
} // namespace dom