Bug 1308260 - Part 1: Emit an event with the new grid layout actors on page navigations from the LayoutActor. r=pbro
authorGabriel Luong <gabriel.luong@gmail.com>
Wed, 16 Nov 2016 00:52:32 +0900
changeset 322729 fef1eecca5bf6e3afa3b379974c4fe14c0342289
parent 322728 5c79c47c39795fbe4c530813d47663dea8813079
child 322730 b1a768d3a1ea834a4898e3c6703f295089b67f3b
push id30961
push userkwierso@gmail.com
push dateThu, 17 Nov 2016 01:08:03 +0000
treeherdermozilla-central@c27117f67fa3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1308260
milestone53.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 1308260 - Part 1: Emit an event with the new grid layout actors on page navigations from the LayoutActor. r=pbro
devtools/server/actors/layout.js
devtools/shared/specs/layout.js
--- a/devtools/server/actors/layout.js
+++ b/devtools/server/actors/layout.js
@@ -1,17 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const events = require("sdk/event/core");
 const { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
+const { getStringifiableFragments } =
+  require("devtools/server/actors/utils/css-grid-utils");
 const { gridSpec, layoutSpec } = require("devtools/shared/specs/layout");
-const { getStringifiableFragments } = require("devtools/server/actors/utils/css-grid-utils");
 
 /**
  * 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.
  *
  * The |Grid| actor provides the grid fragment information to inspect the grid container.
@@ -65,21 +67,27 @@ var GridActor = ActorClassWithSpec(gridS
  * The CSS layout actor provides layout information for the given document.
  */
 var LayoutActor = ActorClassWithSpec(layoutSpec, {
   initialize: function (conn, tabActor, walker) {
     Actor.prototype.initialize.call(this, conn);
 
     this.tabActor = tabActor;
     this.walker = walker;
+
+    this.onNavigate = this.onNavigate.bind(this);
+
+    events.on(this.tabActor, "navigate", this.onNavigate);
   },
 
   destroy: function () {
     Actor.prototype.destroy.call(this);
 
+    events.off(this.tabActor, "navigate", this.onNavigate);
+
     this.tabActor = null;
     this.walker = null;
   },
 
   /**
    * Returns an array of GridActor objects for all the grid containers found by iterating
    * below the given rootNode.
    *
@@ -109,23 +117,28 @@ var LayoutActor = ActorClassWithSpec(lay
    *
    * @param  {NodeActor} rootNode
    * @param  {Boolean} traverseFrames
    *         Whether or not we should iterate through nested frames.
    * @return {Array} An array of GridActor objects.
    */
   getAllGrids: function (rootNode, traverseFrames) {
     if (!traverseFrames) {
-      return this.getGridActors(rootNode);
+      return this.getGrids(rootNode.rawNode);
     }
 
     let grids = [];
     for (let {document} of this.tabActor.windows) {
       grids = [...grids, ...this.getGrids(document.documentElement)];
     }
 
     return grids;
   },
 
+  onNavigate: function () {
+    let grids = this.getAllGrids(this.walker.rootNode);
+    events.emit(this, "grid-layout-changed", grids);
+  },
+
 });
 
 exports.GridActor = GridActor;
 exports.LayoutActor = LayoutActor;
--- a/devtools/shared/specs/layout.js
+++ b/devtools/shared/specs/layout.js
@@ -11,21 +11,28 @@ const gridSpec = generateActorSpec({
   typeName: "grid",
 
   methods: {},
 });
 
 const layoutSpec = generateActorSpec({
   typeName: "layout",
 
+  events: {
+    "grid-layout-changed": {
+      type: "grid-layout-changed",
+      grids: Arg(0, "array:grid")
+    }
+  },
+
   methods: {
     getAllGrids: {
       request: {
         rootNode: Arg(0, "domnode"),
-        traverseFrames: Arg(1, "boolean")
+        traverseFrames: Arg(1, "nullable:boolean")
       },
       response: {
         grids: RetVal("array:grid")
       }
     }
   },
 });