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 11 matching lines...) Expand all Loading... | |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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/frame/DOMWindow.h" | |
32 #include "core/page/Page.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 : DeviceSensorEventController(document) | 41 : DeviceSensorEventController(document) |
41 , DOMWindowLifecycleObserver(document.domWindow()) | 42 , DOMWindowLifecycleObserver(document.domWindow()) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 { | 87 { |
87 DeviceMotionDispatcher::instance().removeDeviceMotionController(this); | 88 DeviceMotionDispatcher::instance().removeDeviceMotionController(this); |
88 } | 89 } |
89 | 90 |
90 bool DeviceMotionController::isNullEvent(Event* event) | 91 bool DeviceMotionController::isNullEvent(Event* event) |
91 { | 92 { |
92 DeviceMotionEvent* motionEvent = toDeviceMotionEvent(event); | 93 DeviceMotionEvent* motionEvent = toDeviceMotionEvent(event); |
93 return !motionEvent->deviceMotionData()->canProvideEventData(); | 94 return !motionEvent->deviceMotionData()->canProvideEventData(); |
94 } | 95 } |
95 | 96 |
96 void DeviceMotionController::didAddEventListener(DOMWindow*, const AtomicString& eventType) | 97 void DeviceMotionController::didAddEventListener(DOMWindow* window, const Atomic String& eventType) |
97 { | 98 { |
98 if (eventType == EventTypeNames::devicemotion && RuntimeEnabledFeatures::dev iceMotionEnabled()) { | 99 if (eventType == EventTypeNames::devicemotion |
100 && RuntimeEnabledFeatures::deviceMotionEnabled() | |
101 && window->hasEventListeners(EventTypeNames::devicemotion)) { | |
Inactive
2014/04/17 14:38:20
How can this new condition ever be false?
Inactive
2014/04/17 14:43:17
Unless I am mistaken, when didAddEventListener() i
timvolodine
2014/04/17 15:34:13
I think you are right. Also it cannot hurt to call
| |
102 | |
99 if (page() && page()->visibilityState() == PageVisibilityStateVisible) | 103 if (page() && page()->visibilityState() == PageVisibilityStateVisible) |
100 startUpdating(); | 104 startUpdating(); |
105 | |
101 m_hasEventListener = true; | 106 m_hasEventListener = true; |
102 } | 107 } |
103 } | 108 } |
104 | 109 |
105 void DeviceMotionController::didRemoveEventListener(DOMWindow*, const AtomicStri ng& eventType) | 110 void DeviceMotionController::didRemoveEventListener(DOMWindow* window, const Ato micString& eventType) |
106 { | 111 { |
107 if (eventType == EventTypeNames::devicemotion) { | 112 if (eventType == EventTypeNames::devicemotion |
113 && RuntimeEnabledFeatures::deviceMotionEnabled() | |
114 && !window->hasEventListeners(EventTypeNames::devicemotion)) { | |
Inactive
2014/04/17 14:38:20
Right, much better than my "counter" idea :)
Peter Beverloo
2014/04/17 14:48:17
nit: you could early return here.
timvolodine
2014/04/17 15:34:13
Done.
timvolodine
2014/04/17 15:34:13
;)
| |
115 | |
108 stopUpdating(); | 116 stopUpdating(); |
109 m_hasEventListener = false; | 117 m_hasEventListener = false; |
110 } | 118 } |
111 } | 119 } |
112 | 120 |
113 void DeviceMotionController::didRemoveAllEventListeners(DOMWindow*) | 121 void DeviceMotionController::didRemoveAllEventListeners(DOMWindow*) |
114 { | 122 { |
115 stopUpdating(); | 123 stopUpdating(); |
116 m_hasEventListener = false; | 124 m_hasEventListener = false; |
117 } | 125 } |
118 | 126 |
119 } // namespace WebCore | 127 } // namespace WebCore |
OLD | NEW |