Chromium Code Reviews| Index: Source/WebCore/dom/DeviceMotionController.cpp |
| diff --git a/Source/WebCore/dom/DeviceMotionController.cpp b/Source/WebCore/dom/DeviceMotionController.cpp |
| index 8cf04a691023ec470bcdde50d65135c657bec7fd..e91d71724d2016211bd761dda843197a9013a6af 100644 |
| --- a/Source/WebCore/dom/DeviceMotionController.cpp |
| +++ b/Source/WebCore/dom/DeviceMotionController.cpp |
| @@ -1,29 +1,25 @@ |
| /* |
| - * Copyright (C) 2013 Google Inc. All rights reserved. |
|
eseidel
2013/04/23 15:21:24
Do you mean to be deleting Google copyright?
timvolodine
2013/04/23 18:10:40
I've reverted this to the original copyright. This
|
| + * Copyright 2010 Apple Inc. All rights reserved. |
| + * Copyright (C) 2012 Samsung Electronics. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| - * modification, are permitted provided that the following conditions are |
| - * met: |
| + * modification, are permitted provided that the following conditions |
| + * are met: |
| + * * Redistributions of source code must retain the above copyright |
|
eseidel
2013/04/23 15:21:24
Why are you changing this license block? I would
timvolodine
2013/04/23 18:10:40
This is the original copyright. Rietveld seems to
|
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above copyright |
| + * notice, this list of conditions and the following disclaimer in the |
| + * documentation and/or other materials provided with the distribution. |
| * |
| - * * Redistributions of source code must retain the above copyright |
| - * notice, this list of conditions and the following disclaimer. |
| - * * Redistributions in binary form must reproduce the above |
| - * copyright notice, this list of conditions and the following disclaimer |
| - * in the documentation and/or other materials provided with the |
| - * distribution. |
| - * * Neither the name of Google Inc. nor the names of its |
| - * contributors may be used to endorse or promote products derived from |
| - * this software without specific prior written permission. |
| - * |
| - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
| + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| @@ -33,20 +29,20 @@ |
| #include "DeviceMotionData.h" |
| #include "DeviceMotionEvent.h" |
| +#include "Document.h" |
| #include "Page.h" |
| - |
| #include "PlatformDeviceMotion.h" |
| namespace WebCore { |
| -DeviceMotionController::DeviceMotionController() : DeviceController() |
| +PassRefPtr<DeviceMotionController> DeviceMotionController::create() |
| { |
| + return adoptRef(new DeviceMotionController()); |
| } |
| -DeviceMotionController& DeviceMotionController::shared() |
| -{ |
| - DEFINE_STATIC_LOCAL(DeviceMotionController, deviceMotionController, ()); |
| - return deviceMotionController; |
| +DeviceMotionController::~DeviceMotionController() { |
|
eseidel
2013/04/23 15:21:24
{ goes on a new line.
timvolodine
2013/04/23 18:10:40
Done.
|
| + // This is a no-op if the controller has not registered with the device motion pump. |
| + unregisterForDeviceMotionUpdates(this); |
| } |
| void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotionData) |
| @@ -56,20 +52,18 @@ void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotio |
| bool DeviceMotionController::hasLastData() |
| { |
| - return lastDeviceMotionData(); |
| + return latestDeviceMotionData(); |
| } |
| PassRefPtr<Event> DeviceMotionController::getLastEvent() |
| { |
| - return DeviceMotionEvent::create(eventNames().devicemotionEvent, lastDeviceMotionData()); |
| + return DeviceMotionEvent::create(eventNames().devicemotionEvent, latestDeviceMotionData()); |
| } |
| - |
| void DeviceMotionController::addDeviceEventListener(DOMWindow* window) |
| { |
| bool wasEmpty = m_listeners.isEmpty(); |
| m_listeners.add(window); |
| - m_activePages.add(window->page()); |
| if (hasLastData()) { |
| m_lastEventListeners.add(window); |
| @@ -84,7 +78,6 @@ void DeviceMotionController::addDeviceEventListener(DOMWindow* window) |
| void DeviceMotionController::removeDeviceEventListener(DOMWindow* window) |
| { |
| m_listeners.remove(window); |
| - m_activePages.remove(window->page()); |
| m_lastEventListeners.remove(window); |
| if (m_listeners.isEmpty()) |
| stopUpdating(); |
| @@ -93,20 +86,72 @@ void DeviceMotionController::removeDeviceEventListener(DOMWindow* window) |
| void DeviceMotionController::removeAllDeviceEventListeners(DOMWindow* window) |
| { |
| m_listeners.removeAll(window); |
| - m_activePages.removeAll(window->page()); |
| m_lastEventListeners.removeAll(window); |
| if (m_listeners.isEmpty()) |
| stopUpdating(); |
| } |
| +void DeviceMotionController::dispatchDeviceEvent(const PassRefPtr<Event> event) |
| +{ |
| + Vector<RefPtr<DOMWindow> > listenerVector; |
| + copyToVector(m_listeners, listenerVector); |
|
eseidel
2013/04/23 15:21:24
I presume this clears the list?
timvolodine
2013/04/23 18:10:40
what list? this is how it was done originally in D
|
| + dispatchEventToActiveDocuments(listenerVector, event); |
| +} |
| + |
| +void DeviceMotionController::fireDeviceEvent(Timer<DeviceMotionController>* timer) |
| +{ |
| + ASSERT_UNUSED(timer, timer == &m_timer); |
| + ASSERT(hasLastData()); |
| + |
| + m_timer.stop(); |
|
eseidel
2013/04/23 15:21:24
Is this a repeating timer? Normally fireOnce just
timvolodine
2013/04/23 18:10:40
hmm, not sure why, but this was in the original De
|
| + Vector<RefPtr<DOMWindow> > listenerVector; |
| + copyToVector(m_lastEventListeners, listenerVector); |
| + m_lastEventListeners.clear(); |
| + dispatchEventToActiveDocuments(listenerVector, getLastEvent()); |
| +} |
| + |
| +void DeviceMotionController::dispatchEventToActiveDocuments(Vector<RefPtr<DOMWindow> >& listeners, |
| + const PassRefPtr<Event> prpEvent) |
| +{ |
| + RefPtr<Event> event = prpEvent; |
| + for (size_t i = 0; i < listeners.size(); ++i) { |
| + if (listeners[i]->document() |
|
eseidel
2013/04/23 15:21:24
Is there no Document::isActive() helper for these
timvolodine
2013/04/23 18:10:40
No, looks like there is no such helper method.
|
| + && !listeners[i]->document()->activeDOMObjectsAreSuspended() |
| + && !listeners[i]->document()->activeDOMObjectsAreStopped()) |
|
eseidel
2013/04/23 15:21:24
I'm confused as to when active DOM objects are eve
timvolodine
2013/04/23 18:10:40
As I understand this it's either javascript debugg
|
| + listeners[i]->dispatchEvent(event); |
| + } |
| +} |
| + |
| +const char* DeviceMotionController::supplementName() |
| +{ |
| + return "DeviceMotionController"; |
| +} |
| + |
| +DeviceMotionController* DeviceMotionController::from(Page* page) |
| +{ |
| + return static_cast<DeviceMotionController*>(RefCountedSupplement<Page, DeviceMotionController>::from(page, supplementName())); |
| +} |
| + |
| +bool DeviceMotionController::isActiveAt(Page* page) |
| +{ |
| + if (DeviceMotionController* self = DeviceMotionController::from(page)) |
| + return self->isActive(); |
| + return false; |
| +} |
| + |
| void DeviceMotionController::startUpdating() |
| { |
| - startMonitoringDeviceMotion(); |
| + registerForDeviceMotionUpdates(this); |
| } |
| void DeviceMotionController::stopUpdating() |
| { |
| - stopMonitoringDeviceMotion(); |
| + unregisterForDeviceMotionUpdates(this); |
| +} |
| + |
| +void provideDeviceMotionTo(Page* page) |
| +{ |
| + DeviceMotionController::provideTo(page, DeviceMotionController::supplementName(), DeviceMotionController::create()); |
| } |
| } // namespace WebCore |