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..40f510f774f31e3b6b1e3165edc9fd3ff8061a0a 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. |
| + * 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 |
| + * 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() { |
| + // this is a noop if the controller is not registered for updates. |
|
Peter Beverloo
2013/04/17 19:08:23
nit: "This is a no-op if the controller has not re
timvolodine
2013/04/18 12:37:38
Done.
|
| + unRegisterForDeviceMotionUpdates(this); |
|
Peter Beverloo
2013/04/17 19:08:23
"Unregister" is one word, so no need to capitalize
timvolodine
2013/04/18 12:37:38
Done.
|
| } |
| 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,71 @@ 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(PassRefPtr<Event> prpEvent) |
|
Peter Beverloo
2013/04/17 19:08:23
Please don't use acronyms and spell out the "prpEv
timvolodine
2013/04/18 12:37:38
I believe this is a guideline from WebKit on how t
Peter Beverloo
2013/04/18 13:56:06
Since you store it in a normal RefPtr on line 96 i
timvolodine
2013/04/18 14:55:37
Done.
|
| +{ |
| + RefPtr<Event> event = prpEvent; |
| + Vector<RefPtr<DOMWindow> > listenerVector; |
| + copyToVector(m_listeners, listenerVector); |
| + for (size_t i = 0; i < listenerVector.size(); ++i) { |
| + if (listenerVector[i]->document() |
| + && !listenerVector[i]->document()->activeDOMObjectsAreSuspended() |
|
eseidel
2013/04/17 01:51:16
When are active dom objects stopped?
timvolodine
2013/04/17 17:47:25
What I can see from the code the three reasons to
|
| + && !listenerVector[i]->document()->activeDOMObjectsAreStopped()) |
| + listenerVector[i]->dispatchEvent(event); |
| + } |
| +} |
| + |
| +void DeviceMotionController::fireDeviceEvent(Timer<DeviceMotionController>* timer) |
| +{ |
| + ASSERT_UNUSED(timer, timer == &m_timer); |
| + ASSERT(hasLastData()); |
| + |
| + m_timer.stop(); |
| + Vector<RefPtr<DOMWindow> > listenerVector; |
| + copyToVector(m_lastEventListeners, listenerVector); |
| + m_lastEventListeners.clear(); |
| + for (size_t i = 0; i < listenerVector.size(); ++i) { |
| + if (listenerVector[i]->document() |
| + && !listenerVector[i]->document()->activeDOMObjectsAreSuspended() |
| + && !listenerVector[i]->document()->activeDOMObjectsAreStopped()) |
| + listenerVector[i]->dispatchEvent(getLastEvent()); |
|
Peter Beverloo
2013/04/17 19:08:23
Since we have two paths for dispatching events, do
timvolodine
2013/04/18 12:37:38
Done.
|
| + } |
| +} |
| + |
| +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 |