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