Bug 1521188 - Make findGridParentContainerForNode not depend on the walker; r=gl
authorPatrick Brosset <pbrosset@mozilla.com>
Tue, 21 May 2019 14:30:33 +0000
changeset 474760 1d79999a70f3ffd534c55fd4093d7c766a04f942
parent 474759 9051ccc6218a54481d16a929c33cf0f9beab5f1c
child 474761 2a4a5afa1ff204c9052697e573391992ee99e4c7
push id36046
push useraiakab@mozilla.com
push dateTue, 21 May 2019 21:45:52 +0000
treeherdermozilla-central@257f2c96cef5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1521188
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1521188 - Make findGridParentContainerForNode not depend on the walker; r=gl Differential Revision: https://phabricator.services.mozilla.com/D31633
devtools/server/actors/layout.js
--- a/devtools/server/actors/layout.js
+++ b/devtools/server/actors/layout.js
@@ -7,17 +7,16 @@
 const { Cu } = require("chrome");
 const { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
 const {
   flexboxSpec,
   flexItemSpec,
   gridSpec,
   layoutSpec,
 } = require("devtools/shared/specs/layout");
-const { SHOW_ELEMENT } = require("devtools/shared/dom-node-filter-constants");
 const { getStringifiableFragments } =
   require("devtools/server/actors/utils/css-grid-utils");
 
 loader.lazyRequireGetter(this, "CssLogic", "devtools/server/actors/inspector/css-logic", true);
 loader.lazyRequireGetter(this, "getCSSStyleRules", "devtools/shared/inspector/css-logic", true);
 loader.lazyRequireGetter(this, "isCssPropertyKnown", "devtools/server/actors/css-properties", true);
 loader.lazyRequireGetter(this, "parseDeclarations", "devtools/shared/css/parsing-utils", true);
 loader.lazyRequireGetter(this, "nodeConstants", "devtools/shared/dom-node-constants");
@@ -370,17 +369,17 @@ const LayoutActor = ActorClassWithSpec(l
     // container.
     // Note that text nodes that are children of flex/grid containers are wrapped in
     // anonymous containers, so even if their displayType getter returns null we still
     // want to walk up the chain to find their container.
     const parentFlexElement = node.parentFlexElement;
     if (parentFlexElement && flexType) {
       return new FlexboxActor(this, parentFlexElement);
     }
-    const container = findGridParentContainerForNode(node, this.walker);
+    const container = findGridParentContainerForNode(node);
     if (container && gridType) {
       return new GridActor(this, container);
     }
 
     return null;
   },
 
   /**
@@ -456,35 +455,27 @@ function isNodeDead(node) {
   return !node || (node.rawNode && Cu.isDeadWrapper(node.rawNode));
 }
 
 /**
  * If the provided node is a grid item, then return its parent grid.
  *
  * @param  {DOMNode} node
  *         The node that is supposedly a grid item.
- * @param  {WalkerActor} walkerActor
- *         The current instance of WalkerActor.
  * @return {DOMNode|null}
  *         The parent grid if found, null otherwise.
  */
-function findGridParentContainerForNode(node, walker) {
-  const treeWalker = walker.getDocumentWalker(node, SHOW_ELEMENT);
-  let currentNode = treeWalker.currentNode;
-
+function findGridParentContainerForNode(node) {
   try {
-    while ((currentNode = treeWalker.parentNode())) {
-      const displayType = walker.getNode(currentNode).displayType;
-      if (!displayType) {
-        break;
-      }
+    while ((node = node.parentNode)) {
+      const display = node.ownerGlobal.getComputedStyle(node).display;
 
-      if (displayType.includes("grid")) {
-        return currentNode;
-      } else if (displayType === "contents") {
+      if (display.includes("grid")) {
+        return node;
+      } else if (display === "contents") {
         // Continue walking up the tree since the parent node is a content element.
         continue;
       }
 
       break;
     }
   } catch (e) {
     // Getting the parentNode can fail when the supplied node is in shadow DOM.