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

Side by Side Diff: Source/modules/device_light/DeviceLightController.cpp

Issue 315023006: Revert of Generalize and refactor DeviceSensorEvent* architecture to support multi-event type targets. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/device_light/DeviceLightController.h" 6 #include "modules/device_light/DeviceLightController.h"
7 7
8 #include "RuntimeEnabledFeatures.h" 8 #include "RuntimeEnabledFeatures.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/frame/DOMWindow.h" 10 #include "core/frame/DOMWindow.h"
11 #include "core/page/Page.h" 11 #include "core/page/Page.h"
12 #include "modules/device_light/DeviceLightDispatcher.h" 12 #include "modules/device_light/DeviceLightDispatcher.h"
13 #include "modules/device_light/DeviceLightEvent.h" 13 #include "modules/device_light/DeviceLightEvent.h"
14 14
15 namespace WebCore { 15 namespace WebCore {
16 16
17 DeviceLightController::DeviceLightController(Document& document) 17 DeviceLightController::DeviceLightController(Document& document)
18 : DeviceSingleWindowEventController(document) 18 : DeviceSensorEventController(document.page())
19 , DOMWindowLifecycleObserver(document.domWindow())
20 , m_document(document)
19 { 21 {
20 } 22 }
21 23
22 DeviceLightController::~DeviceLightController() 24 DeviceLightController::~DeviceLightController()
23 { 25 {
24 stopUpdating(); 26 stopUpdating();
25 } 27 }
26 28
29 void DeviceLightController::didChangeDeviceLight(double value)
30 {
31 dispatchDeviceEvent(DeviceLightEvent::create(EventTypeNames::devicelight, va lue));
32 }
33
27 const char* DeviceLightController::supplementName() 34 const char* DeviceLightController::supplementName()
28 { 35 {
29 return "DeviceLightController"; 36 return "DeviceLightController";
30 } 37 }
31 38
32 DeviceLightController& DeviceLightController::from(Document& document) 39 DeviceLightController& DeviceLightController::from(Document& document)
33 { 40 {
34 DeviceLightController* controller = static_cast<DeviceLightController*>(Docu mentSupplement::from(document, supplementName())); 41 DeviceLightController* controller = static_cast<DeviceLightController*>(Docu mentSupplement::from(document, supplementName()));
35 if (!controller) { 42 if (!controller) {
36 controller = new DeviceLightController(document); 43 controller = new DeviceLightController(document);
37 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller)); 44 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBe Noop(controller));
38 } 45 }
39 return *controller; 46 return *controller;
40 } 47 }
41 48
42 bool DeviceLightController::hasLastData() 49 bool DeviceLightController::hasLastData()
43 { 50 {
44 return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0; 51 return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0;
45 } 52 }
46 53
47 void DeviceLightController::registerWithDispatcher() 54 PassRefPtrWillBeRawPtr<Event> DeviceLightController::getLastEvent()
48 {
49 DeviceLightDispatcher::instance().addController(this);
50 }
51
52 void DeviceLightController::unregisterWithDispatcher()
53 {
54 DeviceLightDispatcher::instance().removeController(this);
55 }
56
57 PassRefPtrWillBeRawPtr<Event> DeviceLightController::lastEvent() const
58 { 55 {
59 return DeviceLightEvent::create(EventTypeNames::devicelight, 56 return DeviceLightEvent::create(EventTypeNames::devicelight,
60 DeviceLightDispatcher::instance().latestDeviceLightData()); 57 DeviceLightDispatcher::instance().latestDeviceLightData());
61 } 58 }
62 59
63 bool DeviceLightController::isNullEvent(Event* event) const 60 void DeviceLightController::registerWithDispatcher()
61 {
62 DeviceLightDispatcher::instance().addDeviceLightController(this);
63 }
64
65 void DeviceLightController::unregisterWithDispatcher()
66 {
67 DeviceLightDispatcher::instance().removeDeviceLightController(this);
68 }
69
70 bool DeviceLightController::isNullEvent(Event* event)
64 { 71 {
65 DeviceLightEvent* lightEvent = toDeviceLightEvent(event); 72 DeviceLightEvent* lightEvent = toDeviceLightEvent(event);
66 return lightEvent->value() == std::numeric_limits<double>::infinity(); 73 return lightEvent->value() == std::numeric_limits<double>::infinity();
67 } 74 }
68 75
69 const AtomicString& DeviceLightController::eventTypeName() const 76 Document* DeviceLightController::document()
70 { 77 {
71 return EventTypeNames::devicelight; 78 return &m_document;
79 }
80
81 void DeviceLightController::didAddEventListener(DOMWindow* window, const AtomicS tring& eventType)
82 {
83 if (eventType == EventTypeNames::devicelight && RuntimeEnabledFeatures::devi ceLightEnabled()) {
84 if (page() && page()->visibilityState() == PageVisibilityStateVisible)
85 startUpdating();
86 m_hasEventListener = true;
87 }
88 }
89
90 void DeviceLightController::didRemoveEventListener(DOMWindow* window, const Atom icString& eventType)
91 {
92 if (eventType != EventTypeNames::devicelight || window->hasEventListeners(Ev entTypeNames::devicelight))
93 return;
94
95 stopUpdating();
96 m_hasEventListener = false;
97 }
98
99 void DeviceLightController::didRemoveAllEventListeners(DOMWindow* window)
100 {
101 stopUpdating();
102 m_hasEventListener = false;
72 } 103 }
73 104
74 } // namespace WebCore 105 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/device_light/DeviceLightController.h ('k') | Source/modules/device_light/DeviceLightDispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698