Bug 1378853 - Stop using sdk/core/heritage in DevTools reflow actor. r=jdescottes
MozReview-Commit-ID: IZr8qrCUdU8
--- a/devtools/server/actors/reflow.js
+++ b/devtools/server/actors/reflow.js
@@ -23,17 +23,16 @@
* listens to reflow events via the docshell,
* These dedicated classes are used by the LayoutChangesObserver.
*/
const {Ci} = require("chrome");
const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
const protocol = require("devtools/shared/protocol");
const events = require("sdk/event/core");
-const Heritage = require("sdk/core/heritage");
const EventEmitter = require("devtools/shared/event-emitter");
const {reflowSpec} = require("devtools/shared/specs/reflow");
/**
* The reflow actor tracks reflows and emits events about them.
*/
exports.ReflowActor = protocol.ActorClassWithSpec(reflowSpec, {
initialize: function (conn, tabActor) {
@@ -420,85 +419,86 @@ function releaseLayoutChangesObserver(ta
exports.releaseLayoutChangesObserver = releaseLayoutChangesObserver;
/**
* Reports any reflow that occurs in the tabActor's docshells.
* @extends Observable
* @param {TabActor} tabActor
* @param {Function} callback Executed everytime a reflow occurs
*/
-function ReflowObserver(tabActor, callback) {
- Observable.call(this, tabActor, callback);
-}
+class ReflowObserver extends Observable {
+ constructor(tabActor, callback) {
+ super(tabActor, callback);
+ }
-ReflowObserver.prototype = Heritage.extend(Observable.prototype, {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIReflowObserver,
- Ci.nsISupportsWeakReference]),
-
- _startListeners: function (windows) {
+ _startListeners(windows) {
for (let window of windows) {
let docshell = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);
docshell.addWeakReflowObserver(this);
}
- },
+ }
- _stopListeners: function (windows) {
+ _stopListeners(windows) {
for (let window of windows) {
try {
let docshell = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);
docshell.removeWeakReflowObserver(this);
} catch (e) {
// Corner cases where a global has already been freed may happen, in
// which case, no need to remove the observer.
}
}
- },
+ }
- reflow: function (start, end) {
+ reflow(start, end) {
this.notifyCallback(start, end, false);
- },
+ }
- reflowInterruptible: function (start, end) {
+ reflowInterruptible(start, end) {
this.notifyCallback(start, end, true);
}
-});
+}
+
+ReflowObserver.prototype.QueryInterface = XPCOMUtils
+ .generateQI([Ci.nsIReflowObserver, Ci.nsISupportsWeakReference]);
/**
* Reports window resize events on the tabActor's windows.
* @extends Observable
* @param {TabActor} tabActor
* @param {Function} callback Executed everytime a resize occurs
*/
-function WindowResizeObserver(tabActor, callback) {
- Observable.call(this, tabActor, callback);
- this.onResize = this.onResize.bind(this);
-}
+class WindowResizeObserver extends Observable {
-WindowResizeObserver.prototype = Heritage.extend(Observable.prototype, {
- _startListeners: function () {
+ constructor(tabActor, callback) {
+ super(tabActor, callback);
+ this.onResize = this.onResize.bind(this);
+ }
+
+ _startListeners() {
this.listenerTarget.addEventListener("resize", this.onResize);
- },
+ }
- _stopListeners: function () {
+ _stopListeners() {
this.listenerTarget.removeEventListener("resize", this.onResize);
- },
+ }
- onResize: function () {
+ onResize() {
this.notifyCallback();
- },
+ }
get listenerTarget() {
// For the rootActor, return its window.
if (this.tabActor.isRootActor) {
return this.tabActor.window;
}
// Otherwise, get the tabActor's chromeEventHandler.
return this.tabActor.window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
}
-});
+}