summaryrefslogtreecommitdiffstats
path: root/WebKit/android/nav/SelectText.cpp
diff options
context:
space:
mode:
authorCary Clark <cary@android.com>2010-11-11 13:02:24 -0500
committerCary Clark <cary@android.com>2010-11-11 13:06:15 -0500
commit62e1f86fe500eeb622fe50cdb5cc0e09e18069d1 (patch)
tree7ff6af07f3a1bd817414ca720add4c4a593231eb /WebKit/android/nav/SelectText.cpp
parent2b36633c8e1183d3b024dea63d958eaff71bdc64 (diff)
downloadexternal_webkit-62e1f86fe500eeb622fe50cdb5cc0e09e18069d1.zip
external_webkit-62e1f86fe500eeb622fe50cdb5cc0e09e18069d1.tar.gz
external_webkit-62e1f86fe500eeb622fe50cdb5cc0e09e18069d1.tar.bz2
compute select text distance biasing x over y
Rather than using a regular distance function, first find the closest match in Y then look for the closest match in X. This allows the touch point to be well to the right or left of the paragraph and still move the selection to the next or preceeding line while the selection is extended. bug:3183434 Change-Id: I6abf14b9dbca4b7bafe2cb9a96a2915732038ce1
Diffstat (limited to 'WebKit/android/nav/SelectText.cpp')
-rw-r--r--WebKit/android/nav/SelectText.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/WebKit/android/nav/SelectText.cpp b/WebKit/android/nav/SelectText.cpp
index f6548cf..36530b6 100644
--- a/WebKit/android/nav/SelectText.cpp
+++ b/WebKit/android/nav/SelectText.cpp
@@ -423,23 +423,26 @@ public:
*/
int dx = rect.fLeft + rect.fRight - (mFocusX << 1);
int dy = top() + bottom() - (mFocusY << 1);
- int distance = dx * dx + dy * dy;
+ dx = abs(dx);
+ dy = abs(dy);
#ifdef EXTRA_NOISY_LOGGING
- if (distance < 500 || abs(distance - mDistance) < 500)
- DBG_NAV_LOGD("FirstCheck distance=%d mDistance=%d", distance, mDistance);
+ if (dy < 15)
+ DBG_NAV_LOGD("FirstCheck dx/y=(%d, %d) mDx/y=(%d, %d)",
+ dx>>1, dy>>1, mDx>>1, mDy>>1);
#endif
- if (mDistance > distance) {
+ if (mDy > dy || (mDy == dy && mDx > dx)) {
mBestBase = base();
mBestBounds.set(rect.fLeft, top(), rect.fRight, bottom());
#ifndef EXTRA_NOISY_LOGGING
- if (distance < 100)
+ if (dy < 10 && dx < 10)
#endif
{
- DBG_NAV_LOGD("FirstCheck mBestBounds={%d,%d,r=%d,b=%d} distance=%d",
+ DBG_NAV_LOGD("FirstCheck mBestBounds={%d,%d,r=%d,b=%d} dx/y=(%d, %d)",
mBestBounds.fLeft, mBestBounds.fTop,
- mBestBounds.fRight, mBestBounds.fBottom, distance >> 2);
+ mBestBounds.fRight, mBestBounds.fBottom, dx>>1, dy>>1);
}
- mDistance = distance;
+ mDx = dx;
+ mDy = dy;
if (mRecordGlyph)
recordGlyph(rec);
}
@@ -449,7 +452,7 @@ public:
void reset()
{
mBestBounds.setEmpty();
- mDistance = INT_MAX;
+ mDx = mDy = INT_MAX;
}
void setRecordGlyph()
@@ -460,7 +463,8 @@ public:
protected:
int mBestBase;
SkIRect mBestBounds;
- int mDistance;
+ int mDx;
+ int mDy;
int mFocusX;
int mFocusY;
bool mRecordGlyph;
@@ -496,28 +500,30 @@ public:
{
int dx = mLeft ? mFocusX - rect.fRight : rect.fLeft - mFocusX;
int dy = ((top() + bottom()) >> 1) - mFocusY;
+ dx = abs(dx);
+ dy = abs(dy);
if (mLeft ? mFocusX <= rect.fLeft : mFocusX >= rect.fRight) {
- if (abs(dx) <= 10 && abs(dy) <= 10) {
+ if (dx <= 10 && dy <= 10) {
DBG_NAV_LOGD("EdgeCheck fLeft=%d fRight=%d mFocusX=%d dx=%d dy=%d",
rect.fLeft, rect.fRight, mFocusX, dx, dy);
}
return false;
}
- int distance = dx * dx + dy * dy;
- if (mDistance > distance) {
+ if (mDy > dy || (mDy == dy && mDx > dx)) {
if (rec.fLSB == mLastGlyph.fLSB && rec.fRSB == mLastGlyph.fRSB) {
DBG_NAV_LOGD("dup rec.fLSB.fX=%g rec.fRSB.fX=%g",
SkFixedToScalar(rec.fLSB.fX), SkFixedToScalar(rec.fRSB.fX));
return false;
}
recordGlyph(rec);
- mDistance = distance;
+ mDx = dx;
+ mDy = dy;
mBestBase = base();
mBestBounds.set(rect.fLeft, top(), rect.fRight, bottom());
- if (distance <= 100) {
- DBG_NAV_LOGD("EdgeCheck mBestBounds={%d,%d,r=%d,b=%d} distance=%d",
+ if (dx <= 10 && dy <= 10) {
+ DBG_NAV_LOGD("EdgeCheck mBestBounds={%d,%d,r=%d,b=%d} dx/y=(%d, %d)",
mBestBounds.fLeft, mBestBounds.fTop,
- mBestBounds.fRight, mBestBounds.fBottom, distance);
+ mBestBounds.fRight, mBestBounds.fBottom, dx, dy);
}
}
return false;