Update To 11.40.268.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 #if !ENABLE(OILPAN)
24     stopUpdating();
25 #endif
26 }
27
28 const char* DeviceLightController::supplementName()
29 {
30     return "DeviceLightController";
31 }
32
33 DeviceLightController& DeviceLightController::from(Document& document)
34 {
35     DeviceLightController* controller = static_cast<DeviceLightController*>(DocumentSupplement::from(document, supplementName()));
36     if (!controller) {
37         controller = new DeviceLightController(document);
38         DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBeNoop(controller));
39     }
40     return *controller;
41 }
42
43 bool DeviceLightController::hasLastData()
44 {
45     return DeviceLightDispatcher::instance().latestDeviceLightData() >= 0;
46 }
47
48 void DeviceLightController::registerWithDispatcher()
49 {
50     DeviceLightDispatcher::instance().addController(this);
51 }
52
53 void DeviceLightController::unregisterWithDispatcher()
54 {
55     DeviceLightDispatcher::instance().removeController(this);
56 }
57
58 PassRefPtrWillBeRawPtr<Event> DeviceLightController::lastEvent() const
59 {
60     return DeviceLightEvent::create(EventTypeNames::devicelight,
61         DeviceLightDispatcher::instance().latestDeviceLightData());
62 }
63
64 bool DeviceLightController::isNullEvent(Event* event) const
65 {
66     DeviceLightEvent* lightEvent = toDeviceLightEvent(event);
67     return lightEvent->value() == std::numeric_limits<double>::infinity();
68 }
69
70 const AtomicString& DeviceLightController::eventTypeName() const
71 {
72     return EventTypeNames::devicelight;
73 }
74
75 void DeviceLightController::trace(Visitor* visitor)
76 {
77     DeviceSingleWindowEventController::trace(visitor);
78     DocumentSupplement::trace(visitor);
79 }
80
81
82 } // namespace blink