Frame flattening: Change the logic on whether resize event needs to be dispatched.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Aug 2013 08:58:23 +0000 (08:58 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Aug 2013 08:58:23 +0000 (08:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=119394

Reviewed by Simon Fraser.

http://trac.webkit.org/changeset/149287 changed the logic so that resize events are
sent out from FrameView::setFrameRect() too. Checking whether frame flattening is
enabled is sufficient enough to ensure that no extra resize events are dispatched.

Source/WebCore:

Test: fast/frames/flattening/iframe-flattening-resize-event-count.html

* page/FrameView.cpp:
(WebCore::FrameView::FrameView):
(WebCore::FrameView::setFrameRect):
(WebCore::FrameView::frameFlatteningEnabled):
(WebCore::FrameView::supportsFrameFlattening):
(WebCore::FrameView::avoidScrollbarCreation):
(WebCore::FrameView::calculateScrollbarModesForLayout):
(WebCore::FrameView::layout):
(WebCore::FrameView::isInChildFrameWithFrameFlattening):
* page/FrameView.h:
* rendering/RenderFrameBase.cpp:
(WebCore::RenderFrameBase::layoutWithFlattening):

LayoutTests:

* fast/frames/flattening/iframe-flattening-resize-event-count-expected.txt: Added.
* fast/frames/flattening/iframe-flattening-resize-event-count.html: Added.
* fast/frames/flattening/resources/iframe-to-resize.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@153640 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/frames/flattening/iframe-flattening-resize-event-count-expected.txt [new file with mode: 0644]
LayoutTests/fast/frames/flattening/iframe-flattening-resize-event-count.html [new file with mode: 0644]
LayoutTests/fast/frames/flattening/resources/iframe-to-resize.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/rendering/RenderFrameBase.cpp

index 0aca352..23cc3c3 100644 (file)
@@ -1,3 +1,18 @@
+2013-08-02  Zalan Bujtas  <zalan@apple.com>
+
+        Frame flattening: Change the logic on whether resize event needs to be dispatched.
+        https://bugs.webkit.org/show_bug.cgi?id=119394
+
+        Reviewed by Simon Fraser.
+
+        http://trac.webkit.org/changeset/149287 changed the logic so that resize events are
+        sent out from FrameView::setFrameRect() too. Checking whether frame flattening is
+        enabled is sufficient enough to ensure that no extra resize events are dispatched.
+
+        * fast/frames/flattening/iframe-flattening-resize-event-count-expected.txt: Added.
+        * fast/frames/flattening/iframe-flattening-resize-event-count.html: Added.
+        * fast/frames/flattening/resources/iframe-to-resize.html: Added.
+
 2013-08-01  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r153608.
diff --git a/LayoutTests/fast/frames/flattening/iframe-flattening-resize-event-count-expected.txt b/LayoutTests/fast/frames/flattening/iframe-flattening-resize-event-count-expected.txt
new file mode 100644 (file)
index 0000000..48b548d
--- /dev/null
@@ -0,0 +1,5 @@
+This tests the number of resize events dispatched to JavaScript.
+
+PASS
+
+
diff --git a/LayoutTests/fast/frames/flattening/iframe-flattening-resize-event-count.html b/LayoutTests/fast/frames/flattening/iframe-flattening-resize-event-count.html
new file mode 100644 (file)
index 0000000..ad0cd02
--- /dev/null
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+  function start() {
+    if (window.internals)
+      internals.settings.setFrameFlatteningEnabled(true);
+      
+    if (window.testRunner) {
+      testRunner.dumpAsText();
+      testRunner.waitUntilDone();
+    }
+  }
+</script>
+</head>
+<body>
+  <p>This tests the number of resize events dispatched to JavaScript.</p>
+  <p id='result'></p>
+  <iframe onload='start();' frameborder=0; src='resources/iframe-to-resize.html'>
+</body>
+</html>
diff --git a/LayoutTests/fast/frames/flattening/resources/iframe-to-resize.html b/LayoutTests/fast/frames/flattening/resources/iframe-to-resize.html
new file mode 100644 (file)
index 0000000..1deaa79
--- /dev/null
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <script>
+  var resizeEventCounter = 0;
+  var resizeCounter = 0;
+  
+  window.onresize = function(event) {
+    resizeEventCounter++;
+  }
+
+  function getRandomArbitrary(min, max) {
+    return Math.random() * (max - min) + min;
+  }
+
+  function resizeMe() {
+    document.getElementById('contentToResize').style.height = getRandomArbitrary(50, 500) + 'px';
+    document.body.offsetHeight;
+  
+    if (++resizeCounter < 100)
+      setTimeout('resizeMe();', 0);
+    else {
+      parent.document.getElementById('result').innerHTML = resizeEventCounter > 100 ? "FAILED. Too many resize events" : "PASS";
+      if (window.testRunner)
+        testRunner.notifyDone();
+    }
+  }
+  
+</script>
+</head>
+<body onload='resizeMe();'>
+    <p id='contentToResize'></p>
+</body>
+</html>
index fd06a09..6408aae 100644 (file)
@@ -1,3 +1,29 @@
+2013-08-02  Zalan Bujtas  <zalan@apple.com>
+
+        Frame flattening: Change the logic on whether resize event needs to be dispatched.
+        https://bugs.webkit.org/show_bug.cgi?id=119394
+
+        Reviewed by Simon Fraser.
+
+        http://trac.webkit.org/changeset/149287 changed the logic so that resize events are
+        sent out from FrameView::setFrameRect() too. Checking whether frame flattening is
+        enabled is sufficient enough to ensure that no extra resize events are dispatched.
+
+        Test: fast/frames/flattening/iframe-flattening-resize-event-count.html
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::FrameView):
+        (WebCore::FrameView::setFrameRect):
+        (WebCore::FrameView::frameFlatteningEnabled):
+        (WebCore::FrameView::supportsFrameFlattening):
+        (WebCore::FrameView::avoidScrollbarCreation):
+        (WebCore::FrameView::calculateScrollbarModesForLayout):
+        (WebCore::FrameView::layout):
+        (WebCore::FrameView::isInChildFrameWithFrameFlattening):
+        * page/FrameView.h:
+        * rendering/RenderFrameBase.cpp:
+        (WebCore::RenderFrameBase::layoutWithFlattening):
+
 2013-08-01  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r153608.
index 88d44f7..149eeec 100644 (file)
@@ -204,7 +204,6 @@ FrameView::FrameView(Frame* frame)
 #endif
     , m_visualUpdatesAllowedByClient(true)
     , m_scrollPinningBehavior(DoNotPin)
-    , m_resizeEventAllowed(true)
 {
     init();
 
@@ -482,7 +481,7 @@ void FrameView::setFrameRect(const IntRect& newRect)
     }
 #endif
 
-    if (m_resizeEventAllowed)
+    if (!frameFlatteningEnabled())
         sendResizeEventIfNeeded();
 }
 
