OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ | 5 #ifndef UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ |
6 #define UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ | 6 #define UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // dispatcher can process the event, or request that the default dispatchers | 44 // dispatcher can process the event, or request that the default dispatchers |
45 // be invoked by setting |POST_DISPATCH_PERFORM_DEFAULT| flag from the | 45 // be invoked by setting |POST_DISPATCH_PERFORM_DEFAULT| flag from the |
46 // |DispatchEvent()| override. | 46 // |DispatchEvent()| override. |
47 // The returned |ScopedEventDispatcher| object is a handler for the overridden | 47 // The returned |ScopedEventDispatcher| object is a handler for the overridden |
48 // dispatcher. When this handler is destroyed, it removes the overridden | 48 // dispatcher. When this handler is destroyed, it removes the overridden |
49 // dispatcher, and restores the previous override-dispatcher (or NULL if there | 49 // dispatcher, and restores the previous override-dispatcher (or NULL if there |
50 // wasn't any). | 50 // wasn't any). |
51 scoped_ptr<ScopedEventDispatcher> OverrideDispatcher( | 51 scoped_ptr<ScopedEventDispatcher> OverrideDispatcher( |
52 PlatformEventDispatcher* dispatcher); | 52 PlatformEventDispatcher* dispatcher); |
53 | 53 |
| 54 // Called to indicate that the source should stop dispatching the current |
| 55 // stream of events and wait until the next iteration of the message-loop to |
| 56 // dispatch the rest of the events. |
| 57 virtual void StopCurrentEventStream(); |
| 58 |
54 void AddPlatformEventObserver(PlatformEventObserver* observer); | 59 void AddPlatformEventObserver(PlatformEventObserver* observer); |
55 void RemovePlatformEventObserver(PlatformEventObserver* observer); | 60 void RemovePlatformEventObserver(PlatformEventObserver* observer); |
56 | 61 |
57 static scoped_ptr<PlatformEventSource> CreateDefault(); | 62 static scoped_ptr<PlatformEventSource> CreateDefault(); |
58 | 63 |
59 protected: | 64 protected: |
60 PlatformEventSource(); | 65 PlatformEventSource(); |
61 | 66 |
62 // Dispatches |platform_event| to the dispatchers. If there is an override | 67 // Dispatches |platform_event| to the dispatchers. If there is an override |
63 // dispatcher installed using |OverrideDispatcher()|, then that dispatcher | 68 // dispatcher installed using |OverrideDispatcher()|, then that dispatcher |
64 // receives the event first. |POST_DISPATCH_QUIT_LOOP| flag is set in the | 69 // receives the event first. |POST_DISPATCH_QUIT_LOOP| flag is set in the |
65 // returned value if the event-source should stop dispatching events at the | 70 // returned value if the event-source should stop dispatching events at the |
66 // current message-loop iteration. | 71 // current message-loop iteration. |
67 virtual uint32_t DispatchEvent(PlatformEvent platform_event); | 72 virtual uint32_t DispatchEvent(PlatformEvent platform_event); |
68 | 73 |
69 private: | 74 private: |
70 friend class ScopedEventDispatcher; | 75 friend class ScopedEventDispatcher; |
71 static PlatformEventSource* instance_; | 76 static PlatformEventSource* instance_; |
72 | 77 |
73 // Called to indicate that the source should stop dispatching the current | |
74 // stream of events and wait until the next iteration of the message-loop to | |
75 // dispatch the rest of the events. | |
76 virtual void StopCurrentEventStream(); | |
77 | |
78 // This is invoked when the list of dispatchers changes (i.e. a new dispatcher | 78 // This is invoked when the list of dispatchers changes (i.e. a new dispatcher |
79 // is added, or a dispatcher is removed). | 79 // is added, or a dispatcher is removed). |
80 virtual void OnDispatcherListChanged(); | 80 virtual void OnDispatcherListChanged(); |
81 | 81 |
82 void OnOverriddenDispatcherRestored(); | 82 void OnOverriddenDispatcherRestored(); |
83 | 83 |
84 // Use a base::ObserverList<> instead of an std::vector<> to store the list of | 84 // Use an base::ObserverList<> instead of an std::vector<> to store the list |
| 85 // of |
85 // dispatchers, so that adding/removing dispatchers during an event dispatch | 86 // dispatchers, so that adding/removing dispatchers during an event dispatch |
86 // is well-defined. | 87 // is well-defined. |
87 typedef base::ObserverList<PlatformEventDispatcher> | 88 typedef base::ObserverList<PlatformEventDispatcher> |
88 PlatformEventDispatcherList; | 89 PlatformEventDispatcherList; |
89 PlatformEventDispatcherList dispatchers_; | 90 PlatformEventDispatcherList dispatchers_; |
90 PlatformEventDispatcher* overridden_dispatcher_; | 91 PlatformEventDispatcher* overridden_dispatcher_; |
91 | 92 |
92 // Used to keep track of whether the current override-dispatcher has been | 93 // Used to keep track of whether the current override-dispatcher has been |
93 // reset and a previous override-dispatcher has been restored. | 94 // reset and a previous override-dispatcher has been restored. |
94 bool overridden_dispatcher_restored_; | 95 bool overridden_dispatcher_restored_; |
95 | 96 |
96 base::ObserverList<PlatformEventObserver> observers_; | 97 base::ObserverList<PlatformEventObserver> observers_; |
97 | 98 |
98 DISALLOW_COPY_AND_ASSIGN(PlatformEventSource); | 99 DISALLOW_COPY_AND_ASSIGN(PlatformEventSource); |
99 }; | 100 }; |
100 | 101 |
101 } // namespace ui | 102 } // namespace ui |
102 | 103 |
103 #endif // UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ | 104 #endif // UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ |
OLD | NEW |