keep frames associated with regular hits and direct hits
The hit test on the nav cache returns a node/frame pair.
It looks for the closest hit, but gives priority to a direct
hit. Track the frame associated with the direct hit
separately, so that the correct node/frame pair is returned.
Change-Id: Icb1e3de4a0aad3c6dd9b2b81669f9c7bbb260282
http://b/2316138
diff --git a/WebKit/android/nav/CachedFrame.cpp b/WebKit/android/nav/CachedFrame.cpp
index bd36bfb..21a4115 100644
--- a/WebKit/android/nav/CachedFrame.cpp
+++ b/WebKit/android/nav/CachedFrame.cpp
@@ -355,6 +355,7 @@
const CachedNode* CachedFrame::findBestAt(const WebCore::IntRect& rect,
int* best, bool* inside, const CachedNode** directHit,
+ const CachedFrame** directHitFramePtr,
const CachedFrame** framePtr, int* x, int* y,
bool checkForHiddenStart) const
{
@@ -392,7 +393,7 @@
// We have a direct hit.
if (*directHit == NULL) {
*directHit = test;
- *framePtr = this;
+ *directHitFramePtr = this;
*x = center.x();
*y = center.y();
} else {
@@ -402,7 +403,7 @@
// This rectangle is inside the other one, so it is
// the best one.
*directHit = test;
- *framePtr = this;
+ *directHitFramePtr = this;
}
}
}
@@ -444,12 +445,13 @@
for (const CachedFrame* frame = mCachedFrames.begin();
frame != mCachedFrames.end(); frame++) {
const CachedNode* frameResult = frame->findBestAt(rect, best, inside,
- directHit, framePtr, x, y, checkForHiddenStart);
+ directHit, directHitFramePtr, framePtr, x, y, checkForHiddenStart);
if (NULL != frameResult)
result = frameResult;
}
if (NULL != *directHit) {
result = *directHit;
+ *framePtr = *directHitFramePtr;
}
return result;
}
diff --git a/WebKit/android/nav/CachedFrame.h b/WebKit/android/nav/CachedFrame.h
index f7276c1..ed76583 100644
--- a/WebKit/android/nav/CachedFrame.h
+++ b/WebKit/android/nav/CachedFrame.h
@@ -92,7 +92,8 @@
const CachedNode* document() const { return mCachedNodes.begin(); }
bool empty() const { return mCachedNodes.size() < 2; } // must have 1 past doc
const CachedNode* findBestAt(const WebCore::IntRect& , int* best,
- bool* inside, const CachedNode** , const CachedFrame** , int* x,
+ bool* inside, const CachedNode** , const CachedFrame** directFrame,
+ const CachedFrame** resultFrame, int* x,
int* y, bool checkForHidden) const;
const CachedFrame* findBestFrameAt(int x, int y) const;
const CachedNode* findBestHitAt(const WebCore::IntRect& ,
diff --git a/WebKit/android/nav/CachedRoot.cpp b/WebKit/android/nav/CachedRoot.cpp
index 0941c7c..71c0993 100644
--- a/WebKit/android/nav/CachedRoot.cpp
+++ b/WebKit/android/nav/CachedRoot.cpp
@@ -780,9 +780,10 @@
int best = INT_MAX;
bool inside = false;
(const_cast<CachedRoot*>(this))->resetClippedOut();
+ const CachedFrame* directHitFramePtr;
const CachedNode* directHit = NULL;
const CachedNode* node = findBestAt(rect, &best, &inside, &directHit,
- framePtr, x, y, checkForHidden);
+ &directHitFramePtr, framePtr, x, y, checkForHidden);
DBG_NAV_LOGD("node=%d (%p)", node == NULL ? 0 : node->index(),
node == NULL ? NULL : node->nodePointer());
if (node == NULL) {