OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ | |
6 #define UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/auto_reset.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/observer_list.h" | |
15 #include "ui/events/events_export.h" | |
16 #include "ui/events/platform/platform_event_types.h" | |
17 | |
18 namespace ui { | |
19 | |
20 class Event; | |
21 class PlatformEventDispatcher; | |
22 class PlatformEventObserver; | |
23 class ScopedEventDispatcher; | |
24 | |
25 // PlatformEventSource receives events from a source and dispatches the events | |
26 // to the appropriate dispatchers. | |
27 class EVENTS_EXPORT PlatformEventSource { | |
28 public: | |
29 virtual ~PlatformEventSource(); | |
30 | |
31 static PlatformEventSource* GetInstance(); | |
32 | |
33 void AddPlatformEventDispatcher(PlatformEventDispatcher* dispatcher); | |
34 void RemovePlatformEventDispatcher(PlatformEventDispatcher* dispatcher); | |
35 | |
36 // Installs a PlatformEventDispatcher that receives all the events. The | |
37 // dispatched can process the event, or request that the default dispatchers | |
sky
2014/03/25 15:51:15
dispatched->dispatcher
sadrul
2014/03/25 18:33:15
Done.
| |
38 // be invoked by setting |POST_DISPATCH_PERFORM_DEFAULT| flag from the | |
39 // |DispatchEvent()| override. | |
40 // The returned |ScopedEventDispatcher| object is a handler for the overridden | |
41 // dispatcher. When this handler is destroyed, it removes the overridden | |
42 // dispatcher, and restores the previous override-dispatcher (or NULL if there | |
43 // wasn't any). | |
44 scoped_ptr<ScopedEventDispatcher> OverrideDispatcher( | |
45 PlatformEventDispatcher* dispatcher); | |
46 | |
47 void AddPlatformEventObserver(PlatformEventObserver* observer); | |
48 void RemovePlatformEventObserver(PlatformEventObserver* observer); | |
49 | |
50 protected: | |
51 PlatformEventSource(); | |
52 | |
53 // Dispatches |platform_event| to the dispatchers. If there is an override | |
54 // dispatcher installed using |OverrideDispatcher()|, then that dispatcher | |
55 // receives the event first. |POST_DISPATCH_QUIT_LOOP| flag is set in the | |
56 // returned value if the event-source should stop dispatching events at the | |
57 // current message-loop iteration. | |
58 virtual uint32_t DispatchEvent(PlatformEvent platform_event); | |
59 | |
60 private: | |
61 friend class ScopedEventDispatcher; | |
62 static PlatformEventSource* instance_; | |
63 | |
64 void OnOverriddenDispatcherRestored(); | |
65 | |
66 // Invokes the corresponding methods on the PlatformEventObservers added to | |
67 // the event-source. | |
68 // Returns true from |WillProcessEvent()| if any of the observers in the list | |
69 // consumes the event and returns true from |WillProcessEvent()|. | |
70 bool WillProcessEvent(PlatformEvent platform_event); | |
71 void DidProcessEvent(PlatformEvent platform_event); | |
72 | |
73 typedef std::vector<PlatformEventDispatcher*> PlatformEventDispatcherList; | |
74 PlatformEventDispatcherList dispatchers_; | |
75 PlatformEventDispatcher* overridden_dispatcher_; | |
76 | |
77 // Used to keep track of whether the current override-dispatcher has been | |
78 // reset and a previous override-dispatcher has been restored. | |
79 bool overridden_dispatcher_restored_; | |
80 | |
81 ObserverList<PlatformEventObserver> observers_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(PlatformEventSource); | |
84 }; | |
85 | |
86 } // namespace ui | |
87 | |
88 #endif // UI_EVENTS_PLATFORM_PLATFORM_EVENT_SOURCE_H_ | |
OLD | NEW |