Closed Bug 1519988 Opened 7 years ago Closed 7 years ago

Implement toggling on/off of a CSS declaration

Categories

(DevTools :: Inspector: Rules, enhancement, P3)

enhancement

Tracking

(firefox66 fixed)

RESOLVED FIXED
Firefox 66
Tracking Status
firefox66 --- fixed

People

(Reporter: gl, Assigned: gl)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

No description provided.
Attachment #9036447 - Flags: review?(rcaliman)

Regarding the Math.random(), I was looking up a good way to generate a UUID for an unique identifier for the declarations since indexes won't work well when we add new declarations, and this method came up the most in my searches.

Blocks: 1520389
Comment on attachment 9036447 [details] [diff] [review] 1519988.patch [1.0] Review of attachment 9036447 [details] [diff] [review]: ----------------------------------------------------------------- ::: devtools/client/inspector/rules/components/Declaration.js @@ +38,5 @@ > }); > } > > + onToggleDeclarationEnabledClick(event) { > + event.stopPropagation(); Is this `event.stopPropagation();` necessary? ::: devtools/client/inspector/rules/components/Declarations.js @@ +15,5 @@ > class Declarations extends PureComponent { > static get propTypes() { > return { > declarations: PropTypes.arrayOf(PropTypes.shape(Types.declaration)).isRequired, > + onToggleDeclarationEnabled: PropTypes.object.isRequired, Shouldn't this be `PropTypes.func.isRequired` ? ::: devtools/client/inspector/rules/models/element-style.js @@ +332,5 @@ > } > }, > > /** > + * Toggles the enabled property of the given CSS declaration. s/property/state @@ +340,5 @@ > + * @param {String} declarationId > + * The TextProperty id for the CSS declaration. > + * > + */ > + toggleDeclarationEnabled: function(ruleId, declarationId) { `toggleDeclarationEnabled` is very wordy and appears in many places in this patch. I suggest renaming it to `toggleDeclaration` which is adequately explicit. Plus, it follows the naming precedent set by `togglePseudoClass`. @@ +341,5 @@ > + * The TextProperty id for the CSS declaration. > + * > + */ > + toggleDeclarationEnabled: function(ruleId, declarationId) { > + const rule = this.getRule(ruleId); If rule or declaration can be undefined, perhaps it's best to guard against those here. ::: devtools/client/inspector/rules/models/text-property.js @@ +34,5 @@ > * coming from parseDeclarations. > */ > function TextProperty(rule, name, value, priority, enabled = true, > invisible = false) { > + this.id = name + "_" + Math.random().toString(36).substr(2, 5); We seem to have a uuid generator avaialble: https://searchfox.org/mozilla-central/source/devtools/shared/generate-uuid.js It does seem to cross the JS/C++ boundary so I don't know if using that incurs any substantial performance hit. I wonder if this id is stable across the session (or perhaps that doesn't matter; the implications are a bit obscure to me right now). There is at least one place where the list of text properties is rebuilt and replaced during the same session in Rule.refresh(): https://searchfox.org/mozilla-central/source/devtools/client/inspector/rules/models/rule.js#518-529 This gets called on the element style model by _maybeAddRule(): https://searchfox.org/mozilla-central/source/devtools/client/inspector/rules/models/element-style.js#188 ::: devtools/client/inspector/rules/new-rules.js @@ +144,5 @@ > + * @param {String} declarationId > + * The TextProperty id for the CSS declaration. > + */ > + onToggleDeclarationEnabled(ruleId, declarationId) { > + this.elementStyle.toggleDeclarationEnabled(ruleId, declarationId); `ElementStyle.toggleDeclarationEnabled()` ends up calling `Rule._applyProperties()` which makes a call to the server and returns a promise. Once that promise is resolved, we can be sure our computed object model with rules is up to date (for example, overwritten properties which become active as a result of toggling another property). We should wait for that to finish before dispatching `updateRules(this.elementStyle.rules)` on the next line. There's an `onChanged` callback that can be declared on `ElementStyle` to be notified when it has completed its computations: https://searchfox.org/mozilla-central/source/devtools/client/inspector/rules/models/element-style.js#75-77
Attachment #9036447 - Flags: review?(rcaliman) → review+

(In reply to Razvan Caliman [:rcaliman] from comment #4)

Comment on attachment 9036447 [details] [diff] [review]
1519988.patch [1.0]

Review of attachment 9036447 [details] [diff] [review]:

::: devtools/client/inspector/rules/components/Declaration.js
@@ +38,5 @@

 });

}

  • onToggleDeclarationEnabledClick(event) {
  • event.stopPropagation();

Is this event.stopPropagation(); necessary?

Yes. We actually end up calling the function twice if we don't stop the event from bubbling.

::: devtools/client/inspector/rules/components/Declarations.js
@@ +15,5 @@

class Declarations extends PureComponent {
static get propTypes() {
return {
declarations: PropTypes.arrayOf(PropTypes.shape(Types.declaration)).isRequired,

  •  onToggleDeclarationEnabled: PropTypes.object.isRequired,
    

Shouldn't this be PropTypes.func.isRequired ?

Good catch and thanks!

::: devtools/client/inspector/rules/models/element-style.js
@@ +332,5 @@

 }

},

/**

    • Toggles the enabled property of the given CSS declaration.

s/property/state

@@ +340,5 @@

    • @param {String} declarationId
    •    The TextProperty id for the CSS declaration.
      
  • */
  • toggleDeclarationEnabled: function(ruleId, declarationId) {

toggleDeclarationEnabled is very wordy and appears in many places in this
patch.

I suggest renaming it to toggleDeclaration which is adequately explicit.
Plus, it follows the naming precedent set by togglePseudoClass.

Fixed.

@@ +341,5 @@

    •    The TextProperty id for the CSS declaration.
      
  • */
  • toggleDeclarationEnabled: function(ruleId, declarationId) {
  • const rule = this.getRule(ruleId);

If rule or declaration can be undefined, perhaps it's best to guard against
those here.

Fixed.

::: devtools/client/inspector/rules/models/text-property.js
@@ +34,5 @@

  •    coming from parseDeclarations.
    

*/
function TextProperty(rule, name, value, priority, enabled = true,
invisible = false) {

  • this.id = name + "_" + Math.random().toString(36).substr(2, 5);

We seem to have a uuid generator avaialble:
https://searchfox.org/mozilla-central/source/devtools/shared/generate-uuid.js

It does seem to cross the JS/C++ boundary so I don't know if using that
incurs any substantial performance hit.

I wonder if this id is stable across the session (or perhaps that doesn't
matter; the implications are a bit obscure to me right now).

There is at least one place where the list of text properties is rebuilt and
replaced during the same session in Rule.refresh():

https://searchfox.org/mozilla-central/source/devtools/client/inspector/rules/
models/rule.js#518-529

This gets called on the element style model by _maybeAddRule():
https://searchfox.org/mozilla-central/source/devtools/client/inspector/rules/
models/element-style.js#188

::: devtools/client/inspector/rules/new-rules.js
@@ +144,5 @@

    • @param {String} declarationId
    •     The TextProperty id for the CSS declaration.
      
  • */
  • onToggleDeclarationEnabled(ruleId, declarationId) {
  • this.elementStyle.toggleDeclarationEnabled(ruleId, declarationId);

ElementStyle.toggleDeclarationEnabled() ends up calling
Rule._applyProperties() which makes a call to the server and returns a
promise. Once that promise is resolved, we can be sure our computed object
model with rules is up to date (for example, overwritten properties which
become active as a result of toggling another property).

We should wait for that to finish before dispatching
updateRules(this.elementStyle.rules) on the next line.

There's an onChanged callback that can be declared on ElementStyle to be
notified when it has completed its computations:

https://searchfox.org/mozilla-central/source/devtools/client/inspector/rules/
models/element-style.js#75-77

Fixed.

Pushed by gabriel.luong@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/83c3a433bd15 Implement toggling on/off of a CSS declaration. r=rcaliman
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 66
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: