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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sky/engine/config.h"
6 #include "sky/engine/core/dom/custom2/new_custom_element.h"
7
8 #include "base/bind.h"
9 #include "dart/runtime/include/dart_api.h"
10 #include "sky/engine/core/dom/Document.h"
11 #include "sky/engine/core/dom/Element.h"
12 #include "sky/engine/core/dom/Microtask.h"
13 #include "sky/engine/core/dom/custom2/new_custom_element_callback_scope.h"
14 #include "sky/engine/core/dom/custom2/new_custom_element_registry.h"
15 #include "sky/engine/tonic/dart_converter.h"
16 #include "sky/engine/tonic/dart_state.h"
17 #include "sky/engine/wtf/text/AtomicString.h"
18
19 namespace blink {
20 namespace {
21
22 void ScheduleCallback(const base::Closure& callback) {
23 if (auto* scope = NewCustomElementCallbackScope::Current()) {
24 scope->Enqueue(callback);
25 } else {
26 Microtask::enqueueMicrotask(callback);
27 }
28 }
29
30 void CallAttributeDidChangedCallback(RefPtr<Element> element,
31 AtomicString name,
32 AtomicString oldValue,
33 AtomicString newValue) {
34 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
35 if (!dart_state)
36 return;
37 DartState::Scope scope(dart_state);
38 Dart_Handle wrapper = ToDart(element);
39 Dart_Handle callback = Dart_NewStringFromCString("attributeChangedCallback");
40 Dart_Handle args[] = {
41 StringToDart(dart_state, name),
42 StringToDart(dart_state, oldValue),
43 StringToDart(dart_state, newValue),
44 };
45 LogIfError(Dart_Invoke(wrapper, callback, arraysize(args), args));
46 }
47
48 void CallDidAttachedCallback(RefPtr<Element> element, RefPtr<Document> document) {
49 auto* dart_state = document->elementRegistry().dart_state().get();
50 if (!dart_state)
51 return;
52 DartState::Scope scope(dart_state);
53 Dart_Handle wrapper = ToDart(element);
54 Dart_Handle callback = Dart_NewStringFromCString("attachedCallback");
55 LogIfError(Dart_Invoke(wrapper, callback, 0, nullptr));
56 }
57
58 void CallDidDetachedCallback(RefPtr<Element> element, RefPtr<Document> document) {
59 auto* dart_state = document->elementRegistry().dart_state().get();
60 if (!dart_state)
61 return;
62 DartState::Scope scope(dart_state);
63 Dart_Handle wrapper = ToDart(element);
64 Dart_Handle callback = Dart_NewStringFromCString("detachedCallback");
65 LogIfError(Dart_Invoke(wrapper, callback, 0, nullptr));
66 }
67
68 } // namespace
69
70 void NewCustomElement::AttributeDidChange(Element* element,
71 const AtomicString& name,
72 const AtomicString& oldValue,
73 const AtomicString& newValue) {
74 ScheduleCallback(base::Bind(CallAttributeDidChangedCallback,
75 element, name, oldValue, newValue));
76 }
77
78 void NewCustomElement::DidAttach(Element* element, Document& document) {
79 ScheduleCallback(base::Bind(CallDidAttachedCallback, element, &document));
80 }
81
82 void NewCustomElement::DidDetach(Element* element, Document& document) {
83 ScheduleCallback(base::Bind(CallDidDetachedCallback, element, &document));
84 }
85
86 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698