| 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 |
| 11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "ui/events/events_export.h" | 15 #include "ui/events/events_export.h" |
| 16 #include "ui/events/platform/platform_event_types.h" | 16 #include "ui/events/platform/platform_event_types.h" |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 class Event; | 20 class Event; |
| 21 class PlatformEventDispatcher; | 21 class PlatformEventDispatcher; |
| 22 class PlatformEventFilter; |
| 22 class PlatformEventObserver; | 23 class PlatformEventObserver; |
| 23 class ScopedEventDispatcher; | 24 class ScopedEventDispatcher; |
| 24 | 25 |
| 25 // PlatformEventSource receives events from a source and dispatches the events | 26 // PlatformEventSource receives events from a source and dispatches the events |
| 26 // to the appropriate dispatchers. | 27 // to the appropriate dispatchers. |
| 27 class EVENTS_EXPORT PlatformEventSource { | 28 class EVENTS_EXPORT PlatformEventSource { |
| 28 public: | 29 public: |
| 29 virtual ~PlatformEventSource(); | 30 virtual ~PlatformEventSource(); |
| 30 | 31 |
| 31 static PlatformEventSource* GetInstance(); | 32 static PlatformEventSource* GetInstance(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 47 // The returned |ScopedEventDispatcher| object is a handler for the overridden | 48 // The returned |ScopedEventDispatcher| object is a handler for the overridden |
| 48 // dispatcher. When this handler is destroyed, it removes the overridden | 49 // dispatcher. When this handler is destroyed, it removes the overridden |
| 49 // dispatcher, and restores the previous override-dispatcher (or NULL if there | 50 // dispatcher, and restores the previous override-dispatcher (or NULL if there |
| 50 // wasn't any). | 51 // wasn't any). |
| 51 scoped_ptr<ScopedEventDispatcher> OverrideDispatcher( | 52 scoped_ptr<ScopedEventDispatcher> OverrideDispatcher( |
| 52 PlatformEventDispatcher* dispatcher); | 53 PlatformEventDispatcher* dispatcher); |
| 53 | 54 |
| 54 void AddPlatformEventObserver(PlatformEventObserver* observer); | 55 void AddPlatformEventObserver(PlatformEventObserver* observer); |
| 55 void RemovePlatformEventObserver(PlatformEventObserver* observer); | 56 void RemovePlatformEventObserver(PlatformEventObserver* observer); |
| 56 | 57 |
| 58 void AddPlatformEventFilter(PlatformEventFilter* filter); |
| 59 void RemovePlatformEventFilter(PlatformEventFilter* filter); |
| 60 |
| 57 static scoped_ptr<PlatformEventSource> CreateDefault(); | 61 static scoped_ptr<PlatformEventSource> CreateDefault(); |
| 58 | 62 |
| 59 protected: | 63 protected: |
| 60 PlatformEventSource(); | 64 PlatformEventSource(); |
| 61 | 65 |
| 62 // Dispatches |platform_event| to the dispatchers. If there is an override | 66 // Dispatches |platform_event| to the dispatchers. If there is an override |
| 63 // dispatcher installed using |OverrideDispatcher()|, then that dispatcher | 67 // dispatcher installed using |OverrideDispatcher()|, then that dispatcher |
| 64 // receives the event first. |POST_DISPATCH_QUIT_LOOP| flag is set in the | 68 // 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 | 69 // returned value if the event-source should stop dispatching events at the |
| 66 // current message-loop iteration. | 70 // current message-loop iteration. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 85 // dispatchers, so that adding/removing dispatchers during an event dispatch | 89 // dispatchers, so that adding/removing dispatchers during an event dispatch |
| 86 // is well-defined. | 90 // is well-defined. |
| 87 typedef ObserverList<PlatformEventDispatcher> PlatformEventDispatcherList; | 91 typedef ObserverList<PlatformEventDispatcher> PlatformEventDispatcherList; |
| 88 PlatformEventDispatcherList dispatchers_; | 92 PlatformEventDispatcherList dispatchers_; |
| 89 PlatformEventDispatcher* overridden_dispatcher_; | 93 PlatformEventDispatcher* overridden_dispatcher_; |
| 90 | 94 |
| 91 // Used to keep track of whether the current override-dispatcher has been | 95 // Used to keep track of whether the current override-dispatcher has been |
| 92 // reset and a previous override-dispatcher has been restored. | 96 // reset and a previous override-dispatcher has been restored. |
| 93 bool overridden_dispatcher_restored_; | 97 bool overridden_dispatcher_restored_; |
| 94 | 98 |
| 99 // Use an ObserverList<> instead of an std::vector<> to store the list of |
| 100 // filters as well, so that adding/removing filters during event filtering |
| 101 // is well-defined. |
| 102 typedef ObserverList<PlatformEventFilter> PlatformEventFilterList; |
| 103 PlatformEventFilterList filters_; |
| 104 |
| 95 ObserverList<PlatformEventObserver> observers_; | 105 ObserverList<PlatformEventObserver> observers_; |
| 96 | 106 |
| 97 DISALLOW_COPY_AND_ASSIGN(PlatformEventSource); | 107 DISALLOW_COPY_AND_ASSIGN(PlatformEventSource); |
| 98 }; | 108 }; |
| 99 | 109 |
| 100 } // namespace ui | 110 } // namespace ui |
| 101 | 111 |
| 102 #endif // UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ | 112 #endif // UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ |
| OLD | NEW |