@@ -509,30 +508,35 @@ void FrameView::setMarginHeight(LayoutUnit h)
     m_margins.setHeight(h);
 }
 
-static bool frameFlatteningEnabled(Frame* frame)
+bool FrameView::frameFlatteningEnabled() const
 {
-    return frame && frame->settings() && frame->settings()->frameFlatteningEnabled();
+    Settings* settings = frame() ? frame()->settings() : 0;
+    if (!settings)
+        return false;
+
+    return settings->frameFlatteningEnabled();
 }
 
-static bool supportsFrameFlattening(Frame* frame)
+bool FrameView::isFrameFlatteningValidForThisFrame() const
 {
-    if (!frame)
+    if (!frameFlatteningEnabled())
+        return false;
+
+    HTMLFrameOwnerElement* owner = frame() ? frame()->ownerElement() : 0;
+    if (!owner)
         return false;
 
     // Frame flattening is valid only for <frame> and <iframe>.
-    HTMLFrameOwnerElement* owner = frame->ownerElement();
-    return owner && (owner->hasTagName(frameTag) || owner->hasTagName(iframeTag));
+    return owner->hasTagName(frameTag) || owner->hasTagName(iframeTag);
 }
 
 bool FrameView::avoidScrollbarCreation() const
 {
     ASSERT(m_frame);
-
     // with frame flattening no subframe can have scrollbars
     // but we also cannot turn scrollbars off as we determine
     // our flattening policy using that.
-
-    return frameFlatteningEnabled(frame()) && supportsFrameFlattening(frame());
+    return isFrameFlatteningValidForThisFrame();
 }
 
 void FrameView::setCanHaveScrollbars(bool canHaveScrollbars)
