From f81c672a4f5c06621000a6df0984cde689397d94 Mon Sep 17 00:00:00 2001 From: Cary Clark Date: Fri, 7 Jan 2011 16:05:17 -0500 Subject: [PATCH] return the scrollable layer's content bounds Compute and return the scrollable layer's bounds in content space and return it to the java side. The layer's bounds is used to determine if the select text touch point is close to the edge and should invoke scrolling. Also, added a null check to selectBestAt Requires a companion change in frameworks/base bug:3191699 bug:3334943 Change-Id: Id066997f56da59f37350c14a4cc43fe4a7ce7312 --- WebKit/android/nav/WebView.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp index 862b99b6e..a7a48cb12 100644 --- a/WebKit/android/nav/WebView.cpp +++ b/WebKit/android/nav/WebView.cpp @@ -903,6 +903,8 @@ void selectBestAt(const WebCore::IntRect& rect) const CachedFrame* frame; int rx, ry; CachedRoot* root = getFrameCache(AllowNewer); + if (!root) + return; const CachedNode* node = findAt(root, rect, &frame, &rx, &ry); if (!node) { @@ -990,7 +992,8 @@ bool motionUp(int x, int y, int slop) } #if USE(ACCELERATED_COMPOSITING) -static const ScrollableLayerAndroid* findScrollableLayer(const LayerAndroid* parent, int x, int y) { +static const ScrollableLayerAndroid* findScrollableLayer( + const LayerAndroid* parent, int x, int y, SkIRect* foundBounds) { SkRect bounds; parent->bounds(&bounds); // Check the parent bounds first; this will clip to within a masking layer's @@ -1003,23 +1006,35 @@ static const ScrollableLayerAndroid* findScrollableLayer(const LayerAndroid* par int count = parent->countChildren(); for (int i = 0; i < count; i++) { const LayerAndroid* child = parent->getChild(i); - const ScrollableLayerAndroid* result = findScrollableLayer(child, x, y); - if (result) + const ScrollableLayerAndroid* result = findScrollableLayer(child, x, y, + foundBounds); + if (result) { + foundBounds->offset(bounds.fLeft, bounds.fTop); + if (parent->masksToBounds()) { + if (bounds.width() < foundBounds->width()) + foundBounds->fRight = foundBounds->fLeft + bounds.width(); + if (bounds.height() < foundBounds->height()) + foundBounds->fBottom = foundBounds->fTop + bounds.height(); + } return result; + } } - if (parent->contentIsScrollable()) + if (parent->contentIsScrollable()) { + foundBounds->set(0, 0, bounds.width(), bounds.height()); return static_cast(parent); + } return 0; } #endif -int scrollableLayer(int x, int y, SkIRect* layerRect) +int scrollableLayer(int x, int y, SkIRect* layerRect, SkIRect* bounds) { #if USE(ACCELERATED_COMPOSITING) const LayerAndroid* layerRoot = compositeRoot(); if (!layerRoot) return 0; - const ScrollableLayerAndroid* result = findScrollableLayer(layerRoot, x, y); + const ScrollableLayerAndroid* result = findScrollableLayer(layerRoot, x, y, + bounds); if (result) { result->getScrollRect(layerRect); return result->uniqueId(); @@ -2253,13 +2268,15 @@ static void nativeDumpDisplayTree(JNIEnv* env, jobject jwebview, jstring jurl) #endif } -static int nativeScrollableLayer(JNIEnv* env, jobject jwebview, jint x, jint y, jobject rect) +static int nativeScrollableLayer(JNIEnv* env, jobject jwebview, jint x, jint y, + jobject rect, jobject bounds) { WebView* view = GET_NATIVE_VIEW(env, jwebview); LOG_ASSERT(view, "view not set in %s", __FUNCTION__); - SkIRect nativeRect; - int id = view->scrollableLayer(x, y, &nativeRect); + SkIRect nativeRect, nativeBounds; + int id = view->scrollableLayer(x, y, &nativeRect, &nativeBounds); GraphicsJNI::irect_to_jrect(nativeRect, env, rect); + GraphicsJNI::irect_to_jrect(nativeBounds, env, bounds); return id; } @@ -2447,7 +2464,7 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeWordSelection }, { "nativeGetBlockLeftEdge", "(IIF)I", (void*) nativeGetBlockLeftEdge }, - { "nativeScrollableLayer", "(IILandroid/graphics/Rect;)I", + { "nativeScrollableLayer", "(IILandroid/graphics/Rect;Landroid/graphics/Rect;)I", (void*) nativeScrollableLayer }, { "nativeScrollLayer", "(III)Z", (void*) nativeScrollLayer }, -- 2.11.0