summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-10-05 13:09:08 +0100
committerSteve Block <steveblock@google.com>2010-10-07 11:17:32 +0100
commit43cbb6a517664df15ba6cfa5ed9c612ffe92f646 (patch)
treefee7cc31d4cf3368ab7c28c6a9595497d256426e
parentdb58df4991c8c4dc1da936fb1ae866cf394d3646 (diff)
downloadexternal_webkit-43cbb6a517664df15ba6cfa5ed9c612ffe92f646.zip
external_webkit-43cbb6a517664df15ba6cfa5ed9c612ffe92f646.tar.gz
external_webkit-43cbb6a517664df15ba6cfa5ed9c612ffe92f646.tar.bz2
Prepare DeviceOrientationManager for implementation of DeviceMotion
To avoid additional boilerplate, this class will will be used for both DeviceOrientation and DeviceMotion. This change does not involve any change in behaviour, only renaming and adding stubs. Change-Id: I0d6c9e1c2fc8d919ccbd048b068d898110707f0e
-rw-r--r--WebKit/android/WebCoreSupport/DeviceOrientationClientAndroid.cpp2
-rw-r--r--WebKit/android/jni/DeviceOrientationManager.cpp59
-rw-r--r--WebKit/android/jni/DeviceOrientationManager.h26
-rw-r--r--WebKit/android/jni/WebViewCore.cpp4
4 files changed, 60 insertions, 31 deletions
diff --git a/WebKit/android/WebCoreSupport/DeviceOrientationClientAndroid.cpp b/WebKit/android/WebCoreSupport/DeviceOrientationClientAndroid.cpp
index 36fc445..3f5f32b 100644
--- a/WebKit/android/WebCoreSupport/DeviceOrientationClientAndroid.cpp
+++ b/WebKit/android/WebCoreSupport/DeviceOrientationClientAndroid.cpp
@@ -75,7 +75,7 @@ void DeviceOrientationClientAndroid::deviceOrientationControllerDestroyed()
DeviceOrientationClient* DeviceOrientationClientAndroid::client() const
{
if (!m_client) {
- m_client = m_webViewCore->deviceOrientationManager()->client();
+ m_client = m_webViewCore->deviceOrientationManager()->orientationClient();
m_client->setController(m_controller);
}
return m_client;
diff --git a/WebKit/android/jni/DeviceOrientationManager.cpp b/WebKit/android/jni/DeviceOrientationManager.cpp
index 621e646..e4d964d 100644
--- a/WebKit/android/jni/DeviceOrientationManager.cpp
+++ b/WebKit/android/jni/DeviceOrientationManager.cpp
@@ -50,38 +50,65 @@ void DeviceOrientationManager::useMock()
m_useMock = true;
}
+void DeviceOrientationManager::setMockMotion(PassRefPtr<DeviceMotionData> motion)
+{
+ if (m_useMock)
+ ; // TODO: Pass the motion to the mock client.
+}
+
+void DeviceOrientationManager::onMotionChange(PassRefPtr<DeviceMotionData> motion)
+{
+ ASSERT(!m_useMock);
+ // TODO: Pass the motion to the client impl.
+}
+
void DeviceOrientationManager::setMockOrientation(PassRefPtr<DeviceOrientation> orientation)
{
- if (!m_useMock)
- return;
- static_cast<DeviceOrientationClientMock*>(client())->setOrientation(orientation);
-};
+ if (m_useMock)
+ static_cast<DeviceOrientationClientMock*>(orientationClient())->setOrientation(orientation);
+}
void DeviceOrientationManager::onOrientationChange(PassRefPtr<DeviceOrientation> orientation)
{
ASSERT(!m_useMock);
- static_cast<DeviceOrientationClientImpl*>(m_client.get())->onOrientationChange(orientation);
+ static_cast<DeviceOrientationClientImpl*>(m_orientationClient.get())->onOrientationChange(orientation);
+}
+
+void DeviceOrientationManager::maybeSuspendClients()
+{
+ if (!m_useMock) {
+ if (m_motionClient)
+ ; // TODO: Suspend the client impl.
+ if (m_orientationClient)
+ static_cast<DeviceOrientationClientImpl*>(m_orientationClient.get())->suspend();
+ }
}
-void DeviceOrientationManager::maybeSuspendClient()
+void DeviceOrientationManager::maybeResumeClients()
{
- if (!m_useMock && m_client)
- static_cast<DeviceOrientationClientImpl*>(m_client.get())->suspend();
+ if (!m_useMock) {
+ if (m_motionClient)
+ ; // TODO: Resume the client impl.
+ if (m_orientationClient)
+ static_cast<DeviceOrientationClientImpl*>(m_orientationClient.get())->resume();
+ }
}
-void DeviceOrientationManager::maybeResumeClient()
+DeviceMotionClient* DeviceOrientationManager::motionClient()
{
- if (!m_useMock && m_client)
- static_cast<DeviceOrientationClientImpl*>(m_client.get())->resume();
+ if (!m_motionClient)
+ ; // TODO: Create the client.
+ ASSERT(m_motionClient);
+ return m_motionClient.get();
}
-DeviceOrientationClient* DeviceOrientationManager::client()
+DeviceOrientationClient* DeviceOrientationManager::orientationClient()
{
- if (!m_client)
- m_client.set(m_useMock ? new DeviceOrientationClientMock
+ if (!m_orientationClient)
+ m_orientationClient.set(m_useMock ? new DeviceOrientationClientMock
: static_cast<DeviceOrientationClient*>(new DeviceOrientationClientImpl(m_webViewCore)));
- ASSERT(m_client);
- return m_client.get();
+ ASSERT(m_orientationClient);
+ return m_orientationClient.get();
}
// JNI for android.webkit.DeviceOrientationManager
diff --git a/WebKit/android/jni/DeviceOrientationManager.h b/WebKit/android/jni/DeviceOrientationManager.h
index a0da32f..8c22b0f 100644
--- a/WebKit/android/jni/DeviceOrientationManager.h
+++ b/WebKit/android/jni/DeviceOrientationManager.h
@@ -26,39 +26,41 @@
#ifndef DeviceOrientationManager_h
#define DeviceOrientationManager_h
+#include <DeviceMotionData.h>
+#include <DeviceMotionClient.h>
#include <DeviceOrientation.h>
#include <DeviceOrientationClient.h>
#include <OwnPtr.h>
#include <PassRefPtr.h>
#include <RefPtr.h>
-namespace WebCore {
-class DeviceOrientation;
-}
-
namespace android {
class WebViewCore;
-// This class takes care of the fact that the client used for DeviceOrientation
-// may be either the real implementation or a mock. It also handles setting the
-// orientation on both the real and mock clients. This class is owned by
-// WebViewCore and exists to keep cruft out of that class.
+// This class takes care of the fact that the clients used for DeviceMotion and
+// DeviceOrientation may be either the real implementations or mocks. It also
+// handles setting the data on both the real and mock clients. This class is
+// owned by WebViewCore and exists to keep cruft out of that class.
class DeviceOrientationManager {
public:
DeviceOrientationManager(WebViewCore*);
void useMock();
+ void setMockMotion(PassRefPtr<WebCore::DeviceMotionData>);
+ void onMotionChange(PassRefPtr<WebCore::DeviceMotionData>);
void setMockOrientation(PassRefPtr<WebCore::DeviceOrientation>);
void onOrientationChange(PassRefPtr<WebCore::DeviceOrientation>);
- void maybeSuspendClient();
- void maybeResumeClient();
- WebCore::DeviceOrientationClient* client();
+ void maybeSuspendClients();
+ void maybeResumeClients();
+ WebCore::DeviceMotionClient* motionClient();
+ WebCore::DeviceOrientationClient* orientationClient();
private:
bool m_useMock;
WebViewCore* m_webViewCore;
- OwnPtr<WebCore::DeviceOrientationClient> m_client;
+ OwnPtr<WebCore::DeviceMotionClient> m_motionClient;
+ OwnPtr<WebCore::DeviceOrientationClient> m_orientationClient;
};
} // namespace android
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index 70d1b71..1ed2080 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -3819,7 +3819,7 @@ static void Pause(JNIEnv* env, jobject obj)
geolocation->suspend();
}
- GET_NATIVE_VIEW(env, obj)->deviceOrientationManager()->maybeSuspendClient();
+ GET_NATIVE_VIEW(env, obj)->deviceOrientationManager()->maybeSuspendClients();
ANPEvent event;
SkANP::InitEvent(&event, kLifecycle_ANPEventType);
@@ -3838,7 +3838,7 @@ static void Resume(JNIEnv* env, jobject obj)
geolocation->resume();
}
- GET_NATIVE_VIEW(env, obj)->deviceOrientationManager()->maybeResumeClient();
+ GET_NATIVE_VIEW(env, obj)->deviceOrientationManager()->maybeResumeClients();
ANPEvent event;
SkANP::InitEvent(&event, kLifecycle_ANPEventType);