OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/device_orientation/DeviceOrientationDispatcher.h" | 32 #include "modules/device_orientation/DeviceOrientationDispatcher.h" |
33 | 33 |
34 #include "modules/device_orientation/DeviceOrientationController.h" | 34 #include "modules/device_orientation/DeviceOrientationController.h" |
35 #include "modules/device_orientation/DeviceOrientationData.h" | 35 #include "modules/device_orientation/DeviceOrientationData.h" |
36 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
| 37 #include "wtf/TemporaryChange.h" |
37 | 38 |
38 namespace WebCore { | 39 namespace WebCore { |
39 | 40 |
40 DeviceOrientationDispatcher& DeviceOrientationDispatcher::instance() | 41 DeviceOrientationDispatcher& DeviceOrientationDispatcher::instance() |
41 { | 42 { |
42 DEFINE_STATIC_LOCAL(DeviceOrientationDispatcher, deviceOrientationDispatcher
, ()); | 43 DEFINE_STATIC_LOCAL(DeviceOrientationDispatcher, deviceOrientationDispatcher
, ()); |
43 return deviceOrientationDispatcher; | 44 return deviceOrientationDispatcher; |
44 } | 45 } |
45 | 46 |
46 DeviceOrientationDispatcher::DeviceOrientationDispatcher() | 47 DeviceOrientationDispatcher::DeviceOrientationDispatcher() |
47 { | 48 { |
48 } | 49 } |
49 | 50 |
50 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() | 51 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() |
51 { | 52 { |
52 } | 53 } |
53 | 54 |
| 55 void DeviceOrientationDispatcher::addDeviceOrientationController(DeviceOrientati
onController* controller) |
| 56 { |
| 57 addController(controller); |
| 58 } |
| 59 |
| 60 void DeviceOrientationDispatcher::removeDeviceOrientationController(DeviceOrient
ationController* controller) |
| 61 { |
| 62 removeController(controller); |
| 63 } |
| 64 |
54 void DeviceOrientationDispatcher::startListening() | 65 void DeviceOrientationDispatcher::startListening() |
55 { | 66 { |
56 blink::Platform::current()->setDeviceOrientationListener(this); | 67 blink::Platform::current()->setDeviceOrientationListener(this); |
57 } | 68 } |
58 | 69 |
59 void DeviceOrientationDispatcher::stopListening() | 70 void DeviceOrientationDispatcher::stopListening() |
60 { | 71 { |
61 blink::Platform::current()->setDeviceOrientationListener(0); | 72 blink::Platform::current()->setDeviceOrientationListener(0); |
62 m_lastDeviceOrientationData.clear(); | 73 m_lastDeviceOrientationData.clear(); |
63 } | 74 } |
64 | 75 |
65 void DeviceOrientationDispatcher::didChangeDeviceOrientation(const blink::WebDev
iceOrientationData& motion) | 76 void DeviceOrientationDispatcher::didChangeDeviceOrientation(const blink::WebDev
iceOrientationData& motion) |
66 { | 77 { |
67 m_lastDeviceOrientationData = DeviceOrientationData::create(motion); | 78 m_lastDeviceOrientationData = DeviceOrientationData::create(motion); |
68 notifyControllers(); | 79 |
| 80 { |
| 81 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true); |
| 82 // Don't fire controllers removed or added during event dispatch. |
| 83 size_t size = m_controllers.size(); |
| 84 for (size_t i = 0; i < size; ++i) { |
| 85 if (m_controllers[i]) |
| 86 static_cast<DeviceOrientationController*>(m_controllers[i])->did
ChangeDeviceOrientation(m_lastDeviceOrientationData.get()); |
| 87 } |
| 88 } |
| 89 |
| 90 if (m_needsPurge) |
| 91 purgeControllers(); |
69 } | 92 } |
70 | 93 |
71 DeviceOrientationData* DeviceOrientationDispatcher::latestDeviceOrientationData(
) | 94 DeviceOrientationData* DeviceOrientationDispatcher::latestDeviceOrientationData(
) |
72 { | 95 { |
73 return m_lastDeviceOrientationData.get(); | 96 return m_lastDeviceOrientationData.get(); |
74 } | 97 } |
75 | 98 |
76 } // namespace WebCore | 99 } // namespace WebCore |
OLD | NEW |