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

Side by Side Diff: Source/core/dom/CustomElementCallbackDispatcher.h

Issue 17707002: Implement Custom Elements inserted and removed callbacks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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 22 matching lines...) Expand all
33 33
34 #include "core/dom/CustomElementCallback.h" 34 #include "core/dom/CustomElementCallback.h"
35 #include "core/dom/Element.h" 35 #include "core/dom/Element.h"
36 #include "wtf/OwnPtr.h" 36 #include "wtf/OwnPtr.h"
37 #include "wtf/PassRefPtr.h" 37 #include "wtf/PassRefPtr.h"
38 #include "wtf/RefPtr.h" 38 #include "wtf/RefPtr.h"
39 #include "wtf/Vector.h" 39 #include "wtf/Vector.h"
40 40
41 namespace WebCore { 41 namespace WebCore {
42 42
43 class Element;
44
43 class CustomElementCallbackDispatcher { 45 class CustomElementCallbackDispatcher {
44 WTF_MAKE_NONCOPYABLE(CustomElementCallbackDispatcher); 46 WTF_MAKE_NONCOPYABLE(CustomElementCallbackDispatcher);
45 public: 47 public:
46 static CustomElementCallbackDispatcher& instance(); 48 static CustomElementCallbackDispatcher& instance();
47 49
48 class CallbackDeliveryScope { 50 class CallbackDeliveryScope {
dglazkov 2013/06/25 18:04:31 Do you still use this guy?
49 public: 51 public:
50 CallbackDeliveryScope() { } 52 CallbackDeliveryScope() { }
51 ~CallbackDeliveryScope() 53 ~CallbackDeliveryScope()
52 { 54 {
53 CustomElementCallbackDispatcher& dispatcher = CustomElementCallbackD ispatcher::instance(); 55 CustomElementCallbackDispatcher& dispatcher = CustomElementCallbackD ispatcher::instance();
54 if (dispatcher.hasQueuedCallbacks()) 56 if (dispatcher.hasQueuedCallbacks())
55 dispatcher.dispatch(); 57 dispatcher.dispatch();
56 } 58 }
57 }; 59 };
58 60
59 void enqueueReadyCallback(CustomElementCallback*, Element*); 61 void enqueueCreationCallbacks(CustomElementCallback*, Element*, bool created ByParser);
62 void enqueueInsertedCallback(CustomElementCallback*, Element*);
63 void enqueueRemovedCallback(CustomElementCallback*, Element*);
60 64
61 // Returns true if more work may have to be performed at the 65 // Returns true if more work may have to be performed at the
62 // checkpoint by this or other workers (for example, this work 66 // checkpoint by this or other workers (for example, this work
63 // invoked author scripts) 67 // invoked author scripts)
64 bool dispatch(); 68 bool dispatch();
65 69
66 // Eagerly dispatches the ready callback. Used for createElement, 70 // Eagerly dispatches the ready callback. Used for createElement,
67 // createElementNS and generated constructors. 71 // createElementNS and generated constructors.
68 void dispatchReadyCallback(Element*); 72 void dispatchReadyCallback(Element*);
69 73
70 private: 74 class Invocation {
71 explicit CustomElementCallbackDispatcher() { }
72
73 bool hasQueuedCallbacks() { return !m_invocations.isEmpty(); }
74
75 class ReadyInvocation {
76 public: 75 public:
77 ReadyInvocation(PassRefPtr<CustomElementCallback>, PassRefPtr<Element>); 76 Invocation(CustomElementCallback::CallbackType, PassRefPtr<CustomElement Callback>, PassRefPtr<Element>);
78 virtual ~ReadyInvocation() { }
79 void invoke() { m_callback->ready(m_element.get()); }
80 Element* element() { return m_element.get(); } 77 Element* element() { return m_element.get(); }
78 CustomElementCallback::CallbackType type() { return m_type; }
79 void invoke();
81 80
82 private: 81 private:
82 CustomElementCallback::CallbackType m_type;
83 RefPtr<CustomElementCallback> m_callback; 83 RefPtr<CustomElementCallback> m_callback;
84 RefPtr<Element> m_element; 84 RefPtr<Element> m_element;
85 }; 85 };
86 86
87 typedef Vector<OwnPtr<ReadyInvocation> > InvocationList; 87 private:
88 explicit CustomElementCallbackDispatcher() { }
89 bool hasQueuedCallbacks() { return !m_invocations.isEmpty(); }
90
91 typedef Vector<OwnPtr<Invocation> > InvocationList;
88 InvocationList m_invocations; 92 InvocationList m_invocations;
89 }; 93 };
90 94
91 } 95 }
92 96
93 #endif // CustomElementCallbackDispatcher_h 97 #endif // CustomElementCallbackDispatcher_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698