Avoid compositing invisible fixed positioned elements
authorwangxianzhu@chromium.org <wangxianzhu@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Feb 2012 06:34:52 +0000 (06:34 +0000)
committerwangxianzhu@chromium.org <wangxianzhu@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Feb 2012 06:34:52 +0000 (06:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78186

Reviewed by James Robinson.

Source/WebCore:

Test: compositing/layer-creation/fixed-position-out-of-view.html

* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::requiresCompositingForPosition):

LayoutTests:

* compositing/layer-creation/fixed-position-out-of-view-expected.txt: Added.
* compositing/layer-creation/fixed-position-out-of-view.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/compositing/layer-creation/fixed-position-out-of-view-expected.txt [new file with mode: 0644]
LayoutTests/compositing/layer-creation/fixed-position-out-of-view.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderLayerCompositor.cpp

index 30c6835..3538f38 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-09  Xianzhu Wang  <wangxianzhu@chromium.org>
+
+        Avoid compositing invisible fixed positioned elements
+        https://bugs.webkit.org/show_bug.cgi?id=78186
+
+        Reviewed by James Robinson.
+
+        * compositing/layer-creation/fixed-position-out-of-view-expected.txt: Added.
+        * compositing/layer-creation/fixed-position-out-of-view.html: Added.
+
 2012-02-09  James Robinson  <jamesr@chromium.org>
 
         [chromium] Update compositing test baselines for mock scrollbars
diff --git a/LayoutTests/compositing/layer-creation/fixed-position-out-of-view-expected.txt b/LayoutTests/compositing/layer-creation/fixed-position-out-of-view-expected.txt
new file mode 100644 (file)
index 0000000..7592a52
--- /dev/null
@@ -0,0 +1,24 @@
+(GraphicsLayer
+  (bounds 785.00 1021.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 785.00 600.00)
+      (children 1
+        (GraphicsLayer
+          (bounds 785.00 1021.00)
+          (drawsContent 1)
+          (children 2
+            (GraphicsLayer
+              (bounds 10.00 10.00)
+            )
+            (GraphicsLayer
+              (bounds 785.00 1021.00)
+              (drawsContent 1)
+            )
+          )
+        )
+      )
+    )
+  )
+)
+
diff --git a/LayoutTests/compositing/layer-creation/fixed-position-out-of-view.html b/LayoutTests/compositing/layer-creation/fixed-position-out-of-view.html
new file mode 100644 (file)
index 0000000..6525ca3
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+  <style>
+    .fixed {
+      position: fixed;
+      width: 10px;
+      height: 10px;
+    }
+  </style>
+
+  <script type="text/javascript">
+    if (window.internals)
+      window.internals.settings.setEnableCompositingForFixedPosition(true);
+
+    if (window.layoutTestController) {
+      layoutTestController.dumpAsText();
+
+      window.addEventListener("load", function() {
+        document.getElementById("layertree").innerText = layoutTestController.layerTreeAsText();
+      }, false);
+    }
+  </script>
+</head>
+
+<body>
+  <div style="height: 1000px">
+    <pre id="layertree"></pre>
+  </div>
+
+  <!-- Neither of the following elements gets its own layer. -->
+  <div class="fixed" style="z-index: -1"></div>
+  <div class="fixed" style="z-index: -1; top: -100px"></div>
+  <div class="fixed" style="z-index: -1; top: 0px; left: 1000px"></div>
+
+  <!-- This element gets its own layer because it intersects with the viewport. -->
+  <div class="fixed" style="z-index: -1; top: 0px; left: 0px"></div>
+</body>
+</html>
+
index 5a5bd1d..f6e0473 100644 (file)
@@ -1,3 +1,15 @@
+2012-02-09  Xianzhu Wang  <wangxianzhu@chromium.org>
+
+        Avoid compositing invisible fixed positioned elements
+        https://bugs.webkit.org/show_bug.cgi?id=78186
+
+        Reviewed by James Robinson.
+
+        Test: compositing/layer-creation/fixed-position-out-of-view.html
+
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::requiresCompositingForPosition):
+
 2012-02-09  Timothy Hatcher  <timothy@apple.com>
 
         Prevent attaching when inspecting the Web Inspector.
index 6d4668b..5942520 100644 (file)
@@ -1567,6 +1567,11 @@ bool RenderLayerCompositor::requiresCompositingForPosition(RenderObject* rendere
     if (container != m_renderView)
         return false;
 
+    // Fixed position elements that are invisible in the current view don't get their own layer.
+    FrameView* frameView = m_renderView->frameView();
+    if (frameView && !layer->absoluteBoundingBox().intersects(LayoutRect(frameView->scrollXForFixedPosition(), frameView->scrollYForFixedPosition(), frameView->layoutWidth(), frameView->layoutHeight())))
+        return false;
+
     return true;
 }