Closed Bug 705707 Opened 13 years ago Closed 12 years ago

Style Inspector doesn't take into account chrome:// stylesheets

Categories

(DevTools :: Inspector, defect, P2)

defect

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 13

People

(Reporter: past, Assigned: miker)

References

Details

(Whiteboard: [computedview][ruleview])

Attachments

(1 file, 7 obsolete files)

Apparently using the rule view or the property view of our style inspector does not work for XUL documents. I've tried both chrome:// and file:// URLs, without any observable difference. Try opening one of the following:

chrome://browser/content/styleeditor.xul
file:///path/to/your/repo/browser/devtools/styleeditor/styleeditor.xul

For the latter you need to set dom.allow_XUL_XBL_for_file to true. Highlight the search box and observe that the rule view is empty. The property view is empty as well, but if you uncheck the "only user styles" option, you can see there is a matching max-width rule from splitview.css. There is also a -moz-margin-start in that rule that is not displayed at all.

It would make working in browser/extension code much easier if these tools could properly display such information.
Whiteboard: [styleinspector]
Bug triage, filter on PEGASUS.
Priority: -- → P2
Whiteboard: [styleinspector] → [computedview][ruleview]
Assignee: nobody → mratcliffe
Status: NEW → ASSIGNED
This is because we block chrome stylesheets when the "only user styles" checkbox is checked (that is the meaning of the option).

