summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-09-28 11:12:08 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-09-28 11:12:08 -0700
commit147584417806316450f4adb02baed00fdd47f9cd (patch)
treee3d105076860559f33759ece6de3ae9bcd292c95
parentebcd36bcdbefb452a0be4e9e452a054ffdff4763 (diff)
parent62740ff35119cc54e82b6af582a01dd34b9e027e (diff)
downloadexternal_webkit-147584417806316450f4adb02baed00fdd47f9cd.zip
external_webkit-147584417806316450f4adb02baed00fdd47f9cd.tar.gz
external_webkit-147584417806316450f4adb02baed00fdd47f9cd.tar.bz2
Merge "Don't scale text selection handles"
-rw-r--r--Source/WebKit/android/nav/SelectText.cpp67
-rw-r--r--Source/WebKit/android/nav/SelectText.h5
-rw-r--r--Source/WebKit/android/nav/WebView.cpp33
3 files changed, 86 insertions, 19 deletions
diff --git a/Source/WebKit/android/nav/SelectText.cpp b/Source/WebKit/android/nav/SelectText.cpp
index 7d18d5d..8427e6f 100644
--- a/Source/WebKit/android/nav/SelectText.cpp
+++ b/Source/WebKit/android/nav/SelectText.cpp
@@ -50,6 +50,7 @@
#define VERBOSE_LOGGING 0
// #define EXTRA_NOISY_LOGGING 1
+#define DEBUG_TOUCH_HANDLES 0
// TextRunIterator has been copied verbatim from GraphicsContext.cpp
namespace WebCore {
@@ -1306,8 +1307,10 @@ static WTF::String text(const SkPicture& picture, const SkIRect& area,
}
#define CONTROL_NOTCH 16
-#define CONTROL_HEIGHT 35
-#define CONTROL_WIDTH 21
+// TODO: Now that java is the one actually drawing these, get the real values
+// from the drawable itself
+#define CONTROL_HEIGHT 47
+#define CONTROL_WIDTH 26
#define STROKE_WIDTH 1.0f
#define STROKE_OUTSET 3.5f
#define STROKE_I_OUTSET 4 // (int) ceil(STROKE_OUTSET)
@@ -1315,9 +1318,9 @@ static WTF::String text(const SkPicture& picture, const SkIRect& area,
#define OUTER_COLOR 0x33000000
#define INNER_COLOR 0xe6aae300
-#define SLOP 35
-
SelectText::SelectText()
+ : m_controlWidth(CONTROL_WIDTH)
+ , m_controlHeight(CONTROL_HEIGHT)
{
m_picture = 0;
reset();
@@ -1512,14 +1515,31 @@ void SelectText::drawSelectionRegion(SkCanvas* canvas, IntRect* inval)
paint.setColor(SkColorSetARGB(0x80, 0x83, 0xCC, 0x39));
canvas->drawPath(path, paint);
// experiment to draw touchable controls that resize the selection
+ float scale = m_controlHeight / (float)CONTROL_HEIGHT;
canvas->save();
canvas->translate(m_selStart.fLeft, m_selStart.fBottom);
+ canvas->scale(scale, scale);
canvas->drawPicture(m_startControl);
canvas->restore();
canvas->save();
canvas->translate(m_selEnd.fRight, m_selEnd.fBottom);
+ canvas->scale(scale, scale);
canvas->drawPicture(m_endControl);
canvas->restore();
+
+#if DEBUG_TOUCH_HANDLES
+ SkRect touchHandleRect;
+ paint.setColor(SkColorSetARGB(0xA0, 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.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);
+#endif
+
SkIRect a = diff.getBounds();
SkIRect b = m_selRegion.getBounds();
diff.op(m_selRegion, SkRegion::kXOR_Op);
@@ -1759,22 +1779,29 @@ void SelectText::getSelectionCaret(SkPath* path)
bool SelectText::hitCorner(int cx, int cy, int x, int y) const
{
SkIRect test;
- test.set(cx, cy, cx, cy);
- test.inset(-SLOP, -SLOP);
+ test.set(cx, cy, cx + m_controlWidth, cy + m_controlHeight);
return test.contains(x, y);
}
+bool SelectText::hitStartHandle(int x, int y) const
+{
+ int left = m_selStart.fLeft - m_controlWidth;
+ return hitCorner(left, m_selStart.fBottom, x, y);
+}
+
+bool SelectText::hitEndHandle(int x, int y) const
+{
+ int left = m_selEnd.fRight;
+ return hitCorner(left, m_selEnd.fBottom, x, y);
+}
+
bool SelectText::hitSelection(int x, int y) const
{
x -= m_startOffset.fX;
y -= m_startOffset.fY;
- int left = m_selStart.fLeft - CONTROL_WIDTH / 2;
- int top = m_selStart.fBottom + CONTROL_HEIGHT / 2;
- if (hitCorner(left, top, x, y))
+ if (hitStartHandle(x, y))
return true;
- int right = m_selEnd.fRight + CONTROL_WIDTH / 2;
- int bottom = m_selEnd.fBottom + CONTROL_HEIGHT / 2;
- if (hitCorner(right, bottom, x, y))
+ if (hitEndHandle(x, y))
return true;
return m_selRegion.contains(x, y);
}
@@ -1897,15 +1924,11 @@ bool SelectText::startSelection(const CachedRoot* root, const IntRect& vis,
m_startSelection = true;
return true;
}
- int left = m_selStart.fLeft - CONTROL_WIDTH / 2;
- int top = m_selStart.fBottom + CONTROL_HEIGHT / 2;
- m_hitTopLeft = hitCorner(left, top, x, y);
- int right = m_selEnd.fRight + CONTROL_WIDTH / 2;
- int bottom = m_selEnd.fBottom + CONTROL_HEIGHT / 2;
- bool hitBottomRight = hitCorner(right, bottom, x, y);
+ m_hitTopLeft = hitStartHandle(x, y);
+ bool hitBottomRight = hitEndHandle(x, y);
DBG_NAV_LOGD("picture=(%d,%d) left=%d top=%d right=%d bottom=%d x=%d y=%d",
m_picture->width(), m_picture->height(),left, top, right, bottom, x, y);
- if (m_hitTopLeft && (!hitBottomRight || y - top < bottom - y)) {
+ if (m_hitTopLeft) {
DBG_NAV_LOG("hit top left");
m_original.fX -= m_selStart.fLeft;
m_original.fY -= (m_selStart.fTop + m_selStart.fBottom) >> 1;
@@ -1917,6 +1940,12 @@ bool SelectText::startSelection(const CachedRoot* root, const IntRect& vis,
return m_hitTopLeft || hitBottomRight;
}
+void SelectText::updateHandleScale(float handleScale)
+{
+ m_controlHeight = CONTROL_HEIGHT * handleScale;
+ m_controlWidth = CONTROL_WIDTH * handleScale;
+}
+
/* selects the word at (x, y)
* a word is normally delimited by spaces
* a string of digits (even with inside spaces) is a word (for phone numbers)
diff --git a/Source/WebKit/android/nav/SelectText.h b/Source/WebKit/android/nav/SelectText.h
index 272cfd1..b1e1f11 100644
--- a/Source/WebKit/android/nav/SelectText.h
+++ b/Source/WebKit/android/nav/SelectText.h
@@ -58,11 +58,14 @@ public:
bool startSelection(const CachedRoot* , const IntRect& vis, int x, int y);
bool wordSelection(const CachedRoot* , const IntRect& vis, int x, int y);
void getSelectionRegion(const IntRect& vis, SkRegion *region);
+ void updateHandleScale(float handleScale);
public:
float m_inverseScale; // inverse scale, x, y used for drawing select path
int m_selectX;
int m_selectY;
private:
+ int m_controlWidth;
+ int m_controlHeight;
class FirstCheck;
class EdgeCheck;
void drawSelectionPointer(SkCanvas* , IntRect* );
@@ -77,6 +80,8 @@ private:
static void getSelectionArrow(SkPath* );
void getSelectionCaret(SkPath* );
bool hitCorner(int cx, int cy, int x, int y) const;
+ bool hitStartHandle(int x, int y) const;
+ bool hitEndHandle(int x, int y) const;
void setVisibleRect(const IntRect& );
void swapAsNeeded();
SkIPoint m_original; // computed start of extend selection
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp
index 9d5ac59..7aae758 100644
--- a/Source/WebKit/android/nav/WebView.cpp
+++ b/Source/WebKit/android/nav/WebView.cpp
@@ -142,6 +142,7 @@ struct JavaGlue {
jfieldID m_rectFTop;
jmethodID m_rectFWidth;
jmethodID m_rectFHeight;
+ jmethodID m_getTextHandleScale;
AutoJObject object(JNIEnv* env) {
return getRealObject(env, m_obj);
}
@@ -171,6 +172,7 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl, WTF::String drawableDir)
"viewInvalidateDelayed", "(JIIII)V");
m_javaGlue.m_pageSwapCallback = GetJMethod(env, clazz, "pageSwapCallback", "()V");
m_javaGlue.m_inFullScreenMode = GetJMethod(env, clazz, "inFullScreenMode", "()Z");
+ m_javaGlue.m_getTextHandleScale = GetJMethod(env, clazz, "getTextHandleScale", "()F");
env->DeleteLocalRef(clazz);
jclass rectClass = env->FindClass("android/graphics/Rect");
@@ -240,6 +242,26 @@ WebViewCore* getWebViewCore() const {
return m_viewImpl;
}
+float getTextHandleScale()
+{
+ LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue.object(env);
+ if (!javaObject.get())
+ return 0;
+ float result = env->CallFloatMethod(javaObject.get(), m_javaGlue.m_getTextHandleScale);
+ checkException(env);
+ return result;
+}
+
+void updateSelectionHandles()
+{
+ if (!m_baseLayer)
+ return;
+ // Adjust for device density & scale
+ m_selectText.updateHandleScale(getTextHandleScale());
+}
+
// removes the cursor altogether (e.g., when going to a new page)
void clearCursor()
{
@@ -526,6 +548,10 @@ bool drawGL(WebCore::IntRect& viewRect, WebCore::IntRect* invalRect, WebCore::In
extra = &m_findOnPage;
break;
case DrawExtrasSelection:
+ // This will involve a JNI call, but under normal circumstances we will
+ // not hit this anyway. Only if USE_JAVA_TEXT_SELECTION is disabled
+ // in WebView.java will we hit this (so really debug only)
+ updateSelectionHandles();
extra = &m_selectText;
break;
case DrawExtrasCursorRing:
@@ -644,6 +670,10 @@ PictureSet* draw(SkCanvas* canvas, SkColor bgColor, int extras, bool split)
extra = &m_findOnPage;
break;
case DrawExtrasSelection:
+ // This will involve a JNI call, but under normal circumstances we will
+ // not hit this anyway. Only if USE_JAVA_TEXT_SELECTION is disabled
+ // in WebView.java will we hit this (so really debug only)
+ updateSelectionHandles();
extra = &m_selectText;
break;
case DrawExtrasCursorRing:
@@ -1276,6 +1306,7 @@ bool startSelection(int x, int y)
const CachedRoot* root = getFrameCache(DontAllowNewer);
if (!root)
return false;
+ updateSelectionHandles();
return m_selectText.startSelection(root, getVisibleRect(), x, y);
}
@@ -1284,6 +1315,7 @@ bool wordSelection(int x, int y)
const CachedRoot* root = getFrameCache(DontAllowNewer);
if (!root)
return false;
+ updateSelectionHandles();
return m_selectText.wordSelection(root, getVisibleRect(), x, y);
}
@@ -1295,6 +1327,7 @@ bool extendSelection(int x, int y)
bool hitSelection(int x, int y)
{
+ updateSelectionHandles();
return m_selectText.hitSelection(x, y);
}