commit b0acb7e26ceec793ab86fce1a67be972d8eab09a
parent e14aa255aac1443e42eb814cba47418e38931524
Author: Lorenz A <me@lorenzackermann.xyz>
Date: Mon, 15 Dec 2025 17:42:47 +0000
Bug 2004275 - [devtools] Turn devtools/client/inspector/shared/style-inspector-menu.js into an ES class. r=devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D276220
Diffstat:
1 file changed, 49 insertions(+), 49 deletions(-)
diff --git a/devtools/client/inspector/shared/style-inspector-menu.js b/devtools/client/inspector/shared/style-inspector-menu.js
@@ -43,35 +43,33 @@ const PREF_ORIG_SOURCES = "devtools.source-map.client-service.enabled";
/**
* Style inspector context menu
- *
- * @param {RuleView|ComputedView} view
- * RuleView or ComputedView instance controlling this menu
- * @param {object} options
- * Option menu configuration
*/
-function StyleInspectorMenu(view, { isRuleView = false } = {}) {
- this.view = view;
- this.inspector = this.view.inspector;
- this.styleWindow = this.view.styleWindow || this.view.doc.defaultView;
- this.isRuleView = isRuleView;
-
- this._onCopy = this._onCopy.bind(this);
- this._onCopyColor = this._onCopyColor.bind(this);
- this._onCopyImageDataUrl = this._onCopyImageDataUrl.bind(this);
- this._onCopyLocation = this._onCopyLocation.bind(this);
- this._onCopyDeclaration = this._onCopyDeclaration.bind(this);
- this._onCopyPropertyName = this._onCopyPropertyName.bind(this);
- this._onCopyPropertyValue = this._onCopyPropertyValue.bind(this);
- this._onCopyRule = this._onCopyRule.bind(this);
- this._onCopySelector = this._onCopySelector.bind(this);
- this._onCopyUrl = this._onCopyUrl.bind(this);
- this._onSelectAll = this._onSelectAll.bind(this);
- this._onToggleOrigSources = this._onToggleOrigSources.bind(this);
-}
-
-module.exports = StyleInspectorMenu;
-
-StyleInspectorMenu.prototype = {
+class StyleInspectorMenu {
+ /**
+ * @param {RuleView|ComputedView} view
+ * RuleView or ComputedView instance controlling this menu
+ * @param {object} options
+ * Option menu configuration
+ */
+ constructor(view, { isRuleView = false } = {}) {
+ this.view = view;
+ this.inspector = this.view.inspector;
+ this.styleWindow = this.view.styleWindow || this.view.doc.defaultView;
+ this.isRuleView = isRuleView;
+
+ this._onCopy = this._onCopy.bind(this);
+ this._onCopyColor = this._onCopyColor.bind(this);
+ this._onCopyImageDataUrl = this._onCopyImageDataUrl.bind(this);
+ this._onCopyLocation = this._onCopyLocation.bind(this);
+ this._onCopyDeclaration = this._onCopyDeclaration.bind(this);
+ this._onCopyPropertyName = this._onCopyPropertyName.bind(this);
+ this._onCopyPropertyValue = this._onCopyPropertyValue.bind(this);
+ this._onCopyRule = this._onCopyRule.bind(this);
+ this._onCopySelector = this._onCopySelector.bind(this);
+ this._onCopyUrl = this._onCopyUrl.bind(this);
+ this._onSelectAll = this._onSelectAll.bind(this);
+ this._onToggleOrigSources = this._onToggleOrigSources.bind(this);
+ }
/**
* Display the style inspector context menu
*/
@@ -85,7 +83,7 @@ StyleInspectorMenu.prototype = {
} catch (e) {
console.error(e);
}
- },
+ }
_openMenu({ target, screenX = 0, screenY = 0 } = {}) {
this.currentTarget = target;
@@ -278,7 +276,7 @@ StyleInspectorMenu.prototype = {
menu.popup(screenX, screenY, this.inspector.toolbox.doc);
return menu;
- },
+ }
_hasTextSelected() {
let hasTextSelected;
@@ -296,7 +294,7 @@ StyleInspectorMenu.prototype = {
}
return hasTextSelected;
- },
+ }
/**
* Get the type of the currently clicked node
@@ -304,7 +302,7 @@ StyleInspectorMenu.prototype = {
_getClickedNodeInfo() {
const node = this._getClickedNode();
return this.view.getNodeInfo(node);
- },
+ }
/**
* A helper that determines if the popup was opened with a click to a color
@@ -328,7 +326,7 @@ StyleInspectorMenu.prototype = {
this._colorToCopy = colorNode.dataset.color;
return true;
- },
+ }
/**
* Check if the current node (clicked node) is an image URL
@@ -341,7 +339,7 @@ StyleInspectorMenu.prototype = {
return false;
}
return nodeInfo.type == VIEW_NODE_IMAGE_URL_TYPE;
- },
+ }
/**
* Get the DOM Node container for the current target node.
@@ -358,7 +356,7 @@ StyleInspectorMenu.prototype = {
}
return node.nodeType === node.TEXT_NODE ? node.parentElement : node;
- },
+ }
/**
* Select all text.
@@ -373,21 +371,21 @@ StyleInspectorMenu.prototype = {
} else {
selection.selectAllChildren(this.view.element);
}
- },
+ }
/**
* Copy the most recently selected color value to clipboard.
*/
_onCopy() {
this.view.copySelection(this.currentTarget);
- },
+ }
/**
* Copy the most recently selected color value to clipboard.
*/
_onCopyColor() {
clipboardHelper.copyString(this._colorToCopy);
- },
+ }
/*
* Retrieve the url for the selected image and copy it to the clipboard
@@ -398,7 +396,7 @@ StyleInspectorMenu.prototype = {
}
clipboardHelper.copyString(this._clickedNodeInfo.value.url);
- },
+ }
/**
* Retrieve the image data for the selected image url and copy it to the
@@ -422,7 +420,7 @@ StyleInspectorMenu.prototype = {
}
clipboardHelper.copyString(message);
- },
+ }
/**
* Copy the rule source location of the current clicked node.
@@ -433,7 +431,7 @@ StyleInspectorMenu.prototype = {
}
clipboardHelper.copyString(this._clickedNodeInfo.value);
- },
+ }
/**
* Copy the CSS declaration of the current clicked node.
@@ -445,7 +443,7 @@ StyleInspectorMenu.prototype = {
const textProp = this._clickedNodeInfo.value.textProperty;
clipboardHelper.copyString(textProp.stringifyProperty());
- },
+ }
/**
* Copy the rule property name of the current clicked node.
@@ -456,7 +454,7 @@ StyleInspectorMenu.prototype = {
}
clipboardHelper.copyString(this._clickedNodeInfo.value.property);
- },
+ }
/**
* Copy the rule property value of the current clicked node.
@@ -467,7 +465,7 @@ StyleInspectorMenu.prototype = {
}
clipboardHelper.copyString(this._clickedNodeInfo.value.value);
- },
+ }
/**
* Copy the rule of the current clicked node.
@@ -480,7 +478,7 @@ StyleInspectorMenu.prototype = {
return;
}
clipboardHelper.copyString(rule.stringifyRule());
- },
+ }
/**
* Copy the rule selector of the current clicked node.
@@ -491,7 +489,7 @@ StyleInspectorMenu.prototype = {
}
clipboardHelper.copyString(this._clickedNodeInfo.value);
- },
+ }
/**
* Toggle the original sources pref.
@@ -499,12 +497,14 @@ StyleInspectorMenu.prototype = {
_onToggleOrigSources() {
const isEnabled = Services.prefs.getBoolPref(PREF_ORIG_SOURCES);
Services.prefs.setBoolPref(PREF_ORIG_SOURCES, !isEnabled);
- },
+ }
destroy() {
this.currentTarget = null;
this.view = null;
this.inspector = null;
this.styleWindow = null;
- },
-};
+ }
+}
+
+module.exports = StyleInspectorMenu;