OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 12 matching lines...) Expand all Loading... | |
23 * You should have received a copy of the GNU Library General Public License | 23 * You should have received a copy of the GNU Library General Public License |
24 * along with this library; see the file COPYING.LIB. If not, write to | 24 * along with this library; see the file COPYING.LIB. If not, write to |
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 * Boston, MA 02110-1301, USA. | 26 * Boston, MA 02110-1301, USA. |
27 */ | 27 */ |
28 | 28 |
29 #include "core/dom/VisitedLinkState.h" | 29 #include "core/dom/VisitedLinkState.h" |
30 | 30 |
31 #include "core/HTMLNames.h" | 31 #include "core/HTMLNames.h" |
32 #include "core/dom/ElementTraversal.h" | 32 #include "core/dom/ElementTraversal.h" |
33 #include "core/dom/shadow/ElementShadow.h" | |
34 #include "core/dom/shadow/ShadowRoot.h" | |
33 #include "core/html/HTMLAnchorElement.h" | 35 #include "core/html/HTMLAnchorElement.h" |
34 #include "core/svg/SVGURIReference.h" | 36 #include "core/svg/SVGURIReference.h" |
35 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
36 | 38 |
37 namespace blink { | 39 namespace blink { |
38 | 40 |
39 static inline const AtomicString& linkAttribute(const Element& element) | 41 static inline const AtomicString& linkAttribute(const Element& element) |
40 { | 42 { |
41 DCHECK(element.isLink()); | 43 DCHECK(element.isLink()); |
42 if (element.isHTMLElement()) | 44 if (element.isHTMLElement()) |
43 return element.fastGetAttribute(HTMLNames::hrefAttr); | 45 return element.fastGetAttribute(HTMLNames::hrefAttr); |
44 DCHECK(element.isSVGElement()); | 46 DCHECK(element.isSVGElement()); |
45 return SVGURIReference::legacyHrefString(toSVGElement(element)); | 47 return SVGURIReference::legacyHrefString(toSVGElement(element)); |
46 } | 48 } |
47 | 49 |
48 static inline LinkHash linkHashForElement(const Element& element, const AtomicSt ring& attribute = AtomicString()) | 50 static inline LinkHash linkHashForElement(const Element& element, const AtomicSt ring& attribute = AtomicString()) |
49 { | 51 { |
50 DCHECK(attribute.isNull() || linkAttribute(element) == attribute); | 52 DCHECK(attribute.isNull() || linkAttribute(element) == attribute); |
51 if (isHTMLAnchorElement(element)) | 53 if (isHTMLAnchorElement(element)) |
52 return toHTMLAnchorElement(element).visitedLinkHash(); | 54 return toHTMLAnchorElement(element).visitedLinkHash(); |
53 return visitedLinkHash(element.document().baseURL(), attribute.isNull() ? li nkAttribute(element) : attribute); | 55 return visitedLinkHash(element.document().baseURL(), attribute.isNull() ? li nkAttribute(element) : attribute); |
54 } | 56 } |
55 | 57 |
56 VisitedLinkState::VisitedLinkState(const Document& document) | 58 VisitedLinkState::VisitedLinkState(const Document& document) |
57 : m_document(document) | 59 : m_document(document) |
58 { | 60 { |
59 } | 61 } |
60 | 62 |
61 void VisitedLinkState::invalidateStyleForAllLinks(bool invalidateVisitedLinkHash es) | 63 static void invalidateStyleForAllLinksRecursively(Node& rootNode, bool invalidat eVisitedLinkHashes) |
62 { | 64 { |
63 if (m_linksCheckedForVisitedState.isEmpty()) | 65 for (Node& node : NodeTraversal::startsAt(&rootNode)) { |
64 return; | |
65 for (Node& node : NodeTraversal::startsAt(document().firstChild())) { | |
66 if (node.isLink()) { | 66 if (node.isLink()) { |
67 if (invalidateVisitedLinkHashes && isHTMLAnchorElement(node)) | 67 if (invalidateVisitedLinkHashes && isHTMLAnchorElement(node)) |
68 toHTMLAnchorElement(node).invalidateCachedVisitedLinkHash(); | 68 toHTMLAnchorElement(node).invalidateCachedVisitedLinkHash(); |
69 toElement(node).pseudoStateChanged(CSSSelector::PseudoLink); | 69 toElement(node).pseudoStateChanged(CSSSelector::PseudoLink); |
70 toElement(node).pseudoStateChanged(CSSSelector::PseudoVisited); | 70 toElement(node).pseudoStateChanged(CSSSelector::PseudoVisited); |
71 toElement(node).pseudoStateChanged(CSSSelector::PseudoAnyLink); | 71 toElement(node).pseudoStateChanged(CSSSelector::PseudoAnyLink); |
72 } | 72 } |
73 if (isShadowHost(&node)) { | |
74 for (ShadowRoot* root = node.youngestShadowRoot(); root; root = root ->olderShadowRoot()) | |
75 invalidateStyleForAllLinksRecursively(*root, invalidateVisitedLi nkHashes); | |
76 } | |
77 } | |
78 } | |
79 | |
80 void VisitedLinkState::invalidateStyleForAllLinks(bool invalidateVisitedLinkHash es) | |
81 { | |
82 if (!m_linksCheckedForVisitedState.isEmpty()) | |
83 invalidateStyleForAllLinksRecursively(*document().firstChild(), invalida teVisitedLinkHashes); | |
esprehn
2016/04/21 08:14:03
I think the document firstChild can be null here.
| |
84 } | |
85 | |
86 static void invalidateStyleForLinkRecursively(Node& rootNode, LinkHash linkHash) | |
87 { | |
88 for (Node& node : NodeTraversal::startsAt(&rootNode)) { | |
89 if (node.isLink() && linkHashForElement(toElement(node)) == linkHash) { | |
90 toElement(node).pseudoStateChanged(CSSSelector::PseudoLink); | |
91 toElement(node).pseudoStateChanged(CSSSelector::PseudoVisited); | |
92 toElement(node).pseudoStateChanged(CSSSelector::PseudoAnyLink); | |
93 } | |
94 if (isShadowHost(&node)) | |
95 for (ShadowRoot* root = node.youngestShadowRoot(); root; root = root ->olderShadowRoot()) | |
96 invalidateStyleForLinkRecursively(*root, linkHash); | |
73 } | 97 } |
74 } | 98 } |
75 | 99 |
76 void VisitedLinkState::invalidateStyleForLink(LinkHash linkHash) | 100 void VisitedLinkState::invalidateStyleForLink(LinkHash linkHash) |
77 { | 101 { |
78 if (!m_linksCheckedForVisitedState.contains(linkHash)) | 102 if (m_linksCheckedForVisitedState.contains(linkHash)) |
79 return; | 103 invalidateStyleForLinkRecursively(*document().firstChild(), linkHash); |
esprehn
2016/04/21 08:14:03
Ditto.
| |
80 for (Node& node : NodeTraversal::startsAt(document().firstChild())) { | |
81 if (node.isLink() && linkHashForElement(toElement(node)) == linkHash) { | |
82 toElement(node).pseudoStateChanged(CSSSelector::PseudoLink); | |
83 toElement(node).pseudoStateChanged(CSSSelector::PseudoVisited); | |
84 toElement(node).pseudoStateChanged(CSSSelector::PseudoAnyLink); | |
85 } | |
86 } | |
87 } | 104 } |
88 | 105 |
89 EInsideLink VisitedLinkState::determineLinkStateSlowCase(const Element& element) | 106 EInsideLink VisitedLinkState::determineLinkStateSlowCase(const Element& element) |
90 { | 107 { |
91 DCHECK(element.isLink()); | 108 DCHECK(element.isLink()); |
92 DCHECK(document().isActive()); | 109 DCHECK(document().isActive()); |
93 DCHECK(document() == element.document()); | 110 DCHECK(document() == element.document()); |
94 | 111 |
95 const AtomicString& attribute = linkAttribute(element); | 112 const AtomicString& attribute = linkAttribute(element); |
96 | 113 |
(...skipping 15 matching lines...) Expand all Loading... | |
112 | 129 |
113 return InsideUnvisitedLink; | 130 return InsideUnvisitedLink; |
114 } | 131 } |
115 | 132 |
116 DEFINE_TRACE(VisitedLinkState) | 133 DEFINE_TRACE(VisitedLinkState) |
117 { | 134 { |
118 visitor->trace(m_document); | 135 visitor->trace(m_document); |
119 } | 136 } |
120 | 137 |
121 } // namespace blink | 138 } // namespace blink |
OLD | NEW |