@@ -743,7 +747,7 @@ void FrameView::calculateScrollbarModesForLayout(ScrollbarMode& hMode, Scrollbar
         RenderObject* rootRenderer = documentElement ? documentElement->renderer() : 0;
         Node* body = document->body();
         if (body && body->renderer()) {
-            if (body->hasTagName(framesetTag) && !frameFlatteningEnabled(frame())) {
+            if (body->hasTagName(framesetTag) && !frameFlatteningEnabled()) {
                 vMode = ScrollbarAlwaysOff;
                 hMode = ScrollbarAlwaysOff;
             } else if (body->hasTagName(bodyTag)) {
@@ -1235,7 +1239,7 @@ void FrameView::layout(bool allowSubtree)
             Document* document = m_frame->document();
             Node* body = document->body();
             if (body && body->renderer()) {
-                if (body->hasTagName(framesetTag) && !frameFlatteningEnabled(frame())) {
+                if (body->hasTagName(framesetTag) && !frameFlatteningEnabled()) {
                     body->renderer()->setChildNeedsLayout(true);
                 } else if (body->hasTagName(bodyTag)) {
                     if (!m_firstLayout && m_size.height() != layoutHeight() && body->renderer()->enclosingBox()->stretchesToViewport())
@@ -3464,7 +3468,7 @@ bool FrameView::isInChildFrameWithFrameFlattening() const
             return true;
     }
 
-    if (!frameFlatteningEnabled(frame()))
+    if (!frameFlatteningEnabled())
         return false;
 
     if (m_frame->ownerElement()->hasTagName(frameTag))
index 431b293..6040c9b 100644 (file)
@@ -439,9 +439,6 @@ public:
     
     void setScrollPinningBehavior(ScrollPinningBehavior);
 
-    void setResizeEventAllowed(bool resizeEventAllowed) { m_resizeEventAllowed = resizeEventAllowed; }
-    bool resizeEventAllowed() const { return m_resizeEventAllowed; }
-
 protected:
     virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect);
     virtual void scrollContentsSlowPath(const IntRect& updateRect);
@@ -538,6 +535,8 @@ private:
     FrameView* parentFrameView() const;
 
     bool doLayoutWithFrameFlattening(bool allowSubtree);
+    bool frameFlatteningEnabled() const;
+    bool isFrameFlatteningValidForThisFrame() const;
 
     bool qualifiesAsVisuallyNonEmpty() const;
 
@@ -674,7 +673,6 @@ private:
     bool m_visualUpdatesAllowedByClient;
     
     ScrollPinningBehavior m_scrollPinningBehavior;
-    bool m_resizeEventAllowed;
 };
 
 inline void FrameView::incrementVisuallyNonEmptyCharacterCount(unsigned count)
index b55cb79..94c0900 100644 (file)
@@ -65,8 +65,6 @@ void RenderFrameBase::layoutWithFlattening(bool hasFixedWidth, bool hasFixedHeig
         return;
     }
 
-    childFrameView->setResizeEventAllowed(false);
-
     // need to update to calculate min/max correctly
     updateWidgetPosition();
 
@@ -95,7 +93,6 @@ void RenderFrameBase::layoutWithFlattening(bool hasFixedWidth, bool hasFixedHeig
         setWidth(max<LayoutUnit>(width(), childFrameView->contentsWidth() + hBorder));
 
     updateWidgetPosition();
-    childFrameView->setResizeEventAllowed(true);
 
     ASSERT(!childFrameView->layoutPending());
     ASSERT(!childRoot->needsLayout());