| 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 "core/frame/PlatformEventDispatcher.h" | 5 #include "core/frame/PlatformEventDispatcher.h" |
| 6 | 6 |
| 7 #include "core/frame/PlatformEventController.h" | 7 #include "core/frame/PlatformEventController.h" |
| 8 #include "platform/wtf/AutoReset.h" | 8 #include "platform/wtf/AutoReset.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 PlatformEventDispatcher::PlatformEventDispatcher() | 12 PlatformEventDispatcher::PlatformEventDispatcher() |
| 13 : is_dispatching_(false), is_listening_(false) {} | 13 : is_dispatching_(false), is_listening_(false) {} |
| 14 | 14 |
| 15 void PlatformEventDispatcher::AddController( | 15 void PlatformEventDispatcher::AddController( |
| 16 PlatformEventController* controller) { | 16 PlatformEventController* controller) { |
| 17 ASSERT(controller); | 17 DCHECK(controller); |
| 18 // TODO: If we can avoid to register a same controller twice, we can change | 18 // TODO: If we can avoid to register a same controller twice, we can change |
| 19 // this 'if' to ASSERT. | 19 // this 'if' to ASSERT. |
| 20 if (controllers_.Contains(controller)) | 20 if (controllers_.Contains(controller)) |
| 21 return; | 21 return; |
| 22 | 22 |
| 23 controllers_.insert(controller); | 23 controllers_.insert(controller); |
| 24 | 24 |
| 25 if (!is_listening_) { | 25 if (!is_listening_) { |
| 26 StartListening(); | 26 StartListening(); |
| 27 is_listening_ = true; | 27 is_listening_ = true; |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 void PlatformEventDispatcher::RemoveController( | 31 void PlatformEventDispatcher::RemoveController( |
| 32 PlatformEventController* controller) { | 32 PlatformEventController* controller) { |
| 33 ASSERT(controllers_.Contains(controller)); | 33 DCHECK(controllers_.Contains(controller)); |
| 34 | 34 |
| 35 controllers_.erase(controller); | 35 controllers_.erase(controller); |
| 36 if (!is_dispatching_ && controllers_.IsEmpty()) { | 36 if (!is_dispatching_ && controllers_.IsEmpty()) { |
| 37 StopListening(); | 37 StopListening(); |
| 38 is_listening_ = false; | 38 is_listening_ = false; |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 void PlatformEventDispatcher::NotifyControllers() { | 42 void PlatformEventDispatcher::NotifyControllers() { |
| 43 if (controllers_.IsEmpty()) | 43 if (controllers_.IsEmpty()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 59 StopListening(); | 59 StopListening(); |
| 60 is_listening_ = false; | 60 is_listening_ = false; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 DEFINE_TRACE(PlatformEventDispatcher) { | 64 DEFINE_TRACE(PlatformEventDispatcher) { |
| 65 visitor->Trace(controllers_); | 65 visitor->Trace(controllers_); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace blink | 68 } // namespace blink |
| OLD | NEW |