| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/dom/CustomElementCallbackInvocation.h" | 32 #include "core/dom/CustomElementCallbackInvocation.h" |
| 33 | 33 |
| 34 #include "core/dom/CustomElementLifecycleCallbacks.h" | 34 #include "core/dom/CustomElementCallbackDispatcher.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 class CreatedInvocation : public CustomElementCallbackInvocation { |
| 39 public: |
| 40 CreatedInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks) |
| 41 : CustomElementCallbackInvocation(callbacks) |
| 42 { |
| 43 } |
| 44 |
| 45 private: |
| 46 virtual void dispatch(Element*) OVERRIDE; |
| 47 }; |
| 48 |
| 49 void CreatedInvocation::dispatch(Element* element) |
| 50 { |
| 51 if (element->inDocument()) |
| 52 CustomElementCallbackDispatcher::instance().enqueueEnteredDocumentCallba
ck(callbacks(), element); |
| 53 callbacks()->created(element); |
| 54 } |
| 55 |
| 56 class EnteredLeftDocumentInvocation : public CustomElementCallbackInvocation { |
| 57 public: |
| 58 EnteredLeftDocumentInvocation(PassRefPtr<CustomElementLifecycleCallbacks>, C
ustomElementLifecycleCallbacks::CallbackType which); |
| 59 |
| 60 private: |
| 61 virtual void dispatch(Element*) OVERRIDE; |
| 62 |
| 63 CustomElementLifecycleCallbacks::CallbackType m_which; |
| 64 }; |
| 65 |
| 66 EnteredLeftDocumentInvocation::EnteredLeftDocumentInvocation(PassRefPtr<CustomEl
ementLifecycleCallbacks> callbacks, CustomElementLifecycleCallbacks::CallbackTyp
e which) |
| 67 : CustomElementCallbackInvocation(callbacks) |
| 68 , m_which(which) |
| 69 { |
| 70 ASSERT(m_which == CustomElementLifecycleCallbacks::EnteredDocument || m_whic
h == CustomElementLifecycleCallbacks::LeftDocument); |
| 71 } |
| 72 |
| 73 void EnteredLeftDocumentInvocation::dispatch(Element* element) |
| 74 { |
| 75 switch (m_which) { |
| 76 case CustomElementLifecycleCallbacks::EnteredDocument: |
| 77 callbacks()->enteredDocument(element); |
| 78 break; |
| 79 case CustomElementLifecycleCallbacks::LeftDocument: |
| 80 callbacks()->leftDocument(element); |
| 81 break; |
| 82 default: |
| 83 ASSERT_NOT_REACHED(); |
| 84 } |
| 85 } |
| 86 |
| 38 class AttributeChangedInvocation : public CustomElementCallbackInvocation { | 87 class AttributeChangedInvocation : public CustomElementCallbackInvocation { |
| 39 public: | 88 public: |
| 40 AttributeChangedInvocation(const AtomicString& name, const AtomicString& old
Value, const AtomicString& newValue); | 89 AttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks>, cons
t AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue
); |
| 41 | 90 |
| 42 private: | 91 private: |
| 43 virtual void dispatch(CustomElementLifecycleCallbacks*, Element*) OVERRIDE; | 92 virtual void dispatch(Element*) OVERRIDE; |
| 44 | 93 |
| 45 AtomicString m_name; | 94 AtomicString m_name; |
| 46 AtomicString m_oldValue; | 95 AtomicString m_oldValue; |
| 47 AtomicString m_newValue; | 96 AtomicString m_newValue; |
| 48 }; | 97 }; |
| 49 | 98 |
| 50 class CreatedInvocation : public CustomElementCallbackInvocation { | 99 AttributeChangedInvocation::AttributeChangedInvocation(PassRefPtr<CustomElementL
ifecycleCallbacks> callbacks, const AtomicString& name, const AtomicString& oldV
alue, const AtomicString& newValue) |
| 51 public: | 100 : CustomElementCallbackInvocation(callbacks) |
| 52 CreatedInvocation() { } | 101 , m_name(name) |
| 53 private: | |
| 54 virtual void dispatch(CustomElementLifecycleCallbacks*, Element*) OVERRIDE; | |
| 55 }; | |
| 56 | |
| 57 PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::cre
ateCreatedInvocation() | |
| 58 { | |
| 59 return adoptPtr(new CreatedInvocation()); | |
| 60 } | |
| 61 | |
| 62 PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::cre
ateAttributeChangedInvocation(const AtomicString& name, const AtomicString& oldV
alue, const AtomicString& newValue) | |
| 63 { | |
| 64 return adoptPtr(new AttributeChangedInvocation(name, oldValue, newValue)); | |
| 65 } | |
| 66 | |
| 67 AttributeChangedInvocation::AttributeChangedInvocation(const AtomicString& name,
const AtomicString& oldValue, const AtomicString& newValue) | |
| 68 : m_name(name) | |
| 69 , m_oldValue(oldValue) | 102 , m_oldValue(oldValue) |
| 70 , m_newValue(newValue) | 103 , m_newValue(newValue) |
| 71 { | 104 { |
| 72 } | 105 } |
| 73 | 106 |
| 74 void AttributeChangedInvocation::dispatch(CustomElementLifecycleCallbacks* callb
acks, Element* element) | 107 void AttributeChangedInvocation::dispatch(Element* element) |
| 75 { | 108 { |
| 76 callbacks->attributeChanged(element, m_name, m_oldValue, m_newValue); | 109 callbacks()->attributeChanged(element, m_name, m_oldValue, m_newValue); |
| 77 } | 110 } |
| 78 | 111 |
| 79 void CreatedInvocation::dispatch(CustomElementLifecycleCallbacks* callbacks, Ele
ment* element) | 112 PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::cre
ateInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, CustomEleme
ntLifecycleCallbacks::CallbackType which) |
| 80 { | 113 { |
| 81 callbacks->created(element); | 114 switch (which) { |
| 115 case CustomElementLifecycleCallbacks::Created: |
| 116 return adoptPtr(new CreatedInvocation(callbacks)); |
| 117 |
| 118 case CustomElementLifecycleCallbacks::EnteredDocument: |
| 119 case CustomElementLifecycleCallbacks::LeftDocument: |
| 120 return adoptPtr(new EnteredLeftDocumentInvocation(callbacks, which)); |
| 121 |
| 122 default: |
| 123 ASSERT_NOT_REACHED(); |
| 124 return PassOwnPtr<CustomElementCallbackInvocation>(); |
| 125 } |
| 126 } |
| 127 |
| 128 PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::cre
ateAttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callba
cks, const AtomicString& name, const AtomicString& oldValue, const AtomicString&
newValue) |
| 129 { |
| 130 return adoptPtr(new AttributeChangedInvocation(callbacks, name, oldValue, ne
wValue)); |
| 82 } | 131 } |
| 83 | 132 |
| 84 } // namespace WebCore | 133 } // namespace WebCore |
| OLD | NEW |