diff options
author | Cary Clark <cary@android.com> | 2010-03-03 08:35:20 -0500 |
---|---|---|
committer | Cary Clark <cary@android.com> | 2010-03-03 10:42:12 -0500 |
commit | afa40c89b27e6edbc28a5ad400eb8bb9176a88a8 (patch) | |
tree | 56e2d8a96b856b0b509719ba06ce1b422a8f49dc | |
parent | cf9d0b9a12d2ae509c2a3075c4edb0fe38dc17a7 (diff) | |
download | external_webkit-afa40c89b27e6edbc28a5ad400eb8bb9176a88a8.zip external_webkit-afa40c89b27e6edbc28a5ad400eb8bb9176a88a8.tar.gz external_webkit-afa40c89b27e6edbc28a5ad400eb8bb9176a88a8.tar.bz2 |
refactor find state and scrolling
Separate out state when find is up and is empty.
Request a scroll when setting a match, rather than when drawing.
Don't draw if there's no match.
Companion fix in frameworks/base
http://b/2370069
-rw-r--r-- | WebKit/android/nav/FindCanvas.cpp | 2 | ||||
-rw-r--r-- | WebKit/android/nav/WebView.cpp | 45 |
2 files changed, 29 insertions, 18 deletions
diff --git a/WebKit/android/nav/FindCanvas.cpp b/WebKit/android/nav/FindCanvas.cpp index 3a0ef33..139bd2c 100644 --- a/WebKit/android/nav/FindCanvas.cpp +++ b/WebKit/android/nav/FindCanvas.cpp @@ -537,7 +537,7 @@ void FindOnPage::storeCurrentMatchLocation() { #define MAX_NUMBER_OF_MATCHES_TO_DRAW 101 void FindOnPage::draw(SkCanvas* canvas, LayerAndroid* layer) { - if (!m_matches || !m_matches->size()) + if (!m_hasCurrentLocation || !m_matches || !m_matches->size()) return; int layerId = layer->uniqueId(); if (m_findIndex >= m_matches->size()) diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp index 2283110..40e96bf 100644 --- a/WebKit/android/nav/WebView.cpp +++ b/WebKit/android/nav/WebView.cpp @@ -296,11 +296,15 @@ void nativeRecordButtons(bool hasFocus, bool pressed, bool invalidate) } } -bool scrollRectOnScreen(int left, int top, int right, int bottom) +void scrollRectOnScreen(const IntRect& rect) { + if (rect.isEmpty()) + return; WebCore::IntRect visible; getVisibleRect(&visible); int dx = 0; + int left = rect.x(); + int right = rect.right(); if (left < visible.x()) { dx = left - visible.x(); // Only scroll right if the entire width can fit on screen. @@ -308,6 +312,8 @@ bool scrollRectOnScreen(int left, int top, int right, int bottom) dx = right - visible.right(); } int dy = 0; + int top = rect.y(); + int bottom = rect.bottom(); if (top < visible.y()) { dy = top - visible.y(); // Only scroll down if the entire height can fit on screen @@ -315,9 +321,8 @@ bool scrollRectOnScreen(int left, int top, int right, int bottom) dy = bottom - visible.bottom(); } if ((dx|dy) == 0 || !scrollBy(dx, dy)) - return false; + return; viewInvalidate(); - return true; } void resetCursorRing() @@ -396,12 +401,6 @@ void drawExtras(SkCanvas* canvas, int extras) } if (extra) extra->draw(canvas, &mainPicture); - if (extras == DrawExtrasFind) { - IntRect currentMatchBounds = m_findOnPage.currentMatchBounds(); - if (!currentMatchBounds.isEmpty()) - scrollRectOnScreen(currentMatchBounds.x(), currentMatchBounds.y(), - currentMatchBounds.right(), currentMatchBounds.bottom()); - } #if USE(ACCELERATED_COMPOSITING) if (!m_rootLayer) return; @@ -898,9 +897,14 @@ void overrideUrlLoading(const WebCore::String& url) void setFindIsUp(bool up) { + DBG_NAV_LOGD("up=%d", up); m_viewImpl->m_findIsUp = up; - if (!up) - m_findOnPage.clearCurrentLocation(); +} + +void setFindIsEmpty() +{ + DBG_NAV_LOG(""); + m_findOnPage.clearCurrentLocation(); } void setFollowedLink(bool followed) @@ -995,6 +999,7 @@ void sendMotionUp( void findNext(bool forward) { m_findOnPage.findNext(forward); + scrollRectOnScreen(m_findOnPage.currentMatchBounds()); viewInvalidate(); } @@ -1003,6 +1008,7 @@ void findNext(bool forward) void setMatches(WTF::Vector<MatchInfo>* matches) { m_findOnPage.setMatches(matches); + scrollRectOnScreen(m_findOnPage.currentMatchBounds()); viewInvalidate(); } @@ -1549,11 +1555,16 @@ static void nativeRecordButtons(JNIEnv* env, jobject obj, bool hasFocus, view->nativeRecordButtons(hasFocus, pressed, invalidate); } -static void nativeSetFindIsUp(JNIEnv *env, jobject obj) +static void nativeSetFindIsUp(JNIEnv *env, jobject obj, jboolean isUp) { WebView* view = GET_NATIVE_VIEW(env, obj); LOG_ASSERT(view, "view not set in %s", __FUNCTION__); - view->setFindIsUp(false); + view->setFindIsUp(isUp); +} + +static void nativeSetFindIsEmpty(JNIEnv *env, jobject obj) +{ + GET_NATIVE_VIEW(env, obj)->setFindIsEmpty(); } static void nativeSetFollowedLink(JNIEnv *env, jobject obj, bool followed) @@ -1606,7 +1617,6 @@ static int nativeFindAll(JNIEnv *env, jobject obj, jstring findLower, } WebView* view = GET_NATIVE_VIEW(env, obj); LOG_ASSERT(view, "view not set in nativeFindAll"); - view->setFindIsUp(true); CachedRoot* root = view->getFrameCache(WebView::AllowNewer); if (!root) { env->ReleaseStringChars(findLower, findLowerChars); @@ -1707,8 +1717,7 @@ static bool nativeMoveCursorToNextTextInput(JNIEnv *env, jobject obj) const_cast<CachedNode*>(next)); view->sendMoveFocus(static_cast<WebCore::Frame*>(frame->framePointer()), static_cast<WebCore::Node*>(next->nodePointer())); - view->scrollRectOnScreen(bounds.x(), bounds.y(), bounds.right(), - bounds.bottom()); + view->scrollRectOnScreen(bounds); view->getWebViewCore()->m_moveGeneration++; return true; } @@ -1903,7 +1912,9 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeRecordButtons }, { "nativeSelectBestAt", "(Landroid/graphics/Rect;)V", (void*) nativeSelectBestAt }, - { "nativeSetFindIsUp", "()V", + { "nativeSetFindIsEmpty", "()V", + (void*) nativeSetFindIsEmpty }, + { "nativeSetFindIsUp", "(Z)V", (void*) nativeSetFindIsUp }, { "nativeSetFollowedLink", "(Z)V", (void*) nativeSetFollowedLink }, |