Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: Source/WebCore/dom/DeviceMotionController.cpp

Issue 13866007: WebKit & WebCore part of the device motion implementation using the platform layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@devicemotion-webcore
Patch Set: added new LICENSE header Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
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 */
Peter Beverloo 2013/04/09 17:29:53 We can't just change the copyright header if Apple
timvolodine 2013/04/10 19:06:12 Done.
26 30
27 #include "config.h" 31 #include "config.h"
28 #include "DeviceMotionController.h" 32 #include "DeviceMotionController.h"
29 33
30 #include "DeviceMotionClient.h"
31 #include "DeviceMotionData.h" 34 #include "DeviceMotionData.h"
32 #include "DeviceMotionEvent.h" 35 #include "DeviceMotionEvent.h"
33 #include "Page.h" 36 #include "Page.h"
34 37
38 #include "PlatformDeviceMotion.h"
39
35 namespace WebCore { 40 namespace WebCore {
36 41
37 DeviceMotionController::DeviceMotionController(DeviceMotionClient* client) 42 DeviceMotionController::DeviceMotionController() : DeviceController()
38 : DeviceController(client)
39 { 43 {
40 ASSERT(m_client);
41 deviceMotionClient()->setController(this);
42 } 44 }
43 45
44 PassOwnPtr<DeviceMotionController> DeviceMotionController::create(DeviceMotionCl ient* client) 46 DeviceMotionController& DeviceMotionController::shared()
Peter Beverloo 2013/04/09 17:29:53 While not that common in WebKit (yet), I'd prefer
timvolodine 2013/04/10 19:06:12 Done.
45 { 47 {
46 return adoptPtr(new DeviceMotionController(client)); 48 DEFINE_STATIC_LOCAL(DeviceMotionController, deviceMotionController, ());
49 return deviceMotionController;
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));
52 } 55 }
53 56
54 DeviceMotionClient* DeviceMotionController::deviceMotionClient()
55 {
56 return static_cast<DeviceMotionClient*>(m_client);
57 }
58
59 bool DeviceMotionController::hasLastData() 57 bool DeviceMotionController::hasLastData()
60 { 58 {
61 return deviceMotionClient()->lastMotion(); 59 return lastDeviceMotionData();
Peter Beverloo 2013/04/09 17:29:53 Where does lastDeviceMotionData come from?
timvolodine 2013/04/10 19:06:12 if I understand the question correctly: from the p
62 } 60 }
63 61
64 PassRefPtr<Event> DeviceMotionController::getLastEvent() 62 PassRefPtr<Event> DeviceMotionController::getLastEvent()
65 { 63 {
66 return DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotio nClient()->lastMotion()); 64 return DeviceMotionEvent::create(eventNames().devicemotionEvent, lastDeviceM otionData());
Peter Beverloo 2013/04/09 17:29:53 dito to line 59.
timvolodine 2013/04/10 19:06:12 Done.
67 } 65 }
68 66
69 const char* DeviceMotionController::supplementName() 67
68 void DeviceMotionController::addDeviceEventListener(DOMWindow* window)
70 { 69 {
71 return "DeviceMotionController"; 70 bool wasEmpty = m_listeners.isEmpty();
71 m_listeners.add(window);
72 m_activePages.add(window->page());
73
74 if (hasLastData()) {
75 m_lastEventListeners.add(window);
76 if (!m_timer.isActive())
77 m_timer.startOneShot(0);
78 }
79
80 if (wasEmpty)
81 startUpdating();
Peter Beverloo 2013/04/09 17:29:53 Unless we need to publicly expose startUpdating/st
timvolodine 2013/04/10 19:06:12 we don't need start/stop to be public, I've kept t
72 } 82 }
73 83
74 DeviceMotionController* DeviceMotionController::from(Page* page) 84 void DeviceMotionController::removeDeviceEventListener(DOMWindow* window)
75 { 85 {
76 return static_cast<DeviceMotionController*>(Supplement<Page>::from(page, sup plementName())); 86 m_listeners.remove(window);
87 m_activePages.remove(window->page());
88 m_lastEventListeners.remove(window);
89 if (m_listeners.isEmpty())
90 stopUpdating();
77 } 91 }
78 92
79 bool DeviceMotionController::isActiveAt(Page* page) 93 void DeviceMotionController::removeAllDeviceEventListeners(DOMWindow* window)
80 { 94 {
81 if (DeviceMotionController* self = DeviceMotionController::from(page)) 95 m_listeners.removeAll(window);
82 return self->isActive(); 96 m_activePages.removeAll(window->page());
83 return false; 97 m_lastEventListeners.removeAll(window);
98 if (m_listeners.isEmpty())
99 stopUpdating();
84 } 100 }
85 101
86 void provideDeviceMotionTo(Page* page, DeviceMotionClient* client) 102 void DeviceMotionController::startUpdating()
87 { 103 {
88 DeviceMotionController::provideTo(page, DeviceMotionController::supplementNa me(), DeviceMotionController::create(client)); 104 startMonitoringDeviceMotion();
105 }
106
107 void DeviceMotionController::stopUpdating()
108 {
109 stopMonitoringDeviceMotion();
89 } 110 }
90 111
91 } // namespace WebCore 112 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698