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

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: added unregister in destructor of DeviceMotionController 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 class DeviceMotionController : public RefCountedSupplement<Page, DeviceMotionCon troller> {
Peter Beverloo 2013/04/17 19:08:23 We don't inherit from DeviceController anymore. Is
timvolodine 2013/04/18 12:37:38 Done.
41
41 public: 42 public:
42 virtual ~DeviceMotionController() { }; 43 virtual ~DeviceMotionController();
43 44
44 static DeviceMotionController& shared(); 45 static PassRefPtr<DeviceMotionController> create();
45 46
46 void didChangeDeviceMotion(DeviceMotionData*); 47 void didChangeDeviceMotion(DeviceMotionData*);
47 48
48 virtual bool hasLastData() OVERRIDE; 49 virtual bool hasLastData() OVERRIDE;
49 virtual PassRefPtr<Event> getLastEvent() OVERRIDE; 50 virtual PassRefPtr<Event> getLastEvent() OVERRIDE;
50 bool isActiveAt(Page* page) { return m_activePages.contains(page); }
51 51
52 virtual void startUpdating(); 52 static const char* supplementName();
53 virtual void stopUpdating(); 53 static DeviceMotionController* from(Page*);
54 static bool isActiveAt(Page*);
54 55
55 // ------------------------------------------------- 56 // FIXME move these methods to DeviceController once the device orientation
57 // switches to the client-less design.
58 void dispatchDeviceEvent(PassRefPtr<Event>);
Peter Beverloo 2013/04/17 19:08:23 Can we add the "const" modifier to the argument?
timvolodine 2013/04/18 12:37:38 Done.
59 bool isActive() { return !m_listeners.isEmpty(); }
56 60
57 void addDeviceEventListener(DOMWindow*) OVERRIDE; 61 virtual void addDeviceEventListener(DOMWindow*) OVERRIDE;
58 void removeDeviceEventListener(DOMWindow*) OVERRIDE; 62 virtual void removeDeviceEventListener(DOMWindow*) OVERRIDE;
59 void removeAllDeviceEventListeners(DOMWindow*) OVERRIDE; 63 virtual void removeAllDeviceEventListeners(DOMWindow*) OVERRIDE;
60 64
61 // void dispatchDeviceEvent(PassRefPtr<Event>); 65 private:
62 // bool isActive() { return !m_listeners.isEmpty(); } 66 DeviceMotionController() : m_timer(this, &DeviceMotionController::fireDevice Event) { }
63 // DeviceClient* client() { return m_client; }
64 67
65 protected: 68 void startUpdating();
66 DeviceMotionController(); 69 void stopUpdating();
67 HashCountedSet<Page*> m_activePages; 70 void fireDeviceEvent(Timer<DeviceMotionController>*);
71
72 HashCountedSet<RefPtr<DOMWindow> > m_listeners;
73 HashCountedSet<RefPtr<DOMWindow> > m_lastEventListeners;
74 Timer<DeviceMotionController> m_timer;
68 }; 75 };
69 76
77 void provideDeviceMotionTo(Page*);
Peter Beverloo 2013/04/17 19:08:23 It's very unfortunate that we still need this. I s
timvolodine 2013/04/18 12:37:38 yes, agree this is not very clean. But this is how
78
70 } // namespace WebCore 79 } // namespace WebCore
71 80
72 #endif // DeviceMotionController_h 81 #endif // DeviceMotionController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698