Web Inspector: identify reflection layers in LayerTreeAgent
authorgraouts@apple.com <graouts@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Mar 2013 22:48:54 +0000 (22:48 +0000)
committergraouts@apple.com <graouts@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Mar 2013 22:48:54 +0000 (22:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=111419

Source/WebCore:

We add a new property "isReflection" to the Layer objects returned
to the front-end to indicate whether the layer was created to host
the reflection for an element. When this new property is true, the
"nodeId" property is set to point to the reflected element's node
id, since there is no node per-se directly associated with this layer.
We also change the "bounds" property to return absolute page coordinates
such that the front-end can use this information to highlight that
region in the page since metrics would otherwise be unavailable.

Reviewed by Dean Jackson.

Test: inspector-protocol/layers/layers-reflected-content.html

* inspector/Inspector.json:
* inspector/InspectorLayerTreeAgent.cpp:
(WebCore::InspectorLayerTreeAgent::buildObjectForLayer):

LayoutTests:

New test for reflection layers and an updated output for the
existing layersForNode() test since we changed the coordinates
for the "bounds" property to be absolute instead of local.

Reviewed by Dean Jackson.

* inspector-protocol/layers/layers-for-node-expected.txt:
* inspector-protocol/layers/layers-reflected-content-expected.txt: Added.
* inspector-protocol/layers/layers-reflected-content.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector-protocol/layers/layers-for-node-expected.txt
LayoutTests/inspector-protocol/layers/layers-reflected-content-expected.txt [new file with mode: 0644]
LayoutTests/inspector-protocol/layers/layers-reflected-content.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorLayerTreeAgent.cpp

index 5eb1803..c64ed81 100644 (file)
@@ -1,3 +1,18 @@
+2013-03-05  Antoine Quint  <graouts@apple.com>
+
+        Web Inspector: identify reflection layers in LayerTreeAgent
+        https://bugs.webkit.org/show_bug.cgi?id=111419
+
+        New test for reflection layers and an updated output for the
+        existing layersForNode() test since we changed the coordinates
+        for the "bounds" property to be absolute instead of local.
+
+        Reviewed by Dean Jackson.
+
+        * inspector-protocol/layers/layers-for-node-expected.txt:
+        * inspector-protocol/layers/layers-reflected-content-expected.txt: Added.
+        * inspector-protocol/layers/layers-reflected-content.html: Added.
+
 2013-03-05  Alok Priyadarshi  <alokp@chromium.org>
 
         Rebaseline text output for opaque GraphicsLayers
index 794d61b..399baca 100644 (file)
@@ -34,8 +34,8 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
-            "y": 0,
+            "x": 25,
+            "y": 25,
             "width": 50,
             "height": 50
         },
@@ -52,8 +52,8 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
-            "y": 0,
+            "x": 50,
+            "y": 50,
             "width": 50,
             "height": 50
         },
@@ -70,7 +70,7 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
+            "x": 200,
             "y": 0,
             "width": 100,
             "height": 100
@@ -88,8 +88,8 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
-            "y": 0,
+            "x": 225,
+            "y": 25,
             "width": 50,
             "height": 50
         },
@@ -153,8 +153,8 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
-            "y": 0,
+            "x": 25,
+            "y": 25,
             "width": 50,
             "height": 50
         },
@@ -171,8 +171,8 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
-            "y": 0,
+            "x": 50,
+            "y": 50,
             "width": 50,
             "height": 50
         },
@@ -189,7 +189,7 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
+            "x": 200,
             "y": 0,
             "width": 100,
             "height": 100
@@ -207,8 +207,8 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
-            "y": 0,
+            "x": 225,
+            "y": 25,
             "width": 50,
             "height": 50
         },
@@ -243,8 +243,8 @@ PASS
         "layerId": "string",
         "nodeId": "number",
         "bounds": {
-            "x": 0,
-            "y": 0,
+            "x": 25,
+            "y": 25,
             "width": 50,
             "height": 50
         },
