bug 1403871 - use getElementsWithGrid to retrieve grid containers in devtools;r=gl
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 21 Nov 2017 15:28:22 +0100
changeset 701827 c9a12455c869b6c6774098f10431ec51d96dc932
parent 701826 731a141e8c319370c81c0ad8eb87fe9176fc9111
child 701828 fb858a306b2fdc693898184e9d4b328fa1c2772a
push id90298
push userbmo:bpostelnicu@mozilla.com
push dateWed, 22 Nov 2017 10:54:01 +0000
reviewersgl
bugs1403871
milestone59.0a1
bug 1403871 - use getElementsWithGrid to retrieve grid containers in devtools;r=gl MozReview-Commit-ID: 3AHPg5aEbBN
devtools/server/actors/layout.js
--- a/devtools/server/actors/layout.js
+++ b/devtools/server/actors/layout.js
@@ -5,16 +5,17 @@
 "use strict";
 
 const { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
 const { flexboxSpec, gridSpec, layoutSpec } = require("devtools/shared/specs/layout");
 const nodeFilterConstants = require("devtools/shared/dom-node-filter-constants");
 const { getStringifiableFragments } =
   require("devtools/server/actors/utils/css-grid-utils");
 
+loader.lazyRequireGetter(this, "nodeConstants", "devtools/shared/dom-node-constants");
 loader.lazyRequireGetter(this, "CssLogic", "devtools/server/css-logic", true);
 
 /**
  * Set of actors the expose the CSS layout information to the devtools protocol clients.
  *
  * The |Layout| actor is the main entry point. It is used to get various CSS
  * layout-related information from the document.
  *
@@ -192,43 +193,42 @@ const LayoutActor = ActorClassWithSpec(l
     for (let {document} of this.tabActor.windows) {
       flexboxes = [...flexboxes, ...this.getFlexbox(document.documentElement)];
     }
 
     return flexboxes;
   },
 
   /**
-   * Returns an array of GridActor objects for all the grid containers found by iterating
-   * below the given rootNode.
+   * Returns an array of GridActor objects for all the grid elements contained in the
+   * given root node.
    *
-   * @param  {Node|NodeActor} rootNode
-   *         The root node to start iterating at.
+   * @param  {Node} node
+   *         The root node for grid elements
    * @return {Array} An array of GridActor objects.
    */
-  getGrids(rootNode) {
-    let grids = [];
-
-    if (!rootNode) {
-      return grids;
+  getGrids(node) {
+    if (!node) {
+      return [];
     }
 
-    let treeWalker = this.walker.getDocumentWalker(rootNode,
-      nodeFilterConstants.SHOW_ELEMENT);
-
-    while (treeWalker.nextNode()) {
-      let currentNode = treeWalker.currentNode;
-
-      if (currentNode.getGridFragments && currentNode.getGridFragments().length > 0) {
-        let gridActor = new GridActor(this, currentNode);
-        grids.push(gridActor);
-      }
+    // Root node can be a #document object, which does not support getElementsWithGrid.
+    if (node.nodeType === nodeConstants.DOCUMENT_NODE) {
+      node = node.documentElement;
     }
 
-    return grids;
+    let gridElements = node.getElementsWithGrid();
+    let gridActors = gridElements.map(n => new GridActor(this, n));
+
+    let frames = node.querySelectorAll("iframe, frame");
+    for (let frame of frames) {
+      gridActors = gridActors.concat(this.getGrids(frame.contentDocument));
+    }
+
+    return gridActors;
   },
 
   /**
    * Returns an array of GridActor objects for all existing grid containers found by
    * iterating below the given rootNode and including nested frames.
    *
    * @param  {NodeActor} rootNode
    * @return {Array} An array of GridActor objects.