OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/CSSURIValue.h" | 5 #include "core/css/CSSURIValue.h" |
6 | 6 |
7 #include "core/css/CSSMarkup.h" | 7 #include "core/css/CSSMarkup.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/svg/SVGElementProxy.h" | 9 #include "core/svg/SVGElementProxy.h" |
10 #include "core/svg/SVGURIReference.h" | 10 #include "platform/weborigin/KURL.h" |
| 11 #include "wtf/text/WTFString.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 CSSURIValue::CSSURIValue(const String& urlString) | 15 CSSURIValue::CSSURIValue(const AtomicString& relativeUrl, |
15 : CSSValue(URIClass), m_url(urlString) {} | 16 const AtomicString& absoluteUrl) |
| 17 : CSSValue(URIClass), |
| 18 m_relativeUrl(relativeUrl), |
| 19 m_isLocal(relativeUrl.startsWith('#')), |
| 20 m_absoluteUrl(absoluteUrl) {} |
| 21 |
| 22 CSSURIValue::CSSURIValue(const AtomicString& relativeUrl, const KURL& url) |
| 23 : CSSURIValue(relativeUrl, AtomicString(url.getString())) {} |
16 | 24 |
17 CSSURIValue::~CSSURIValue() {} | 25 CSSURIValue::~CSSURIValue() {} |
18 | 26 |
19 SVGElementProxy& CSSURIValue::ensureElementProxy(Document& document) const { | 27 SVGElementProxy& CSSURIValue::ensureElementProxy( |
| 28 const Document& document) const { |
20 if (m_proxy) | 29 if (m_proxy) |
21 return *m_proxy; | 30 return *m_proxy; |
22 SVGURLReferenceResolver resolver(m_url, document); | 31 AtomicString fragmentId = fragmentIdentifier(); |
23 AtomicString fragmentId = resolver.fragmentIdentifier(); | 32 if (isLocal(document)) |
24 if (resolver.isLocal()) { | |
25 m_proxy = SVGElementProxy::create(fragmentId); | 33 m_proxy = SVGElementProxy::create(fragmentId); |
26 } else { | 34 else |
27 m_proxy = | 35 m_proxy = SVGElementProxy::create(m_absoluteUrl, fragmentId); |
28 SVGElementProxy::create(resolver.absoluteUrl().getString(), fragmentId); | |
29 } | |
30 return *m_proxy; | 36 return *m_proxy; |
31 } | 37 } |
32 | 38 |
| 39 void CSSURIValue::reResolveUrl(const Document& document) const { |
| 40 if (m_isLocal) |
| 41 return; |
| 42 KURL url = document.completeURL(m_relativeUrl); |
| 43 AtomicString urlString(url.getString()); |
| 44 if (urlString == m_absoluteUrl) |
| 45 return; |
| 46 m_absoluteUrl = urlString; |
| 47 m_proxy = nullptr; |
| 48 } |
| 49 |
33 String CSSURIValue::customCSSText() const { | 50 String CSSURIValue::customCSSText() const { |
34 return serializeURI(m_url); | 51 return serializeURI(m_relativeUrl); |
| 52 } |
| 53 |
| 54 AtomicString CSSURIValue::fragmentIdentifier() const { |
| 55 if (m_isLocal) |
| 56 return AtomicString(m_relativeUrl.getString().substring(1)); |
| 57 return AtomicString(absoluteUrl().fragmentIdentifier()); |
| 58 } |
| 59 |
| 60 KURL CSSURIValue::absoluteUrl() const { |
| 61 return KURL(ParsedURLString, m_absoluteUrl); |
| 62 } |
| 63 |
| 64 bool CSSURIValue::isLocal(const Document& document) const { |
| 65 return m_isLocal || |
| 66 equalIgnoringFragmentIdentifier(absoluteUrl(), document.url()); |
35 } | 67 } |
36 | 68 |
37 bool CSSURIValue::equals(const CSSURIValue& other) const { | 69 bool CSSURIValue::equals(const CSSURIValue& other) const { |
38 return m_url == other.m_url; | 70 // If only one has the 'local url' flag set, the URLs can't match. |
| 71 if (m_isLocal != other.m_isLocal) |
| 72 return false; |
| 73 return (m_isLocal && m_relativeUrl == other.m_relativeUrl) || |
| 74 m_absoluteUrl == other.m_absoluteUrl; |
39 } | 75 } |
40 | 76 |
41 DEFINE_TRACE_AFTER_DISPATCH(CSSURIValue) { | 77 DEFINE_TRACE_AFTER_DISPATCH(CSSURIValue) { |
42 visitor->trace(m_proxy); | 78 visitor->trace(m_proxy); |
43 CSSValue::traceAfterDispatch(visitor); | 79 CSSValue::traceAfterDispatch(visitor); |
44 } | 80 } |
45 | 81 |
46 } // namespace blink | 82 } // namespace blink |
OLD | NEW |