diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:50 +0000 |
commit | def92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch) | |
tree | 2ef34b9ad8bb9a9220e05d60352558b15f513894 /devtools/server/actors/utils | |
parent | Adding debian version 125.0.3-1. (diff) | |
download | firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/actors/utils')
-rw-r--r-- | devtools/server/actors/utils/event-breakpoints.js | 15 | ||||
-rw-r--r-- | devtools/server/actors/utils/style-utils.js | 66 | ||||
-rw-r--r-- | devtools/server/actors/utils/stylesheets-manager.js | 31 |
3 files changed, 36 insertions, 76 deletions
diff --git a/devtools/server/actors/utils/event-breakpoints.js b/devtools/server/actors/utils/event-breakpoints.js index a7752b8201..8fbefec804 100644 --- a/devtools/server/actors/utils/event-breakpoints.js +++ b/devtools/server/actors/utils/event-breakpoints.js @@ -131,7 +131,8 @@ const AVAILABLE_BREAKPOINTS = [ items: [ // The condition should be removed when "dom.element.popover.enabled" is removed generalEvent("control", "beforetoggle", () => - Services.prefs.getBoolPref("dom.element.popover.enabled") + // Services.prefs isn't available on worker targets + Services.prefs?.getBoolPref("dom.element.popover.enabled") ), generalEvent("control", "blur"), generalEvent("control", "change"), @@ -139,7 +140,11 @@ const AVAILABLE_BREAKPOINTS = [ generalEvent("control", "focusin"), generalEvent("control", "focusout"), // The condition should be removed when "dom.element.invokers.enabled" is removed - generalEvent("control", "invoke", win => "InvokeEvent" in win), + generalEvent( + "control", + "invoke", + global => global && "InvokeEvent" in global + ), generalEvent("control", "reset"), generalEvent("control", "resize"), generalEvent("control", "scroll"), @@ -483,17 +488,17 @@ exports.getAvailableEventBreakpoints = getAvailableEventBreakpoints; /** * Get all available event breakpoints * - * @param {Window} window + * @param {Window|WorkerGlobalScope} global * @returns {Array<Object>} An array containing object with 2 properties, an id and a name, * representing the event. */ -function getAvailableEventBreakpoints(window) { +function getAvailableEventBreakpoints(global) { const available = []; for (const { name, items } of AVAILABLE_BREAKPOINTS) { available.push({ name, events: items - .filter(item => !item.condition || item.condition(window)) + .filter(item => !item.condition || item.condition(global)) .map(item => ({ id: item.id, name: item.name, diff --git a/devtools/server/actors/utils/style-utils.js b/devtools/server/actors/utils/style-utils.js index 5f2e912002..1d52448fb6 100644 --- a/devtools/server/actors/utils/style-utils.js +++ b/devtools/server/actors/utils/style-utils.js @@ -4,8 +4,6 @@ "use strict"; -const { getCSSLexer } = require("resource://devtools/shared/css/lexer.js"); - const XHTML_NS = "http://www.w3.org/1999/xhtml"; const FONT_PREVIEW_TEXT = "Abc"; const FONT_PREVIEW_FONT_SIZE = 40; @@ -120,66 +118,12 @@ function getRuleText(initialText, line, column) { throw new Error("Location information is missing"); } - const { offset: textOffset, text } = getTextAtLineColumn( - initialText, - line, - column - ); - const lexer = getCSSLexer(text); - - // Search forward for the opening brace. - while (true) { - const token = lexer.nextToken(); - if (!token) { - throw new Error("couldn't find start of the rule"); - } - if (token.tokenType === "symbol" && token.text === "{") { - break; - } - } - - // Now collect text until we see the matching close brace. - let braceDepth = 1; - let startOffset, endOffset; - while (true) { - const token = lexer.nextToken(); - if (!token) { - break; - } - if (startOffset === undefined) { - startOffset = token.startOffset; - } - if (token.tokenType === "symbol") { - if (token.text === "{") { - ++braceDepth; - } else if (token.text === "}") { - --braceDepth; - if (braceDepth == 0) { - break; - } - } - } - endOffset = token.endOffset; - } - - // If the rule was of the form "selector {" with no closing brace - // and no properties, just return an empty string. - if (startOffset === undefined) { - return { offset: 0, text: "" }; - } - // If the input didn't have any tokens between the braces (e.g., - // "div {}"), then the endOffset won't have been set yet; so account - // for that here. - if (endOffset === undefined) { - endOffset = startOffset; + const { text } = getTextAtLineColumn(initialText, line, column); + const res = InspectorUtils.getRuleBodyText(text); + if (res === null || typeof res === "undefined") { + throw new Error("Couldn't find rule"); } - - // Note that this approach will preserve comments, despite the fact - // that cssTokenizer skips them. - return { - offset: textOffset + startOffset, - text: text.substring(startOffset, endOffset), - }; + return res; } exports.getRuleText = getRuleText; diff --git a/devtools/server/actors/utils/stylesheets-manager.js b/devtools/server/actors/utils/stylesheets-manager.js index a9c0705e8d..1c065afd4e 100644 --- a/devtools/server/actors/utils/stylesheets-manager.js +++ b/devtools/server/actors/utils/stylesheets-manager.js @@ -446,10 +446,12 @@ class StyleSheetsManager extends EventEmitter { InspectorUtils.parseStyleSheet(styleSheet, text); modifiedStyleSheets.set(styleSheet, text); - const { atRules, ruleCount } = - this.getStyleSheetRuleCountAndAtRules(styleSheet); - + // getStyleSheetRuleCountAndAtRules can be costly, so only call it when needed, + // i.e. when the whole stylesheet is modified, not when a rule body is. + let atRules, ruleCount; if (kind !== UPDATE_PRESERVING_RULES) { + ({ atRules, ruleCount } = + this.getStyleSheetRuleCountAndAtRules(styleSheet)); this.#notifyPropertyChanged(resourceId, "ruleCount", ruleCount); } @@ -465,13 +467,15 @@ class StyleSheetsManager extends EventEmitter { }); } - this.#onStyleSheetUpdated({ - resourceId, - updateKind: "at-rules-changed", - updates: { - resourceUpdates: { atRules }, - }, - }); + if (kind !== UPDATE_PRESERVING_RULES) { + this.#onStyleSheetUpdated({ + resourceId, + updateKind: "at-rules-changed", + updates: { + resourceUpdates: { atRules }, + }, + }); + } } /** @@ -705,6 +709,13 @@ class StyleSheetsManager extends EventEmitter { line: InspectorUtils.getRelativeRuleLine(rule), column: InspectorUtils.getRuleColumn(rule), }); + } else if (className === "CSSPropertyRule") { + atRules.push({ + type: "property", + propertyName: rule.name, + line: InspectorUtils.getRelativeRuleLine(rule), + column: InspectorUtils.getRuleColumn(rule), + }); } } return { |