diff options
| -rw-r--r-- | WebKit/android/nav/SelectText.cpp | 19 | ||||
| -rw-r--r-- | WebKit/android/nav/SelectText.h | 2 | ||||
| -rw-r--r-- | WebKit/android/nav/WebView.cpp | 20 |
3 files changed, 41 insertions, 0 deletions
diff --git a/WebKit/android/nav/SelectText.cpp b/WebKit/android/nav/SelectText.cpp index 0862284..7597450 100644 --- a/WebKit/android/nav/SelectText.cpp +++ b/WebKit/android/nav/SelectText.cpp @@ -1853,6 +1853,25 @@ void SelectText::reset() m_layerId = 0; } +IntPoint SelectText::selectableText(const CachedRoot* root) +{ + int x = 0; + int y = 0; + SkPicture* picture = root->pictureAt(&x, &y, &m_layerId); + if (!picture) { + DBG_NAV_LOG("picture==0"); + return IntPoint(0, 0); + } + int width = picture->width(); + int height = picture->height(); + IntRect vis(0, 0, width, height); + FirstCheck center(width >> 1, height >> 1, vis); + int base; + const SkIRect& closest = findClosest(center, *picture, &base); + return IntPoint((closest.fLeft + closest.fRight) >> 1, + (closest.fTop + closest.fBottom) >> 1); +} + void SelectText::selectAll() { if (!m_picture) diff --git a/WebKit/android/nav/SelectText.h b/WebKit/android/nav/SelectText.h index 8f4747f..3b15c0b 100644 --- a/WebKit/android/nav/SelectText.h +++ b/WebKit/android/nav/SelectText.h @@ -27,6 +27,7 @@ #define SELECT_TEXT_H #include "DrawExtra.h" +#include "IntPoint.h" #include "IntRect.h" #include "PlatformString.h" #include "SkPath.h" @@ -48,6 +49,7 @@ public: bool hitSelection(int x, int y) const; void moveSelection(const IntRect& vis, int x, int y); void reset(); + IntPoint selectableText(const CachedRoot* ); void selectAll(); int selectionX() const; int selectionY() const; diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp index fdca064..a022fe1 100644 --- a/WebKit/android/nav/WebView.cpp +++ b/WebKit/android/nav/WebView.cpp @@ -1081,6 +1081,14 @@ void moveSelection(int x, int y) m_selectText.moveSelection(getVisibleRect(), x, y); } +IntPoint selectableText() +{ + const CachedRoot* root = getFrameCache(DontAllowNewer); + if (!root) + return IntPoint(0, 0); + return m_selectText.selectableText(root); +} + void selectAll() { m_selectText.selectAll(); @@ -2113,6 +2121,16 @@ static void nativeResetSelection(JNIEnv *env, jobject obj) return GET_NATIVE_VIEW(env, obj)->resetSelection(); } +static jobject nativeSelectableText(JNIEnv* env, jobject obj) +{ + IntPoint pos = GET_NATIVE_VIEW(env, obj)->selectableText(); + jclass pointClass = env->FindClass("android/graphics/Point"); + jmethodID init = env->GetMethodID(pointClass, "<init>", "(II)V"); + jobject point = env->NewObject(pointClass, init, pos.x(), pos.y()); + env->DeleteLocalRef(pointClass); + return point; +} + static void nativeSelectAll(JNIEnv* env, jobject obj) { GET_NATIVE_VIEW(env, obj)->selectAll(); @@ -2364,6 +2382,8 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeRecordButtons }, { "nativeResetSelection", "()V", (void*) nativeResetSelection }, + { "nativeSelectableText", "()Landroid/graphics/Point;", + (void*) nativeSelectableText }, { "nativeSelectAll", "()V", (void*) nativeSelectAll }, { "nativeSelectBestAt", "(Landroid/graphics/Rect;)V", |
