summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk2
-rw-r--r--CleanSpec.mk2
-rw-r--r--WebKit/Android.mk1
-rw-r--r--WebKit/android/WebCoreSupport/WebRequest.cpp11
-rw-r--r--WebKit/android/jni/DeviceOrientationClientImpl.cpp129
-rw-r--r--WebKit/android/jni/DeviceOrientationClientImpl.h70
-rw-r--r--WebKit/android/jni/DeviceOrientationManager.cpp41
-rw-r--r--WebKit/android/jni/DeviceOrientationManager.h20
-rw-r--r--WebKit/android/jni/WebViewCore.cpp18
-rw-r--r--WebKit/android/jni/WebViewCore.h2
-rw-r--r--WebKit/android/nav/SelectText.cpp6
11 files changed, 283 insertions, 19 deletions
diff --git a/Android.mk b/Android.mk
index 5cd23b3..ddae467 100644
--- a/Android.mk
+++ b/Android.mk
@@ -78,7 +78,7 @@ endif
# Read the HTTP_STACK environment variable, default is android
ifneq ($(TARGET_SIMULATOR),true)
HTTP_STACK = $(HTTP)
-ifneq ($(HTTP_STACK),android)
+ifeq ($(HTTP_STACK),chrome)
# Chrome net stack has dependencies on V8.
ifeq ($(JAVASCRIPT_ENGINE), v8)
HTTP_STACK = chrome
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 586a7ae..ce051f9 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -60,6 +60,8 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libwebcore_int
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libwebcore_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libwebcore_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libwebcore_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libwebcore_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libwebcore_intermediates)
# ************************************************
diff --git a/WebKit/Android.mk b/WebKit/Android.mk
index 000fa68..01ede0f 100644
--- a/WebKit/Android.mk
+++ b/WebKit/Android.mk
@@ -55,6 +55,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
\
android/icu/unicode/ucnv.cpp \
\
+ android/jni/DeviceOrientationClientImpl.cpp \
android/jni/DeviceOrientationManager.cpp \
android/jni/GeolocationPermissionsBridge.cpp \
android/jni/JavaBridge.cpp \
diff --git a/WebKit/android/WebCoreSupport/WebRequest.cpp b/WebKit/android/WebCoreSupport/WebRequest.cpp
index 9118baf..79e780e 100644
--- a/WebKit/android/WebCoreSupport/WebRequest.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequest.cpp
@@ -51,7 +51,6 @@ namespace {
WebRequest::WebRequest(WebUrlLoaderClient* loader, WebResourceRequest webResourceRequest)
: m_urlLoader(loader)
- , m_request(0)
{
GURL gurl(webResourceRequest.url());
m_request = new URLRequest(gurl, this);
@@ -81,6 +80,7 @@ void WebRequest::finish(bool success)
void WebRequest::AppendBytesToUpload(const char* bytes, int bytesLen)
{
+ // This should always be called after start and before finish.
m_request->AppendBytesToUpload(bytes, bytesLen);
}
@@ -100,8 +100,13 @@ void WebRequest::start(bool isPrivateBrowsing)
void WebRequest::cancel()
{
- if (m_request)
- m_request->Cancel();
+ // There is a possible race condition between the IO thread finishing the request and
+ // the WebCore thread cancelling it. If the request has already finished, do
+ // nothing to avoid sending duplicate finish messages to WebCore.
+ if (!m_request)
+ return;
+
+ m_request->Cancel();
finish(true);
}
diff --git a/WebKit/android/jni/DeviceOrientationClientImpl.cpp b/WebKit/android/jni/DeviceOrientationClientImpl.cpp
new file mode 100644
index 0000000..a295bf3
--- /dev/null
+++ b/WebKit/android/jni/DeviceOrientationClientImpl.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 "DeviceOrientationClientImpl.h"
+
+#include "WebViewCore.h"
+#include <DeviceOrientationController.h>
+#include <Frame.h>
+#include <JNIHelp.h>
+
+namespace android {
+
+using JSC::Bindings::getJNIEnv;
+
+enum javaDeviceOrientationServiceClassMethods {
+ DeviceOrientationServiceMethodStart = 0,
+ DeviceOrientationServiceMethodStop,
+ DeviceOrientationServiceMethodSuspend,
+ DeviceOrientationServiceMethodResume,
+ DeviceOrientationServiceMethodCount
+};
+static jmethodID javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodCount];
+
+DeviceOrientationClientImpl::DeviceOrientationClientImpl(WebViewCore* webViewCore)
+ : m_webViewCore(webViewCore)
+ , m_javaDeviceOrientationServiceObject(0)
+{
+ ASSERT(m_webViewCore);
+}
+
+DeviceOrientationClientImpl::~DeviceOrientationClientImpl()
+{
+ releaseJavaInstance();
+}
+
+jobject DeviceOrientationClientImpl::getJavaInstance()
+{
+ // Lazily get the Java object. We can't do this until the WebViewCore is all
+ // set up.
+ if (m_javaDeviceOrientationServiceObject)
+ return m_javaDeviceOrientationServiceObject;
+
+ JNIEnv* env = getJNIEnv();
+
+ ASSERT(m_webViewCore);
+ jobject object = m_webViewCore->getDeviceOrientationService();
+
+ // Get the Java DeviceOrientationService class.
+ jclass javaDeviceOrientationServiceClass = env->GetObjectClass(object);
+ ASSERT(javaDeviceOrientationServiceClass);
+
+ // Set up the methods we wish to call on the Java DeviceOrientationService
+ // class.
+ javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodStart] =
+ env->GetMethodID(javaDeviceOrientationServiceClass, "start", "()V");
+ javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodStop] =
+ env->GetMethodID(javaDeviceOrientationServiceClass, "stop", "()V");
+ javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodSuspend] =
+ env->GetMethodID(javaDeviceOrientationServiceClass, "suspend", "()V");
+ javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodResume] =
+ env->GetMethodID(javaDeviceOrientationServiceClass, "resume", "()V");
+
+ m_javaDeviceOrientationServiceObject = getJNIEnv()->NewGlobalRef(object);
+ getJNIEnv()->DeleteLocalRef(object);
+
+ ASSERT(m_javaDeviceOrientationServiceObject);
+ return m_javaDeviceOrientationServiceObject;
+}
+
+void DeviceOrientationClientImpl::releaseJavaInstance()
+{
+ ASSERT(m_javaDeviceOrientationServiceObject);
+ getJNIEnv()->DeleteGlobalRef(m_javaDeviceOrientationServiceObject);
+}
+
+void DeviceOrientationClientImpl::startUpdating()
+{
+ getJNIEnv()->CallVoidMethod(getJavaInstance(),
+ javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodStart]);
+}
+
+void DeviceOrientationClientImpl::stopUpdating()
+{
+ getJNIEnv()->CallVoidMethod(getJavaInstance(),
+ javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodStop]);
+}
+
+void DeviceOrientationClientImpl::onOrientationChange(PassRefPtr<DeviceOrientation> orientation)
+{
+ m_lastOrientation = orientation;
+ m_controller->didChangeDeviceOrientation(m_lastOrientation.get());
+}
+
+void DeviceOrientationClientImpl::suspend()
+{
+ getJNIEnv()->CallVoidMethod(getJavaInstance(),
+ javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodSuspend]);
+}
+
+void DeviceOrientationClientImpl::resume()
+{
+ getJNIEnv()->CallVoidMethod(getJavaInstance(),
+ javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodResume]);
+}
+
+} // namespace android
diff --git a/WebKit/android/jni/DeviceOrientationClientImpl.h b/WebKit/android/jni/DeviceOrientationClientImpl.h
new file mode 100644
index 0000000..8514a6b
--- /dev/null
+++ b/WebKit/android/jni/DeviceOrientationClientImpl.h
@@ -0,0 +1,70 @@
+/*
+ * 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 DeviceOrientationClientImpl_h
+#define DeviceOrientationClientImpl_h
+
+#include <DeviceOrientation.h>
+#include <DeviceOrientationClient.h>
+#include <JNIUtility.h>
+#include <PassRefPtr.h>
+#include <RefPtr.h>
+
+using namespace WebCore;
+
+namespace android {
+
+class DeviceOrientationManager;
+class WebViewCore;
+
+class DeviceOrientationClientImpl : public DeviceOrientationClient {
+public:
+ DeviceOrientationClientImpl(WebViewCore*);
+
+ void onOrientationChange(PassRefPtr<DeviceOrientation>);
+ void suspend();
+ void resume();
+
+ // DeviceOrientationClient methods
+ virtual void startUpdating();
+ virtual void stopUpdating();
+ virtual DeviceOrientation* lastOrientation() const { return m_lastOrientation.get(); }
+ virtual void setController(DeviceOrientationController* controller) { m_controller = controller; }
+
+protected:
+ virtual ~DeviceOrientationClientImpl();
+
+ jobject getJavaInstance();
+ void releaseJavaInstance();
+
+ WebViewCore* m_webViewCore;
+ jobject m_javaDeviceOrientationServiceObject;
+ DeviceOrientationController* m_controller;
+ RefPtr<DeviceOrientation> m_lastOrientation;
+};
+
+} // namespace android
+
+#endif // DeviceOrientationClientImpl_h
diff --git a/WebKit/android/jni/DeviceOrientationManager.cpp b/WebKit/android/jni/DeviceOrientationManager.cpp
index 8a48ce8..621e646 100644
--- a/WebKit/android/jni/DeviceOrientationManager.cpp
+++ b/WebKit/android/jni/DeviceOrientationManager.cpp
@@ -26,7 +26,12 @@
#include "config.h"
#include "DeviceOrientationManager.h"
+#include "DeviceOrientationClientImpl.h"
+#include "DeviceOrientationController.h"
#include "WebViewCore.h"
+#include "Frame.h"
+#include "Page.h"
+
#include <DeviceOrientationClientMock.h>
#include <JNIHelp.h>
@@ -34,8 +39,9 @@ using namespace WebCore;
namespace android {
-DeviceOrientationManager::DeviceOrientationManager()
+DeviceOrientationManager::DeviceOrientationManager(WebViewCore* webViewCore)
: m_useMock(false)
+ , m_webViewCore(webViewCore)
{
}
@@ -51,16 +57,34 @@ void DeviceOrientationManager::setMockOrientation(PassRefPtr<DeviceOrientation>
static_cast<DeviceOrientationClientMock*>(client())->setOrientation(orientation);
};
+void DeviceOrientationManager::onOrientationChange(PassRefPtr<DeviceOrientation> orientation)
+{
+ ASSERT(!m_useMock);
+ static_cast<DeviceOrientationClientImpl*>(m_client.get())->onOrientationChange(orientation);
+}
+
+void DeviceOrientationManager::maybeSuspendClient()
+{
+ if (!m_useMock && m_client)
+ static_cast<DeviceOrientationClientImpl*>(m_client.get())->suspend();
+}
+
+void DeviceOrientationManager::maybeResumeClient()
+{
+ if (!m_useMock && m_client)
+ static_cast<DeviceOrientationClientImpl*>(m_client.get())->resume();
+}
+
DeviceOrientationClient* DeviceOrientationManager::client()
{
- // FIXME: Implement real client.
if (!m_client)
- m_client.set(m_useMock ? new DeviceOrientationClientMock() : 0);
+ m_client.set(m_useMock ? new DeviceOrientationClientMock
+ : static_cast<DeviceOrientationClient*>(new DeviceOrientationClientImpl(m_webViewCore)));
ASSERT(m_client);
return m_client.get();
}
-// JNI for android.webkit.MockDeviceOrientation
+// JNI for android.webkit.DeviceOrientationManager
static const char* javaDeviceOrientationManagerClass = "android/webkit/DeviceOrientationManager";
static WebViewCore* getWebViewCore(JNIEnv* env, jobject webViewCoreObject)
@@ -81,9 +105,16 @@ static void setMockOrientation(JNIEnv* env, jobject, jobject webViewCoreObject,
getWebViewCore(env, webViewCoreObject)->deviceOrientationManager()->setMockOrientation(orientation.release());
}
+static void onOrientationChange(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);
+ getWebViewCore(env, webViewCoreObject)->deviceOrientationManager()->onOrientationChange(orientation.release());
+}
+
static JNINativeMethod gDeviceOrientationManagerMethods[] = {
{ "nativeUseMock", "(Landroid/webkit/WebViewCore;)V", (void*) useMock },
- { "nativeSetMockOrientation", "(Landroid/webkit/WebViewCore;ZDZDZD)V", (void*) setMockOrientation }
+ { "nativeSetMockOrientation", "(Landroid/webkit/WebViewCore;ZDZDZD)V", (void*) setMockOrientation },
+ { "nativeOnOrientationChange", "(Landroid/webkit/WebViewCore;ZDZDZD)V", (void*) onOrientationChange }
};
int register_device_orientation_manager(JNIEnv* env)
diff --git a/WebKit/android/jni/DeviceOrientationManager.h b/WebKit/android/jni/DeviceOrientationManager.h
index 0e43c18..a0da32f 100644
--- a/WebKit/android/jni/DeviceOrientationManager.h
+++ b/WebKit/android/jni/DeviceOrientationManager.h
@@ -26,9 +26,11 @@
#ifndef DeviceOrientationManager_h
#define DeviceOrientationManager_h
+#include <DeviceOrientation.h>
#include <DeviceOrientationClient.h>
-#include <PassRefPtr.h>
#include <OwnPtr.h>
+#include <PassRefPtr.h>
+#include <RefPtr.h>
namespace WebCore {
class DeviceOrientation;
@@ -36,20 +38,26 @@ class DeviceOrientation;
namespace android {
-// This class handles providing a client for DeviceOrientation. This is
-// non-trivial because of the need to be able to use and configure a mock
-// client. This class is owned by WebViewCore and exists to keep cruft out of
-// that class.
+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.
class DeviceOrientationManager {
public:
- DeviceOrientationManager();
+ DeviceOrientationManager(WebViewCore*);
void useMock();
void setMockOrientation(PassRefPtr<WebCore::DeviceOrientation>);
+ void onOrientationChange(PassRefPtr<WebCore::DeviceOrientation>);
+ void maybeSuspendClient();
+ void maybeResumeClient();
WebCore::DeviceOrientationClient* client();
private:
bool m_useMock;
+ WebViewCore* m_webViewCore;
OwnPtr<WebCore::DeviceOrientationClient> m_client;
};
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index 7646fd0..72b4eac 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -244,6 +244,7 @@ struct WebViewCore::JavaGlue {
jmethodID m_populateVisitedLinks;
jmethodID m_geolocationPermissionsShowPrompt;
jmethodID m_geolocationPermissionsHidePrompt;
+ jmethodID m_getDeviceOrientationService;
jmethodID m_addMessageToConsole;
jmethodID m_getPluginClass;
jmethodID m_showFullScreenPlugin;
@@ -278,7 +279,8 @@ Mutex WebViewCore::gButtonMutex;
Mutex WebViewCore::gCursorBoundsMutex;
WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* mainframe)
- : m_pluginInvalTimer(this, &WebViewCore::pluginInvalTimerFired)
+ : m_pluginInvalTimer(this, &WebViewCore::pluginInvalTimerFired)
+ , m_deviceOrientationManager(this)
{
m_mainFrame = mainframe;
@@ -332,6 +334,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_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_getPluginClass = GetJMethod(env, clazz, "getPluginClass", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Class;");
m_javaGlue->m_showFullScreenPlugin = GetJMethod(env, clazz, "showFullScreenPlugin", "(Landroid/webkit/ViewManager$ChildView;I)V");
@@ -2598,6 +2601,15 @@ void WebViewCore::geolocationPermissionsHidePrompt()
checkException(env);
}
+jobject WebViewCore::getDeviceOrientationService()
+{
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ jobject object = env->CallObjectMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_getDeviceOrientationService);
+ checkException(env);
+ return object;
+}
+
bool WebViewCore::jsConfirm(const WTF::String& url, const WTF::String& text)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
@@ -3370,6 +3382,8 @@ static void Pause(JNIEnv* env, jobject obj)
geolocation->suspend();
}
+ GET_NATIVE_VIEW(env, obj)->deviceOrientationManager()->maybeSuspendClient();
+
ANPEvent event;
SkANP::InitEvent(&event, kLifecycle_ANPEventType);
event.data.lifecycle.action = kPause_ANPLifecycleAction;
@@ -3387,6 +3401,8 @@ static void Resume(JNIEnv* env, jobject obj)
geolocation->resume();
}
+ GET_NATIVE_VIEW(env, obj)->deviceOrientationManager()->maybeResumeClient();
+
ANPEvent event;
SkANP::InitEvent(&event, kLifecycle_ANPEventType);
event.data.lifecycle.action = kResume_ANPLifecycleAction;
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index d29cc88..11a7228 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -242,6 +242,8 @@ namespace android {
*/
void geolocationPermissionsHidePrompt();
+ jobject getDeviceOrientationService();
+
void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID, int msgLevel);
/**
diff --git a/WebKit/android/nav/SelectText.cpp b/WebKit/android/nav/SelectText.cpp
index 9792cd3..3716b03 100644
--- a/WebKit/android/nav/SelectText.cpp
+++ b/WebKit/android/nav/SelectText.cpp
@@ -1542,9 +1542,9 @@ bool SelectText::wordSelection(const SkPicture* picture)
void SelectText::swapAsNeeded()
{
- if (m_selStart.fTop >= m_selEnd.fBottom
- || (m_selStart.fBottom > m_selEnd.fTop
- && m_selStart.fRight > m_selEnd.fLeft))
+ if (m_selStart.fTop >= (m_selEnd.fTop + m_selEnd.fBottom) >> 1
+ || (m_selEnd.fTop < (m_selStart.fTop + m_selStart.fBottom) >> 1
+ && m_selStart.fRight > m_selEnd.fLeft))
{
SkTSwap(m_startBase, m_endBase);
SkTSwap(m_selStart, m_selEnd);