summaryrefslogtreecommitdiffstats
path: root/WebKit
diff options
context:
space:
mode:
authorCary Clark <cary@android.com>2010-11-19 11:28:17 -0500
committerCary Clark <cary@android.com>2010-11-19 11:33:45 -0500
commit30e6cb5f8fb67f83bb5f51dbc581b2b4b115f7b1 (patch)
treed07d82b8aacd813a5d49d155ddca4ef6727aeeed /WebKit
parentf9547834d9faf8b38b60a98d57b961b97065cdcd (diff)
downloadexternal_webkit-30e6cb5f8fb67f83bb5f51dbc581b2b4b115f7b1.zip
external_webkit-30e6cb5f8fb67f83bb5f51dbc581b2b4b115f7b1.tar.gz
external_webkit-30e6cb5f8fb67f83bb5f51dbc581b2b4b115f7b1.tar.bz2
do a better job of finding closest selectable text
Measure the closest to the edge, instead of closest to the center. Identify vertical overlaps, and use them to discount characters which are vertically closer. Add more debugging. bug:3183434 Change-Id: I80a14be25260113220e446b876868566440be252
Diffstat (limited to 'WebKit')
-rw-r--r--WebKit/android/nav/SelectText.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/WebKit/android/nav/SelectText.cpp b/WebKit/android/nav/SelectText.cpp
index 352ec7e..aa97ff6 100644
--- a/WebKit/android/nav/SelectText.cpp
+++ b/WebKit/android/nav/SelectText.cpp
@@ -421,25 +421,38 @@ public:
* centerX = (rect.L + rect.R) / 2
* multiply centerX and comparison x by 2 to retain better precision
*/
- int dx = rect.fLeft + rect.fRight - (mFocusX << 1);
- int dy = top() + bottom() - (mFocusY << 1);
- dx = abs(dx);
- dy = abs(dy);
+ SkIRect testBounds = {rect.fLeft, top(), rect.fRight, bottom()};
+ int dx = std::max(0, std::max(testBounds.fLeft - mFocusX,
+ mFocusX - testBounds.fRight));
+ int dy = std::max(0, std::max(testBounds.fTop - mFocusY,
+ mFocusY - testBounds.fBottom));
+ bool overlaps = testBounds.fTop < mBestBounds.fBottom
+ && testBounds.fBottom > mBestBounds.fTop;
#ifdef EXTRA_NOISY_LOGGING
- if (dy < 15)
- DBG_NAV_LOGD("FirstCheck dx/y=(%d, %d) mDx/y=(%d, %d)",
- dx>>1, dy>>1, mDx>>1, mDy>>1);
+ if (dy < 10) {
+ SkUnichar ch = getUniChar(rec);
+ DBG_NAV_LOGD("FirstCheck dx/y=(%d,%d) mDx/y=(%d,%d)"
+ " testBounds=(%d,%d,r=%d,b=%d) mBestBounds=(%d,%d,r=%d,b=%d)"
+ " overlaps=%s ch=%c", dx, dy, mDx, mDy,
+ testBounds.fLeft, testBounds.fTop, testBounds.fRight,
+ testBounds.fBottom, mBestBounds.fLeft, mBestBounds.fTop,
+ mBestBounds.fRight, mBestBounds.fBottom,
+ overlaps ? "true" : "false", ch < 0x7f ? ch : '?');
+ }
#endif
- if (mDy > dy || (mDy == dy && mDx > dx)) {
+ if ((mDy > dy && !overlaps)
+ || ((mDy == dy || overlaps) && mDx > dx)) {
mBestBase = base();
- mBestBounds.set(rect.fLeft, top(), rect.fRight, bottom());
+ mBestBounds = testBounds;
#ifndef EXTRA_NOISY_LOGGING
if (dy < 10 && dx < 10)
#endif
{
- DBG_NAV_LOGD("FirstCheck mBestBounds={%d,%d,r=%d,b=%d} dx/y=(%d, %d)",
+ DBG_NAV_LOGD("FirstCheck dx/y=(%d,%d) mFocus=(%d,%d)"
+ " mBestBounds={%d,%d,r=%d,b=%d}",
+ dx, dy, mFocusX, mFocusY,
mBestBounds.fLeft, mBestBounds.fTop,
- mBestBounds.fRight, mBestBounds.fBottom, dx>>1, dy>>1);
+ mBestBounds.fRight, mBestBounds.fBottom);
}
mDx = dx;
mDy = dy;