| 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 #include "ui/events/platform/platform_event_source.h" | 5 #include "ui/events/platform/platform_event_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "ui/events/platform/platform_event_dispatcher.h" | 10 #include "ui/events/platform/platform_event_dispatcher.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 scoped_ptr<ScopedEventDispatcher> PlatformEventSource::OverrideDispatcher( | 46 scoped_ptr<ScopedEventDispatcher> PlatformEventSource::OverrideDispatcher( |
| 47 PlatformEventDispatcher* dispatcher) { | 47 PlatformEventDispatcher* dispatcher) { |
| 48 CHECK(dispatcher); | 48 CHECK(dispatcher); |
| 49 overridden_dispatcher_restored_ = false; | 49 overridden_dispatcher_restored_ = false; |
| 50 return make_scoped_ptr( | 50 return make_scoped_ptr( |
| 51 new ScopedEventDispatcher(&overridden_dispatcher_, dispatcher)); | 51 new ScopedEventDispatcher(&overridden_dispatcher_, dispatcher)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void PlatformEventSource::StopCurrentEventStream() { |
| 55 } |
| 56 |
| 54 void PlatformEventSource::AddPlatformEventObserver( | 57 void PlatformEventSource::AddPlatformEventObserver( |
| 55 PlatformEventObserver* observer) { | 58 PlatformEventObserver* observer) { |
| 56 CHECK(observer); | 59 CHECK(observer); |
| 57 observers_.AddObserver(observer); | 60 observers_.AddObserver(observer); |
| 58 } | 61 } |
| 59 | 62 |
| 60 void PlatformEventSource::RemovePlatformEventObserver( | 63 void PlatformEventSource::RemovePlatformEventObserver( |
| 61 PlatformEventObserver* observer) { | 64 PlatformEventObserver* observer) { |
| 62 observers_.RemoveObserver(observer); | 65 observers_.RemoveObserver(observer); |
| 63 } | 66 } |
| 64 | 67 |
| 65 uint32_t PlatformEventSource::DispatchEvent(PlatformEvent platform_event) { | 68 uint32_t PlatformEventSource::DispatchEvent(PlatformEvent platform_event) { |
| 66 uint32_t action = POST_DISPATCH_PERFORM_DEFAULT; | 69 uint32_t action = POST_DISPATCH_PERFORM_DEFAULT; |
| 67 | 70 |
| 68 FOR_EACH_OBSERVER(PlatformEventObserver, observers_, | 71 FOR_EACH_OBSERVER(PlatformEventObserver, observers_, |
| 69 WillProcessEvent(platform_event)); | 72 WillProcessEvent(platform_event)); |
| 70 // Give the overridden dispatcher a chance to dispatch the event first. | 73 // Give the overridden dispatcher a chance to dispatch the event first. |
| 71 if (overridden_dispatcher_) | 74 if (overridden_dispatcher_) |
| 72 action = overridden_dispatcher_->DispatchEvent(platform_event); | 75 action = overridden_dispatcher_->DispatchEvent(platform_event); |
| 73 | 76 |
| 74 if ((action & POST_DISPATCH_PERFORM_DEFAULT) && | 77 if ((action & POST_DISPATCH_PERFORM_DEFAULT) && |
| 75 dispatchers_.might_have_observers()) { | 78 dispatchers_.might_have_observers()) { |
| 76 ObserverList<PlatformEventDispatcher>::Iterator iter(dispatchers_); | 79 ObserverList<PlatformEventDispatcher>::Iterator iter(&dispatchers_); |
| 77 while (PlatformEventDispatcher* dispatcher = iter.GetNext()) { | 80 while (PlatformEventDispatcher* dispatcher = iter.GetNext()) { |
| 78 if (dispatcher->CanDispatchEvent(platform_event)) | 81 if (dispatcher->CanDispatchEvent(platform_event)) |
| 79 action = dispatcher->DispatchEvent(platform_event); | 82 action = dispatcher->DispatchEvent(platform_event); |
| 80 if (action & POST_DISPATCH_STOP_PROPAGATION) | 83 if (action & POST_DISPATCH_STOP_PROPAGATION) |
| 81 break; | 84 break; |
| 82 } | 85 } |
| 83 } | 86 } |
| 84 FOR_EACH_OBSERVER(PlatformEventObserver, observers_, | 87 FOR_EACH_OBSERVER(PlatformEventObserver, observers_, |
| 85 DidProcessEvent(platform_event)); | 88 DidProcessEvent(platform_event)); |
| 86 | 89 |
| 87 // If an overridden dispatcher has been destroyed, then the platform | 90 // If an overridden dispatcher has been destroyed, then the platform |
| 88 // event-source should halt dispatching the current stream of events, and wait | 91 // event-source should halt dispatching the current stream of events, and wait |
| 89 // until the next message-loop iteration for dispatching events. This lets any | 92 // until the next message-loop iteration for dispatching events. This lets any |
| 90 // nested message-loop to unwind correctly and any new dispatchers to receive | 93 // nested message-loop to unwind correctly and any new dispatchers to receive |
| 91 // the correct sequence of events. | 94 // the correct sequence of events. |
| 92 if (overridden_dispatcher_restored_) | 95 if (overridden_dispatcher_restored_) |
| 93 StopCurrentEventStream(); | 96 StopCurrentEventStream(); |
| 94 | 97 |
| 95 overridden_dispatcher_restored_ = false; | 98 overridden_dispatcher_restored_ = false; |
| 96 | 99 |
| 97 return action; | 100 return action; |
| 98 } | 101 } |
| 99 | 102 |
| 100 void PlatformEventSource::StopCurrentEventStream() { | |
| 101 } | |
| 102 | |
| 103 void PlatformEventSource::OnDispatcherListChanged() { | 103 void PlatformEventSource::OnDispatcherListChanged() { |
| 104 } | 104 } |
| 105 | 105 |
| 106 void PlatformEventSource::OnOverriddenDispatcherRestored() { | 106 void PlatformEventSource::OnOverriddenDispatcherRestored() { |
| 107 CHECK(overridden_dispatcher_); | 107 CHECK(overridden_dispatcher_); |
| 108 overridden_dispatcher_restored_ = true; | 108 overridden_dispatcher_restored_ = true; |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace ui | 111 } // namespace ui |
| OLD | NEW |