OSDN Git Service

Keep text handles in sync with native touch targets
authorJohn Reck <jreck@google.com>
Thu, 27 Oct 2011 16:07:40 +0000 (09:07 -0700)
committerJohn Reck <jreck@google.com>
Thu, 27 Oct 2011 18:29:40 +0000 (11:29 -0700)
 Bug: 5522153
 Also add some slop to the handle targets, cleaned
 up the JNI and improved debugging.

Change-Id: I3b2c3c8b1543d4a1aa599ae2938fa78fe95e01bf

Source/WebKit/android/nav/SelectText.cpp
Source/WebKit/android/nav/SelectText.h
Source/WebKit/android/nav/WebView.cpp

index 98ec574..4a6b509 100644 (file)
 #define VERBOSE_LOGGING 0
 // #define EXTRA_NOISY_LOGGING 1
 #define DEBUG_TOUCH_HANDLES 0
+#if DEBUG_TOUCH_HANDLES
+#define DBG_HANDLE_LOG(format, ...) LOGD("%s " format, __FUNCTION__, __VA_ARGS__)
+#else
+#define DBG_HANDLE_LOG(...)
+#endif
 
 // TextRunIterator has been copied verbatim from GraphicsContext.cpp
 namespace WebCore {
@@ -1311,6 +1316,7 @@ static WTF::String text(const SkPicture& picture, const SkIRect& area,
 // from the drawable itself
 #define CONTROL_HEIGHT 47
 #define CONTROL_WIDTH 26
+#define CONTROL_SLOP 5
 #define STROKE_WIDTH 1.0f
 #define STROKE_OUTSET 3.5f
 #define STROKE_I_OUTSET 4 // (int) ceil(STROKE_OUTSET)
@@ -1321,6 +1327,7 @@ static WTF::String text(const SkPicture& picture, const SkIRect& area,
 SelectText::SelectText()
     : m_controlWidth(CONTROL_WIDTH)
     , m_controlHeight(CONTROL_HEIGHT)
+    , m_controlSlop(CONTROL_SLOP)
 {
     m_picture = 0;
     reset();
@@ -1538,15 +1545,19 @@ void SelectText::drawSelectionRegion(SkCanvas* canvas, IntRect* inval)
 
 #if DEBUG_TOUCH_HANDLES
     SkRect touchHandleRect;
-    paint.setColor(SkColorSetARGB(0xA0, 0xFF, 0x00, 0x00));
+    paint.setColor(SkColorSetARGB(0x60, 0xFF, 0x00, 0x00));
     touchHandleRect.set(0, m_selStart.fBottom, m_selStart.fLeft, 0);
     touchHandleRect.fBottom = touchHandleRect.fTop + m_controlHeight;
     touchHandleRect.fLeft = touchHandleRect.fRight - m_controlWidth;
     canvas->drawRect(touchHandleRect, paint);
+    touchHandleRect.inset(-m_controlSlop, -m_controlSlop);
+    canvas->drawRect(touchHandleRect, paint);
     touchHandleRect.set(m_selEnd.fRight, m_selEnd.fBottom, 0, 0);
     touchHandleRect.fBottom = touchHandleRect.fTop + m_controlHeight;
     touchHandleRect.fRight = touchHandleRect.fLeft + m_controlWidth;
     canvas->drawRect(touchHandleRect, paint);
+    touchHandleRect.inset(-m_controlSlop, -m_controlSlop);
+    canvas->drawRect(touchHandleRect, paint);
 #endif
 
     SkIRect a = diff.getBounds();
@@ -1789,6 +1800,9 @@ bool SelectText::hitCorner(int cx, int cy, int x, int y) const
 {
     SkIRect test;
     test.set(cx, cy, cx + m_controlWidth, cy + m_controlHeight);
+    test.inset(-m_controlSlop, -m_controlSlop);
+    DBG_HANDLE_LOG("checking if %dx%d,%d-%d contains %dx%d",
+                   cx, cy, m_controlWidth, m_controlHeight, x,  y);
     return test.contains(x, y);
 }
 
@@ -1815,6 +1829,14 @@ bool SelectText::hitSelection(int x, int y) const
     return m_selRegion.contains(x, y);
 }
 
+void SelectText::getSelectionHandles(int* handles)
+{
+    handles[0] = m_selStart.fLeft;
+    handles[1] = m_selStart.fBottom;
+    handles[2] = m_selEnd.fRight;
+    handles[3] = m_selEnd.fBottom;
+}
+
 void SelectText::moveSelection(const IntRect& vis, int x, int y)
 {
     if (!m_picture)
@@ -1953,6 +1975,7 @@ void SelectText::updateHandleScale(float handleScale)
 {
     m_controlHeight = CONTROL_HEIGHT * handleScale;
     m_controlWidth = CONTROL_WIDTH * handleScale;
+    m_controlSlop = CONTROL_SLOP * handleScale;
 }
 
 /* selects the word at (x, y)
index e5f7f59..4abf378 100644 (file)
@@ -59,6 +59,7 @@ public:
     bool wordSelection(const CachedRoot* , const IntRect& vis, int x, int y);
     void getSelectionRegion(const IntRect& vis, SkRegion *region, LayerAndroid* root);
     void updateHandleScale(float handleScale);
+    void getSelectionHandles(int* handles);
 public:
     float m_inverseScale; // inverse scale, x, y used for drawing select path
     int m_selectX;
@@ -66,6 +67,7 @@ public:
 private:
     int m_controlWidth;
     int m_controlHeight;
+    int m_controlSlop;
     class FirstCheck;
     class EdgeCheck;
     void drawSelectionPointer(SkCanvas* , IntRect* );
index 46f608b..10f679d 100644 (file)
@@ -1555,6 +1555,11 @@ void getTextSelectionRegion(SkRegion *region)
     m_selectText.getSelectionRegion(getVisibleRect(), region, compositeRoot());
 }
 
+void getTextSelectionHandles(int* handles)
+{
+    m_selectText.getSelectionHandles(handles);
+}
+
 void replaceBaseContent(PictureSet* set)
 {
     if (!m_baseLayer)
@@ -1984,12 +1989,22 @@ static void nativeSetBaseLayer(JNIEnv *env, jobject obj, jint layer, jobject inv
                                             registerPageSwapCallback);
 }
 
-static void nativeGetTextSelectionRegion(JNIEnv *env, jobject obj, jobject region)
+static void nativeGetTextSelectionRegion(JNIEnv *env, jobject obj, jint view,
+                                         jobject region)
 {
     if (!region)
         return;
     SkRegion* nregion = GraphicsJNI::getNativeRegion(env, region);
-    GET_NATIVE_VIEW(env, obj)->getTextSelectionRegion(nregion);
+    ((WebView*)view)->getTextSelectionRegion(nregion);
+}
+
+static void nativeGetSelectionHandles(JNIEnv *env, jobject obj, jint view,
+                                      jintArray arr)
+{
+    int handles[4];
+    ((WebView*)view)->getTextSelectionHandles(handles);
+    env->SetIntArrayRegion(arr, 0, 4, handles);
+    checkException(env);
 }
 
 static BaseLayerAndroid* nativeGetBaseLayer(JNIEnv *env, jobject obj)
@@ -2897,8 +2912,10 @@ static JNINativeMethod gJavaWebViewMethods[] = {
         (void*) nativeSetHeightCanMeasure },
     { "nativeSetBaseLayer", "(ILandroid/graphics/Region;ZZZ)V",
         (void*) nativeSetBaseLayer },
-    { "nativeGetTextSelectionRegion", "(Landroid/graphics/Region;)V",
+    { "nativeGetTextSelectionRegion", "(ILandroid/graphics/Region;)V",
         (void*) nativeGetTextSelectionRegion },
+    { "nativeGetSelectionHandles", "(I[I)V",
+        (void*) nativeGetSelectionHandles },
     { "nativeGetBaseLayer", "()I",
         (void*) nativeGetBaseLayer },
     { "nativeReplaceBaseContent", "(I)V",