mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 02:40:22 -10:00
The fix for [Bug 1557689](https://bugzilla.mozilla.org/show_bug.cgi?id=1557689) created a situation in the [`Rule.onDeclarationsChanged()`](https://searchfox.org/mozilla-central/rev/6566d92dd46417a2f57e75c515135ebe84c9cef5/devtools/client/inspector/rules/models/rule.js#869-887) whereby the `isUsed` state of client-side declarations was made to point to a fixed `isUsed` state received from the server, thus losing sync with the latest state of the `StyleRuleActor`. Until another "declarations-update" event was fired from the `StyleRuleActor`, the rule's declarations' `isUsed` flag would point to the state with which they were overwritten on the last event handler call. As a reminder, the root cause of [Bug 1557689](https://bugzilla.mozilla.org/show_bug.cgi?id=1557689) was the inability force a "refresh" of the `StyleRuleFront` so it picked-up the latest `isUsed` state for its declarations when they depend on other declarations from other rules (ex: `justify-content: center` depends on `display:flex`). Therefore, the "declarations-updated" event was introduced with a payload of changed declarations to overwrite the client-side ones. It was convoluted, but it worked. However, while investigating the cause of this newer bug [Bug 1593944](https://bugzilla.mozilla.org/show_bug.cgi?id=1593944), I discovered an unusual but perhaps expected side-effect: when dispatching an event over the protocol with a payload of the `StyleRuleActor`, its corresponding `StyleRuleFront` on the client would "refresh" automatically (meaning that, looking up state on the previous front reference would point to the latest state from the actor) . The client doesn't even need to use this payload to replace its previous front reference. Surprisingly, the client doesn't even need to explicitly listen to the event which carries the `StyleRuleActor`/`StyleRuleFront` reference. So long as a previous reference of the front exists on the client, it will point to the updated state of the actor. I haven't been able to identify whether this is a known and expected behavior, so I'm pinging @jdescottes and @ochameau to weigh in on the validity of these findings. Relying on this behavior, the fix for both [Bug 1557689](https://bugzilla.mozilla.org/show_bug.cgi?id=1557689) and [Bug 1557689](https://bugzilla.mozilla.org/show_bug.cgi?id=1557689) involves simply emitting an event, "rule-updated", with the `StyleRuleActor` instance as payload whenever its internal state changes meaningfully so the corresponding front updates. The client will pick-up the latest `isUsed` state of declarations from its reference to the `StyleRuleFront`. --- Another way to check this behavior and hypothesis is to do the following: - In [`StyleRuleActor.setRuleText()`](https://searchfox.org/mozilla-central/rev/6566d92dd46417a2f57e75c515135ebe84c9cef5/devtools/server/actors/styles.js#1704) replace `return this` with `return null`; (this will no longer return the `StyleRuleActor` over the protocol; it's not explicitly used on the client anyway). - In the spec, replace the [`setRuleText()`](https://searchfox.org/mozilla-central/rev/6566d92dd46417a2f57e75c515135ebe84c9cef5/devtools/shared/specs/styles.js#222) return value with `RetVal("nullable:domstylerule")` so the protocol doesn't throw an error when getting the `null` from the actor. - Make a build. - Then, open the Inspector -> Rules View and change the value of a valid declaration, say: `display: block`, to something invalid, like `display: booo`. Notice that the declaration is no longer marked invalid with a warning sign. That's because the declaration's [`isValid`](https://searchfox.org/mozilla-central/rev/6566d92dd46417a2f57e75c515135ebe84c9cef5/devtools/server/actors/styles.js#1447) flag is set on the actor but it no longer syncs with the client which uses the corresponding front to render the declaration after the change. Not returning the `StyleRuleActor` over the protocol breaks this sync actor-front sync. Differential Revision: https://phabricator.services.mozilla.com/D52560
246 lines
6.1 KiB
JavaScript
246 lines
6.1 KiB
JavaScript
/* 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 {
|
|
Arg,
|
|
Option,
|
|
RetVal,
|
|
generateActorSpec,
|
|
types,
|
|
} = require("devtools/shared/protocol");
|
|
|
|
// Predeclare the domstylerule actor type
|
|
types.addActorType("domstylerule");
|
|
|
|
/**
|
|
* DOM Nodes returned by the style actor will be owned by the DOM walker
|
|
* for the connection.
|
|
*/
|
|
types.addLifetime("walker", "walker");
|
|
|
|
/**
|
|
* When asking for the styles applied to a node, we return a list of
|
|
* appliedstyle json objects that lists the rules that apply to the node
|
|
* and which element they were inherited from (if any).
|
|
*
|
|
* Note appliedstyle only sends the list of actorIDs and is not a valid return
|
|
* value on its own. appliedstyle should be returned with the actual list of
|
|
* StyleRuleActor and StyleSheetActor. See appliedStylesReturn.
|
|
*/
|
|
types.addDictType("appliedstyle", {
|
|
rule: "domstylerule#actorid",
|
|
inherited: "nullable:domnode#actorid",
|
|
keyframes: "nullable:domstylerule#actorid",
|
|
});
|
|
|
|
types.addDictType("matchedselector", {
|
|
rule: "domstylerule#actorid",
|
|
selector: "string",
|
|
value: "string",
|
|
status: "number",
|
|
});
|
|
|
|
types.addDictType("appliedStylesReturn", {
|
|
entries: "array:appliedstyle",
|
|
rules: "array:domstylerule",
|
|
sheets: "array:stylesheet",
|
|
});
|
|
|
|
types.addDictType("modifiedStylesReturn", {
|
|
isMatching: RetVal("boolean"),
|
|
ruleProps: RetVal("nullable:appliedStylesReturn"),
|
|
});
|
|
|
|
types.addDictType("fontpreview", {
|
|
data: "nullable:longstring",
|
|
size: "json",
|
|
});
|
|
|
|
types.addDictType("fontvariationaxis", {
|
|
tag: "string",
|
|
name: "string",
|
|
minValue: "number",
|
|
maxValue: "number",
|
|
defaultValue: "number",
|
|
});
|
|
|
|
types.addDictType("fontvariationinstancevalue", {
|
|
axis: "string",
|
|
value: "number",
|
|
});
|
|
|
|
types.addDictType("fontvariationinstance", {
|
|
name: "string",
|
|
values: "array:fontvariationinstancevalue",
|
|
});
|
|
|
|
types.addDictType("fontface", {
|
|
name: "string",
|
|
CSSFamilyName: "string",
|
|
rule: "nullable:domstylerule",
|
|
srcIndex: "number",
|
|
URI: "string",
|
|
format: "string",
|
|
preview: "nullable:fontpreview",
|
|
localName: "string",
|
|
metadata: "string",
|
|
variationAxes: "array:fontvariationaxis",
|
|
variationInstances: "array:fontvariationinstance",
|
|
});
|
|
|
|
const pageStyleSpec = generateActorSpec({
|
|
typeName: "pagestyle",
|
|
|
|
events: {
|
|
"stylesheet-updated": {
|
|
type: "styleSheetUpdated",
|
|
styleSheet: Arg(0, "stylesheet"),
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
getComputed: {
|
|
request: {
|
|
node: Arg(0, "domnode"),
|
|
markMatched: Option(1, "boolean"),
|
|
onlyMatched: Option(1, "boolean"),
|
|
filter: Option(1, "string"),
|
|
filterProperties: Option(1, "nullable:array:string"),
|
|
},
|
|
response: {
|
|
computed: RetVal("json"),
|
|
},
|
|
},
|
|
getAllUsedFontFaces: {
|
|
request: {
|
|
includePreviews: Option(0, "boolean"),
|
|
includeVariations: Option(1, "boolean"),
|
|
previewText: Option(0, "string"),
|
|
previewFontSize: Option(0, "string"),
|
|
previewFillStyle: Option(0, "string"),
|
|
},
|
|
response: {
|
|
fontFaces: RetVal("array:fontface"),
|
|
},
|
|
},
|
|
getUsedFontFaces: {
|
|
request: {
|
|
node: Arg(0, "domnode"),
|
|
includePreviews: Option(1, "boolean"),
|
|
includeVariations: Option(1, "boolean"),
|
|
previewText: Option(1, "string"),
|
|
previewFontSize: Option(1, "string"),
|
|
previewFillStyle: Option(1, "string"),
|
|
},
|
|
response: {
|
|
fontFaces: RetVal("array:fontface"),
|
|
},
|
|
},
|
|
getMatchedSelectors: {
|
|
request: {
|
|
node: Arg(0, "domnode"),
|
|
property: Arg(1, "string"),
|
|
filter: Option(2, "string"),
|
|
},
|
|
response: RetVal(
|
|
types.addDictType("matchedselectorresponse", {
|
|
rules: "array:domstylerule",
|
|
sheets: "array:stylesheet",
|
|
matched: "array:matchedselector",
|
|
})
|
|
),
|
|
},
|
|
getRule: {
|
|
request: {
|
|
ruleId: Arg(0, "string"),
|
|
},
|
|
response: {
|
|
rule: RetVal("nullable:domstylerule"),
|
|
},
|
|
},
|
|
getApplied: {
|
|
request: {
|
|
node: Arg(0, "domnode"),
|
|
inherited: Option(1, "boolean"),
|
|
matchedSelectors: Option(1, "boolean"),
|
|
skipPseudo: Option(1, "boolean"),
|
|
filter: Option(1, "string"),
|
|
},
|
|
response: RetVal("appliedStylesReturn"),
|
|
},
|
|
isPositionEditable: {
|
|
request: { node: Arg(0, "domnode") },
|
|
response: { value: RetVal("boolean") },
|
|
},
|
|
getLayout: {
|
|
request: {
|
|
node: Arg(0, "domnode"),
|
|
autoMargins: Option(1, "boolean"),
|
|
},
|
|
response: RetVal("json"),
|
|
},
|
|
addNewRule: {
|
|
request: {
|
|
node: Arg(0, "domnode"),
|
|
pseudoClasses: Arg(1, "nullable:array:string"),
|
|
},
|
|
response: RetVal("appliedStylesReturn"),
|
|
},
|
|
},
|
|
});
|
|
|
|
exports.pageStyleSpec = pageStyleSpec;
|
|
|
|
const styleRuleSpec = generateActorSpec({
|
|
typeName: "domstylerule",
|
|
|
|
events: {
|
|
"location-changed": {
|
|
type: "locationChanged",
|
|
line: Arg(0, "number"),
|
|
column: Arg(1, "number"),
|
|
},
|
|
"rule-updated": {
|
|
type: "ruleUpdated",
|
|
rule: Arg(0, "domstylerule"),
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
getRuleText: {
|
|
response: {
|
|
text: RetVal("string"),
|
|
},
|
|
},
|
|
setRuleText: {
|
|
request: {
|
|
newText: Arg(0, "string"),
|
|
modifications: Arg(1, "array:json"),
|
|
},
|
|
response: { rule: RetVal("domstylerule") },
|
|
},
|
|
modifyProperties: {
|
|
request: { modifications: Arg(0, "array:json") },
|
|
response: { rule: RetVal("domstylerule") },
|
|
},
|
|
modifySelector: {
|
|
request: {
|
|
node: Arg(0, "domnode"),
|
|
value: Arg(1, "string"),
|
|
editAuthored: Arg(2, "boolean"),
|
|
},
|
|
response: RetVal("modifiedStylesReturn"),
|
|
},
|
|
},
|
|
});
|
|
|
|
exports.styleRuleSpec = styleRuleSpec;
|
|
|
|
// The PageStyle actor flattens the DOM CSS objects a little bit, merging
|
|
// Rules and their Styles into one actor. For elements (which have a style
|
|
// but no associated rule) we fake a rule with the following style id.
|
|
const ELEMENT_STYLE = 100;
|
|
exports.ELEMENT_STYLE = ELEMENT_STYLE;
|