OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
tkent
2014/06/05 16:06:18
Ditto.
timvolodine
2014/06/05 17:29:04
Done.
| |
3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. | |
4 * | 3 * |
5 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions are |
7 * are met: | 6 * met: |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | 7 * |
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | 8 * * Redistributions of source code must retain the above copyright |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 9 * notice, this list of conditions and the following disclaimer. |
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 10 * * Redistributions in binary form must reproduce the above |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | 11 * copyright notice, this list of conditions and the following disclaimer |
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 12 * in the documentation and/or other materials provided with the |
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 13 * distribution. |
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 14 * * Neither the name of Google Inc. nor the names of its |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 15 * contributors may be used to endorse or promote products derived from |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 16 * this software without specific prior written permission. |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 * (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 |
24 * 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. |
25 */ | 29 */ |
26 | 30 |
27 #include "config.h" | 31 #include "config.h" |
28 #include "modules/device_orientation/DeviceOrientationController.h" | 32 #include "modules/device_orientation/DeviceOrientationController.h" |
29 | 33 |
30 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
31 #include "core/frame/DOMWindow.h" | 35 #include "modules/EventModules.h" |
32 #include "core/page/Page.h" | |
33 #include "modules/device_orientation/DeviceOrientationData.h" | 36 #include "modules/device_orientation/DeviceOrientationData.h" |
34 #include "modules/device_orientation/DeviceOrientationDispatcher.h" | 37 #include "modules/device_orientation/DeviceOrientationDispatcher.h" |
35 #include "modules/device_orientation/DeviceOrientationEvent.h" | 38 #include "modules/device_orientation/DeviceOrientationEvent.h" |
36 | 39 |
37 namespace WebCore { | 40 namespace WebCore { |
38 | 41 |
39 DeviceOrientationController::DeviceOrientationController(Document& document) | 42 DeviceOrientationController::DeviceOrientationController(Document& document) |
40 : DeviceSensorEventController(document.page()) | 43 : DeviceSingleWindowEventController(document) |
41 , DOMWindowLifecycleObserver(document.domWindow()) | |
42 , m_document(document) | |
43 { | 44 { |
44 } | 45 } |
45 | 46 |
46 DeviceOrientationController::~DeviceOrientationController() | 47 DeviceOrientationController::~DeviceOrientationController() |
47 { | 48 { |
48 stopUpdating(); | 49 stopUpdating(); |
49 } | 50 } |
50 | 51 |
51 void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationDa ta* deviceOrientationData) | 52 void DeviceOrientationController::didUpdateData() |
52 { | 53 { |
53 if (m_overrideOrientationData) | 54 if (m_overrideOrientationData) |
54 return; | 55 return; |
55 dispatchDeviceEvent(DeviceOrientationEvent::create(EventTypeNames::deviceori entation, deviceOrientationData)); | 56 dispatchDeviceEvent(lastEvent()); |
56 } | 57 } |
57 | 58 |
58 const char* DeviceOrientationController::supplementName() | 59 const char* DeviceOrientationController::supplementName() |
59 { | 60 { |
60 return "DeviceOrientationController"; | 61 return "DeviceOrientationController"; |
61 } | 62 } |
62 | 63 |
63 DeviceOrientationController& DeviceOrientationController::from(Document& documen t) | 64 DeviceOrientationController& DeviceOrientationController::from(Document& documen t) |
64 { | 65 { |
65 DeviceOrientationController* controller = static_cast<DeviceOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); | 66 DeviceOrientationController* controller = static_cast<DeviceOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); |
66 if (!controller) { | 67 if (!controller) { |
67 controller = new DeviceOrientationController(document); | 68 controller = new DeviceOrientationController(document); |
68 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller)); | 69 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller)); |
69 } | 70 } |
70 return *controller; | 71 return *controller; |
71 } | 72 } |
72 | 73 |
73 DeviceOrientationData* DeviceOrientationController::lastData() | 74 DeviceOrientationData* DeviceOrientationController::lastData() const |
74 { | 75 { |
75 return m_overrideOrientationData ? m_overrideOrientationData.get() : DeviceO rientationDispatcher::instance().latestDeviceOrientationData(); | 76 return m_overrideOrientationData ? m_overrideOrientationData.get() : DeviceO rientationDispatcher::instance().latestDeviceOrientationData(); |
76 } | 77 } |
77 | 78 |
78 bool DeviceOrientationController::hasLastData() | 79 bool DeviceOrientationController::hasLastData() |
79 { | 80 { |
80 return lastData(); | 81 return lastData(); |
81 } | 82 } |
82 | 83 |
83 PassRefPtrWillBeRawPtr<Event> DeviceOrientationController::getLastEvent() | |
84 { | |
85 return DeviceOrientationEvent::create(EventTypeNames::deviceorientation, las tData()); | |
86 } | |
87 | |
88 void DeviceOrientationController::registerWithDispatcher() | 84 void DeviceOrientationController::registerWithDispatcher() |
89 { | 85 { |
90 DeviceOrientationDispatcher::instance().addDeviceOrientationController(this) ; | 86 DeviceOrientationDispatcher::instance().addController(this); |
91 } | 87 } |
92 | 88 |
93 void DeviceOrientationController::unregisterWithDispatcher() | 89 void DeviceOrientationController::unregisterWithDispatcher() |
94 { | 90 { |
95 DeviceOrientationDispatcher::instance().removeDeviceOrientationController(th is); | 91 DeviceOrientationDispatcher::instance().removeController(this); |
96 } | 92 } |
97 | 93 |
98 bool DeviceOrientationController::isNullEvent(Event* event) | 94 PassRefPtrWillBeRawPtr<Event> DeviceOrientationController::lastEvent() const |
95 { | |
96 return DeviceOrientationEvent::create(eventTypeName(), lastData()); | |
97 } | |
98 | |
99 bool DeviceOrientationController::isNullEvent(Event* event) const | |
99 { | 100 { |
100 DeviceOrientationEvent* orientationEvent = toDeviceOrientationEvent(event); | 101 DeviceOrientationEvent* orientationEvent = toDeviceOrientationEvent(event); |
101 return !orientationEvent->orientation()->canProvideEventData(); | 102 return !orientationEvent->orientation()->canProvideEventData(); |
102 } | 103 } |
103 | 104 |
104 Document* DeviceOrientationController::document() | 105 const AtomicString& DeviceOrientationController::eventTypeName() const |
105 { | 106 { |
106 return &m_document; | 107 return EventTypeNames::deviceorientation; |
107 } | |
108 | |
109 void DeviceOrientationController::didAddEventListener(DOMWindow* window, const A tomicString& eventType) | |
110 { | |
111 if (eventType != EventTypeNames::deviceorientation) | |
112 return; | |
113 | |
114 if (page() && page()->visibilityState() == PageVisibilityStateVisible) | |
115 startUpdating(); | |
116 | |
117 m_hasEventListener = true; | |
118 } | |
119 | |
120 void DeviceOrientationController::didRemoveEventListener(DOMWindow* window, cons t AtomicString& eventType) | |
121 { | |
122 if (eventType != EventTypeNames::deviceorientation || window->hasEventListen ers(EventTypeNames::deviceorientation)) | |
123 return; | |
124 | |
125 stopUpdating(); | |
126 m_hasEventListener = false; | |
127 } | |
128 | |
129 void DeviceOrientationController::didRemoveAllEventListeners(DOMWindow* window) | |
130 { | |
131 stopUpdating(); | |
132 m_hasEventListener = false; | |
133 } | 108 } |
134 | 109 |
135 void DeviceOrientationController::setOverride(DeviceOrientationData* deviceOrien tationData) | 110 void DeviceOrientationController::setOverride(DeviceOrientationData* deviceOrien tationData) |
136 { | 111 { |
137 m_overrideOrientationData.clear(); | 112 ASSERT(deviceOrientationData); |
138 didChangeDeviceOrientation(deviceOrientationData); | |
139 m_overrideOrientationData = deviceOrientationData; | 113 m_overrideOrientationData = deviceOrientationData; |
114 dispatchDeviceEvent(lastEvent()); | |
140 } | 115 } |
141 | 116 |
142 void DeviceOrientationController::clearOverride() | 117 void DeviceOrientationController::clearOverride() |
143 { | 118 { |
144 if (!m_overrideOrientationData) | 119 if (!m_overrideOrientationData) |
145 return; | 120 return; |
146 m_overrideOrientationData.clear(); | 121 m_overrideOrientationData.clear(); |
147 DeviceOrientationData* orientation = lastData(); | 122 if (lastData()) |
148 if (orientation) | 123 didUpdateData(); |
149 didChangeDeviceOrientation(orientation); | |
150 } | 124 } |
151 | 125 |
152 void DeviceOrientationController::trace(Visitor* visitor) | 126 void DeviceOrientationController::trace(Visitor* visitor) |
153 { | 127 { |
154 visitor->trace(m_overrideOrientationData); | 128 visitor->trace(m_overrideOrientationData); |
155 DocumentSupplement::trace(visitor); | 129 DocumentSupplement::trace(visitor); |
156 } | 130 } |
157 | 131 |
158 } // namespace WebCore | 132 } // namespace WebCore |
OLD | NEW |