Bug 1494162 - Part 28: Lazy initialize TooltipToggle in HTMLTooltip. r=jdescottes
authorGabriel Luong <gabriel.luong@gmail.com>
Mon, 01 Oct 2018 11:24:41 -0400
changeset 494723 d8ba9d86cee499c2d1eb10cfc7970b633c780eef
parent 494722 0e25b53020039e5cf1fcd54a308302fda2e4bd3a
child 494724 a91bad5598839b3de0560cd34d5013e9bf69da3f
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1494162
milestone64.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 1494162 - Part 28: Lazy initialize TooltipToggle in HTMLTooltip. r=jdescottes
devtools/client/shared/widgets/tooltip/HTMLTooltip.js
--- a/devtools/client/shared/widgets/tooltip/HTMLTooltip.js
+++ b/devtools/client/shared/widgets/tooltip/HTMLTooltip.js
@@ -3,19 +3,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 Services = require("Services");
 const EventEmitter = require("devtools/shared/event-emitter");
-const {TooltipToggle} = require("devtools/client/shared/widgets/tooltip/TooltipToggle");
 
 loader.lazyRequireGetter(this, "focusableSelector", "devtools/client/shared/focus", true);
+loader.lazyRequireGetter(this, "TooltipToggle", "devtools/client/shared/widgets/tooltip/TooltipToggle", true);
 loader.lazyRequireGetter(this, "getCurrentZoom", "devtools/shared/layout/utils", true);
 loader.lazyRequireGetter(this, "listenOnce", "devtools/shared/async-utils", true);
 
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 
 const POSITION = {
   TOP: "top",
@@ -324,20 +324,16 @@ function HTMLTooltip(toolboxDoc, {
   this.topWindow = this._getTopWindow();
 
   this._position = null;
 
   this._onClick = this._onClick.bind(this);
   this._onMouseup = this._onMouseup.bind(this);
   this._onXulPanelHidden = this._onXulPanelHidden.bind(this);
 
-  this._toggle = new TooltipToggle(this);
-  this.startTogglingOnHover = this._toggle.start.bind(this._toggle);
-  this.stopTogglingOnHover = this._toggle.stop.bind(this._toggle);
-
   this.container = this._createContainer();
 
   if (this.useXulWrapper) {
     // When using a XUL panel as the wrapper, the actual markup for the tooltip is as
     // follows :
     // <panel> <!-- XUL panel used to position the tooltip anywhere on screen -->
     //   <div> <!-- div wrapper used to isolate the tooltip container -->
     //     <div> <! the actual tooltip.container element -->
@@ -375,16 +371,24 @@ HTMLTooltip.prototype = {
 
   /**
    * Retrieve the displayed position used for the tooltip. Null if the tooltip is hidden.
    */
   get position() {
     return this.isVisible() ? this._position : null;
   },
 
+  get toggle() {
+    if (!this._toggle) {
+      this._toggle = new TooltipToggle(this);
+    }
+
+    return this._toggle;
+  },
+
   /**
    * Set the preferred width/height of the panel content.
    * The panel content is set by appending content to `this.panel`.
    *
    * @param {Object}
    *        - {Number} width: preferred width for the tooltip container. If not specified
    *          the tooltip container will be measured before being displayed, and the
    *          measured width will be used as the preferred width.
@@ -444,16 +448,24 @@ HTMLTooltip.prototype = {
       // Update the top window reference each time in case the host changes.
       this.topWindow = this._getTopWindow();
       this.topWindow.addEventListener("click", this._onClick, true);
       this.topWindow.addEventListener("mouseup", this._onMouseup, true);
       this.emit("shown");
     }, 0);
   },
 
+  startTogglingOnHover(baseNode, targetNodeCb, options) {
+    this.toggle.start(baseNode, targetNodeCb, options);
+  },
+
+  stopTogglingOnHover() {
+    this.toggle.stop();
+  },
+
   /**
    * Recalculate the dimensions and position of the tooltip in response to
    * changes to its content.
    *
    * Parameters are identical to show().
    */
   updateContainerBounds(anchor, options) {
     if (!this.isVisible()) {
@@ -731,17 +743,20 @@ HTMLTooltip.prototype = {
    */
   destroy: function() {
     this.hide();
     this.removeEventListeners();
     this.container.remove();
     if (this.xulPanelWrapper) {
       this.xulPanelWrapper.remove();
     }
-    this._toggle.destroy();
+    if (this._toggle) {
+      this._toggle.destroy();
+      this._toggle = null;
+    }
   },
 
   _createContainer: function() {
     const container = this.doc.createElementNS(XHTML_NS, "div");
     container.setAttribute("type", this.type);
 
     if (this.id) {
       container.setAttribute("id", this.id);