bug 1403871 - use getElementsWithGrid to retrieve grid containers in devtools;r=gl draft
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 21 Nov 2017 15:28:22 +0100
changeset 701562 df0bb583afa34df7d0a6b25e2e733f253863d030
parent 701561 db3c8ab4afd726379294198bdadd3383a6a73f1f
child 701563 c1aaa0195adea95e1158edb6943060e73684a605
push id90196
push userjdescottes@mozilla.com
push dateTue, 21 Nov 2017 20:45:38 +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.