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.
6 #include "modules/device_orientation/DeviceMotionController.h"
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"
16 DeviceMotionController::DeviceMotionController(Document& document)
17 : DeviceSingleWindowEventController(document)
21 DeviceMotionController::~DeviceMotionController()
28 const char* DeviceMotionController::supplementName()
30 return "DeviceMotionController";
33 DeviceMotionController& DeviceMotionController::from(Document& document)
35 DeviceMotionController* controller = static_cast<DeviceMotionController*>(DocumentSupplement::from(document, supplementName()));
37 controller = new DeviceMotionController(document);
38 DocumentSupplement::provideTo(document, supplementName(), adoptPtrWillBeNoop(controller));
43 bool DeviceMotionController::hasLastData()
45 return DeviceMotionDispatcher::instance().latestDeviceMotionData();
48 void DeviceMotionController::registerWithDispatcher()
50 DeviceMotionDispatcher::instance().addController(this);
53 void DeviceMotionController::unregisterWithDispatcher()
55 DeviceMotionDispatcher::instance().removeController(this);
58 PassRefPtrWillBeRawPtr<Event> DeviceMotionController::lastEvent() const
60 return DeviceMotionEvent::create(EventTypeNames::devicemotion, DeviceMotionDispatcher::instance().latestDeviceMotionData());
63 bool DeviceMotionController::isNullEvent(Event* event) const
65 DeviceMotionEvent* motionEvent = toDeviceMotionEvent(event);
66 return !motionEvent->deviceMotionData()->canProvideEventData();
69 const AtomicString& DeviceMotionController::eventTypeName() const
71 return EventTypeNames::devicemotion;
74 void DeviceMotionController::trace(Visitor* visitor)
76 DeviceSingleWindowEventController::trace(visitor);
77 DocumentSupplement::trace(visitor);