summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-10-05 14:28:30 +0100
committerSteve Block <steveblock@google.com>2010-10-08 15:55:31 +0100
commitd9b2f2e1e22ec3dfc73795d9e5476c7ab7ddb43d (patch)
treee16f2ec51c31d82b2bcab75c77ceb44fe92da70d
parentc386a1109bd0af0c8b792c7ebf3059bf1d8bb30d (diff)
downloadexternal_webkit-d9b2f2e1e22ec3dfc73795d9e5476c7ab7ddb43d.zip
external_webkit-d9b2f2e1e22ec3dfc73795d9e5476c7ab7ddb43d.tar.gz
external_webkit-d9b2f2e1e22ec3dfc73795d9e5476c7ab7ddb43d.tar.bz2
Implement DeviceMotionEvent
Requires a corresponding change in frameworks/base ... https://android-git.corp.google.com/g/72907 Bug: 2495651 Change-Id: I8ba07a0280b96379b3717a707184d719da6266bf
-rw-r--r--WebKit/Android.mk1
-rw-r--r--WebKit/android/WebCoreSupport/DeviceMotionClientAndroid.cpp3
-rw-r--r--WebKit/android/jni/DeviceMotionClientImpl.cpp129
-rw-r--r--WebKit/android/jni/DeviceMotionClientImpl.h71
-rw-r--r--WebKit/android/jni/DeviceOrientationManager.cpp23
-rw-r--r--WebKit/android/jni/WebViewCore.cpp11
-rw-r--r--WebKit/android/jni/WebViewCore.h1
7 files changed, 233 insertions, 6 deletions
diff --git a/WebKit/Android.mk b/WebKit/Android.mk
index 8b15740..b8fdd60 100644
--- a/WebKit/Android.mk
+++ b/WebKit/Android.mk
@@ -57,6 +57,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
\
android/icu/unicode/ucnv.cpp \
\
+ android/jni/DeviceMotionClientImpl.cpp \
android/jni/DeviceOrientationClientImpl.cpp \
android/jni/DeviceOrientationManager.cpp \
android/jni/GeolocationPermissionsBridge.cpp \
diff --git a/WebKit/android/WebCoreSupport/DeviceMotionClientAndroid.cpp b/WebKit/android/WebCoreSupport/DeviceMotionClientAndroid.cpp
index e12eacd..fae11c1 100644
--- a/WebKit/android/WebCoreSupport/DeviceMotionClientAndroid.cpp
+++ b/WebKit/android/WebCoreSupport/DeviceMotionClientAndroid.cpp
@@ -75,7 +75,8 @@ void DeviceMotionClientAndroid::deviceMotionControllerDestroyed()
DeviceMotionClient* DeviceMotionClientAndroid::client() const
{
if (!m_client) {
- // TODO: Get the client from the WebViewCore and set its controller.
+ m_client = m_webViewCore->deviceOrientationManager()->motionClient();
+ m_client->setController(m_controller);
}
return m_client;
}
diff --git a/WebKit/android/jni/DeviceMotionClientImpl.cpp b/WebKit/android/jni/DeviceMotionClientImpl.cpp
new file mode 100644
index 0000000..1517a19
--- /dev/null
+++ b/WebKit/android/jni/DeviceMotionClientImpl.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "DeviceMotionClientImpl.h"
+
+#include "WebViewCore.h"
+#include <DeviceMotionController.h>
+#include <Frame.h>
+#include <JNIHelp.h>
+
+namespace android {
+
+using JSC::Bindings::getJNIEnv;
+
+enum javaServiceClassMethods {
+ ServiceMethodStart = 0,
+ ServiceMethodStop,
+ ServiceMethodSuspend,
+ ServiceMethodResume,
+ ServiceMethodCount
+};
+static jmethodID javaServiceClassMethodIDs[ServiceMethodCount];
+
+DeviceMotionClientImpl::DeviceMotionClientImpl(WebViewCore* webViewCore)
+ : m_webViewCore(webViewCore)
+ , m_javaServiceObject(0)
+{
+ ASSERT(m_webViewCore);
+}
+
+DeviceMotionClientImpl::~DeviceMotionClientImpl()
+{
+ releaseJavaInstance();
+}
+
+jobject DeviceMotionClientImpl::getJavaInstance()
+{
+ // Lazily get the Java object. We can't do this until the WebViewCore is all
+ // set up.
+ if (m_javaServiceObject)
+ return m_javaServiceObject;
+
+ JNIEnv* env = getJNIEnv();
+
+ ASSERT(m_webViewCore);
+ jobject object = m_webViewCore->getDeviceMotionService();
+
+ // Get the Java DeviceMotionService class.
+ jclass javaServiceClass = env->GetObjectClass(object);
+ ASSERT(javaServiceClass);
+
+ // Set up the methods we wish to call on the Java DeviceMotionService
+ // class.
+ javaServiceClassMethodIDs[ServiceMethodStart] =
+ env->GetMethodID(javaServiceClass, "start", "()V");
+ javaServiceClassMethodIDs[ServiceMethodStop] =
+ env->GetMethodID(javaServiceClass, "stop", "()V");
+ javaServiceClassMethodIDs[ServiceMethodSuspend] =
+ env->GetMethodID(javaServiceClass, "suspend", "()V");
+ javaServiceClassMethodIDs[ServiceMethodResume] =
+ env->GetMethodID(javaServiceClass, "resume", "()V");
+
+ m_javaServiceObject = getJNIEnv()->NewGlobalRef(object);
+ getJNIEnv()->DeleteLocalRef(object);
+
+ ASSERT(m_javaServiceObject);
+ return m_javaServiceObject;
+}
+
+void DeviceMotionClientImpl::releaseJavaInstance()
+{
+ ASSERT(m_javaServiceObject);
+ getJNIEnv()->DeleteGlobalRef(m_javaServiceObject);
+}
+
+void DeviceMotionClientImpl::startUpdating()
+{
+ getJNIEnv()->CallVoidMethod(getJavaInstance(),
+ javaServiceClassMethodIDs[ServiceMethodStart]);
+}
+
+void DeviceMotionClientImpl::stopUpdating()
+{
+ getJNIEnv()->CallVoidMethod(getJavaInstance(),
+ javaServiceClassMethodIDs[ServiceMethodStop]);
+}
+
+void DeviceMotionClientImpl::onMotionChange(PassRefPtr<DeviceMotionData> motion)
+{
+ m_lastMotion = motion;
+ m_controller->didChangeDeviceMotion(m_lastMotion.get());
+}
+
+void DeviceMotionClientImpl::suspend()
+{
+ getJNIEnv()->CallVoidMethod(getJavaInstance(),
+ javaServiceClassMethodIDs[ServiceMethodSuspend]);
+}
+
+void DeviceMotionClientImpl::resume()
+{
+ getJNIEnv()->CallVoidMethod(getJavaInstance(),
+ javaServiceClassMethodIDs[ServiceMethodResume]);
+}
+
+} // namespace android
diff --git a/WebKit/android/jni/DeviceMotionClientImpl.h b/WebKit/android/jni/DeviceMotionClientImpl.h
new file mode 100644
index 0000000..364f1d3
--- /dev/null
+++ b/WebKit/android/jni/DeviceMotionClientImpl.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#ifndef DeviceMotionClientImpl_h
+#define DeviceMotionClientImpl_h
+
+#include <DeviceMotionClient.h>
+#include <DeviceMotionData.h>
+#include <JNIUtility.h>
+#include <PassRefPtr.h>
+#include <RefPtr.h>
+
+using namespace WebCore;
+
+namespace android {
+
+class DeviceOrientationManager;
+class WebViewCore;
+
+class DeviceMotionClientImpl : public DeviceMotionClient {
+public:
+ DeviceMotionClientImpl(WebViewCore*);
+
+ void onMotionChange(PassRefPtr<DeviceMotionData>);
+ void suspend();
+ void resume();
+
+ // DeviceMotionClient methods
+ virtual void startUpdating();
+ virtual void stopUpdating();
+ virtual DeviceMotionData* currentDeviceMotion() const { return m_lastMotion.get(); }
+ virtual void setController(DeviceMotionController* controller) { m_controller = controller; }
+ virtual void deviceMotionControllerDestroyed() { }
+
+protected:
+ virtual ~DeviceMotionClientImpl();
+
+ jobject getJavaInstance();
+ void releaseJavaInstance();
+
+ WebViewCore* m_webViewCore;
+ jobject m_javaServiceObject;
+ DeviceMotionController* m_controller;
+ RefPtr<DeviceMotionData> m_lastMotion;
+};
+
+} // namespace android
+
+#endif // DeviceMotionClientImpl_h
diff --git a/WebKit/android/jni/DeviceOrientationManager.cpp b/WebKit/android/jni/DeviceOrientationManager.cpp
index e4d964d..8daafa7 100644
--- a/WebKit/android/jni/DeviceOrientationManager.cpp
+++ b/WebKit/android/jni/DeviceOrientationManager.cpp
@@ -26,6 +26,7 @@
#include "config.h"
#include "DeviceOrientationManager.h"
+#include "DeviceMotionClientImpl.h"
#include "DeviceOrientationClientImpl.h"
#include "DeviceOrientationController.h"
#include "WebViewCore.h"
@@ -53,13 +54,13 @@ void DeviceOrientationManager::useMock()
void DeviceOrientationManager::setMockMotion(PassRefPtr<DeviceMotionData> motion)
{
if (m_useMock)
- ; // TODO: Pass the motion to the mock client.
+ ; // TODO: There is not yet a DeviceMotion mock.
}
void DeviceOrientationManager::onMotionChange(PassRefPtr<DeviceMotionData> motion)
{
ASSERT(!m_useMock);
- // TODO: Pass the motion to the client impl.
+ static_cast<DeviceMotionClientImpl*>(m_motionClient.get())->onMotionChange(motion);
}
void DeviceOrientationManager::setMockOrientation(PassRefPtr<DeviceOrientation> orientation)
@@ -78,7 +79,7 @@ void DeviceOrientationManager::maybeSuspendClients()
{
if (!m_useMock) {
if (m_motionClient)
- ; // TODO: Suspend the client impl.
+ static_cast<DeviceMotionClientImpl*>(m_motionClient.get())->suspend();
if (m_orientationClient)
static_cast<DeviceOrientationClientImpl*>(m_orientationClient.get())->suspend();
}
@@ -88,7 +89,7 @@ void DeviceOrientationManager::maybeResumeClients()
{
if (!m_useMock) {
if (m_motionClient)
- ; // TODO: Resume the client impl.
+ static_cast<DeviceMotionClientImpl*>(m_motionClient.get())->resume();
if (m_orientationClient)
static_cast<DeviceOrientationClientImpl*>(m_orientationClient.get())->resume();
}
@@ -96,8 +97,10 @@ void DeviceOrientationManager::maybeResumeClients()
DeviceMotionClient* DeviceOrientationManager::motionClient()
{
+ // TODO: There is not yet a DeviceMotion mock.
if (!m_motionClient)
- ; // TODO: Create the client.
+ m_motionClient.set(m_useMock ? 0
+ : static_cast<DeviceMotionClient*>(new DeviceMotionClientImpl(m_webViewCore)));
ASSERT(m_motionClient);
return m_motionClient.get();
}
@@ -126,6 +129,15 @@ static void useMock(JNIEnv* env, jobject, jobject webViewCoreObject)
getWebViewCore(env, webViewCoreObject)->deviceOrientationManager()->useMock();
}
+static void onMotionChange(JNIEnv* env, jobject, jobject webViewCoreObject, bool canProvideX, double x, bool canProvideY, double y, bool canProvideZ, double z, double interval)
+{
+ // We only provide accelerationIncludingGravity.
+ RefPtr<DeviceMotionData::Acceleration> accelerationIncludingGravity = DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y, canProvideZ, z);
+ bool canProvideInterval = canProvideX || canProvideY || canProvideZ;
+ RefPtr<DeviceMotionData> motion = DeviceMotionData::create(0, accelerationIncludingGravity.release(), 0, canProvideInterval, interval);
+ getWebViewCore(env, webViewCoreObject)->deviceOrientationManager()->onMotionChange(motion.release());
+}
+
static void setMockOrientation(JNIEnv* env, jobject, jobject webViewCoreObject, bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
{
RefPtr<DeviceOrientation> orientation = DeviceOrientation::create(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
@@ -140,6 +152,7 @@ static void onOrientationChange(JNIEnv* env, jobject, jobject webViewCoreObject,
static JNINativeMethod gDeviceOrientationManagerMethods[] = {
{ "nativeUseMock", "(Landroid/webkit/WebViewCore;)V", (void*) useMock },
+ { "nativeOnMotionChange", "(Landroid/webkit/WebViewCore;ZDZDZDD)V", (void*) onMotionChange },
{ "nativeSetMockOrientation", "(Landroid/webkit/WebViewCore;ZDZDZD)V", (void*) setMockOrientation },
{ "nativeOnOrientationChange", "(Landroid/webkit/WebViewCore;ZDZDZD)V", (void*) onOrientationChange }
};
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index 1ed2080..6845141 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -268,6 +268,7 @@ struct WebViewCore::JavaGlue {
jmethodID m_populateVisitedLinks;
jmethodID m_geolocationPermissionsShowPrompt;
jmethodID m_geolocationPermissionsHidePrompt;
+ jmethodID m_getDeviceMotionService;
jmethodID m_getDeviceOrientationService;
jmethodID m_addMessageToConsole;
jmethodID m_formDidBlur;
@@ -360,6 +361,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m
m_javaGlue->m_populateVisitedLinks = GetJMethod(env, clazz, "populateVisitedLinks", "()V");
m_javaGlue->m_geolocationPermissionsShowPrompt = GetJMethod(env, clazz, "geolocationPermissionsShowPrompt", "(Ljava/lang/String;)V");
m_javaGlue->m_geolocationPermissionsHidePrompt = GetJMethod(env, clazz, "geolocationPermissionsHidePrompt", "()V");
+ m_javaGlue->m_getDeviceMotionService = GetJMethod(env, clazz, "getDeviceMotionService", "()Landroid/webkit/DeviceMotionService;");
m_javaGlue->m_getDeviceOrientationService = GetJMethod(env, clazz, "getDeviceOrientationService", "()Landroid/webkit/DeviceOrientationService;");
m_javaGlue->m_addMessageToConsole = GetJMethod(env, clazz, "addMessageToConsole", "(Ljava/lang/String;ILjava/lang/String;I)V");
m_javaGlue->m_formDidBlur = GetJMethod(env, clazz, "formDidBlur", "(I)V");
@@ -3011,6 +3013,15 @@ void WebViewCore::geolocationPermissionsHidePrompt()
checkException(env);
}
+jobject WebViewCore::getDeviceMotionService()
+{
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ jobject object = env->CallObjectMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_getDeviceMotionService);
+ checkException(env);
+ return object;
+}
+
jobject WebViewCore::getDeviceOrientationService()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index 7f4f4fa..e5fd210 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -266,6 +266,7 @@ namespace android {
*/
void geolocationPermissionsHidePrompt();
+ jobject getDeviceMotionService();
jobject getDeviceOrientationService();
void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID, int msgLevel);