OSDN Git Service

DO NOT MERGE Offset scroll area by the scroll origin on Android
authorGeorge Mount <mount@google.com>
Mon, 24 Oct 2011 22:45:31 +0000 (15:45 -0700)
committerGeorge Mount <mount@google.com>
Wed, 9 Nov 2011 23:36:04 +0000 (15:36 -0800)
 Bug 5268793
 The scrolled area for WebView is 0,0 - maxX,maxY while
 ScrollView can have any origin. On RTL pages, the origin
 is negative when it can scroll. This scrolls the page
 to the right when it detects an RTL page.

 Cherry-picked from master CL: I6a91b97f

 Framework CL: I2537b84a

Change-Id: I6a91b97f90f5ba4c323c56dda9d125108d9502c4

Source/WebCore/platform/android/ScrollViewAndroid.cpp
Source/WebKit/android/jni/WebCoreFrameBridge.cpp
Source/WebKit/android/jni/WebViewCore.cpp

index f54e5ea..f29e998 100644 (file)
@@ -100,7 +100,8 @@ void ScrollView::platformSetScrollPosition(const WebCore::IntPoint& pt)
 {
     if (parent()) // don't attempt to scroll subframes; they're fully visible
         return;
-    PlatformBridge::setScrollPosition(this, pt.x(), pt.y());
+    PlatformBridge::setScrollPosition(this, m_scrollOrigin.x() + pt.x(),
+            m_scrollOrigin.y() + pt.y());
 }
 
 void ScrollView::platformSetScrollbarModes()
@@ -119,7 +120,9 @@ void ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) cons
 
 void ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now)
 {
-    android::WebViewCore::getWebViewCore(this)->contentInvalidate(rect);
+    IntRect offsetRect = rect;
+    offsetRect.move(m_scrollOrigin.x(), m_scrollOrigin.y());
+    android::WebViewCore::getWebViewCore(this)->contentInvalidate(offsetRect);
 }
 
 #ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS
index bb28d28..d53ddb6 100644 (file)
@@ -2117,6 +2117,25 @@ static void OrientationChanged(JNIEnv *env, jobject obj, int orientation)
     pFrame->sendOrientationChangeEvent(orientation);
 }
 
+static jboolean GetShouldStartScrolledRight(JNIEnv *env, jobject obj,
+        jint browserFrame)
+{
+    jboolean startScrolledRight = false; // default is start scrolled left
+    WebCore::Frame* frame = reinterpret_cast<WebCore::Frame*>(browserFrame);
+    WebCore::Document* document = frame->document();
+    if (document) {
+        RenderStyle* style = document->renderer()->style();
+        WritingMode writingMode = style->writingMode();
+        LOG_ASSERT(writingMode != WebCore::BottomToTopWritingMode,
+                "BottomToTopWritingMode isn't supported");
+        if (writingMode == WebCore::RightToLeftWritingMode)
+            startScrolledRight = true; // vertical-rl pages start scrolled right
+        else if (writingMode == WebCore::TopToBottomWritingMode)
+            startScrolledRight = !style->isLeftToRightDirection(); // RTL starts right
+    }
+    return startScrolledRight;
+}
+
 #if USE(CHROME_NETWORK_STACK)
 
 static void AuthenticationProceed(JNIEnv *env, jobject obj, int handle, jstring jUsername, jstring jPassword)
@@ -2315,6 +2334,8 @@ static JNINativeMethod gBrowserFrameNativeMethods[] = {
         (void*) SslCertErrorCancel },
     { "nativeSslClientCert", "(I[B[[B)V",
         (void*) SslClientCert },
+    { "nativeGetShouldStartScrolledRight", "(I)Z",
+        (void*) GetShouldStartScrolledRight },
 };
 
 int registerWebFrame(JNIEnv* env)
index 0708d5c..7692de1 100644 (file)
@@ -832,10 +832,12 @@ SkPicture* WebViewCore::rebuildPicture(const SkIRect& inval)
 
     WebCore::PlatformGraphicsContext pgc(recordingCanvas);
     WebCore::GraphicsContext gc(&pgc);
-    recordingCanvas->translate(-inval.fLeft, -inval.fTop);
+    IntPoint origin = view->minimumScrollPosition();
+    WebCore::IntRect drawArea(inval.fLeft + origin.x(), inval.fTop + origin.y(),
+            inval.width(), inval.height());
+    recordingCanvas->translate(-drawArea.x(), -drawArea.y());
     recordingCanvas->save();
-    view->platformWidget()->draw(&gc, WebCore::IntRect(inval.fLeft,
-        inval.fTop, inval.width(), inval.height()));
+    view->platformWidget()->draw(&gc, drawArea);
     m_rebuildInval.op(inval, SkRegion::kUnion_Op);
     DBG_SET_LOGD("m_rebuildInval={%d,%d,r=%d,b=%d}",
         m_rebuildInval.getBounds().fLeft, m_rebuildInval.getBounds().fTop,
@@ -1094,7 +1096,10 @@ void WebViewCore::didFirstLayout()
             // When redirect with locked history, we would like to reset the
             // scale factor. This is important for www.yahoo.com as it is
             // redirected to www.yahoo.com/?rs=1 on load.
-            || loadType == WebCore::FrameLoadTypeRedirectWithLockedBackForwardList);
+            || loadType == WebCore::FrameLoadTypeRedirectWithLockedBackForwardList
+            // When "request desktop page" is used, we want to treat it as
+            // a newly-loaded page.
+            || loadType == WebCore::FrameLoadTypeSame);
     checkException(env);
 
     DBG_NAV_LOG("call updateFrameCache");
@@ -1340,11 +1345,11 @@ void WebViewCore::setSizeScreenWidthAndScale(int width, int height,
             if (width != screenWidth) {
                 m_mainFrame->view()->setUseFixedLayout(true);
                 m_mainFrame->view()->setFixedLayoutSize(IntSize(width, height));
-            } else {
+            } else
                 m_mainFrame->view()->setUseFixedLayout(false);
-            }
             r->setNeedsLayoutAndPrefWidthsRecalc();
-            m_mainFrame->view()->forceLayout();
+            if (m_mainFrame->view()->didFirstLayout())
+                m_mainFrame->view()->forceLayout();
 
             // scroll to restore current screen center
             if (node) {
@@ -1382,9 +1387,8 @@ void WebViewCore::setSizeScreenWidthAndScale(int width, int height,
         if (width != screenWidth) {
             m_mainFrame->view()->setUseFixedLayout(true);
             m_mainFrame->view()->setFixedLayoutSize(IntSize(width, height));
-        } else {
+        } else
             m_mainFrame->view()->setUseFixedLayout(false);
-        }
     }
 
     // update the currently visible screen as perceived by the plugin