Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 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 | 37 |
| 38 namespace { | |
| 39 | |
| 40 blink::WebPlatformEventType getWebPlatformEventType(bool absolute) | |
|
Rick Byers
2015/10/22 16:00:52
nit: make this a private const method of the class
timvolodine
2015/10/27 16:38:35
Done.
| |
| 41 { | |
| 42 return (absolute) ? blink::WebPlatformEventTypeDeviceOrientationAbsolute : b link::WebPlatformEventTypeDeviceOrientation; | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 38 namespace blink { | 47 namespace blink { |
| 39 | 48 |
| 40 DeviceOrientationDispatcher& DeviceOrientationDispatcher::instance() | 49 template<> |
| 50 DeviceOrientationDispatcher& DeviceOrientationDispatcher::instance<true>() | |
| 41 { | 51 { |
| 42 DEFINE_STATIC_LOCAL(Persistent<DeviceOrientationDispatcher>, deviceOrientati onDispatcher, (new DeviceOrientationDispatcher())); | 52 DEFINE_STATIC_LOCAL(Persistent<DeviceOrientationDispatcher>, deviceOrientati onAbsoluteDispatcher, (new DeviceOrientationDispatcher(true))); |
|
Rick Byers
2015/10/22 16:00:52
rather than use template specialization here, woul
timvolodine
2015/10/27 16:38:35
yes, looks like using a template is a bit of overk
| |
| 53 return *deviceOrientationAbsoluteDispatcher; | |
| 54 } | |
| 55 | |
| 56 template<> | |
| 57 DeviceOrientationDispatcher& DeviceOrientationDispatcher::instance<false>() | |
| 58 { | |
| 59 DEFINE_STATIC_LOCAL(Persistent<DeviceOrientationDispatcher>, deviceOrientati onDispatcher, (new DeviceOrientationDispatcher(false))); | |
| 43 return *deviceOrientationDispatcher; | 60 return *deviceOrientationDispatcher; |
| 44 } | 61 } |
| 45 | 62 |
| 46 DeviceOrientationDispatcher::DeviceOrientationDispatcher() | 63 DeviceOrientationDispatcher::DeviceOrientationDispatcher(bool absolute) : m_abso lute(absolute) |
| 47 { | 64 { |
| 48 } | 65 } |
| 49 | 66 |
| 50 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() | 67 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() |
| 51 { | 68 { |
| 52 } | 69 } |
| 53 | 70 |
| 54 DEFINE_TRACE(DeviceOrientationDispatcher) | 71 DEFINE_TRACE(DeviceOrientationDispatcher) |
| 55 { | 72 { |
| 56 visitor->trace(m_lastDeviceOrientationData); | 73 visitor->trace(m_lastDeviceOrientationData); |
| 57 PlatformEventDispatcher::trace(visitor); | 74 PlatformEventDispatcher::trace(visitor); |
| 58 } | 75 } |
| 59 | 76 |
| 60 void DeviceOrientationDispatcher::startListening() | 77 void DeviceOrientationDispatcher::startListening() |
| 61 { | 78 { |
| 62 Platform::current()->startListening(WebPlatformEventTypeDeviceOrientation, t his); | 79 Platform::current()->startListening(getWebPlatformEventType(m_absolute), thi s); |
| 63 } | 80 } |
| 64 | 81 |
| 65 void DeviceOrientationDispatcher::stopListening() | 82 void DeviceOrientationDispatcher::stopListening() |
| 66 { | 83 { |
| 67 Platform::current()->stopListening(WebPlatformEventTypeDeviceOrientation); | 84 Platform::current()->stopListening(getWebPlatformEventType(m_absolute)); |
| 68 m_lastDeviceOrientationData.clear(); | 85 m_lastDeviceOrientationData.clear(); |
| 69 } | 86 } |
| 70 | 87 |
| 71 void DeviceOrientationDispatcher::didChangeDeviceOrientation(const WebDeviceOrie ntationData& motion) | 88 void DeviceOrientationDispatcher::didChangeDeviceOrientation(const WebDeviceOrie ntationData& motion) |
| 72 { | 89 { |
| 73 m_lastDeviceOrientationData = DeviceOrientationData::create(motion); | 90 m_lastDeviceOrientationData = DeviceOrientationData::create(motion); |
| 74 notifyControllers(); | 91 notifyControllers(); |
| 75 } | 92 } |
| 76 | 93 |
| 77 DeviceOrientationData* DeviceOrientationDispatcher::latestDeviceOrientationData( ) | 94 DeviceOrientationData* DeviceOrientationDispatcher::latestDeviceOrientationData( ) |
| 78 { | 95 { |
| 79 return m_lastDeviceOrientationData.get(); | 96 return m_lastDeviceOrientationData.get(); |
| 80 } | 97 } |
| 81 | 98 |
| 82 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |