After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 612605 - CSS rule style
CSS rule style
Status: RESOLVED INCOMPLETE
Product: gnome-shell
Classification: Core
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
Depends on:
Blocks:
 
 
Reported: 2010-03-11 17:31 UTC by Dan Winship
Modified: 2018-07-11 17:05 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Dan Winship 2010-03-11 17:31:44 UTC
We currently have an inconsistent mix of names and style_classes in our CSS, and inconsistent naming of names and classes.

Proposed style guide rules:

    * CSS names and classes should use a "hyphenated-lowercase-words"
      style. When appropriate, they should be based on the names of their
      corresponding JS delegate classes.

      [Currently most of our rules use hyphenated-lowercase-words, but
      some use camelCase or PascalCase instead.]

    * Use name-based rules for actors that are unique within gnome-shell,
      such as the message tray:

          this.actor = new St.BoxLayout({ name: 'message-tray' });

      [This implies you *must* use name in this case. Do we want that,
      or should we just say that you *can't* use name if it's not unique,
      but you can use either name or class for unique actors?]

    * Use class-based rules for non-unique actors, such as a single
      notification within the message tray:

          this.actor = new St.Table({ style_class: 'notification' });

    * Avoid names and classes that are too generic ('add', 'remove'); use a
      consistent prefix on related classes to disambiguate.
      ('workspace-add', 'workspace-remove')

      [Currently the workspace remove button has class
      'workspace-controls add', but that seems bad IMHO because it could
      accidentally end up picking up rules for some other "add" button.
      It should be (according to this rule) 'workspace-controls workspace-add'.]

Once we agree on what the rules are, we can fix the existing code to match.

Also, not completely related, but I remember Owen saying at one point that you shouldn't do ".style-class-name StWidgetClassName", although it seems to me that this shouldn't be any less efficient than anything else--it always has to look at the entire chain of actors above you to compute your CSS anyway, right? But if I'm wrong, or if there are other efficiency concerns, we should document those too.
Comment 1 Florian Müllner 2010-03-11 18:21:27 UTC
Makes sense to me (both the proposal of adding rules to the style guide and the proposed rules themselves).


(In reply to comment #0)
>     * Use name-based rules for actors that are unique within gnome-shell,
>       such as the message tray:
> 
>           this.actor = new St.BoxLayout({ name: 'message-tray' });
> 
>       [This implies you *must* use name in this case. Do we want that,
>       or should we just say that you *can't* use name if it's not unique,
>       but you can use either name or class for unique actors?]

For me, the important part is to not use name on non-unique actors (StScrollBar/StScrollBar come to mind), no strong opinion on making the use of name for unique elements a requirement - I'd prefer name over style-class for unique actors, but I'm not sure whether it's something that should be "enforced".


> Also, not completely related, but I remember Owen saying at one point that you
> shouldn't do ".style-class-name StWidgetClassName", although it seems to me
> that this shouldn't be any less efficient than anything else--it always has to
> look at the entire chain of actors above you to compute your CSS anyway, right?

If I understood Owen correctly, in the case of StWidgetClassName the GObject-hierarchy of each actor has to be examined in addition to the clutter chain (because we want StWidgetChildClassName to match as well).
Comment 2 Owen Taylor 2010-03-11 18:29:02 UTC
(In reply to comment #1)

> > Also, not completely related, but I remember Owen saying at one point that you
> > shouldn't do ".style-class-name StWidgetClassName", although it seems to me
> > that this shouldn't be any less efficient than anything else--it always has to
> > look at the entire chain of actors above you to compute your CSS anyway, right?
> 
> If I understood Owen correctly, in the case of StWidgetClassName the
> GObject-hierarchy of each actor has to be examined in addition to the clutter
> chain (because we want StWidgetChildClassName to match as well).

No, that isn't the problem I was talking about - we do the GObject-hierarchy match efficiently using GObject type check methods ... if you have a rule "StBoxLayout { }" - that basically boilds down to ST_IS_BOX_LAYOUT(). The problem is (as described above) that we can't reject the rule based only the actor itself, we have to check parent actors in the layout hierarchy.
Comment 3 Dan Winship 2010-03-11 18:52:23 UTC
but don't you *always* have to check parent actors in the layout hierarchy?
Comment 4 Owen Taylor 2010-03-11 19:03:34 UTC
(In reply to comment #3)
> but don't you *always* have to check parent actors in the layout hierarchy?

You have to resolve the style for the parent actor before resolving the style for the child actor to deal with inheritance, but that's very different from having to match against the parent actor for individual rules.

(There are likely sophisticated approaches to resolving CSS rules that could be much more efficient in some cases - it might be interesting to look at the browser CSS engines if we find CSS matching to be a big bottleneck.)
Comment 5 Florian Müllner 2018-07-11 17:05:48 UTC
The style was completely rewritten in 3.16, which cleaned up a lot of the pain points. And while still nobody has spend time on codifying the rules, the designers don't seem overly bothered with it - if they supply us with such guidance, I'm happy to add it in the repo, but an old bugzilla bug is unlikely to make it happen, so closing it now (and thus exclude it from a future gitlab migration).