Tell ScrollView's child Widgets that their frame rects have changed when its own frame rect changes

r79167 moved some code from setFrameRect to setBoundsSize, including a call to
frameRectsChanged. This was done because positionScrollbarLayers, which is called by
frameRectsChanged, only needs to be called when the bounds change, not when the frame rect
changes. But the recursive calls inside frameRectsChanged *do* need to be called when the
frame rect changes.

This patch moves the positionScrollbarLayers call out of frameRectsChanged, since it needs
to be called at different times from frameRectsChanged. Then it restores the
frameRectsChanged call to setFrameRect, which fixes the bug.

Test: platform/win/plugins/iframe-inside-overflow.html

Fixes <http://webkit.org/b/60194> <rdar://problem/9383760> REGRESSION (r79167): Windowed
plugins in Google Reader don't move when the article list is scrolled

Reviewed by Dan Bernstein.

Source/WebCore:

* platform/ScrollView.cpp:
(WebCore::ScrollView::updateScrollbars): Added a positionScrollbarLayers call here now that
frameRectsChanged doesn't call it for us. Also added a FIXME because it seems strange to
call frameRectsChanged here when our frame rect hasn't changed.
(WebCore::ScrollView::setFrameRect): Added back the frameRectsChanged call that was removed
in r79167.
(WebCore::ScrollView::setBoundsSize): Replaced a frameRectsChanged call with a call to
positionScrollbarLayers. We were only calling frameRectsChanged here in order to get
positionScrollbarLayers to be called.
(WebCore::ScrollView::frameRectsChanged): Removed the call to positionScrollbarLayers. All
callers of frameRectsChanged have been updated to call positionScrollbarLayers if needed.

Tools:

Add a plugin test that dumps the plugin window's rect

* DumpRenderTree/TestNetscapePlugIn/Tests/win/DumpWindowRect.cpp: Added.
(DumpWindowRect::DumpWindowRect): Just call up to the base class.
(DumpWindowRect::performWindowGeometryTest): Find our window rect relative to the test
harness window and log it.

* DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj: Added DumpWindowRect.

LayoutTests:

Add a test for windowed plugins inside iframes inside scrolled overflow areas

* platform/win/plugins/iframe-inside-overflow-expected.txt: Added.
* platform/win/plugins/iframe-inside-overflow.html: Added.
(loaded): Scrolls the div and tells the plugin to start its test (which will cause its
window rect to be logged).
* platform/win/plugins/resources/dump-window-rect-iframe.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@86442 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index fd5e447..8b84f64 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,18 @@
+2011-05-13  Adam Roben  <aroben@apple.com>
+
+        Add a test for windowed plugins inside iframes inside scrolled overflow areas
+
+        Part of the test for <http://webkit.org/b/60194> <rdar://problem/9383760> REGRESSION
+        (r79167): Windowed plugins in Google Reader don't move when the article list is scrolled
+
+        Reviewed by Dan Bernstein.
+
+        * platform/win/plugins/iframe-inside-overflow-expected.txt: Added.
+        * platform/win/plugins/iframe-inside-overflow.html: Added.
+        (loaded): Scrolls the div and tells the plugin to start its test (which will cause its
+        window rect to be logged).
+        * platform/win/plugins/resources/dump-window-rect-iframe.html: Added.
+
 2011-05-02  Robert Hogan  <robert@webkit.org>
 
         Reviewed by Eric Seidel.
