Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: Source/core/frame/PlatformEventDispatcher.cpp

Issue 417213002: Introduce PlatformEvent to handle Device events, Battery events and Gamepad events. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/frame/PlatformEventDispatcher.h ('k') | Source/modules/battery/BatteryDispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "core/frame/DeviceEventDispatcherBase.h" 6 #include "core/frame/PlatformEventDispatcher.h"
7 7
8 #include "core/frame/DeviceEventControllerBase.h" 8 #include "core/frame/PlatformEventController.h"
9 #include "wtf/TemporaryChange.h" 9 #include "wtf/TemporaryChange.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 DeviceEventDispatcherBase::DeviceEventDispatcherBase() 13 PlatformEventDispatcher::PlatformEventDispatcher()
14 : m_needsPurge(false) 14 : m_needsPurge(false)
15 , m_isDispatching(false) 15 , m_isDispatching(false)
16 { 16 {
17 } 17 }
18 18
19 DeviceEventDispatcherBase::~DeviceEventDispatcherBase() 19 PlatformEventDispatcher::~PlatformEventDispatcher()
20 { 20 {
21 } 21 }
22 22
23 void DeviceEventDispatcherBase::addController(DeviceEventControllerBase* control ler) 23 void PlatformEventDispatcher::addController(PlatformEventController* controller)
24 { 24 {
25 bool wasEmpty = m_controllers.isEmpty(); 25 bool wasEmpty = m_controllers.isEmpty();
26 if (!m_controllers.contains(controller)) 26 if (!m_controllers.contains(controller))
27 m_controllers.append(controller); 27 m_controllers.append(controller);
28 if (wasEmpty) 28 if (wasEmpty)
29 startListening(); 29 startListening();
30 } 30 }
31 31
32 void DeviceEventDispatcherBase::removeController(DeviceEventControllerBase* cont roller) 32 void PlatformEventDispatcher::removeController(PlatformEventController* controll er)
33 { 33 {
34 // Do not actually remove the controller from the vector, instead zero them out. 34 // Do not actually remove the controller from the vector, instead zero them out.
35 // The zeros are removed in these two cases: 35 // The zeros are removed in these two cases:
36 // 1. either immediately if we are not dispatching any events, 36 // 1. either immediately if we are not dispatching any events,
37 // 2. or after events to all controllers have dispatched (see notifyControll ers()). 37 // 2. or after events to all controllers have dispatched (see notifyControll ers()).
38 // This is to correctly handle the re-entrancy case when a controller is des troyed 38 // This is to correctly handle the re-entrancy case when a controller is des troyed
39 // while the events are still being dispatched. 39 // while the events are still being dispatched.
40 size_t index = m_controllers.find(controller); 40 size_t index = m_controllers.find(controller);
41 if (index == kNotFound) 41 if (index == kNotFound)
42 return; 42 return;
43 43
44 m_controllers[index] = 0; 44 m_controllers[index] = 0;
45 m_needsPurge = true; 45 m_needsPurge = true;
46 46
47 if (!m_isDispatching) 47 if (!m_isDispatching)
48 purgeControllers(); 48 purgeControllers();
49 } 49 }
50 50
51 void DeviceEventDispatcherBase::purgeControllers() 51 void PlatformEventDispatcher::purgeControllers()
52 { 52 {
53 ASSERT(m_needsPurge); 53 ASSERT(m_needsPurge);
54 54
55 size_t i = 0; 55 size_t i = 0;
56 while (i < m_controllers.size()) { 56 while (i < m_controllers.size()) {
57 if (!m_controllers[i]) { 57 if (!m_controllers[i]) {
58 m_controllers[i] = m_controllers.last(); 58 m_controllers[i] = m_controllers.last();
59 m_controllers.removeLast(); 59 m_controllers.removeLast();
60 } else { 60 } else {
61 ++i; 61 ++i;
62 } 62 }
63 } 63 }
64 64
65 m_needsPurge = false; 65 m_needsPurge = false;
66 66
67 if (m_controllers.isEmpty()) 67 if (m_controllers.isEmpty())
68 stopListening(); 68 stopListening();
69 } 69 }
70 70
71 void DeviceEventDispatcherBase::notifyControllers() 71 void PlatformEventDispatcher::notifyControllers()
72 { 72 {
73 { 73 {
74 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true); 74 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
75 // Don't notify controllers removed or added during event dispatch. 75 // Don't notify controllers removed or added during event dispatch.
76 size_t size = m_controllers.size(); 76 size_t size = m_controllers.size();
77 for (size_t i = 0; i < size; ++i) { 77 for (size_t i = 0; i < size; ++i) {
78 if (m_controllers[i]) 78 if (m_controllers[i])
79 m_controllers[i]->didUpdateData(); 79 m_controllers[i]->didUpdateData();
80 } 80 }
81 } 81 }
82 82
83 if (m_needsPurge) 83 if (m_needsPurge)
84 purgeControllers(); 84 purgeControllers();
85 } 85 }
86 86
87 } // namespace blink 87 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/PlatformEventDispatcher.h ('k') | Source/modules/battery/BatteryDispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698