This source file includes following definitions.
- linkAttribute
- linkHashForElement
- invalidateStyleForAllLinks
- invalidateStyleForLink
- determineLinkStateSlowCase
#include "config.h"
#include "core/dom/VisitedLinkState.h"
#include "HTMLNames.h"
#include "XLinkNames.h"
#include "core/dom/ElementTraversal.h"
#include "core/html/HTMLAnchorElement.h"
#include "public/platform/Platform.h"
namespace WebCore {
static inline const AtomicString& linkAttribute(const Element& element)
{
ASSERT(element.isLink());
if (element.isHTMLElement())
return element.fastGetAttribute(HTMLNames::hrefAttr);
ASSERT(element.isSVGElement());
return element.getAttribute(XLinkNames::hrefAttr);
}
static inline LinkHash linkHashForElement(const Element& element, const AtomicString& attribute = AtomicString())
{
ASSERT(attribute.isNull() || linkAttribute(element) == attribute);
if (isHTMLAnchorElement(element))
return toHTMLAnchorElement(element).visitedLinkHash();
return visitedLinkHash(element.document().baseURL(), attribute.isNull() ? linkAttribute(element) : attribute);
}
VisitedLinkState::VisitedLinkState(const Document& document)
: m_document(document)
{
}
void VisitedLinkState::invalidateStyleForAllLinks()
{
if (m_linksCheckedForVisitedState.isEmpty())
return;
for (Element* element = ElementTraversal::firstWithin(m_document); element; element = ElementTraversal::next(*element)) {
if (element->isLink())
element->setNeedsStyleRecalc(SubtreeStyleChange);
}
}
void VisitedLinkState::invalidateStyleForLink(LinkHash linkHash)
{
if (!m_linksCheckedForVisitedState.contains(linkHash))
return;
for (Element* element = ElementTraversal::firstWithin(m_document); element; element = ElementTraversal::next(*element)) {
if (element->isLink() && linkHashForElement(*element) == linkHash)
element->setNeedsStyleRecalc(SubtreeStyleChange);
}
}
EInsideLink VisitedLinkState::determineLinkStateSlowCase(const Element& element)
{
ASSERT(element.isLink());
ASSERT(m_document.isActive());
ASSERT(m_document == element.document());
const AtomicString& attribute = linkAttribute(element);
if (attribute.isNull())
return NotInsideLink;
if (attribute.isEmpty())
return InsideVisitedLink;
if (LinkHash hash = linkHashForElement(element, attribute)) {
m_linksCheckedForVisitedState.add(hash);
if (blink::Platform::current()->isLinkVisited(hash))
return InsideVisitedLink;
}
return InsideUnvisitedLink;
}
}