Bug 1345119 - Part 2: Server side for retrieving offset parent of DOM node. r?pbro draft
authorStanford Lockhart <lockhart@cs.dal.ca>
Fri, 17 Mar 2017 23:05:27 -0300
changeset 502540 ef133157654a
parent 502539 d94f211b5df2
child 502541 e2ec41d82878
push id50319
push userbmo:lockhart@cs.dal.ca
push dateWed, 22 Mar 2017 01:00:22 +0000
reviewerspbro
bugs1345119
milestone55.0a1
Bug 1345119 - Part 2: Server side for retrieving offset parent of DOM node. r?pbro MozReview-Commit-ID: I51NHlxv6Mp
devtools/server/actors/inspector.js
devtools/shared/specs/inspector.js
devtools/shared/specs/node.js
--- a/devtools/server/actors/inspector.js
+++ b/devtools/server/actors/inspector.js
@@ -745,17 +745,17 @@ var NodeActor = exports.NodeActor = prot
     let options = {
       previewText: FONT_FAMILY_PREVIEW_TEXT,
       previewFontSize: FONT_FAMILY_PREVIEW_TEXT_SIZE,
       fillStyle: fillStyle
     };
     let { dataURL, size } = getFontPreviewData(font, doc, options);
 
     return { data: LongStringActor(this.conn, dataURL), size: size };
-  }
+  },
 });
 
 /**
  * Server side of a node list as returned by querySelectorAll()
  */
 var NodeListActor = exports.NodeListActor = protocol.ActorClassWithSpec(nodeListSpec, {
   typeName: "domnodelist",
 
@@ -2642,16 +2642,32 @@ var WalkerActor = protocol.ActorClassWit
    */
   getLayoutInspector: function () {
     if (!this.layoutActor) {
       this.layoutActor = new LayoutActor(this.conn, this.tabActor, this);
     }
 
     return this.layoutActor;
   },
+
+  /**
+   * Get the offset parent of the node
+   * If the offset parent is statically positioned, there is no offset parent
+   * and null is returned.
+   * Returns the DOMNode for the offset parent if it exists
+   */
+  getOffsetParent: function (domnode) {
+    let offsetParent = domnode.rawNode.offsetParent;
+
+    if (!offsetParent || CssLogic.getComputedStyle(offsetParent).position === "static") {
+      return null;
+    }
+
+    return this._ref(offsetParent);
+  },
 });
 
 /**
  * Server side of the inspector actor, which is used to create
  * inspector-related actors, including the walker.
  */
 exports.InspectorActor = protocol.ActorClassWithSpec(inspectorSpec, {
   initialize: function (conn, tabActor) {
@@ -2887,17 +2903,17 @@ exports.InspectorActor = protocol.ActorC
   },
 
   _onColorPicked: function (e, color) {
     events.emit(this, "color-picked", color);
   },
 
   _onColorPickCanceled: function () {
     events.emit(this, "color-pick-canceled");
-  }
+  },
 });
 
 // Exported for test purposes.
 exports._documentWalker = DocumentWalker;
 
 function nodeDocument(node) {
   if (Cu.isDeadWrapper(node)) {
     return null;
--- a/devtools/shared/specs/inspector.js
+++ b/devtools/shared/specs/inspector.js
@@ -369,17 +369,25 @@ const walkerSpec = generateActorSpec({
         node: RetVal("nullable:disconnectedNode")
       }
     },
     getLayoutInspector: {
       request: {},
       response: {
         actor: RetVal("layout")
       }
-    }
+    },
+    getOffsetParent: {
+      request: {
+        node: Arg(0, "domnode")
+      },
+      response: {
+        node: RetVal("nullable:domnode")
+      }
+    },
   }
 });
 
 exports.walkerSpec = walkerSpec;
 
 const inspectorSpec = generateActorSpec({
   typeName: "inspector",
 
--- a/devtools/shared/specs/node.js
+++ b/devtools/shared/specs/node.js
@@ -61,13 +61,13 @@ const nodeSpec = generateActorSpec({
       request: {
         modifications: Arg(0, "array:json")
       },
       response: {}
     },
     getFontFamilyDataURL: {
       request: {font: Arg(0, "string"), fillStyle: Arg(1, "nullable:string")},
       response: RetVal("imageData")
-    }
+    },
   }
 });
 
 exports.nodeSpec = nodeSpec;