diff --git a/LayoutTests/platform/win/plugins/iframe-inside-overflow-expected.txt b/LayoutTests/platform/win/plugins/iframe-inside-overflow-expected.txt
new file mode 100644
index 0000000..944ddc7
--- /dev/null
+++ b/LayoutTests/platform/win/plugins/iframe-inside-overflow-expected.txt
@@ -0,0 +1,4 @@
+CONSOLE MESSAGE: line 0: PLUGIN: Plugin window rect: {left=-227, top=-189, right=73, bottom=111}
+This tests that windowed plugins inside iframes inside overflow areas obey the overflow area's scroll offset.
+
+
diff --git a/LayoutTests/platform/win/plugins/iframe-inside-overflow.html b/LayoutTests/platform/win/plugins/iframe-inside-overflow.html
new file mode 100644
index 0000000..5ea6426
--- /dev/null
+++ b/LayoutTests/platform/win/plugins/iframe-inside-overflow.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        function loaded() {
+            if (window.layoutTestController)
+                layoutTestController.dumpAsText();
+            var container = document.getElementsByTagName('div')[0];
+            container.scrollLeft = 300;
+            container.scrollTop = 300;
+            frames[0].document.getElementsByTagName('embed')[0].startTest();
+        }
+        addEventListener('load', loaded, false);
+    </script>
+    <style>
+        div {
+            float: left;
+            overflow: auto;
+            width: 100px;
+            height: 100px;
+        }
+        iframe {
+            width: 320px;
+            height: 320px;
+            border: none;
+        }
+    </style>
+</head>
+<body>
+    <p>This tests that windowed plugins inside iframes inside overflow areas obey the overflow area's scroll offset.</p>
+
+    <div>
+        <iframe src="resources/dump-window-rect-iframe.html"></iframe>
+    </div>
+</body>
+</html>
+
diff --git a/LayoutTests/platform/win/plugins/resources/dump-window-rect-iframe.html b/LayoutTests/platform/win/plugins/resources/dump-window-rect-iframe.html
new file mode 100644
index 0000000..6b3441e
--- /dev/null
+++ b/LayoutTests/platform/win/plugins/resources/dump-window-rect-iframe.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+        body {
+            margin: 0;
+        }
+        embed {
+            width: 300px;
+            height: 300px;
+            visibility: hidden;
+        }
+    </style>
+</head>
+<body>
+    <embed type="application/x-webkit-test-netscape" test="dump-window-rect"></embed>
+</body>
+</html>
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 2cd28b3..ba8b23e 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,37 @@
+2011-05-13  Adam Roben  <aroben@apple.com>
+
+        Tell ScrollView's child Widgets that their frame rects have changed when its own frame rect
+        changes
+
+        r79167 moved some code from setFrameRect to setBoundsSize, including a call to
+        frameRectsChanged. This was done because positionScrollbarLayers, which is called by
+        frameRectsChanged, only needs to be called when the bounds change, not when the frame rect
+        changes. But the recursive calls inside frameRectsChanged *do* need to be called when the
+        frame rect changes.
+
+        This patch moves the positionScrollbarLayers call out of frameRectsChanged, since it needs
+        to be called at different times from frameRectsChanged. Then it restores the
+        frameRectsChanged call to setFrameRect, which fixes the bug.
+
+        Test: platform/win/plugins/iframe-inside-overflow.html
+
+        Fixes <http://webkit.org/b/60194> <rdar://problem/9383760> REGRESSION (r79167): Windowed
+        plugins in Google Reader don't move when the article list is scrolled
+
+        Reviewed by Dan Bernstein.
+
+        * platform/ScrollView.cpp:
+        (WebCore::ScrollView::updateScrollbars): Added a positionScrollbarLayers call here now that
+        frameRectsChanged doesn't call it for us. Also added a FIXME because it seems strange to
+        call frameRectsChanged here when our frame rect hasn't changed.
+        (WebCore::ScrollView::setFrameRect): Added back the frameRectsChanged call that was removed
+        in r79167.
+        (WebCore::ScrollView::setBoundsSize): Replaced a frameRectsChanged call with a call to
+        positionScrollbarLayers. We were only calling frameRectsChanged here in order to get
+        positionScrollbarLayers to be called.
+        (WebCore::ScrollView::frameRectsChanged): Removed the call to positionScrollbarLayers. All
+        callers of frameRectsChanged have been updated to call positionScrollbarLayers if needed.
+
 2011-05-13  Martin Robinson  <mrobinson@igalia.com>
 
         Reviewed by Eric Seidel.
diff --git a/Source/WebCore/platform/ScrollView.cpp b/Source/WebCore/platform/ScrollView.cpp
index 95c18c1..a3a1745 100644
--- a/Source/WebCore/platform/ScrollView.cpp
+++ b/Source/WebCore/platform/ScrollView.cpp
@@ -579,7 +579,9 @@
     }
 
     if (hasHorizontalScrollbar != (m_horizontalScrollbar != 0) || hasVerticalScrollbar != (m_verticalScrollbar != 0)) {
+        // FIXME: Is frameRectsChanged really necessary here? Have any frame rects changed?
         frameRectsChanged();
+        positionScrollbarLayers();
         updateScrollCorner();
     }
 
