既然命名空间是 XUL,为什么 about:addons 的 about:addons 声明放在 userContent 而不是 userChrome 中?

Why are CSS declarations for about:addons placed in userContent and not userChrome, given that the namespace is XUL?

为什么 about:addons 的 CSS 声明必须放在 userContent 而不是 userChrome,因为 about:addons 的命名空间是 XUL?

这是关于 CSS Firefox 编程的。

相关:What namespace should be defined in Firefox's userContent.css?

对此的简短回答是页面 about:addons 被视为内容。因此,使用 userContent.css<document> 中使用的元素的名称空间(例如 HTML、XUL)与 userChrome.css 中的哪个无关紧要或使用 userContent.css(每个 <document> 只使用一个或另一个)。

重要的是使用 <document> 的角色。如果 <document> 用于 chrome,则使用 userChrome.css。如果它被用于其他任何事情,它被认为是使用 userContent.css 的内容。

如果它是通过导航到页面(例如,通过更改 URL bar 中的条目)在 Firefox 的内容区域中显示的内容,那么它就是内容,即使它使用的是 XUL 元素。

MDN defines "chrome" as:

In a browser, the chrome is any visible aspect of a browser aside from the webpages themselves (e.g., toolbars, menu bar, tabs). This should not to be confused with the Google Chrome browser.

它还提供了一个link给一个博客post,“Browser and GUI Chrome”,它提供了类似的定义:

Chrome is the visual design elements that give users information about or commands to operate on the screen's content (as opposed to being part of that content). These design elements are provided by the underlying system — whether it be an operating system, a website, or an application — and surround the user's data.

在 Firefox 中,显示的内容部分是:

chrome 部分包括其他所有内容。这包括界面弹出窗口(例如添加书签对话框),但不包括内容页面弹出窗口。虽然它还包括 window 周围的边框,但许多人通常认为它包括显示的这一部分:

更多详情

具体来说,只有userChrome.cssuserContent.css中的一个应用于每个<document> .完成了 in this code。代码中的选择归结为 属性 document.docShell.itemType 的值。如果该值为 0,则使用 userChrome.css,如果不是(或不存在等),则使用 userContent.css被使用。

itemType 可以有以下值:

  • typeChrome = 0,
  • typeContent = 1,
  • typeContentWrapper = 2,
  • typeChromeWrapper = 3,
  • typeAll = 2147483647

分配哪个取决于 page/file 的加载方式,而不仅仅是文件类型或 URL。例如,从 chrome:// URL 加载的 .xul 文件可能包含在 typeContent <document> 中(具有 userContent.css 已应用),如果它是从 URL 栏加载的。另一方面,作为 <window>openDialog() 的内容加载的同一个 .xul 文件可能位于 typeChrome 文档中(已应用 userChrome.css)。

文件中包含的元素的命名空间用于 userChrome.css[ 这两个文件中的哪一个无关紧要=108=], 被使用。如果 CSS 应用于元素(至少如果它是 typeChrome <document>),命名空间确实很重要。