SVGURIReference.cpp [plain text]
#include "config.h"
#include "SVGURIReference.h"
#include "Document.h"
#include "Element.h"
#include "SVGAttributeOwnerProxy.h"
#include <wtf/URL.h>
#include "XLinkNames.h"
namespace WebCore {
SVGURIReference::SVGURIReference(SVGElement* contextElement)
: m_attributeOwnerProxy(std::make_unique<AttributeOwnerProxy>(*this, *contextElement))
{
registerAttributes();
}
void SVGURIReference::registerAttributes()
{
auto& registry = attributeRegistry();
if (!registry.isEmpty())
return;
registry.registerAttribute<SVGNames::hrefAttr, &SVGURIReference::m_href>();
registry.registerAttribute<XLinkNames::hrefAttr, &SVGURIReference::m_href>();
}
SVGURIReference::AttributeRegistry& SVGURIReference::attributeRegistry()
{
return AttributeOwnerProxy::attributeRegistry();
}
bool SVGURIReference::isKnownAttribute(const QualifiedName& attributeName)
{
return AttributeOwnerProxy::isKnownAttribute(attributeName);
}
void SVGURIReference::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (isKnownAttribute(name))
m_href.setValue(value);
}
const String& SVGURIReference::href() const
{
return m_href.currentValue(*m_attributeOwnerProxy);
}
RefPtr<SVGAnimatedString> SVGURIReference::hrefAnimated()
{
return m_href.animatedProperty(*m_attributeOwnerProxy);
}
String SVGURIReference::fragmentIdentifierFromIRIString(const String& url, const Document& document)
{
size_t start = url.find('#');
if (start == notFound)
return emptyString();
URL base = start ? URL(document.baseURL(), url.substring(0, start)) : document.baseURL();
String fragmentIdentifier = url.substring(start);
URL kurl(base, fragmentIdentifier);
if (equalIgnoringFragmentIdentifier(kurl, document.url()))
return fragmentIdentifier.substring(1);
return emptyString();
}
auto SVGURIReference::targetElementFromIRIString(const String& iri, const TreeScope& treeScope, RefPtr<Document> externalDocument) -> TargetElementResult
{
size_t startOfFragmentIdentifier = iri.find('#');
if (startOfFragmentIdentifier == notFound)
return { };
auto id = iri.substring(startOfFragmentIdentifier + 1);
if (id.isEmpty())
return { };
auto& document = treeScope.documentScope();
auto url = document.completeURL(iri);
if (externalDocument) {
ASSERT(equalIgnoringFragmentIdentifier(url, externalDocument->url()));
return { externalDocument->getElementById(id), WTFMove(id) };
}
if (isExternalURIReference(iri, document))
return { nullptr, WTFMove(id) };
return { treeScope.getElementById(id), WTFMove(id) };
}
}