Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Unified Diff: third_party/WebKit/Source/core/svg/SVGURIReference.cpp

Issue 2737653006: Add a new mechanism for watching SVGElement 'href' targets (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGURIReference.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/svg/SVGURIReference.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGURIReference.cpp b/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
index 1b64614fdfd42dfe5c7936857ad187ecd3afba03..86b61bdf9a6a228bff4d6ac487db5bd735e923f5 100644
--- a/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
@@ -21,12 +21,29 @@
#include "core/svg/SVGURIReference.h"
#include "core/XLinkNames.h"
+#include "core/dom/IdTargetObserver.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/svg/SVGElement.h"
#include "platform/weborigin/KURL.h"
namespace blink {
+namespace {
+
+class SVGElementReferenceObserver : public IdTargetObserver {
+ public:
+ SVGElementReferenceObserver(TreeScope& treeScope,
+ const AtomicString& id,
+ std::unique_ptr<WTF::Closure> closure)
+ : IdTargetObserver(treeScope.idTargetObserverRegistry(), id),
+ m_closure(std::move(closure)) {}
+
+ private:
+ void idTargetChanged() override { (*m_closure)(); }
+ std::unique_ptr<WTF::Closure> m_closure;
+};
+}
+
SVGURIReference::SVGURIReference(SVGElement* element)
: m_href(SVGAnimatedHref::create(element)) {
ASSERT(element);
@@ -98,4 +115,25 @@ Element* SVGURIReference::targetElementFromIRIString(
return treeScope.getElementById(id);
}
+Element* SVGURIReference::observeTarget(Member<IdTargetObserver>& observer,
+ SVGElement& contextElement) {
+ DCHECK(!observer);
+ TreeScope& treeScope = contextElement.treeScope();
+ AtomicString id = fragmentIdentifierFromIRIString(hrefString(), treeScope);
+ if (id.isEmpty())
+ return nullptr;
+ observer = new SVGElementReferenceObserver(
+ treeScope, id,
+ WTF::bind(&SVGElement::buildPendingResource,
+ wrapWeakPersistent(&contextElement)));
+ return treeScope.getElementById(id);
+}
+
+void SVGURIReference::unobserveTarget(Member<IdTargetObserver>& observer) {
+ if (!observer)
+ return;
+ observer->unregister();
+ observer = nullptr;
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGURIReference.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698