Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / device_light / DeviceLightController.cpp
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "modules/device_light/DeviceLightController.h"
7
8 #include "core/dom/Document.h"
9 #include "modules/EventModules.h"
10 #include "modules/device_light/DeviceLightDispatcher.h"
11 #include "modules/device_light/DeviceLightEvent.h"
12 #include "platform/RuntimeEnabledFeatures.h"
13
14 namespace blink {
15
16 DeviceLightController::DeviceLightController(Document& document)
17     : DeviceSingleWindowEventController(document)
18 {
19 }
20
21 DeviceLightController::~DeviceLightController()
22 {
23     stopUpdating();
24 }
25
26 const char* DeviceLightController::supplementName()
27 {
28     return "DeviceLightController";
29 }
30
31 DeviceLightController& DeviceLightController::from(Document& document)
32 {
33     DeviceLightController* controller = static_cast<DeviceLightController*>(DocumentSupplement::from(document, supplementName()));
34     if (!controller) {
35         controller = new DeviceLightController(document);
36         DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBeNoop(controller));
37     }
38     return *controller;
39 }
40
41 bool DeviceLightController::hasLastData()
42 {
43     return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0;
44 }
45
46 void DeviceLightController::registerWithDispatcher()
47 {
48     DeviceLightDispatcher::instance().addController(this);
49 }
50
51 void DeviceLightController::unregisterWithDispatcher()
52 {
53     DeviceLightDispatcher::instance().removeController(this);
54 }
55
56 PassRefPtrWillBeRawPtr<Event> DeviceLightController::lastEvent() const
57 {
58     return DeviceLightEvent::create(EventTypeNames::devicelight,
59         DeviceLightDispatcher::instance().latestDeviceLightData());
60 }
61
62 bool DeviceLightController::isNullEvent(Event* event) const
63 {
64     DeviceLightEvent* lightEvent = toDeviceLightEvent(event);
65     return lightEvent->value() == std::numeric_limits<double>::infinity();
66 }
67
68 const AtomicString& DeviceLightController::eventTypeName() const
69 {
70     return EventTypeNames::devicelight;
71 }
72
73 void DeviceLightController::trace(Visitor* visitor)
74 {
75     DeviceSingleWindowEventController::trace(visitor);
76     DocumentSupplement::trace(visitor);
77 }
78
79
80 } // namespace blink