summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/nav/WebView.cpp
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2011-11-15 11:21:25 -0800
committerGeorge Mount <mount@google.com>2011-11-16 10:13:45 -0800
commita5e649bc4d58bf3da959deae077307c487e2a3a6 (patch)
tree62fff936068bda1376bb4a0bb0c0692b5a661aa3 /Source/WebKit/android/nav/WebView.cpp
parent1067d8e648ceae4db56ce5cc2b3dac1786d557d1 (diff)
downloadexternal_webkit-a5e649bc4d58bf3da959deae077307c487e2a3a6.zip
external_webkit-a5e649bc4d58bf3da959deae077307c487e2a3a6.tar.gz
external_webkit-a5e649bc4d58bf3da959deae077307c487e2a3a6.tar.bz2
Content and viewport rects set in one step.
Bug 5342918 The content rect of the WebView was being retrieved during the draw while the viewport rect was being set when the draw functor was setup. During animations, the content rect was changing between the time the draw functor was retrieved and it was executed. The content rect is now being set with the viewport rect. Framework change: I1b0978ee Change-Id: I05d68dcc73ede1e919ddc1478f48b372b7b64042
Diffstat (limited to 'Source/WebKit/android/nav/WebView.cpp')
-rw-r--r--Source/WebKit/android/nav/WebView.cpp159
1 files changed, 71 insertions, 88 deletions
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp
index d852790..9a2afc8 100644
--- a/Source/WebKit/android/nav/WebView.cpp
+++ b/Source/WebKit/android/nav/WebView.cpp
@@ -119,7 +119,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;
@@ -157,7 +156,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");
@@ -369,50 +367,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;
@@ -438,9 +415,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
@@ -469,8 +444,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())
@@ -521,15 +497,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) {
@@ -597,11 +571,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)
@@ -743,12 +715,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();
}
}
@@ -1545,6 +1515,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
@@ -1567,6 +1541,7 @@ private: // local state for WebView
bool m_pageSwapCallbackRegistered;
#endif
RenderSkinButton* m_buttonSkin;
+ SkRect m_visibleRect;
}; // end of WebView class
@@ -1578,7 +1553,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;
@@ -1604,7 +1581,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()) {
@@ -1632,7 +1610,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;
@@ -1816,9 +1795,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)
@@ -1859,56 +1849,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);
}
}
@@ -2751,11 +2734,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 },