diff --git a/LayoutTests/inspector-protocol/layers/layers-reflected-content-expected.txt b/LayoutTests/inspector-protocol/layers/layers-reflected-content-expected.txt
new file mode 100644 (file)
index 0000000..d5d8909
--- /dev/null
@@ -0,0 +1,26 @@
+
+=== Enable the LayerTree agent ===
+
+PASS
+
+=== Get the Document ===
+
+PASS
+
+=== Get the layer tree ===
+
+PASS
+
+=== Check layers ===
+
+PASS: Expected number of reflected layers.
+PASS: First reflected layer has a node.
+
+=== Check reflected node ===
+
+PASS: Node for layer was found.
+PASS: Node has expected localName.
+PASS: Node has expected number of attributes.
+PASS: Node has CSS class.
+PASS: Node has expected CSS class.
+
diff --git a/LayoutTests/inspector-protocol/layers/layers-reflected-content.html b/LayoutTests/inspector-protocol/layers/layers-reflected-content.html
new file mode 100644 (file)
index 0000000..60961f5
--- /dev/null
@@ -0,0 +1,149 @@
+<html>
+<head>
+<script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
+<script type="text/javascript">
+
+function test()
+{
+
+    var nodes;
+    InspectorTest.eventHandler["DOM.setChildNodes"] = setChildNodes;
+
+    enableLayerTreeAgent();
+    
+    function enableLayerTreeAgent(result)
+    {
+        step({
+            name: "Enable the LayerTree agent",
+            command: "LayerTree.enable",
+            parameters: {},
+            callback: getDocument
+        });
+    };
+
+    function getDocument()
+    {
+        // We must first get the document so that later on we may get sensible nodeIds.
+        step({
+            name: "Get the Document",
+            command: "DOM.getDocument",
+            parameters: {},
+            callback: getLayerTree
+        });
+    };
+
+    function getLayerTree(result)
+    {
+        step({
+            name: "Get the layer tree",
+            command: "LayerTree.layersForNode",
+            parameters: {"nodeId": result.root.nodeId},
+            callback: gotLayerTree
+        });
+    };
+
+    function gotLayerTree(result)
+    {
+        var reflectedLayers = result.layers.filter(function(layer) {
+            return layer.isReflection;
+        });
+
+        logTestName("Check layers");
+
+        assert("Expected number of reflected layers", reflectedLayers.length, 1);
+        assert("First reflected layer has a node", reflectedLayers[0].nodeId > 0, true);
+
+
+        logTestName("Check reflected node");
+
+        var node;
+        var nodeId = reflectedLayers[0].nodeId;
+        for (var i = 0, count = nodes.length; i < count; ++i) {
+            if (nodes[i].nodeId === nodeId) {
+                node = nodes[i];
+                break;
+            }
+        }
+
+        assert("Node for layer was found", !!node, true);
+        assert("Node has expected localName", node.localName, "div");
+        assert("Node has expected number of attributes", node.attributes.length, 2);
+        assert("Node has CSS class", node.attributes[0], "class");
+        assert("Node has expected CSS class", node.attributes[1], "reflected composited");
+        
+        InspectorTest.completeTest();
+    };
+
+    function setChildNodes (messageObject) {
+        nodes = messageObject.params.nodes;
+    };
+
+    function step(test)
+    {
+        if (test.callback)
+            logTestName(test.name);
+        runCommand(test);
+    };
+
+    function logTestName(name)
+    {
+        InspectorTest.log("\n=== " + name + " ===\n");
+    };
+
+    function runCommand(command)
+    {
+        InspectorTest.sendCommand(command.command, command.parameters, function(messageObject) {
+            if (messageObject.hasOwnProperty("error")) {
+                InspectorTest.log("FAIL: " + messageObject.error.message + " (" + messageObject.error.code + ")");
+                InspectorTest.completeTest();
+                return;
+            }
+
+            if (command.name)
+                InspectorTest.log("PASS");
+
+            if (command.callback)
+                command.callback(messageObject.result);
+        });
+    };
+
+    function assert(name, actual, expected)
+    {
+        if (expected === actual)
+            InspectorTest.log("PASS: " + name + ".");
+        else
+            InspectorTest.log("FAIL: " + name + ". Expected " + expected + " but got " + actual);
+    };
+
+};
+
+window.addEventListener("DOMContentLoaded", function()
+{
+    runTest();
+}, false);
+
+</script>
+<style type="text/css">
+
+    .reflected {
+        position: absolute;
+        width: 100px;
+        height: 100px;
+        background-color: black;
+        -webkit-box-reflect: below;
+    }
+
+    .composited {
+        -webkit-transform: translateZ(0);
+    }
+
+</style>
+</head>
+<body>
+
+    <div class="reflected"></div>
+    <div class="reflected composited"></div>
+
+</body>
+</html>
index cb99fa3..2b7c4aa 100644 (file)
@@ -1,3 +1,25 @@
+2013-03-05  Antoine Quint  <graouts@apple.com>
+
+        Web Inspector: identify reflection layers in LayerTreeAgent
+        https://bugs.webkit.org/show_bug.cgi?id=111419
+
+        We add a new property "isReflection" to the Layer objects returned
+        to the front-end to indicate whether the layer was created to host
+        the reflection for an element. When this new property is true, the
+        "nodeId" property is set to point to the reflected element's node
+        id, since there is no node per-se directly associated with this layer.
+        We also change the "bounds" property to return absolute page coordinates
+        such that the front-end can use this information to highlight that
+        region in the page since metrics would otherwise be unavailable.
+
+        Reviewed by Dean Jackson.
+
+        Test: inspector-protocol/layers/layers-reflected-content.html
+
+        * inspector/Inspector.json:
+        * inspector/InspectorLayerTreeAgent.cpp:
+        (WebCore::InspectorLayerTreeAgent::buildObjectForLayer):
+
 2013-03-05  peavo@outlook.com  <peavo@outlook.com>
 
         [WinCairo] Compile fix after r144024.
