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

Side by Side Diff: Source/core/dom/CustomElementCallbackInvocation.cpp

Issue 18167006: Implement Custom Elements' entered and left document callbacks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Feedback Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
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
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 AttributeChangedInvocation : public CustomElementCallbackInvocation { 38 class AttributeChangedInvocation : public CustomElementCallbackInvocation {
Yuta Kitamura 2013/07/08 03:40:49 The separation between AttributeChangedInvocation
39 public: 39 public:
40 AttributeChangedInvocation(const AtomicString& name, const AtomicString& old Value, const AtomicString& newValue); 40 AttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks>, cons t AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue );
41 41
42 private: 42 private:
43 virtual void dispatch(CustomElementLifecycleCallbacks*, Element*) OVERRIDE; 43 virtual void dispatch(Element*) OVERRIDE;
44 44
45 AtomicString m_name; 45 AtomicString m_name;
46 AtomicString m_oldValue; 46 AtomicString m_oldValue;
47 AtomicString m_newValue; 47 AtomicString m_newValue;
48 }; 48 };
49 49
50 class CreatedInvocation : public CustomElementCallbackInvocation { 50 PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::cre ateInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, CustomEleme ntLifecycleCallbacks::CallbackType which)
51 public: 51 {
52 CreatedInvocation() { } 52 switch (which) {
53 private: 53 case CustomElementLifecycleCallbacks::Created:
54 virtual void dispatch(CustomElementLifecycleCallbacks*, Element*) OVERRIDE; 54 case CustomElementLifecycleCallbacks::EnteredDocument:
55 }; 55 case CustomElementLifecycleCallbacks::LeftDocument:
Yuta Kitamura 2013/07/08 03:40:49 CELifecycleCallbacks::CallbackType looks like a bi
56 return adoptPtr(new CustomElementCallbackInvocation(callbacks, which));
56 57
57 PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::cre ateCreatedInvocation() 58 case CustomElementLifecycleCallbacks::AttributeChanged: // Use createAttribu teChangedInvocation
58 { 59 default:
59 return adoptPtr(new CreatedInvocation()); 60 ASSERT_NOT_REACHED();
61 return PassOwnPtr<CustomElementCallbackInvocation>();
62 }
60 } 63 }
61 64
62 PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::cre ateAttributeChangedInvocation(const AtomicString& name, const AtomicString& oldV alue, const AtomicString& newValue) 65 void CustomElementCallbackInvocation::dispatch(Element* element)
63 { 66 {
64 return adoptPtr(new AttributeChangedInvocation(name, oldValue, newValue)); 67 switch (m_which) {
68 case CustomElementLifecycleCallbacks::Created:
69 if (element->inDocument())
70 CustomElementCallbackDispatcher::instance().enqueueEnteredDocumentCa llback(m_callbacks, element);
71 m_callbacks->created(element);
72 break;
73 case CustomElementLifecycleCallbacks::EnteredDocument:
74 m_callbacks->enteredDocument(element);
75 break;
76 case CustomElementLifecycleCallbacks::LeftDocument:
77 m_callbacks->leftDocument(element);
78 break;
79 default:
80 ASSERT_NOT_REACHED();
81 }
65 } 82 }
66 83
67 AttributeChangedInvocation::AttributeChangedInvocation(const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) 84 PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::cre ateAttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callba cks, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
68 : m_name(name) 85 {
86 return adoptPtr(new AttributeChangedInvocation(callbacks, name, oldValue, ne wValue));
87 }
88
89 AttributeChangedInvocation::AttributeChangedInvocation(PassRefPtr<CustomElementL ifecycleCallbacks> callbacks, const AtomicString& name, const AtomicString& oldV alue, const AtomicString& newValue)
90 : CustomElementCallbackInvocation(callbacks, CustomElementLifecycleCallbacks ::AttributeChanged)
91 , m_name(name)
69 , m_oldValue(oldValue) 92 , m_oldValue(oldValue)
70 , m_newValue(newValue) 93 , m_newValue(newValue)
71 { 94 {
72 } 95 }
73 96
74 void AttributeChangedInvocation::dispatch(CustomElementLifecycleCallbacks* callb acks, Element* element) 97 void AttributeChangedInvocation::dispatch(Element* element)
75 { 98 {
76 callbacks->attributeChanged(element, m_name, m_oldValue, m_newValue); 99 callbacks()->attributeChanged(element, m_name, m_oldValue, m_newValue);
77 }
78
79 void CreatedInvocation::dispatch(CustomElementLifecycleCallbacks* callbacks, Ele ment* element)
80 {
81 callbacks->created(element);
82 } 100 }
83 101
84 } // namespace WebCore 102 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698