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

Side by Side Diff: sky/engine/core/dom/custom/custom_element.cc

Issue 941153003: Add dart_invoke to tonic for calls into App code. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cr comments 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
« no previous file with comments | « sky/engine/bindings/scheduled_action.cc ('k') | sky/engine/core/script/dart_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "sky/engine/config.h" 5 #include "sky/engine/config.h"
6 #include "sky/engine/core/dom/custom/custom_element.h" 6 #include "sky/engine/core/dom/custom/custom_element.h"
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "dart/runtime/include/dart_api.h" 9 #include "dart/runtime/include/dart_api.h"
10 #include "sky/engine/core/dom/Document.h" 10 #include "sky/engine/core/dom/Document.h"
11 #include "sky/engine/core/dom/Element.h" 11 #include "sky/engine/core/dom/Element.h"
12 #include "sky/engine/core/dom/Microtask.h" 12 #include "sky/engine/core/dom/Microtask.h"
13 #include "sky/engine/core/dom/custom/custom_element_callback_scope.h" 13 #include "sky/engine/core/dom/custom/custom_element_callback_scope.h"
14 #include "sky/engine/core/dom/custom/custom_element_registry.h" 14 #include "sky/engine/core/dom/custom/custom_element_registry.h"
15 #include "sky/engine/tonic/dart_converter.h" 15 #include "sky/engine/tonic/dart_converter.h"
16 #include "sky/engine/tonic/dart_invoke.h"
16 #include "sky/engine/tonic/dart_state.h" 17 #include "sky/engine/tonic/dart_state.h"
17 #include "sky/engine/wtf/text/AtomicString.h" 18 #include "sky/engine/wtf/text/AtomicString.h"
18 19
19 namespace blink { 20 namespace blink {
20 namespace { 21 namespace {
21 22
22 void ScheduleCallback(const base::Closure& callback) { 23 void ScheduleCallback(const base::Closure& callback) {
23 if (auto* scope = CustomElementCallbackScope::Current()) { 24 if (auto* scope = CustomElementCallbackScope::Current()) {
24 scope->Enqueue(callback); 25 scope->Enqueue(callback);
25 } else { 26 } else {
26 Microtask::enqueueMicrotask(callback); 27 Microtask::enqueueMicrotask(callback);
27 } 28 }
28 } 29 }
29 30
30 void CallAttributeDidChangedCallback(RefPtr<Element> element, 31 void CallAttributeDidChangedCallback(RefPtr<Element> element,
31 AtomicString name, 32 AtomicString name,
32 AtomicString oldValue, 33 AtomicString oldValue,
33 AtomicString newValue) { 34 AtomicString newValue) {
34 auto* dart_state = element->document().elementRegistry().dart_state().get(); 35 auto* dart_state = element->document().elementRegistry().dart_state().get();
35 if (!dart_state) 36 if (!dart_state)
36 return; 37 return;
37 DartState::Scope scope(dart_state); 38 DartState::Scope scope(dart_state);
38 Dart_Handle wrapper = ToDart(element); 39 Dart_Handle wrapper = ToDart(element);
39 Dart_Handle callback = Dart_NewStringFromCString("attributeChangedCallback"); 40 Dart_Handle callback = Dart_NewStringFromCString("attributeChangedCallback");
40 Dart_Handle args[] = { 41 Dart_Handle args[] = {
41 StringToDart(dart_state, name), 42 StringToDart(dart_state, name),
42 StringToDart(dart_state, oldValue), 43 StringToDart(dart_state, oldValue),
43 StringToDart(dart_state, newValue), 44 StringToDart(dart_state, newValue),
44 }; 45 };
45 LogIfError(Dart_Invoke(wrapper, callback, arraysize(args), args)); 46 DartInvokeAppField(wrapper, callback, arraysize(args), args);
46 } 47 }
47 48
48 void CallDidAttachedCallback(RefPtr<Element> element, RefPtr<Document> document) { 49 void CallDidAttachedCallback(RefPtr<Element> element, RefPtr<Document> document) {
49 auto* dart_state = document->elementRegistry().dart_state().get(); 50 auto* dart_state = document->elementRegistry().dart_state().get();
50 if (!dart_state) 51 if (!dart_state)
51 return; 52 return;
52 DartState::Scope scope(dart_state); 53 DartState::Scope scope(dart_state);
53 Dart_Handle wrapper = ToDart(element); 54 Dart_Handle wrapper = ToDart(element);
54 Dart_Handle callback = Dart_NewStringFromCString("attachedCallback"); 55 Dart_Handle callback = Dart_NewStringFromCString("attachedCallback");
55 LogIfError(Dart_Invoke(wrapper, callback, 0, nullptr)); 56 LogIfError(Dart_Invoke(wrapper, callback, 0, nullptr));
(...skipping 21 matching lines...) Expand all
77 78
78 void CustomElement::DidAttach(Element* element, Document& document) { 79 void CustomElement::DidAttach(Element* element, Document& document) {
79 ScheduleCallback(base::Bind(CallDidAttachedCallback, element, &document)); 80 ScheduleCallback(base::Bind(CallDidAttachedCallback, element, &document));
80 } 81 }
81 82
82 void CustomElement::DidDetach(Element* element, Document& document) { 83 void CustomElement::DidDetach(Element* element, Document& document) {
83 ScheduleCallback(base::Bind(CallDidDetachedCallback, element, &document)); 84 ScheduleCallback(base::Bind(CallDidDetachedCallback, element, &document));
84 } 85 }
85 86
86 } // namespace blink 87 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/bindings/scheduled_action.cc ('k') | sky/engine/core/script/dart_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698