| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Apple Inc. All rights reserved. | 2 * Copyright 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 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 copyright | 10 * * Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "modules/device_orientation/DeviceMotionController.h" | 28 #include "modules/device_orientation/DeviceMotionController.h" |
| 29 | 29 |
| 30 #include "RuntimeEnabledFeatures.h" | 30 #include "RuntimeEnabledFeatures.h" |
| 31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 32 #include "core/dom/EventNames.h" | 32 #include "core/dom/EventNames.h" |
| 33 #include "core/page/Page.h" |
| 33 #include "modules/device_orientation/DeviceMotionData.h" | 34 #include "modules/device_orientation/DeviceMotionData.h" |
| 34 #include "modules/device_orientation/DeviceMotionDispatcher.h" | 35 #include "modules/device_orientation/DeviceMotionDispatcher.h" |
| 35 #include "modules/device_orientation/DeviceMotionEvent.h" | 36 #include "modules/device_orientation/DeviceMotionEvent.h" |
| 36 | 37 |
| 37 namespace WebCore { | 38 namespace WebCore { |
| 38 | 39 |
| 39 DeviceMotionController::DeviceMotionController(Document* document) | 40 DeviceMotionController::DeviceMotionController(Document* document) |
| 40 : DOMWindowLifecycleObserver(document->domWindow()) | 41 : DOMWindowLifecycleObserver(document->domWindow()) |
| 41 , DeviceSensorEventController(document) | 42 , DeviceSensorEventController(document) |
| 43 , PageLifecycleObserver(document->page()) |
| 44 , m_hasEventListener(false) |
| 42 { | 45 { |
| 43 } | 46 } |
| 44 | 47 |
| 45 DeviceMotionController::~DeviceMotionController() | 48 DeviceMotionController::~DeviceMotionController() |
| 46 { | 49 { |
| 47 } | 50 } |
| 48 | 51 |
| 49 void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotio
nData) | 52 void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotio
nData) |
| 50 { | 53 { |
| 51 dispatchDeviceEvent(DeviceMotionEvent::create(eventNames().devicemotionEvent
, deviceMotionData)); | 54 dispatchDeviceEvent(DeviceMotionEvent::create(eventNames().devicemotionEvent
, deviceMotionData)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 91 |
| 89 bool DeviceMotionController::isNullEvent(Event* event) | 92 bool DeviceMotionController::isNullEvent(Event* event) |
| 90 { | 93 { |
| 91 ASSERT(event->type() == eventNames().devicemotionEvent); | 94 ASSERT(event->type() == eventNames().devicemotionEvent); |
| 92 DeviceMotionEvent* motionEvent = static_cast<DeviceMotionEvent*>(event); | 95 DeviceMotionEvent* motionEvent = static_cast<DeviceMotionEvent*>(event); |
| 93 return !motionEvent->deviceMotionData()->canProvideEventData(); | 96 return !motionEvent->deviceMotionData()->canProvideEventData(); |
| 94 } | 97 } |
| 95 | 98 |
| 96 void DeviceMotionController::didAddEventListener(DOMWindow*, const AtomicString&
eventType) | 99 void DeviceMotionController::didAddEventListener(DOMWindow*, const AtomicString&
eventType) |
| 97 { | 100 { |
| 98 if (eventType == eventNames().devicemotionEvent && RuntimeEnabledFeatures::d
eviceMotionEnabled()) | 101 if (eventType == eventNames().devicemotionEvent && RuntimeEnabledFeatures::d
eviceMotionEnabled()) { |
| 99 startUpdating(); | 102 if (page() && page()->visibilityState() == PageVisibilityStateVisible) |
| 103 startUpdating(); |
| 104 m_hasEventListener = true; |
| 105 } |
| 100 } | 106 } |
| 101 | 107 |
| 102 void DeviceMotionController::didRemoveEventListener(DOMWindow*, const AtomicStri
ng& eventType) | 108 void DeviceMotionController::didRemoveEventListener(DOMWindow*, const AtomicStri
ng& eventType) |
| 103 { | 109 { |
| 104 if (eventType == eventNames().devicemotionEvent) | 110 if (eventType == eventNames().devicemotionEvent) { |
| 105 stopUpdating(); | 111 stopUpdating(); |
| 112 m_hasEventListener = false; |
| 113 } |
| 106 } | 114 } |
| 107 | 115 |
| 108 void DeviceMotionController::didRemoveAllEventListeners(DOMWindow*) | 116 void DeviceMotionController::didRemoveAllEventListeners(DOMWindow*) |
| 109 { | 117 { |
| 110 stopUpdating(); | 118 stopUpdating(); |
| 119 m_hasEventListener = false; |
| 120 } |
| 121 |
| 122 void DeviceMotionController::pageVisibilityChanged() |
| 123 { |
| 124 if (!m_hasEventListener) |
| 125 return; |
| 126 |
| 127 if (page()->visibilityState() == PageVisibilityStateVisible) |
| 128 startUpdating(); |
| 129 else |
| 130 stopUpdating(); |
| 111 } | 131 } |
| 112 | 132 |
| 113 } // namespace WebCore | 133 } // namespace WebCore |
| OLD | NEW |