diff options
author | Bart Sears <bsears@google.com> | 2011-11-18 15:22:45 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-11-18 15:22:45 -0800 |
commit | 64bc3d1ae8cee85955feaae53d751404b45b7097 (patch) | |
tree | d904bae8cfcee2239bfdc7bcac69b9561315b843 /Source/WebKit/android/nav/WebView.cpp | |
parent | e9a6f7f6329c1ca43f9d2b460dfae48945dbbdd1 (diff) | |
parent | 59b140f3e2721433929e11087d0fdb626afb1a72 (diff) | |
download | external_webkit-64bc3d1ae8cee85955feaae53d751404b45b7097.zip external_webkit-64bc3d1ae8cee85955feaae53d751404b45b7097.tar.gz external_webkit-64bc3d1ae8cee85955feaae53d751404b45b7097.tar.bz2 |
am 59b140f3: Merge "Content and viewport rects set in one step." into ics-mr1
* commit '59b140f3e2721433929e11087d0fdb626afb1a72':
Content and viewport rects set in one step.
Diffstat (limited to 'Source/WebKit/android/nav/WebView.cpp')
-rw-r--r-- | Source/WebKit/android/nav/WebView.cpp | 159 |
1 files changed, 71 insertions, 88 deletions
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp index 332a183..a02138a 100644 --- a/Source/WebKit/android/nav/WebView.cpp +++ b/Source/WebKit/android/nav/WebView.cpp @@ -116,7 +116,6 @@ enum DrawExtras { // keep this in sync with WebView.java struct JavaGlue { jweak m_obj; - jmethodID m_calcOurContentVisibleRectF; jmethodID m_overrideLoading; jmethodID m_scrollBy; jmethodID m_sendMoveFocus; @@ -154,7 +153,6 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl, WTF::String drawableDir) // m_javaGlue = new JavaGlue; m_javaGlue.m_obj = env->NewWeakGlobalRef(javaWebView); m_javaGlue.m_scrollBy = GetJMethod(env, clazz, "setContentScrollBy", "(IIZ)Z"); - m_javaGlue.m_calcOurContentVisibleRectF = GetJMethod(env, clazz, "calcOurContentVisibleRectF", "(Landroid/graphics/RectF;)V"); m_javaGlue.m_overrideLoading = GetJMethod(env, clazz, "overrideLoading", "(Ljava/lang/String;)V"); m_javaGlue.m_sendMoveFocus = GetJMethod(env, clazz, "sendMoveFocus", "(II)V"); m_javaGlue.m_sendMoveMouse = GetJMethod(env, clazz, "sendMoveMouse", "(IIII)V"); @@ -366,50 +364,29 @@ void scrollRectOnScreen(const IntRect& rect) { if (rect.isEmpty()) return; - SkRect visible = SkRect::MakeEmpty(); - calcOurContentVisibleRect(&visible); int dx = 0; int left = rect.x(); int right = rect.maxX(); - if (left < visible.fLeft) { - dx = left - visible.fLeft; + if (left < m_visibleRect.fLeft) + dx = left - m_visibleRect.fLeft; // Only scroll right if the entire width can fit on screen. - } else if (right > visible.fRight && right - left < visible.width()) { - dx = right - visible.fRight; - } + else if (right > m_visibleRect.fRight + && right - left < m_visibleRect.width()) + dx = right - m_visibleRect.fRight; int dy = 0; int top = rect.y(); int bottom = rect.maxY(); - if (top < visible.fTop) { - dy = top - visible.fTop; + if (top < m_visibleRect.fTop) + dy = top - m_visibleRect.fTop; // Only scroll down if the entire height can fit on screen - } else if (bottom > visible.fBottom && bottom - top < visible.height()) { - dy = bottom - visible.fBottom; - } + else if (bottom > m_visibleRect.fBottom + && bottom - top < m_visibleRect.height()) + dy = bottom - m_visibleRect.fBottom; if ((dx|dy) == 0 || !scrollBy(dx, dy)) return; viewInvalidate(); } -void calcOurContentVisibleRect(SkRect* r) -{ - JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject javaObject = m_javaGlue.object(env); - if (!javaObject.get()) - return; - jclass rectClass = env->FindClass("android/graphics/RectF"); - jmethodID init = env->GetMethodID(rectClass, "<init>", "(FFFF)V"); - jobject jRect = env->NewObject(rectClass, init, 0, 0, 0, 0); - env->CallVoidMethod(javaObject.get(), m_javaGlue.m_calcOurContentVisibleRectF, jRect); - r->fLeft = env->GetFloatField(jRect, m_javaGlue.m_rectFLeft); - r->fTop = env->GetFloatField(jRect, m_javaGlue.m_rectFTop); - r->fRight = r->fLeft + env->CallFloatMethod(jRect, m_javaGlue.m_rectFWidth); - r->fBottom = r->fTop + env->CallFloatMethod(jRect, m_javaGlue.m_rectFHeight); - env->DeleteLocalRef(rectClass); - env->DeleteLocalRef(jRect); - checkException(env); -} - void resetCursorRing() { m_ringAnimationEnd = 0; @@ -435,9 +412,7 @@ bool drawCursorPreamble(CachedRoot* root) #if USE(ACCELERATED_COMPOSITING) if (node->isInLayer() && root->rootLayer()) { LayerAndroid* layer = root->rootLayer(); - SkRect visible; - calcOurContentVisibleRect(&visible); - layer->updateFixedLayersPositions(visible); + layer->updateFixedLayersPositions(m_visibleRect); layer->updatePositions(); } #endif @@ -466,8 +441,9 @@ void drawCursorPostamble() } } -bool drawGL(WebCore::IntRect& viewRect, WebCore::IntRect* invalRect, WebCore::IntRect& webViewRect, - int titleBarHeight, WebCore::IntRect& clip, float scale, int extras) +bool drawGL(WebCore::IntRect& viewRect, WebCore::IntRect* invalRect, + WebCore::IntRect& webViewRect, int titleBarHeight, + WebCore::IntRect& clip, float scale, int extras) { #if USE(ACCELERATED_COMPOSITING) if (!m_baseLayer || inFullScreenMode()) @@ -518,15 +494,13 @@ bool drawGL(WebCore::IntRect& viewRect, WebCore::IntRect* invalRect, WebCore::In unsigned int pic = m_glWebViewState->currentPictureCounter(); m_glWebViewState->glExtras()->setDrawExtra(extra); - SkRect visibleRect; - calcOurContentVisibleRect(&visibleRect); // Make sure we have valid coordinates. We might not have valid coords // if the zoom manager is still initializing. We will be redrawn // once the correct scale is set - if (!visibleRect.hasValidCoordinates()) + if (!m_visibleRect.hasValidCoordinates()) return false; bool pagesSwapped = false; - bool ret = m_glWebViewState->drawGL(viewRect, visibleRect, invalRect, + bool ret = m_glWebViewState->drawGL(viewRect, m_visibleRect, invalRect, webViewRect, titleBarHeight, clip, scale, &pagesSwapped); if (m_pageSwapCallbackRegistered && pagesSwapped) { @@ -594,11 +568,9 @@ PictureSet* draw(SkCanvas* canvas, SkColor bgColor, int extras, bool split) #if USE(ACCELERATED_COMPOSITING) LayerAndroid* compositeLayer = compositeRoot(); if (compositeLayer) { - SkRect visible; - calcOurContentVisibleRect(&visible); // call this to be sure we've adjusted for any scrolling or animations // before we actually draw - compositeLayer->updateFixedLayersPositions(visible); + compositeLayer->updateFixedLayersPositions(m_visibleRect); compositeLayer->updatePositions(); // We have to set the canvas' matrix on the base layer // (to have fixed layers work as intended) @@ -740,12 +712,10 @@ CachedRoot* getFrameCache(FrameCachePermission allowNewer) m_frameCacheUI->setRootLayer(compositeRoot()); #if USE(ACCELERATED_COMPOSITING) if (layerId >= 0) { - SkRect visible; - calcOurContentVisibleRect(&visible); LayerAndroid* layer = const_cast<LayerAndroid*>( m_frameCacheUI->rootLayer()); if (layer) { - layer->updateFixedLayersPositions(visible); + layer->updateFixedLayersPositions(m_visibleRect); layer->updatePositions(); } } @@ -1542,6 +1512,10 @@ BaseLayerAndroid* getBaseLayer() { return m_baseLayer; } +void setVisibleRect(SkRect& visibleRect) { + m_visibleRect = visibleRect; +} + bool m_isDrawingPaused; private: // local state for WebView // private to getFrameCache(); other functions operate in a different thread @@ -1564,6 +1538,7 @@ private: // local state for WebView bool m_pageSwapCallbackRegistered; #endif RenderSkinButton* m_buttonSkin; + SkRect m_visibleRect; }; // end of WebView class @@ -1575,7 +1550,9 @@ private: // local state for WebView class GLDrawFunctor : Functor { public: GLDrawFunctor(WebView* _wvInstance, - bool(WebView::*_funcPtr)(WebCore::IntRect&, WebCore::IntRect*, WebCore::IntRect&, int, WebCore::IntRect&, jfloat, jint), + bool(WebView::*_funcPtr)(WebCore::IntRect&, WebCore::IntRect*, + WebCore::IntRect&, int, WebCore::IntRect&, + jfloat, jint), WebCore::IntRect _viewRect, float _scale, int _extras) { wvInstance = _wvInstance; funcPtr = _funcPtr; @@ -1601,7 +1578,8 @@ class GLDrawFunctor : Functor { info->clipRight - info->clipLeft, info->clipBottom - info->clipTop); - bool retVal = (*wvInstance.*funcPtr)(localViewRect, &inval, webViewRect, titlebarHeight, clip, scale, extras); + bool retVal = (*wvInstance.*funcPtr)(localViewRect, &inval, webViewRect, + titlebarHeight, clip, scale, extras); if (retVal) { IntRect finalInval; if (inval.isEmpty()) { @@ -1629,7 +1607,8 @@ class GLDrawFunctor : Functor { } private: WebView* wvInstance; - bool (WebView::*funcPtr)(WebCore::IntRect&, WebCore::IntRect*, WebCore::IntRect&, int, WebCore::IntRect&, float, int); + bool (WebView::*funcPtr)(WebCore::IntRect&, WebCore::IntRect*, + WebCore::IntRect&, int, WebCore::IntRect&, float, int); WebCore::IntRect viewRect; WebCore::IntRect webViewRect; jfloat scale; @@ -1813,9 +1792,20 @@ static jobject nativeCursorPosition(JNIEnv *env, jobject obj) static WebCore::IntRect jrect_to_webrect(JNIEnv* env, jobject obj) { - int L, T, R, B; - GraphicsJNI::get_jrect(env, obj, &L, &T, &R, &B); - return WebCore::IntRect(L, T, R - L, B - T); + if (obj) { + int L, T, R, B; + GraphicsJNI::get_jrect(env, obj, &L, &T, &R, &B); + return WebCore::IntRect(L, T, R - L, B - T); + } else + return WebCore::IntRect(); +} + +static SkRect jrectf_to_rect(JNIEnv* env, jobject obj) +{ + SkRect rect = SkRect::MakeEmpty(); + if (obj) + GraphicsJNI::jrectf_to_rect(env, obj, &rect); + return rect; } static bool nativeCursorIntersects(JNIEnv *env, jobject obj, jobject visRect) @@ -1856,56 +1846,49 @@ static void nativeDebugDump(JNIEnv *env, jobject obj) #endif } -static jint nativeDraw(JNIEnv *env, jobject obj, jobject canv, jint color, +static jint nativeDraw(JNIEnv *env, jobject obj, jobject canv, + jobject visible, jint color, jint extras, jboolean split) { SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, canv); - return reinterpret_cast<jint>(GET_NATIVE_VIEW(env, obj)->draw(canvas, color, extras, split)); + WebView* webView = GET_NATIVE_VIEW(env, obj); + SkRect visibleRect = jrectf_to_rect(env, visible); + webView->setVisibleRect(visibleRect); + PictureSet* pictureSet = webView->draw(canvas, color, extras, split); + return reinterpret_cast<jint>(pictureSet); } static jint nativeGetDrawGLFunction(JNIEnv *env, jobject obj, jint nativeView, jobject jrect, jobject jviewrect, + jobject jvisiblerect, jfloat scale, jint extras) { - WebCore::IntRect viewRect; - if (jrect == NULL) { - viewRect = WebCore::IntRect(); - } else { - viewRect = jrect_to_webrect(env, jrect); - } + WebCore::IntRect viewRect = jrect_to_webrect(env, jrect); WebView *wvInstance = (WebView*) nativeView; - GLDrawFunctor* functor = new GLDrawFunctor(wvInstance, &android::WebView::drawGL, - viewRect, scale, extras); + SkRect visibleRect = jrectf_to_rect(env, jvisiblerect); + wvInstance->setVisibleRect(visibleRect); + + GLDrawFunctor* functor = new GLDrawFunctor(wvInstance, + &android::WebView::drawGL, viewRect, scale, extras); wvInstance->setFunctor((Functor*) functor); - WebCore::IntRect webViewRect; - if (jviewrect == NULL) { - webViewRect = WebCore::IntRect(); - } else { - webViewRect = jrect_to_webrect(env, jviewrect); - } + WebCore::IntRect webViewRect = jrect_to_webrect(env, jviewrect); functor->updateViewRect(webViewRect); return (jint)functor; } -static void nativeUpdateDrawGLFunction(JNIEnv *env, jobject obj, jobject jrect, jobject jviewrect) { +static void nativeUpdateDrawGLFunction(JNIEnv *env, jobject obj, jobject jrect, + jobject jviewrect, jobject jvisiblerect) { WebView *wvInstance = GET_NATIVE_VIEW(env, obj); - if (wvInstance != NULL) { + if (wvInstance) { GLDrawFunctor* functor = (GLDrawFunctor*) wvInstance->getFunctor(); - if (functor != NULL) { - WebCore::IntRect viewRect; - if (jrect == NULL) { - viewRect = WebCore::IntRect(); - } else { - viewRect = jrect_to_webrect(env, jrect); - } + if (functor) { + WebCore::IntRect viewRect = jrect_to_webrect(env, jrect); functor->updateRect(viewRect); - WebCore::IntRect webViewRect; - if (jviewrect == NULL) { - webViewRect = WebCore::IntRect(); - } else { - webViewRect = jrect_to_webrect(env, jviewrect); - } + SkRect visibleRect = jrectf_to_rect(env, jvisiblerect); + wvInstance->setVisibleRect(visibleRect); + + WebCore::IntRect webViewRect = jrect_to_webrect(env, jviewrect); functor->updateViewRect(webViewRect); } } @@ -2741,11 +2724,11 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeDebugDump }, { "nativeDestroy", "()V", (void*) nativeDestroy }, - { "nativeDraw", "(Landroid/graphics/Canvas;IIZ)I", + { "nativeDraw", "(Landroid/graphics/Canvas;Landroid/graphics/RectF;IIZ)I", (void*) nativeDraw }, - { "nativeGetDrawGLFunction", "(ILandroid/graphics/Rect;Landroid/graphics/Rect;FI)I", + { "nativeGetDrawGLFunction", "(ILandroid/graphics/Rect;Landroid/graphics/Rect;Landroid/graphics/RectF;FI)I", (void*) nativeGetDrawGLFunction }, - { "nativeUpdateDrawGLFunction", "(Landroid/graphics/Rect;Landroid/graphics/Rect;)V", + { "nativeUpdateDrawGLFunction", "(Landroid/graphics/Rect;Landroid/graphics/Rect;Landroid/graphics/RectF;)V", (void*) nativeUpdateDrawGLFunction }, { "nativeDumpDisplayTree", "(Ljava/lang/String;)V", (void*) nativeDumpDisplayTree }, |