If I remember correctly, there was more to this bug ... I will need to discuss it with Panos.
(In reply to Michael Ratcliffe from comment #2)
> This is because we block chrome stylesheets when the "only user styles"
> checkbox is checked (that is the meaning of the option).

Unchecking the option is not a workaround that can be used in the rules view, unfortunately. Furthermore, from the POV of a XUL application/add-on developer, styles included in a XUL file *are* the user styles. The label is misleading in that particular use case.
The meaning of "only user styles" in normal docs is "only show properties that have been changed from their defaults and to hide chrome CSS." The meaning in XUL docs will be "only show properties that have been changed from their defaults."

-moz-*-start and -moz-*-end are simply aliases to -moz-*-left and -moz-*-right (depending on the locale) so they would be shown in computed styles as margin-(left|right). All that we need to do here is include chrome css when inspecting XUL documents.
Sorry, I obviously meant:
-moz-*-start and -moz-*-end are simply aliases to *-left and *-right (depending on the locale) so they would be shown in computed styles as margin-(left|right). All that we need to do here is include chrome css when inspecting XUL documents.
Attached patch Patch (obsolete) — Splinter Review
This patch allows the computed and rule views to work with XUL documents.
Attachment #588883 - Flags: review?(dcamp)
msucan pointed out that using the file extension to determine if we have a xul doc is probably not the best way. I will change this to use the root namespace instead.
Obviously using the file extension to check for a xul doc was not ideal so now we use the root element's namespace instead.
Attachment #588883 - Attachment is obsolete: true
Attachment #588883 - Flags: review?(dcamp)
Attachment #589145 - Flags: review?(dcamp)
Why does CssLogic.isSystemStyleSheet return true for chrome: URIs? This seems bogus.
chrome == system for the sake of this method. The implementation of this is basically straight out of firebug.
(In reply to Rob Campbell [:rc] (robcee) from comment #10)
> chrome == system for the sake of this method.

What chrome stylesheets affect web pages?

> The implementation of this is basically straight out of firebug.

Sure, but this doesn't make it right.
it does for about 99% of our content inspection needs. When we poll the style system for a list of stylesheets, it gives us everything on the page. That includes a good number of chrome: stylesheets that come from the system.

It might be worth somehow separating these from the stylesheets lookup itself, but that'll require some extra smarts from the layout machinery.
Does DOM Inspector use the same approach to solve this?
(In reply to Dão Gottwald [:dao] from comment #13)
> Does DOM Inspector use the same approach to solve this?

I expect so since they were both written by the same guy.

http://hg.mozilla.org/dom-inspector/
But does DOMi contain the patch proposed here? DOMi doesn't suffer from this bug, so presumably it doesn't have exactly the same code as Firebug.
Attached patch Patch without chrome check (obsolete) — Splinter Review
Dão is correct here, we do not need to filter chrome url's in CssLogic.isSystemStyleSheet because they are only included when the UA filter is enabled and then we need to see them anyway.

In effect this check did nothing except waste cycles. Removing the check causes no issues so ... done.
Attachment #589145 - Attachment is obsolete: true
Attachment #589145 - Flags: review?(dcamp)
Attachment #591421 - Flags: review?(dcamp)
Comment on attachment 591421 [details] [diff] [review]
Patch without chrome check

Why do you need to detect XUL documents at this point?

Note that XML documents can mix different namespaces, which makes "XUL document" kind of meaningless...
After discussing this as a group we didn't like the idea of removing the chrome check even though it does not affect CSSLogic. Our reasoning is that CssLogic is a utility that could be used by other tools (it is used by the rule view). And these other tools should be able to make use of this method.

We are struggling to understand exactly what your issue is with this method, to all intents and purposes chrome stylesheets are system stylesheets so all of these checks are valid and there is no bug.

Can you explain your issue with CssLogic.isSystemStyleSheet? Is it just the name of the method or is it the definition of what constitutes a system stylesheet?
Attached patch chrome check added again (obsolete) — Splinter Review
Attachment #591421 - Attachment is obsolete: true
Attachment #591421 - Flags: review?(dcamp)
Attachment #591800 - Flags: review?(dao)
(In reply to Michael Ratcliffe from comment #18)
> After discussing this as a group we didn't like the idea of removing the
> chrome check even though it does not affect CSSLogic. Our reasoning is that
> CssLogic is a utility that could be used by other tools (it is used by the
> rule view). And these other tools should be able to make use of this method.

I'm not sure what this means. What exactly is the impact on the rule view?

> to all intents and purposes chrome stylesheets are system stylesheets so all
> of these checks are valid and there is no bug.

Chrome stylesheets styling chrome documents aren't system stylesheets. This seems to be what this bug is about.

> Can you explain your issue with CssLogic.isSystemStyleSheet? Is it just the name of
> the method or is it the definition of what constitutes a system stylesheet?

The latter.

Has somebody checked by now what DOM Inspector is doing?
Robcee has already looked at this patch so he may as well be the one to review it.

(In reply to Dão Gottwald [:dao] from comment #20)
> (In reply to Michael Ratcliffe from comment #18)
> > After discussing this as a group we didn't like the idea of removing the
> > chrome check even though it does not affect CSSLogic. Our reasoning is that
> > CssLogic is a utility that could be used by other tools (it is used by the
> > rule view). And these other tools should be able to make use of this method.
> 
> I'm not sure what this means. What exactly is the impact on the rule view?
> 

Probably none actually, but the intent of the method should not be changed.

> > to all intents and purposes chrome stylesheets are system stylesheets so all
> > of these checks are valid and there is no bug.
> 
> Chrome stylesheets styling chrome documents aren't system stylesheets. This
> seems to be what this bug is about.
> 

True

> Has somebody checked by now what DOM Inspector is doing?

Yes, but it works completely differently because it has no "only user styles" "only user styles" checkbox.

> > Can you explain your issue with CssLogic.isSystemStyleSheet? Is it just the name of
> > the method or is it the definition of what constitutes a system stylesheet?
> 
> The latter.
> 

Ah, okay then ... method renamed to isNotContentStyleSheet as that is actually the intent of this method.
Attachment #591800 - Attachment is obsolete: true
Attachment #591800 - Flags: review?(dao)
Attachment #592108 - Flags: review?(rcampbell)
Attachment #592108 - Flags: feedback?(dao)
Comment on attachment 592108 [details] [diff] [review]
isSystemStyleSheet renamed to isNotContentStyleSheet

-CssLogic.isSystemStyleSheet = function CssLogic_isSystemStyleSheet(aSheet)
+CssLogic.isNotContentStyleSheet = function CssLogic_isNotContentStyleSheet(aSheet)

I honestly didn't have a problem with the original name, I find this one uglier, but in the interests of appeasing everyone, let's go with it.
Attachment #592108 - Flags: review?(rcampbell) → review+
(In reply to Michael Ratcliffe from comment #21)
> > Has somebody checked by now what DOM Inspector is doing?
> 
> Yes, but it works completely differently because it has no "only user
> styles" "only user styles" checkbox.

Nor does it list chrome: stylesheets for web content. What problem is the exclusion of chrome: trying to solve?
Comment on attachment 592108 [details] [diff] [review]
isSystemStyleSheet renamed to isNotContentStyleSheet

As mentioned earlier, the XUL document check is bogus since XUL and other languages such as HTML can be mixed.
Attachment #592108 - Flags: feedback?(dao) → feedback-
Comment on attachment 592108 [details] [diff] [review]
isSystemStyleSheet renamed to isNotContentStyleSheet

+      // Refresh source filter in case the element being inspected is inside a
+      // XUL document.
+      this.refreshSourceFilter();

...

 
+      // Refresh source filter in case the element being inspected is inside a
+      // XUL document. This must be done after templateRoot has been processed.
+      this.refreshSourceFilter();

...

+    let xul =
+      this.viewedElement.ownerDocument.documentElement.namespaceURI == XUL_NS;

Dão's right about this being overly-specific.

What about using a check similar to the isNotContentStyleSheet (ugh) method to check if the page we're inspecting is one of about: resource: chrome: URLs? That might get us a little closer to being accurate.

I really do wish we had a better name for these classes of pages. "System" feels about right.
Attachment #592108 - Flags: review+
... though the check does conform with the intent of this bug as described in the Summary.

dcamp, what say you?
Whiteboard: [computedview][ruleview] → [computedview][ruleview][has-patch]
(In reply to Rob Campbell [:rc] (robcee) from comment #26)
> ... though the check does conform with the intent of this bug as described
> in the Summary.

Rather than modelling the patch after some inaccurate summary, let's fix the summary? ;)
Summary: XUL documents cannot be inspected with the style inspector → Style Inspector doesn't take into account chrome:// stylesheets
this is acceptable! :)
So, let's rethink this ... if a user has only added one line of CSS to an element they do not expect to see hundreds of rules (we want to show only non-default values by default). We have been doing this by filtering out chrome & system stylesheets.

The problem is that theoretically any chrome: or resource: stylesheet can be used by any page. What we really need is a simple way to tell if a rule comes from a stylesheet on the page or whether it comes from outside the page.

We could just use styleSheets.ownerNode.baseURI to check if the sheet is from outside the document.
Attached patch Complete rewrite (obsolete) — Splinter Review
I have totally rewritten the isSystemStylesheet method and changed it to isContentStylesheet (reversing the logic). We no longer rely on URL prefixes to detect non-content stylesheets as this approach works fine in all situations.
Attachment #592108 - Attachment is obsolete: true
Attachment #593867 - Flags: review?(mihai.sucan)
Attachment #593867 - Flags: feedback?(dao)
Comment on attachment 593867 [details] [diff] [review]
Complete rewrite

>+      // Refresh source filter in case the element being inspected is inside a
>+      // XUL document.

>+      // Refresh source filter in case the element being inspected is inside a
>+      // XUL document. This must be done after templateRoot has been processed.

>+  /**
>+   * When onlyUserStyles.checked is true we do not display properties that have
>+   * no matched selectors, and we do not display UA styles unless we are
>+   * inspecting a XUL document. If .checked is false we display properties with
>+   * and without matched selectors, and we include the UA styles.
>+   */

Are these comments about XUL still accurate? Your code doesn't seem to care for XUL at all (which is good).
Attached patch Fixed bad comments (obsolete) — Splinter Review
You are right, we don't care about the document type any longer.

I have fixed all comments now.
Attachment #593867 - Attachment is obsolete: true
Attachment #593867 - Flags: review?(mihai.sucan)
Attachment #593867 - Flags: feedback?(dao)
Attachment #593914 - Flags: review?(mihai.sucan)
Attachment #593914 - Flags: feedback?(dao)
Comment on attachment 593914 [details] [diff] [review]
Fixed bad comments

Looks solid to me overall.
Attachment #593914 - Flags: feedback?(dao) → feedback+
Comment on attachment 593914 [details] [diff] [review]
Fixed bad comments

Review of attachment 593914 [details] [diff] [review]:
-----------------------------------------------------------------

This looks really good! Thanks Mike!

::: browser/devtools/styleinspector/CssLogic.jsm
@@ +878,5 @@
>      return true;
>    }
>  
> +  // If the sheet has a CSSImportRule we need to check the parent stylesheet.
> +  if (aSheet.ownerRule instanceof Ci.nsIDOMCSSImportRule) {

Can ownerRule be something different than null or Ci.nsIDOMCSSImportRule?
Attachment #593914 - Flags: review?(mihai.sucan) → review+
Nope, just null or importRule ... see http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CSSStyleSheet-ownerRule

I still think we should keep the instance check in case of future expansion.
Whiteboard: [computedview][ruleview][has-patch] → [computedview][ruleview][land-in-fx-team]
https://hg.mozilla.org/integration/fx-team/rev/17a1f5c47b25
Whiteboard: [computedview][ruleview][land-in-fx-team] → [computedview][ruleview][fixed-in-fx-team]
backed out in rev 4a07e7 due to bug 726101
Whiteboard: [computedview][ruleview][fixed-in-fx-team] → [computedview][ruleview]
Green on try now so this should now be landable.
Whiteboard: [computedview][ruleview] → [computedview][ruleview][land-in-fx-team]
Comment on attachment 596676 [details] [diff] [review]
[in-fx-team] Whitelist xul iri for the test

Landed:
https://hg.mozilla.org/integration/fx-team/rev/30cb97299656
Attachment #596676 - Attachment description: Whitelist xul iri for the test → [in-fx-team] Whitelist xul iri for the test
Whiteboard: [computedview][ruleview][land-in-fx-team] → [computedview][ruleview][fixed-in-fx-team]
https://hg.mozilla.org/mozilla-central/rev/30cb97299656
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Whiteboard: [computedview][ruleview][fixed-in-fx-team] → [computedview][ruleview]
Target Milestone: --- → Firefox 13
Depends on: 953379
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: