Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 7b30f46

Browse files
Alexandru Marcamarc-mozilla
authored andcommitted
Revert "Bug 1972505 - [devtools] Don't render rule source for inline style rule. r=devtools-reviewers,ochameau." for causing dt failures @ browser_browser_toolbox_ruleview_stylesheet.js
This reverts commit 1740b401a40bac013c70bb5b68d48aae6df16e19.
1 parent 0e69403 commit 7b30f46

File tree

3 files changed

+51
-43
lines changed

3 files changed

+51
-43
lines changed

devtools/client/inspector/rules/rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ CssRuleView.prototype = {
16721672
? styleSheetSource === this.searchData.strictSearchValue
16731673
: styleSheetSource.includes(this.searchValue);
16741674

1675-
if (isStyleSheetHighlighted && rule.editor.source) {
1675+
if (isStyleSheetHighlighted) {
16761676
rule.editor.source.classList.add("ruleview-highlight");
16771677
}
16781678

devtools/client/inspector/rules/views/rule-editor.js

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,20 @@ RuleEditor.prototype = {
139139
// span to be placed absolutely against.
140140
this.element.style.position = "relative";
141141

142-
// Add the source link for supported rules. inline style and pres hints are not visible
143-
// in the StyleEditor, so don't show anything for such rule.
144-
if (this.rule.domRule.type !== ELEMENT_STYLE) {
145-
this.source = createChild(this.element, "div", {
146-
class: "ruleview-rule-source theme-link",
147-
});
148-
this.source.addEventListener("click", this._onSourceClick);
142+
// Add the source link.
143+
this.source = createChild(this.element, "div", {
144+
class: "ruleview-rule-source theme-link",
145+
});
146+
this.source.addEventListener("click", this._onSourceClick);
147+
148+
// inline style are not visible in the StyleEditor, so don't create an actual link
149+
// element for their location.
150+
const sourceLabel = this.doc.createElement(
151+
this.rule.domRule.type === ELEMENT_STYLE ? "span" : "a"
152+
);
153+
sourceLabel.classList.add("ruleview-rule-source-label");
154+
this.source.appendChild(sourceLabel);
149155

150-
const sourceLabel = this.doc.createElement("a");
151-
sourceLabel.classList.add("ruleview-rule-source-label");
152-
this.source.appendChild(sourceLabel);
153-
}
154156
this.updateSourceLink();
155157

156158
if (this.rule.domRule.ancestorData.length) {
@@ -494,14 +496,13 @@ RuleEditor.prototype = {
494496
* Called when a tool is registered or unregistered.
495497
*/
496498
_onToolChanged() {
497-
if (!this.source) {
498-
return;
499-
}
500-
501499
// When the source editor is registered, update the source links
502500
// to be clickable; and if it is unregistered, update the links to
503-
// be unclickable.
504-
if (this.toolbox.isToolRegistered("styleeditor")) {
501+
// be unclickable. However, some links are never clickable, so
502+
// filter those out first.
503+
if (this.source.getAttribute("unselectable") === "permanent") {
504+
// Nothing.
505+
} else if (this.toolbox.isToolRegistered("styleeditor")) {
505506
this.source.removeAttribute("unselectable");
506507
} else {
507508
this.source.setAttribute("unselectable", "true");
@@ -573,31 +574,38 @@ RuleEditor.prototype = {
573574
},
574575

575576
updateSourceLink() {
576-
if (this.source) {
577-
if (this.rule.isSystem) {
578-
const sourceLabel = this.element.querySelector(
579-
".ruleview-rule-source-label"
580-
);
581-
const uaLabel = STYLE_INSPECTOR_L10N.getStr("rule.userAgentStyles");
582-
sourceLabel.textContent = uaLabel + " " + this.rule.title;
583-
sourceLabel.setAttribute("href", this.rule.sheet?.href);
584-
} else {
585-
this._updateLocation(null);
586-
}
577+
if (this.rule.isSystem) {
578+
const sourceLabel = this.element.querySelector(
579+
".ruleview-rule-source-label"
580+
);
581+
const uaLabel = STYLE_INSPECTOR_L10N.getStr("rule.userAgentStyles");
582+
sourceLabel.textContent = uaLabel + " " + this.rule.title;
583+
sourceLabel.setAttribute("href", this.rule.sheet?.href);
584+
} else {
585+
this._updateLocation(null);
586+
}
587587

588-
if (this.rule.sheet && !this.rule.isSystem) {
589-
// Only get the original source link if the rule isn't a system
590-
// rule and if it isn't an inline rule.
591-
if (this._unsubscribeSourceMap) {
592-
this._unsubscribeSourceMap();
593-
}
594-
this._unsubscribeSourceMap = this.sourceMapURLService.subscribeByID(
595-
this.rule.sheet.resourceId,
596-
this.rule.ruleLine,
597-
this.rule.ruleColumn,
598-
this._updateLocation
599-
);
588+
if (
589+
this.rule.sheet &&
590+
!this.rule.isSystem &&
591+
this.rule.domRule.type !== ELEMENT_STYLE
592+
) {
593+
// Only get the original source link if the rule isn't a system
594+
// rule and if it isn't an inline rule.
595+
if (this._unsubscribeSourceMap) {
596+
this._unsubscribeSourceMap();
600597
}
598+
this._unsubscribeSourceMap = this.sourceMapURLService.subscribeByID(
599+
this.rule.sheet.resourceId,
600+
this.rule.ruleLine,
601+
this.rule.ruleColumn,
602+
this._updateLocation
603+
);
604+
// Set "unselectable" appropriately.
605+
this._onToolChanged();
606+
} else if (this.rule.domRule.type === ELEMENT_STYLE) {
607+
this.source.setAttribute("unselectable", "permanent");
608+
} else {
601609
// Set "unselectable" appropriately.
602610
this._onToolChanged();
603611
}

devtools/client/inspector/test/shared-head.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,8 @@ function getRuleViewSelector(view, selectorText) {
695695
* @return {DOMNode} The link if any at this index
696696
*/
697697
function getRuleViewLinkByIndex(view, index) {
698-
const ruleEl = view.styleDocument.querySelectorAll(".ruleview-rule")[index];
699-
return ruleEl.querySelector(".ruleview-rule-source");
698+
const links = view.styleDocument.querySelectorAll(".ruleview-rule-source");
699+
return links[index];
700700
}
701701

702702
/**

0 commit comments

Comments
 (0)