Bug 1349483 - extract tooltip hidden callback from SwatchColorPickerTooltip;r=pbro
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 09 Jan 2018 19:28:21 +0100
changeset 452725 252d8b06f90f86e9a9c38f986260009d79586ca6
parent 452724 f214ee9699b42437807bc33291276d54996046fb
child 452726 3575689ce19141b040ed28e7b0202259bd0856ae
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1349483
milestone59.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 1349483 - extract tooltip hidden callback from SwatchColorPickerTooltip;r=pbro This allows subclasses to override the implementation,a nd avoids leaking ColorPicker specific implementation details to the base class. MozReview-Commit-ID: 6KHaFPd5xHt
devtools/client/shared/widgets/tooltip/SwatchBasedEditorTooltip.js
devtools/client/shared/widgets/tooltip/SwatchColorPickerTooltip.js
--- a/devtools/client/shared/widgets/tooltip/SwatchBasedEditorTooltip.js
+++ b/devtools/client/shared/widgets/tooltip/SwatchBasedEditorTooltip.js
@@ -104,38 +104,42 @@ class SwatchBasedEditorTooltip {
    */
   show() {
     let tooltipAnchor = this.useInline ?
       this.activeSwatch.closest(`.${INLINE_TOOLTIP_CLASS}`) :
       this.activeSwatch;
 
     if (tooltipAnchor) {
       let onShown = this.tooltip.once("shown");
+
       this.tooltip.show(tooltipAnchor, "topcenter bottomleft");
-
-      // When the tooltip is closed by clicking outside the panel we want to
-      // commit any changes.
-      this.tooltip.once("hidden", () => {
-        if (!this._reverted && !this.eyedropperOpen) {
-          this.commit();
-        }
-        this._reverted = false;
-
-        // Once the tooltip is hidden we need to clean up any remaining objects.
-        if (!this.eyedropperOpen) {
-          this.activeSwatch = null;
-        }
-      });
+      this.tooltip.once("hidden", () => this.onTooltipHidden());
 
       return onShown;
     }
 
     return Promise.resolve();
   }
 
+  /**
+   * Can be overridden by subclasses if implementation specific behavior is needed on
+   * tooltip hidden.
+   */
+  onTooltipHidden() {
+    // When the tooltip is closed by clicking outside the panel we want to commit any
+    // changes.
+    if (!this._reverted) {
+      this.commit();
+    }
+    this._reverted = false;
+
+    // Once the tooltip is hidden we need to clean up any remaining objects.
+    this.activeSwatch = null;
+  }
+
   hide() {
     this.tooltip.hide();
   }
 
   /**
    * Add a new swatch DOM element to the list of swatch elements this editor
    * tooltip knows about. That means from now on, clicking on that swatch will
    * toggle the editor.
--- a/devtools/client/shared/widgets/tooltip/SwatchColorPickerTooltip.js
+++ b/devtools/client/shared/widgets/tooltip/SwatchColorPickerTooltip.js
@@ -152,16 +152,29 @@ class SwatchColorPickerTooltip extends S
       this.preview(color);
 
       if (this.eyedropperOpen) {
         this.commit();
       }
     }
   }
 
+  /**
+   * Override the implementation from SwatchBasedEditorTooltip.
+   */
+  onTooltipHidden() {
+    // If the tooltip is hidden while the eyedropper is being used, we should not commit
+    // the changes.
+    if (this.eyedropperOpen) {
+      return;
+    }
+
+    super.onTooltipHidden();
+  }
+
   _openEyeDropper() {
     let {inspector, toolbox, telemetry} = this.inspector;
     telemetry.toolOpened("pickereyedropper");
 
     // cancelling picker(if it is already selected) on opening eye-dropper
     toolbox.highlighterUtils.cancelPicker();
 
     inspector.pickColorFromPage(toolbox, {copyOnSelect: false}).then(() => {