OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
Rick Byers
2015/10/21 18:54:46
This file seems like a fairly complete copy/paste
timvolodine
2015/10/22 15:06:28
right, ok I've refactored the code a bit to reuse
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "modules/device_orientation/DeviceOrientationAbsoluteController.h" | |
7 | |
8 #include "core/dom/Document.h" | |
9 #include "core/frame/Settings.h" | |
10 #include "modules/EventModules.h" | |
11 #include "modules/device_orientation/DeviceOrientationAbsoluteDispatcher.h" | |
12 #include "modules/device_orientation/DeviceOrientationData.h" | |
13 #include "modules/device_orientation/DeviceOrientationEvent.h" | |
14 #include "public/platform/Platform.h" | |
15 | |
16 namespace blink { | |
17 | |
18 DeviceOrientationAbsoluteController::DeviceOrientationAbsoluteController(Documen t& document) | |
19 : DeviceSingleWindowEventController(document) | |
20 { | |
21 } | |
22 | |
23 DeviceOrientationAbsoluteController::~DeviceOrientationAbsoluteController() | |
24 { | |
25 #if !ENABLE(OILPAN) | |
26 stopUpdating(); | |
27 #endif | |
28 } | |
29 | |
30 void DeviceOrientationAbsoluteController::didUpdateData() | |
31 { | |
32 if (m_overrideOrientationData) | |
33 return; | |
34 dispatchDeviceEvent(lastEvent()); | |
35 } | |
36 | |
37 const char* DeviceOrientationAbsoluteController::supplementName() | |
38 { | |
39 return "DeviceOrientationAbsoluteController"; | |
40 } | |
41 | |
42 DeviceOrientationAbsoluteController& DeviceOrientationAbsoluteController::from(D ocument& document) | |
43 { | |
44 DeviceOrientationAbsoluteController* controller = static_cast<DeviceOrientat ionAbsoluteController*>(WillBeHeapSupplement<Document>::from(document, supplemen tName())); | |
45 if (!controller) { | |
46 controller = new DeviceOrientationAbsoluteController(document); | |
47 WillBeHeapSupplement<Document>::provideTo(document, supplementName(), ad optPtrWillBeNoop(controller)); | |
48 } | |
49 return *controller; | |
50 } | |
51 | |
52 void DeviceOrientationAbsoluteController::didAddEventListener(LocalDOMWindow* wi ndow, const AtomicString& eventType) | |
53 { | |
54 if (eventType != eventTypeName()) | |
55 return; | |
56 | |
57 if (document().frame()) { | |
58 String errorMessage; | |
59 if (!document().isSecureContext(errorMessage) && document().frame()->set tings()->strictPowerfulFeatureRestrictions()) | |
60 return; | |
61 // FIXME: add user counters as in DeviceOrientationController. | |
62 } | |
63 | |
64 // FIXME: add rappor url logging as in DeviceOrientationController. | |
65 | |
66 DeviceSingleWindowEventController::didAddEventListener(window, eventType); | |
67 } | |
68 | |
69 DeviceOrientationData* DeviceOrientationAbsoluteController::lastData() const | |
70 { | |
71 return m_overrideOrientationData ? m_overrideOrientationData.get() : DeviceO rientationAbsoluteDispatcher::instance().latestDeviceOrientationData(); | |
72 } | |
73 | |
74 bool DeviceOrientationAbsoluteController::hasLastData() | |
75 { | |
76 return lastData(); | |
77 } | |
78 | |
79 void DeviceOrientationAbsoluteController::registerWithDispatcher() | |
80 { | |
81 DeviceOrientationAbsoluteDispatcher::instance().addController(this); | |
82 } | |
83 | |
84 void DeviceOrientationAbsoluteController::unregisterWithDispatcher() | |
85 { | |
86 DeviceOrientationAbsoluteDispatcher::instance().removeController(this); | |
87 } | |
88 | |
89 PassRefPtrWillBeRawPtr<Event> DeviceOrientationAbsoluteController::lastEvent() c onst | |
90 { | |
91 return DeviceOrientationEvent::create(eventTypeName(), lastData()); | |
92 } | |
93 | |
94 bool DeviceOrientationAbsoluteController::isNullEvent(Event* event) const | |
95 { | |
96 DeviceOrientationEvent* orientationEvent = toDeviceOrientationEvent(event); | |
97 return !orientationEvent->orientation()->canProvideEventData(); | |
98 } | |
99 | |
100 const AtomicString& DeviceOrientationAbsoluteController::eventTypeName() const | |
101 { | |
102 return EventTypeNames::deviceorientationabsolute; | |
103 } | |
104 | |
105 void DeviceOrientationAbsoluteController::setOverride(DeviceOrientationData* dev iceOrientationData) | |
106 { | |
107 ASSERT(deviceOrientationData); | |
108 m_overrideOrientationData = deviceOrientationData; | |
109 dispatchDeviceEvent(lastEvent()); | |
110 } | |
111 | |
112 void DeviceOrientationAbsoluteController::clearOverride() | |
113 { | |
114 if (!m_overrideOrientationData) | |
115 return; | |
116 m_overrideOrientationData.clear(); | |
117 if (lastData()) | |
118 didUpdateData(); | |
119 } | |
120 | |
121 DEFINE_TRACE(DeviceOrientationAbsoluteController) | |
122 { | |
123 visitor->trace(m_overrideOrientationData); | |
124 DeviceSingleWindowEventController::trace(visitor); | |
125 WillBeHeapSupplement<Document>::trace(visitor); | |
126 } | |
127 | |
128 } // namespace blink | |
OLD | NEW |