@@ -817,6 +819,8 @@
         return;
 
     Widget::setFrameRect(newRect);
+
+    frameRectsChanged();
 }
 
 void ScrollView::setBoundsSize(const IntSize& newSize)
@@ -834,7 +838,7 @@
     if (!m_useFixedLayout)
         contentsResized();
 
-    frameRectsChanged();
+    positionScrollbarLayers();
 }
 
 void ScrollView::setInitialBoundsSize(const IntSize& newSize)
@@ -851,7 +855,6 @@
     HashSet<RefPtr<Widget> >::const_iterator end = m_children.end();
     for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current)
         (*current)->frameRectsChanged();
-    positionScrollbarLayers();
 }
 
 #if USE(ACCELERATED_COMPOSITING)
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index f23bff1..4995759 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,5 +1,21 @@
 2011-05-13  Adam Roben  <aroben@apple.com>
 
+        Add a plugin test that dumps the plugin window's rect
+
+        Part of the test for <http://webkit.org/b/60194> <rdar://problem/9383760> REGRESSION
+        (r79167): Windowed plugins in Google Reader don't move when the article list is scrolled
+
+        Reviewed by Dan Bernstein.
+
+        * DumpRenderTree/TestNetscapePlugIn/Tests/win/DumpWindowRect.cpp: Added.
+        (DumpWindowRect::DumpWindowRect): Just call up to the base class.
+        (DumpWindowRect::performWindowGeometryTest): Find our window rect relative to the test
+        harness window and log it.
+
+        * DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj: Added DumpWindowRect.
+
+2011-05-13  Adam Roben  <aroben@apple.com>
+
         Move code required for most tests of plugin window geometry into a base class
 
         WebKit2's asynchronous plugin window positioning makes testing window geometry tricky. By
diff --git a/Tools/DumpRenderTree/TestNetscapePlugIn/Tests/win/DumpWindowRect.cpp b/Tools/DumpRenderTree/TestNetscapePlugIn/Tests/win/DumpWindowRect.cpp
new file mode 100644
index 0000000..fc2fd45
--- /dev/null
+++ b/Tools/DumpRenderTree/TestNetscapePlugIn/Tests/win/DumpWindowRect.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "WindowGeometryTest.h"
+
+#include "PluginObject.h"
+
+using namespace std;
+
+// This plugin dumps its window rect (relative to the test harness window) to the console when it
+// is instantiated.
+
+class DumpWindowRect : public WindowGeometryTest {
+public:
+    DumpWindowRect(NPP, const string& identifier);
+
+private:
+    virtual void performWindowGeometryTest();
+};
+
+static PluginTest::Register<DumpWindowRect> registrar("dump-window-rect");
+
+DumpWindowRect::DumpWindowRect(NPP npp, const string& identifier)
+    : WindowGeometryTest(npp, identifier)
+{
+}
+
+
+void DumpWindowRect::performWindowGeometryTest()
+{
+    RECT rect;
+    if (!::GetClientRect(window(), &rect)) {
+        log("::GetClientRect failed");
+        return;
+    }
+
+    // MSDN says that calling ::MapWindowPoints this way will tell it to treat the points as a rect.
+    if (!::MapWindowPoints(window(), testHarnessWindow(), reinterpret_cast<LPPOINT>(&rect), 2)) {
+        log("::MapWindowPoints failed");
+        return;
+    }
+
+    log("Plugin window rect: {left=%d, top=%d, right=%d, bottom=%d}", rect.left, rect.top, rect.right, rect.bottom);
+}
diff --git a/Tools/DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj b/Tools/DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj
index 1a084a8..432546e 100644
--- a/Tools/DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj
+++ b/Tools/DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj
@@ -441,6 +441,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\Tests\win\DumpWindowRect.cpp"
+					>
+				</File>
+				<File
 					RelativePath="..\Tests\win\GetValueNetscapeWindow.cpp"
 					>
 				</File>