| 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" |
| 11 #include "ui/events/platform/platform_event_filter.h" |
| 11 #include "ui/events/platform/platform_event_observer.h" | 12 #include "ui/events/platform/platform_event_observer.h" |
| 12 #include "ui/events/platform/scoped_event_dispatcher.h" | 13 #include "ui/events/platform/scoped_event_dispatcher.h" |
| 13 | 14 |
| 14 namespace ui { | 15 namespace ui { |
| 15 | 16 |
| 16 // static | 17 // static |
| 17 PlatformEventSource* PlatformEventSource::instance_ = NULL; | 18 PlatformEventSource* PlatformEventSource::instance_ = NULL; |
| 18 | 19 |
| 19 PlatformEventSource::PlatformEventSource() | 20 PlatformEventSource::PlatformEventSource() |
| 20 : overridden_dispatcher_(NULL), | 21 : overridden_dispatcher_(NULL), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 PlatformEventObserver* observer) { | 56 PlatformEventObserver* observer) { |
| 56 CHECK(observer); | 57 CHECK(observer); |
| 57 observers_.AddObserver(observer); | 58 observers_.AddObserver(observer); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void PlatformEventSource::RemovePlatformEventObserver( | 61 void PlatformEventSource::RemovePlatformEventObserver( |
| 61 PlatformEventObserver* observer) { | 62 PlatformEventObserver* observer) { |
| 62 observers_.RemoveObserver(observer); | 63 observers_.RemoveObserver(observer); |
| 63 } | 64 } |
| 64 | 65 |
| 66 void PlatformEventSource::AddPlatformEventFilter(PlatformEventFilter* filter) { |
| 67 CHECK(filter); |
| 68 filters_.AddObserver(filter); |
| 69 } |
| 70 |
| 71 void PlatformEventSource::RemovePlatformEventFilter( |
| 72 PlatformEventFilter* filter) { |
| 73 filters_.RemoveObserver(filter); |
| 74 } |
| 75 |
| 65 uint32_t PlatformEventSource::DispatchEvent(PlatformEvent platform_event) { | 76 uint32_t PlatformEventSource::DispatchEvent(PlatformEvent platform_event) { |
| 66 uint32_t action = POST_DISPATCH_PERFORM_DEFAULT; | 77 uint32_t action = POST_DISPATCH_PERFORM_DEFAULT; |
| 67 | 78 |
| 79 // Always deliver all events to all PlatformEventFilters, if any of them |
| 80 // specify that the event should not be dispatched, return immediately to |
| 81 // stop propagation. |
| 82 ObserverList<PlatformEventFilter>::Iterator iter(filters_); |
| 83 while (PlatformEventFilter* filter = iter.GetNext()) { |
| 84 if (!filter->ShouldDispatchEvent(platform_event)) |
| 85 action = POST_DISPATCH_STOP_PROPAGATION; |
| 86 } |
| 87 if (action == POST_DISPATCH_STOP_PROPAGATION) |
| 88 return action; |
| 89 |
| 68 FOR_EACH_OBSERVER(PlatformEventObserver, observers_, | 90 FOR_EACH_OBSERVER(PlatformEventObserver, observers_, |
| 69 WillProcessEvent(platform_event)); | 91 WillProcessEvent(platform_event)); |
| 70 // Give the overridden dispatcher a chance to dispatch the event first. | 92 // Give the overridden dispatcher a chance to dispatch the event first. |
| 71 if (overridden_dispatcher_) | 93 if (overridden_dispatcher_) |
| 72 action = overridden_dispatcher_->DispatchEvent(platform_event); | 94 action = overridden_dispatcher_->DispatchEvent(platform_event); |
| 73 | 95 |
| 74 if ((action & POST_DISPATCH_PERFORM_DEFAULT) && | 96 if ((action & POST_DISPATCH_PERFORM_DEFAULT) && |
| 75 dispatchers_.might_have_observers()) { | 97 dispatchers_.might_have_observers()) { |
| 76 ObserverList<PlatformEventDispatcher>::Iterator iter(dispatchers_); | 98 ObserverList<PlatformEventDispatcher>::Iterator iter(dispatchers_); |
| 77 while (PlatformEventDispatcher* dispatcher = iter.GetNext()) { | 99 while (PlatformEventDispatcher* dispatcher = iter.GetNext()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 102 | 124 |
| 103 void PlatformEventSource::OnDispatcherListChanged() { | 125 void PlatformEventSource::OnDispatcherListChanged() { |
| 104 } | 126 } |
| 105 | 127 |
| 106 void PlatformEventSource::OnOverriddenDispatcherRestored() { | 128 void PlatformEventSource::OnOverriddenDispatcherRestored() { |
| 107 CHECK(overridden_dispatcher_); | 129 CHECK(overridden_dispatcher_); |
| 108 overridden_dispatcher_restored_ = true; | 130 overridden_dispatcher_restored_ = true; |
| 109 } | 131 } |
| 110 | 132 |
| 111 } // namespace ui | 133 } // namespace ui |
| OLD | NEW |