index fbe30b2..e87df36 100644 (file)
                 "properties": [
                     { "name": "layerId", "$ref": "LayerId", "description": "The unique id for this layer." },
                     { "name": "nodeId", "$ref": "DOM.NodeId", "description": "The id for the node associated with this layer." },
-                    { "name": "bounds", "$ref": "IntRect", "description": "Bounds of the layer." },
+                    { "name": "bounds", "$ref": "IntRect", "description": "Bounds of the layer in absolute page coordinates." },
                     { "name": "paintCount", "type": "integer", "description": "Indicates how many time this layer has painted." },
                     { "name": "memory", "type": "integer", "description": "Estimated memory used by this layer." },
                     { "name": "compositedBounds", "$ref": "IntRect", "description": "The bounds of the composited layer." },
-                    { "name": "isInShadowTree", "type": "boolean", "optional": true, "description": "Indicates whether this layer is associated with an element hosted in a shadow tree." }
+                    { "name": "isInShadowTree", "type": "boolean", "optional": true, "description": "Indicates whether this layer is associated with an element hosted in a shadow tree." },
+                    { "name": "isReflection", "type": "boolean", "optional": true, "description": "Indicates whether this layer was used to provide a reflection for the element." }
                 ]
             }
         ],
index 22ab8a7..5119ccc 100644 (file)
@@ -150,14 +150,17 @@ void InspectorLayerTreeAgent::gatherLayersUsingRenderLayerHierarchy(ErrorString*
 
 PassRefPtr<TypeBuilder::LayerTree::Layer> InspectorLayerTreeAgent::buildObjectForLayer(ErrorString* errorString, RenderLayer* renderLayer)
 {
-    Node* node = renderLayer->renderer()->node();
+    bool isReflection = renderLayer->isReflection();
+
+    RenderObject* renderer = renderLayer->renderer();
     RenderLayerBacking* backing = renderLayer->backing();
+    Node* node = isReflection ? renderer->parent()->node() : renderer->node();
 
     // Basic set of properties.
     RefPtr<TypeBuilder::LayerTree::Layer> layerObject = TypeBuilder::LayerTree::Layer::create()
         .setLayerId(bind(renderLayer))
         .setNodeId(idForNode(errorString, node))
-        .setBounds(buildObjectForIntRect(enclosingIntRect(renderLayer->localBoundingBox())))
+        .setBounds(buildObjectForIntRect(enclosingIntRect(renderer->absoluteBoundingBoxRect())))
         .setMemory(backing->backingStoreMemoryEstimate())
         .setCompositedBounds(buildObjectForIntRect(backing->compositedBounds()))
         .setPaintCount(backing->graphicsLayer()->repaintCount());
@@ -165,6 +168,9 @@ PassRefPtr<TypeBuilder::LayerTree::Layer> InspectorLayerTreeAgent::buildObjectFo
     if (node && node->shadowHost())
         layerObject->setIsInShadowTree(true);
 
+    if (isReflection)
+        layerObject->setIsReflection(true);
+
     return layerObject;
 }