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

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

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: fixed next round of comments by Peter 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 (C) 2013 Google Inc. All rights reserved. 2 * Copyright 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions
6 * met: 7 * are 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.
7 * 13 *
8 * * Redistributions of source code must retain the above copyright 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
9 * notice, this list of conditions and the following disclaimer. 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10 * * Redistributions in binary form must reproduce the above 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
11 * copyright notice, this list of conditions and the following disclaimer 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
12 * in the documentation and/or other materials provided with the 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
13 * distribution. 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
14 * * Neither the name of Google Inc. nor the names of its 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
15 * contributors may be used to endorse or promote products derived from 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
16 * this software without specific prior written permission. 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
27 * (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
28 * 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.
29 */ 25 */
30 26
31 #ifndef DeviceMotionController_h 27 #ifndef DeviceMotionController_h
32 #define DeviceMotionController_h 28 #define DeviceMotionController_h
33 29
34 #include "DeviceController.h" 30 #include "DOMWindow.h"
31 #include "Event.h"
32 #include "RefCountedSupplement.h"
33 #include "Timer.h"
34 #include <wtf/HashCountedSet.h>
35 35
36 namespace WebCore { 36 namespace WebCore {
37 37
38 class DeviceMotionData; 38 class DeviceMotionData;
39 39
40 class DeviceMotionController : public DeviceController { 40 // FIXME: This class doesn't inherit from DeviceController anymore, which is a t emporary
41 // solution. Once the device orientation switches to the client-less design, mov e some of the
42 // methods in this class to the DeviceController.
43 class DeviceMotionController : public RefCountedSupplement<Page, DeviceMotionCon troller> {
44
41 public: 45 public:
42 virtual ~DeviceMotionController() { }; 46 virtual ~DeviceMotionController();
43 47
44 static DeviceMotionController& shared(); 48 static PassRefPtr<DeviceMotionController> create();
45 49
46 void didChangeDeviceMotion(DeviceMotionData*); 50 void didChangeDeviceMotion(DeviceMotionData*);
47 51
48 virtual bool hasLastData() OVERRIDE; 52 virtual bool hasLastData();
49 virtual PassRefPtr<Event> getLastEvent() OVERRIDE; 53 virtual PassRefPtr<Event> getLastEvent();
50 bool isActiveAt(Page* page) { return m_activePages.contains(page); }
51 54
52 virtual void startUpdating(); 55 static const char* supplementName();
53 virtual void stopUpdating(); 56 static DeviceMotionController* from(Page*);
57 static bool isActiveAt(Page*);
54 58
55 // ------------------------------------------------- 59 // FIXME move these methods to DeviceController
60 void dispatchDeviceEvent(const PassRefPtr<Event>);
61 bool isActive() { return !m_listeners.isEmpty(); }
56 62
57 void addDeviceEventListener(DOMWindow*) OVERRIDE; 63 virtual void addDeviceEventListener(DOMWindow*);
58 void removeDeviceEventListener(DOMWindow*) OVERRIDE; 64 virtual void removeDeviceEventListener(DOMWindow*);
59 void removeAllDeviceEventListeners(DOMWindow*) OVERRIDE; 65 virtual void removeAllDeviceEventListeners(DOMWindow*);
60 66
61 // void dispatchDeviceEvent(PassRefPtr<Event>); 67 private:
62 // bool isActive() { return !m_listeners.isEmpty(); } 68 DeviceMotionController() : m_timer(this, &DeviceMotionController::fireDevice Event) { }
63 // DeviceClient* client() { return m_client; }
64 69
65 protected: 70 void startUpdating();
66 DeviceMotionController(); 71 void stopUpdating();
67 HashCountedSet<Page*> m_activePages; 72 void fireDeviceEvent(Timer<DeviceMotionController>*);
73 void dispatchEventToActiveDocuments(Vector<RefPtr<DOMWindow> >&, const PassR efPtr<Event>);
74
75 HashCountedSet<RefPtr<DOMWindow> > m_listeners;
eseidel 2013/04/23 15:21:24 Confused why this would want to keep a ref-counted
timvolodine 2013/04/23 18:10:40 This is how it is done in the original DeviceContr
76 HashCountedSet<RefPtr<DOMWindow> > m_lastEventListeners;
77 Timer<DeviceMotionController> m_timer;
68 }; 78 };
69 79
80 void provideDeviceMotionTo(Page*);
81
70 } // namespace WebCore 82 } // namespace WebCore
71 83
72 #endif // DeviceMotionController_h 84 #endif // DeviceMotionController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698