Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: Source/WebCore/dom/DeviceMotionController.cpp

Issue 13866007: WebKit & WebCore part of the device motion implementation using the platform layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@devicemotion-webcore
Patch Set: added new LICENSE header Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/WebCore/dom/DeviceMotionController.cpp
diff --git a/Source/WebCore/dom/DeviceMotionController.cpp b/Source/WebCore/dom/DeviceMotionController.cpp
index b5737015d68f46954aa663395268a3e2e647c4cc..8cf04a691023ec470bcdde50d65135c657bec7fd 100644
--- a/Source/WebCore/dom/DeviceMotionController.cpp
+++ b/Source/WebCore/dom/DeviceMotionController.cpp
@@ -1,25 +1,29 @@
/*
- * Copyright 2010 Apple Inc. All rights reserved.
- * Copyright (C) 2012 Samsung Electronics. All rights reserved.
+ * Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
- * 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.
+ * modification, are permitted provided that the following conditions are
+ * met:
*
- * 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
+ * * 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
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
Peter Beverloo 2013/04/09 17:29:53 We can't just change the copyright header if Apple
timvolodine 2013/04/10 19:06:12 Done.
@@ -27,23 +31,22 @@
#include "config.h"
#include "DeviceMotionController.h"
-#include "DeviceMotionClient.h"
#include "DeviceMotionData.h"
#include "DeviceMotionEvent.h"
#include "Page.h"
+#include "PlatformDeviceMotion.h"
+
namespace WebCore {
-DeviceMotionController::DeviceMotionController(DeviceMotionClient* client)
- : DeviceController(client)
+DeviceMotionController::DeviceMotionController() : DeviceController()
{
- ASSERT(m_client);
- deviceMotionClient()->setController(this);
}
-PassOwnPtr<DeviceMotionController> DeviceMotionController::create(DeviceMotionClient* client)
+DeviceMotionController& DeviceMotionController::shared()
Peter Beverloo 2013/04/09 17:29:53 While not that common in WebKit (yet), I'd prefer
timvolodine 2013/04/10 19:06:12 Done.
{
- return adoptPtr(new DeviceMotionController(client));
+ DEFINE_STATIC_LOCAL(DeviceMotionController, deviceMotionController, ());
+ return deviceMotionController;
}
void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotionData)
@@ -51,41 +54,59 @@ void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotio
dispatchDeviceEvent(DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionData));
}
-DeviceMotionClient* DeviceMotionController::deviceMotionClient()
+bool DeviceMotionController::hasLastData()
{
- return static_cast<DeviceMotionClient*>(m_client);
+ return lastDeviceMotionData();
Peter Beverloo 2013/04/09 17:29:53 Where does lastDeviceMotionData come from?
timvolodine 2013/04/10 19:06:12 if I understand the question correctly: from the p
}
-bool DeviceMotionController::hasLastData()
+PassRefPtr<Event> DeviceMotionController::getLastEvent()
{
- return deviceMotionClient()->lastMotion();
+ return DeviceMotionEvent::create(eventNames().devicemotionEvent, lastDeviceMotionData());
Peter Beverloo 2013/04/09 17:29:53 dito to line 59.
timvolodine 2013/04/10 19:06:12 Done.
}
-PassRefPtr<Event> DeviceMotionController::getLastEvent()
+
+void DeviceMotionController::addDeviceEventListener(DOMWindow* window)
{
- return DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionClient()->lastMotion());
+ bool wasEmpty = m_listeners.isEmpty();
+ m_listeners.add(window);
+ m_activePages.add(window->page());
+
+ if (hasLastData()) {
+ m_lastEventListeners.add(window);
+ if (!m_timer.isActive())
+ m_timer.startOneShot(0);
+ }
+
+ if (wasEmpty)
+ startUpdating();
Peter Beverloo 2013/04/09 17:29:53 Unless we need to publicly expose startUpdating/st
timvolodine 2013/04/10 19:06:12 we don't need start/stop to be public, I've kept t
}
-const char* DeviceMotionController::supplementName()
+void DeviceMotionController::removeDeviceEventListener(DOMWindow* window)
{
- return "DeviceMotionController";
+ m_listeners.remove(window);
+ m_activePages.remove(window->page());
+ m_lastEventListeners.remove(window);
+ if (m_listeners.isEmpty())
+ stopUpdating();
}
-DeviceMotionController* DeviceMotionController::from(Page* page)
+void DeviceMotionController::removeAllDeviceEventListeners(DOMWindow* window)
{
- return static_cast<DeviceMotionController*>(Supplement<Page>::from(page, supplementName()));
+ m_listeners.removeAll(window);
+ m_activePages.removeAll(window->page());
+ m_lastEventListeners.removeAll(window);
+ if (m_listeners.isEmpty())
+ stopUpdating();
}
-bool DeviceMotionController::isActiveAt(Page* page)
+void DeviceMotionController::startUpdating()
{
- if (DeviceMotionController* self = DeviceMotionController::from(page))
- return self->isActive();
- return false;
+ startMonitoringDeviceMotion();
}
-void provideDeviceMotionTo(Page* page, DeviceMotionClient* client)
+void DeviceMotionController::stopUpdating()
{
- DeviceMotionController::provideTo(page, DeviceMotionController::supplementName(), DeviceMotionController::create(client));
+ stopMonitoringDeviceMotion();
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698