Upstream version 9.37.197.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 "core/frame/LocalDOMWindow.h"
10 #include "core/page/Page.h"
11 #include "modules/device_light/DeviceLightDispatcher.h"
12 #include "modules/device_light/DeviceLightEvent.h"
13 #include "platform/RuntimeEnabledFeatures.h"
14
15 namespace WebCore {
16
17 DeviceLightController::DeviceLightController(Document& document)
18     : DeviceSingleWindowEventController(document)
19 {
20 }
21
22 DeviceLightController::~DeviceLightController()
23 {
24     stopUpdating();
25 }
26
27 const char* DeviceLightController::supplementName()
28 {
29     return "DeviceLightController";
30 }
31
32 DeviceLightController& DeviceLightController::from(Document& document)
33 {
34     DeviceLightController* controller = static_cast<DeviceLightController*>(DocumentSupplement::from(document, supplementName()));
35     if (!controller) {
36         controller = new DeviceLightController(document);
37         DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBeNoop(controller));
38     }
39     return *controller;
40 }
41
42 bool DeviceLightController::hasLastData()
43 {
44     return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0;
45 }
46
47 void DeviceLightController::registerWithDispatcher()
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 {
59     return DeviceLightEvent::create(EventTypeNames::devicelight,
60         DeviceLightDispatcher::instance().latestDeviceLightData());
61 }
62
63 bool DeviceLightController::isNullEvent(Event* event) const
64 {
65     DeviceLightEvent* lightEvent = toDeviceLightEvent(event);
66     return lightEvent->value() == std::numeric_limits<double>::infinity();
67 }
68
69 const AtomicString& DeviceLightController::eventTypeName() const
70 {
71     return EventTypeNames::devicelight;
72 }
73
74 } // namespace WebCore