summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/nav/WebView.cpp
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2012-03-21 11:09:27 -0700
committerGeorge Mount <mount@google.com>2012-03-28 07:14:49 -0700
commit304991de60a64b43bffd0c910655ee4ef1e9683c (patch)
treefb352c7dbcb3e0f85f8eccc8262b2df7ab787797 /Source/WebKit/android/nav/WebView.cpp
parentec2823d23ab1a53b60599e9192d86b37f2e44d5f (diff)
downloadexternal_webkit-304991de60a64b43bffd0c910655ee4ef1e9683c.zip
external_webkit-304991de60a64b43bffd0c910655ee4ef1e9683c.tar.gz
external_webkit-304991de60a64b43bffd0c910655ee4ef1e9683c.tar.bz2
Snap selection handles to text.
Bug 6198286 Framework Change: I3c51ed5f6988d58440badfbe8b076fd83d48ae2a Change-Id: I55604f3ec28586beaec5fd98a27c9f4b8a59a8a5
Diffstat (limited to 'Source/WebKit/android/nav/WebView.cpp')
-rw-r--r--Source/WebKit/android/nav/WebView.cpp67
1 files changed, 52 insertions, 15 deletions
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp
index ddb9bcb..37291de 100644
--- a/Source/WebKit/android/nav/WebView.cpp
+++ b/Source/WebKit/android/nav/WebView.cpp
@@ -125,6 +125,10 @@ struct JavaGlue {
jfieldID m_rectTop;
jmethodID m_rectWidth;
jmethodID m_rectHeight;
+ jfieldID m_quadFP1;
+ jfieldID m_quadFP2;
+ jfieldID m_quadFP3;
+ jfieldID m_quadFP4;
AutoJObject object(JNIEnv* env) {
return getRealObject(env, m_obj);
}
@@ -156,6 +160,14 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl, WTF::String drawableDir,
m_javaGlue.m_rectHeight = GetJMethod(env, rectClass, "height", "()I");
env->DeleteLocalRef(rectClass);
+ jclass quadFClass = env->FindClass("android/webkit/QuadF");
+ ALOG_ASSERT(quadFClass, "Could not find QuadF class");
+ m_javaGlue.m_quadFP1 = env->GetFieldID(quadFClass, "p1", "Landroid/graphics/PointF;");
+ m_javaGlue.m_quadFP2 = env->GetFieldID(quadFClass, "p2", "Landroid/graphics/PointF;");
+ m_javaGlue.m_quadFP3 = env->GetFieldID(quadFClass, "p3", "Landroid/graphics/PointF;");
+ m_javaGlue.m_quadFP4 = env->GetFieldID(quadFClass, "p4", "Landroid/graphics/PointF;");
+ env->DeleteLocalRef(quadFClass);
+
env->SetIntField(javaWebView, gWebViewField, (jint)this);
m_viewImpl = (WebViewCore*) viewImpl;
m_generation = 0;
@@ -578,12 +590,20 @@ void setTextSelection(SelectText *selection) {
setDrawExtra(selection, DrawExtrasSelection);
}
-int getHandleLayerId(SelectText::HandleId handleId, SkIRect& cursorRect) {
+int getHandleLayerId(SelectText::HandleId handleId, SkIPoint& cursorPoint,
+ FloatQuad& textBounds) {
SelectText* selectText = static_cast<SelectText*>(getDrawExtra(DrawExtrasSelection));
if (!selectText || !m_baseLayer)
return -1;
int layerId = selectText->caretLayerId(handleId);
- cursorRect = selectText->caretRect(handleId);
+ IntRect cursorRect = selectText->caretRect(handleId);
+ IntRect textRect = selectText->textRect(handleId);
+ // Rects exclude the last pixel on right/bottom. We want only included pixels.
+ cursorPoint.set(cursorRect.x(), cursorRect.maxY() - 1);
+ textRect.setHeight(textRect.height() - 1);
+ textRect.setWidth(textRect.width() - 1);
+ textBounds = FloatQuad(textRect);
+
if (layerId != -1) {
// We need to make sure the drawTransform is up to date as this is
// called before a draw() or drawGL()
@@ -594,13 +614,8 @@ int getHandleLayerId(SelectText::HandleId handleId, SkIRect& cursorRect) {
const TransformationMatrix* transform = layer->drawTransform();
// We're overloading the concept of Rect to be just the two
// points (bottom-left and top-right.
- // TODO: Use FloatQuad instead.
- IntPoint bottomLeft = transform->mapPoint(IntPoint(cursorRect.fLeft,
- cursorRect.fBottom));
- IntPoint topRight = transform->mapPoint(IntPoint(cursorRect.fRight,
- cursorRect.fTop));
- cursorRect.setLTRB(bottomLeft.x(), topRight.y(), topRight.x(),
- bottomLeft.y());
+ cursorPoint = transform->mapPoint(cursorPoint);
+ textBounds = transform->mapQuad(textBounds);
}
}
return layerId;
@@ -617,6 +632,23 @@ void mapLayerRect(int layerId, SkIRect& rect) {
}
}
+void floatQuadToQuadF(JNIEnv* env, const FloatQuad& nativeTextQuad,
+ jobject textQuad)
+{
+ jobject p1 = env->GetObjectField(textQuad, m_javaGlue.m_quadFP1);
+ jobject p2 = env->GetObjectField(textQuad, m_javaGlue.m_quadFP2);
+ jobject p3 = env->GetObjectField(textQuad, m_javaGlue.m_quadFP3);
+ jobject p4 = env->GetObjectField(textQuad, m_javaGlue.m_quadFP4);
+ GraphicsJNI::point_to_jpointf(nativeTextQuad.p1(), env, p1);
+ GraphicsJNI::point_to_jpointf(nativeTextQuad.p2(), env, p2);
+ GraphicsJNI::point_to_jpointf(nativeTextQuad.p3(), env, p3);
+ GraphicsJNI::point_to_jpointf(nativeTextQuad.p4(), env, p4);
+ env->DeleteLocalRef(p1);
+ env->DeleteLocalRef(p2);
+ env->DeleteLocalRef(p3);
+ env->DeleteLocalRef(p4);
+}
+
// This is called when WebView switches rendering modes in a more permanent fashion
// such as when the layer type is set or the view is attached/detached from the window
int setHwAccelerated(bool hwAccelerated) {
@@ -1140,13 +1172,18 @@ static void nativeSetTextSelection(JNIEnv *env, jobject obj, jint nativeView,
}
static jint nativeGetHandleLayerId(JNIEnv *env, jobject obj, jint nativeView,
- jint handleIndex, jobject cursorRect)
+ jint handleIndex, jobject cursorPoint,
+ jobject textQuad)
{
WebView* webview = reinterpret_cast<WebView*>(nativeView);
- SkIRect nativeRect;
- int layerId = webview->getHandleLayerId((SelectText::HandleId) handleIndex, nativeRect);
- if (cursorRect)
- GraphicsJNI::irect_to_jrect(nativeRect, env, cursorRect);
+ SkIPoint nativePoint;
+ FloatQuad nativeTextQuad;
+ int layerId = webview->getHandleLayerId((SelectText::HandleId) handleIndex,
+ nativePoint, nativeTextQuad);
+ if (cursorPoint)
+ GraphicsJNI::ipoint_to_jpoint(nativePoint, env, cursorPoint);
+ if (textQuad)
+ webview->floatQuadToQuadF(env, nativeTextQuad, textQuad);
return layerId;
}
@@ -1247,7 +1284,7 @@ static JNINativeMethod gJavaWebViewMethods[] = {
(void*) nativeSetPauseDrawing },
{ "nativeSetTextSelection", "(II)V",
(void*) nativeSetTextSelection },
- { "nativeGetHandleLayerId", "(IILandroid/graphics/Rect;)I",
+ { "nativeGetHandleLayerId", "(IILandroid/graphics/Point;Landroid/webkit/QuadF;)I",
(void*) nativeGetHandleLayerId },
{ "nativeIsBaseFirst", "(I)Z",
(void*) nativeIsBaseFirst },