Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / device_orientation / DeviceMotionController.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_orientation/DeviceMotionController.h"
7
8 #include "core/dom/Document.h"
9 #include "modules/EventModules.h"
10 #include "modules/device_orientation/DeviceMotionData.h"
11 #include "modules/device_orientation/DeviceMotionDispatcher.h"
12 #include "modules/device_orientation/DeviceMotionEvent.h"
13
14 namespace blink {
15
16 DeviceMotionController::DeviceMotionController(Document& document)
17     : DeviceSingleWindowEventController(document)
18 {
19 }
20
21 DeviceMotionController::~DeviceMotionController()
22 {
23 #if !ENABLE(OILPAN)
24     stopUpdating();
25 #endif
26 }
27
28 const char* DeviceMotionController::supplementName()
29 {
30     return "DeviceMotionController";
31 }
32
33 DeviceMotionController& DeviceMotionController::from(Document& document)
34 {
35     DeviceMotionController* controller = static_cast<DeviceMotionController*>(DocumentSupplement::from(document, supplementName()));
36     if (!controller) {
37         controller = new DeviceMotionController(document);
38         DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBeNoop(controller));
39     }
40     return *controller;
41 }
42
43 bool DeviceMotionController::hasLastData()
44 {
45     return DeviceMotionDispatcher::instance().latestDeviceMotionData();
46 }
47
48 void DeviceMotionController::registerWithDispatcher()
49 {
50     DeviceMotionDispatcher::instance().addController(this);
51 }
52
53 void DeviceMotionController::unregisterWithDispatcher()
54 {
55     DeviceMotionDispatcher::instance().removeController(this);
56 }
57
58 PassRefPtrWillBeRawPtr<Event> DeviceMotionController::lastEvent() const
59 {
60     return DeviceMotionEvent::create(EventTypeNames::devicemotion, DeviceMotionDispatcher::instance().latestDeviceMotionData());
61 }
62
63 bool DeviceMotionController::isNullEvent(Event* event) const
64 {
65     DeviceMotionEvent* motionEvent = toDeviceMotionEvent(event);
66     return !motionEvent->deviceMotionData()->canProvideEventData();
67 }
68
69 const AtomicString& DeviceMotionController::eventTypeName() const
70 {
71     return EventTypeNames::devicemotion;
72 }
73
74 void DeviceMotionController::trace(Visitor* visitor)
75 {
76     DeviceSingleWindowEventController::trace(visitor);
77     DocumentSupplement::trace(visitor);
78 }
79
80 } // namespace blink