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

Unified Diff: sky/engine/core/dom/custom2/new_custom_element.cc

Issue 943013002: Implement Custom Elements (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: attributeChanged***d***Callback Created 5 years, 10 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
Index: sky/engine/core/dom/custom2/new_custom_element.cc
diff --git a/sky/engine/core/dom/custom2/new_custom_element.cc b/sky/engine/core/dom/custom2/new_custom_element.cc
new file mode 100644
index 0000000000000000000000000000000000000000..be4b08576d97cd888f870d755894babae664514a
--- /dev/null
+++ b/sky/engine/core/dom/custom2/new_custom_element.cc
@@ -0,0 +1,86 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sky/engine/config.h"
+#include "sky/engine/core/dom/custom2/new_custom_element.h"
+
+#include "base/bind.h"
+#include "dart/runtime/include/dart_api.h"
+#include "sky/engine/core/dom/Document.h"
+#include "sky/engine/core/dom/Element.h"
+#include "sky/engine/core/dom/Microtask.h"
+#include "sky/engine/core/dom/custom2/new_custom_element_callback_scope.h"
+#include "sky/engine/core/dom/custom2/new_custom_element_registry.h"
+#include "sky/engine/tonic/dart_converter.h"
+#include "sky/engine/tonic/dart_state.h"
+#include "sky/engine/wtf/text/AtomicString.h"
+
+namespace blink {
+namespace {
+
+void ScheduleCallback(const base::Closure& callback) {
+ if (auto* scope = NewCustomElementCallbackScope::Current()) {
+ scope->Enqueue(callback);
+ } else {
+ Microtask::enqueueMicrotask(callback);
+ }
+}
+
+void CallAttributeDidChangedCallback(RefPtr<Element> element,
+ AtomicString name,
+ AtomicString oldValue,
+ AtomicString newValue) {
+ auto* dart_state = element->document().elementRegistry().dart_state().get();
ojan 2015/02/20 23:09:34 bikeshed: I don't know that it makes sense to use
abarth-chromium 2015/02/21 00:00:45 Yeah, I agree. Everything in the custom2 director
+ if (!dart_state)
+ return;
+ DartState::Scope scope(dart_state);
+ Dart_Handle wrapper = ToDart(element);
+ Dart_Handle callback = Dart_NewStringFromCString("attributeChangedCallback");
+ Dart_Handle args[] = {
+ StringToDart(dart_state, name),
+ StringToDart(dart_state, oldValue),
+ StringToDart(dart_state, newValue),
+ };
+ LogIfError(Dart_Invoke(wrapper, callback, arraysize(args), args));
+}
+
+void CallDidAttachedCallback(RefPtr<Element> element, RefPtr<Document> document) {
+ auto* dart_state = document->elementRegistry().dart_state().get();
+ if (!dart_state)
+ return;
+ DartState::Scope scope(dart_state);
+ Dart_Handle wrapper = ToDart(element);
+ Dart_Handle callback = Dart_NewStringFromCString("attachedCallback");
+ LogIfError(Dart_Invoke(wrapper, callback, 0, nullptr));
+}
+
+void CallDidDetachedCallback(RefPtr<Element> element, RefPtr<Document> document) {
+ auto* dart_state = document->elementRegistry().dart_state().get();
+ if (!dart_state)
+ return;
+ DartState::Scope scope(dart_state);
+ Dart_Handle wrapper = ToDart(element);
+ Dart_Handle callback = Dart_NewStringFromCString("detachedCallback");
+ LogIfError(Dart_Invoke(wrapper, callback, 0, nullptr));
+}
+
+} // namespace
+
+void NewCustomElement::AttributeDidChange(Element* element,
+ const AtomicString& name,
+ const AtomicString& oldValue,
+ const AtomicString& newValue) {
+ ScheduleCallback(base::Bind(CallAttributeDidChangedCallback,
+ element, name, oldValue, newValue));
+}
+
+void NewCustomElement::DidAttach(Element* element, Document& document) {
+ ScheduleCallback(base::Bind(CallDidAttachedCallback, element, &document));
+}
+
+void NewCustomElement::DidDetach(Element* element, Document& document) {
+ ScheduleCallback(base::Bind(CallDidDetachedCallback, element, &document));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698