Why do CSS declarations for about:addons
have to be placed in userContent
and not userChrome
, given that the namespace of about:addons
is XUL?
This is regarding CSS programming for Firefox.
Related: What namespace should be defined in Firefox's userContent.css?
The short answer to this is that the page
about:addons
is considered content. Thus, userContent.css is used. The namespace(s) (e.g. HTML, XUL) of the elements used in the<document>
don't matter with respect to which of userChrome.css or userContent.css is used (only one or the other is used per<document>
).What does matter is the role for which the
<document>
is being used. If the<document>
is being used for chrome, userChrome.css is used. If it's being used for anything else, it's considered content for which userContent.css is used.If it's something that's displayed in the content area of Firefox by navigating to the page (e.g. by changing the entry in the URL bar), then it's content, even if it's using XUL elements.
MDN defines "chrome" as:
It also provides a link to a blog post, "Browser and GUI Chrome", which provides a similar definition:
In Firefox, the content portion of the display is:
The chrome portion includes everything else. This includes interface popups (e.g. the add bookmarks dialog), but not content-page popups. While it also includes the borders around the window, many people generally think of it including this portion of the display:
More detail
Specifically, only one of userChrome.css or userContent.css is applied to each
<document>
. It is done in this code. The choice in the code comes down to what value is of the propertydocument.docShell.itemType
. If that value is a 0, then userChrome.css is used, if not (or does not exist, etc.) then userContent.css is used.The
itemType
can have the following values:Which is assigned depends on how the page/file is loaded, not just the type of file, or the URL. For instance, an .xul file which is loaded from a
chrome://
URL may be contained in atypeContent
<document>
(has userContent.css applied), if it was loaded from the URLbar. On the other hand, the same .xul file which is loaded as the content for a<window>
withopenDialog()
may be in atypeChrome
document (has userChrome.css applied).The namespace of the elements contained in the file used for the doesn't matter to which of the two files, userChrome.css or userContent.css, is used. The namespace does matter for if the CSS applies to the elements (at least if it is a
typeChrome
<document>
).