| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |