Commit 9ec60814 authored by weinig@apple.com's avatar weinig@apple.com
Browse files

CTTE: VisitedLinkState should hold a Document&

https://bugs.webkit.org/show_bug.cgi?id=122066

Reviewed by Antti Koivisto.

The Document can never be null, so use a reference.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b0608f67
2013-09-28 Sam Weinig <sam@webkit.org>
CTTE: VisitedLinkState should hold a Document&
https://bugs.webkit.org/show_bug.cgi?id=122066
Reviewed by Antti Koivisto.
The Document can never be null, so use a reference.
2013-09-27 Antti Koivisto <antti@apple.com>
 
Clean up code for getting first line style
......@@ -422,7 +422,7 @@ Document::Document(Frame* frame, const URL& url, unsigned documentClasses)
, m_listenerTypes(0)
, m_mutationObserverTypes(0)
, m_styleSheetCollection(*this)
, m_visitedLinkState(VisitedLinkState::create(this))
, m_visitedLinkState(VisitedLinkState::create(*this))
, m_visuallyOrdered(false)
, m_readyState(Complete)
, m_bParsing(false)
......
......@@ -37,28 +37,29 @@
#include "PageGroup.h"
#include "PlatformStrategies.h"
#include "VisitedLinkStrategy.h"
#include "XLinkNames.h"
namespace WebCore {
using namespace HTMLNames;
inline static const AtomicString* linkAttribute(Element* element)
inline static const AtomicString* linkAttribute(Element& element)
{
if (!element->isLink())
if (!element.isLink())
return 0;
if (element->isHTMLElement())
return &element->fastGetAttribute(HTMLNames::hrefAttr);
if (element->isSVGElement())
return &element->getAttribute(XLinkNames::hrefAttr);
if (element.isHTMLElement())
return &element.fastGetAttribute(HTMLNames::hrefAttr);
if (element.isSVGElement())
return &element.getAttribute(XLinkNames::hrefAttr);
return 0;
}
PassOwnPtr<VisitedLinkState> VisitedLinkState::create(Document* document)
PassOwnPtr<VisitedLinkState> VisitedLinkState::create(Document& document)
{
return adoptPtr(new VisitedLinkState(document));
}
VisitedLinkState::VisitedLinkState(Document* document)
VisitedLinkState::VisitedLinkState(Document& document)
: m_document(document)
{
}
......@@ -67,18 +68,18 @@ void VisitedLinkState::invalidateStyleForAllLinks()
{
if (m_linksCheckedForVisitedState.isEmpty())
return;
for (Element* element = ElementTraversal::firstWithin(m_document); element; element = ElementTraversal::next(element)) {
for (Element* element = ElementTraversal::firstWithin(&m_document); element; element = ElementTraversal::next(element)) {
if (element->isLink())
element->setNeedsStyleRecalc();
}
}
inline static LinkHash linkHashForElement(Document* document, Element* element)
inline static LinkHash linkHashForElement(Document& document, Element& element)
{
if (isHTMLAnchorElement(element))
return toHTMLAnchorElement(element)->visitedLinkHash();
return toHTMLAnchorElement(element).visitedLinkHash();
if (const AtomicString* attribute = linkAttribute(element))
return WebCore::visitedLinkHash(document->baseURL(), *attribute);
return WebCore::visitedLinkHash(document.baseURL(), *attribute);
return 0;
}
......@@ -86,15 +87,15 @@ void VisitedLinkState::invalidateStyleForLink(LinkHash linkHash)
{
if (!m_linksCheckedForVisitedState.contains(linkHash))
return;
for (Element* element = ElementTraversal::firstWithin(m_document); element; element = ElementTraversal::next(element)) {
if (linkHashForElement(m_document, element) == linkHash)
for (Element* element = ElementTraversal::firstWithin(&m_document); element; element = ElementTraversal::next(element)) {
if (linkHashForElement(m_document, *element) == linkHash)
element->setNeedsStyleRecalc();
}
}
EInsideLink VisitedLinkState::determineLinkStateSlowCase(Element* element)
EInsideLink VisitedLinkState::determineLinkStateSlowCase(Element& element)
{
ASSERT(element->isLink());
ASSERT(element.isLink());
const AtomicString* attribute = linkAttribute(element);
if (!attribute || attribute->isNull())
......@@ -107,14 +108,14 @@ EInsideLink VisitedLinkState::determineLinkStateSlowCase(Element* element)
LinkHash hash;
if (isHTMLAnchorElement(element))
hash = toHTMLAnchorElement(element)->visitedLinkHash();
hash = toHTMLAnchorElement(element).visitedLinkHash();
else
hash = WebCore::visitedLinkHash(element->document().baseURL(), *attribute);
hash = WebCore::visitedLinkHash(element.document().baseURL(), *attribute);
if (!hash)
return InsideUnvisitedLink;
Frame* frame = element->document().frame();
Frame* frame = element.document().frame();
if (!frame)
return InsideUnvisitedLink;
......@@ -124,8 +125,7 @@ EInsideLink VisitedLinkState::determineLinkStateSlowCase(Element* element)
m_linksCheckedForVisitedState.add(hash);
return platformStrategies()->visitedLinkStrategy()->isLinkVisited(page, hash, element->document().baseURL(), *attribute) ? InsideVisitedLink : InsideUnvisitedLink;
return platformStrategies()->visitedLinkStrategy()->isLinkVisited(page, hash, element.document().baseURL(), *attribute) ? InsideVisitedLink : InsideUnvisitedLink;
}
}
......@@ -32,7 +32,6 @@
#include "Element.h"
#include "LinkHash.h"
#include "RenderStyleConstants.h"
#include "XLinkNames.h"
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
......@@ -43,18 +42,18 @@ class Document;
class VisitedLinkState {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<VisitedLinkState> create(Document*);
static PassOwnPtr<VisitedLinkState> create(Document&);
void invalidateStyleForAllLinks();
void invalidateStyleForLink(LinkHash);
EInsideLink determineLinkState(Element*);
private:
explicit VisitedLinkState(Document*);
explicit VisitedLinkState(Document&);
EInsideLink determineLinkStateSlowCase(Element*);
EInsideLink determineLinkStateSlowCase(Element&);
Document* m_document;
Document& m_document;
HashSet<LinkHash, LinkHashHash> m_linksCheckedForVisitedState;
};
......@@ -62,7 +61,7 @@ inline EInsideLink VisitedLinkState::determineLinkState(Element* element)
{
if (!element || !element->isLink())
return NotInsideLink;
return determineLinkStateSlowCase(element);
return determineLinkStateSlowCase(*element);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment