From 4c663869d9a7a8bc00558e19ad5df77d1b06622c Mon Sep 17 00:00:00 2001 From: Serban Stanca Date: Sat, 24 May 2025 04:50:14 +0300 Subject: [PATCH] Revert "Bug 1968202 - Generalize GlobalStyleSheetCache to support author stylesheets. r=smaug" for causing wpt failures in prefetch-transfer-size-executor.html. This reverts commit e2ac38c2a8a6cca068b3e507bc9d640fc1914bd6. --- .../actors/utils/stylesheets-manager.js | 4 +- dom/base/ShadowRoot.cpp | 10 -- dom/base/ShadowRoot.h | 4 - dom/html/HTMLDetailsElement.cpp | 15 ++- layout/base/AccessibleCaret.cpp | 17 +++- .../tests/browser_stylesheet_change_events.js | 2 +- layout/style/BuiltInStyleSheetList.h | 35 ------- layout/style/BuiltInStyleSheets.h | 38 -------- layout/style/GlobalStyleSheetCache.cpp | 91 ++++++++----------- layout/style/GlobalStyleSheetCache.h | 28 +++--- layout/style/Loader.cpp | 5 +- layout/style/URLExtraData.cpp | 2 +- layout/style/URLExtraData.h | 5 +- layout/style/UserAgentStyleSheetID.h | 23 +++++ layout/style/UserAgentStyleSheetList.h | 33 +++++++ layout/style/jar.mn | 2 - layout/style/moz.build | 6 +- servo/ports/geckolib/glue.rs | 1 + 18 files changed, 149 insertions(+), 172 deletions(-) delete mode 100644 layout/style/BuiltInStyleSheetList.h delete mode 100644 layout/style/BuiltInStyleSheets.h create mode 100644 layout/style/UserAgentStyleSheetID.h create mode 100644 layout/style/UserAgentStyleSheetList.h diff --git a/devtools/server/actors/utils/stylesheets-manager.js b/devtools/server/actors/utils/stylesheets-manager.js index 9bada7757728..00b980d068bc 100644 --- a/devtools/server/actors/utils/stylesheets-manager.js +++ b/devtools/server/actors/utils/stylesheets-manager.js @@ -997,8 +997,8 @@ class StyleSheetsManager extends EventEmitter { // FIXME(bug 1826538): Make accessiblecaret.css and similar UA-widget // sheets system sheets, then remove this special-case. if ( - href === "resource://gre-resources/accessiblecaret.css" || - href === "resource://gre-resources/details.css" || + href === "resource://content-accessible/accessiblecaret.css" || + href === "resource://content-accessible/details.css" || (href === "resource://devtools-highlighter-styles/highlighters.css" && this.#targetActor.sessionContext.type !== "all") ) { diff --git a/dom/base/ShadowRoot.cpp b/dom/base/ShadowRoot.cpp index 449bc189de4f..ad6eb3d328f7 100644 --- a/dom/base/ShadowRoot.cpp +++ b/dom/base/ShadowRoot.cpp @@ -23,7 +23,6 @@ #include "mozilla/dom/TrustedTypeUtils.h" #include "mozilla/dom/TrustedTypesConstants.h" #include "mozilla/dom/UnbindContext.h" -#include "mozilla/GlobalStyleSheetCache.h" #include "mozilla/EventDispatcher.h" #include "mozilla/IdentifierMapEntry.h" #include "mozilla/PresShell.h" @@ -549,15 +548,6 @@ void ShadowRoot::StyleSheetApplicableStateChanged(StyleSheet& aSheet) { } } -void ShadowRoot::AppendBuiltInStyleSheet(BuiltInStyleSheet aSheet) { - auto* cache = GlobalStyleSheetCache::Singleton(); - // NOTE(emilio): It's important to Clone() the stylesheet to avoid leaking, - // since the built-in sheet is kept alive forever, and AppendStyleSheet will - // set the associated shadow root and global of the stylesheet. - RefPtr sheet = cache->BuiltInSheet(aSheet)->Clone(nullptr, nullptr); - AppendStyleSheet(*sheet); -} - void ShadowRoot::RemoveSheetFromStyles(StyleSheet& aSheet) { MOZ_ASSERT(aSheet.IsApplicable()); MOZ_ASSERT(mServoStyles); diff --git a/dom/base/ShadowRoot.h b/dom/base/ShadowRoot.h index 3464da9ab3c4..d3545852f2f4 100644 --- a/dom/base/ShadowRoot.h +++ b/dom/base/ShadowRoot.h @@ -29,7 +29,6 @@ class EventChainPreVisitor; class ServoStyleRuleMap; enum class StyleRuleChangeKind : uint32_t; -enum class BuiltInStyleSheet : uint8_t; namespace css { class Rule; @@ -99,9 +98,6 @@ class ShadowRoot final : public DocumentFragment, public DocumentOrShadowRoot { void SheetCloned(StyleSheet&); void StyleSheetApplicableStateChanged(StyleSheet&); - // Adds a built-in author style-sheet to the shadow tree. - void AppendBuiltInStyleSheet(BuiltInStyleSheet); - /** * Clones internal state, for example stylesheets, of aOther to 'this'. */ diff --git a/dom/html/HTMLDetailsElement.cpp b/dom/html/HTMLDetailsElement.cpp index 3af0423e303b..fe1c8382f7cf 100644 --- a/dom/html/HTMLDetailsElement.cpp +++ b/dom/html/HTMLDetailsElement.cpp @@ -101,7 +101,20 @@ void HTMLDetailsElement::SetupShadowTree() { nsNodeInfoManager* nim = OwnerDoc()->NodeInfoManager(); RefPtr slotNodeInfo = nim->GetNodeInfo( nsGkAtoms::slot, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE); - sr->AppendBuiltInStyleSheet(BuiltInStyleSheet::Details); + { + RefPtr linkNodeInfo = nim->GetNodeInfo( + nsGkAtoms::link, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE); + RefPtr link = + NS_NewHTMLLinkElement(linkNodeInfo.forget()); + if (NS_WARN_IF(!link)) { + return; + } + link->SetAttr(nsGkAtoms::rel, u"stylesheet"_ns, IgnoreErrors()); + link->SetAttr(nsGkAtoms::href, + u"resource://content-accessible/details.css"_ns, + IgnoreErrors()); + sr->AppendChildTo(link, kNotify, IgnoreErrors()); + } { RefPtr slot = NS_NewHTMLSlotElement(do_AddRef(slotNodeInfo)); diff --git a/layout/base/AccessibleCaret.cpp b/layout/base/AccessibleCaret.cpp index 8ccaf8cf17e0..6812774f23f6 100644 --- a/layout/base/AccessibleCaret.cpp +++ b/layout/base/AccessibleCaret.cpp @@ -8,7 +8,6 @@ #include "AccessibleCaretLogger.h" #include "mozilla/Assertions.h" -#include "mozilla/BuiltInStyleSheets.h" #include "mozilla/ErrorResult.h" #include "mozilla/FloatingPoint.h" #include "mozilla/PresShell.h" @@ -204,6 +203,7 @@ void AccessibleCaret::CreateCaretElement() const { // Content structure of AccessibleCaret //
<- CaretElement() // <#shadow-root> + // //
<- TextOverlayElement() //
<- CaretImageElement() @@ -215,7 +215,20 @@ void AccessibleCaret::CreateCaretElement() const { ShadowRoot* root = mCaretElementHolder->Root(); Document* doc = host.OwnerDoc(); - root->AppendBuiltInStyleSheet(BuiltInStyleSheet::AccessibleCaret); + { + RefPtr linkNodeInfo = doc->NodeInfoManager()->GetNodeInfo( + nsGkAtoms::link, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE); + RefPtr link = + NS_NewHTMLLinkElement(linkNodeInfo.forget()); + if (NS_WARN_IF(!link)) { + return; + } + link->SetAttr(nsGkAtoms::rel, u"stylesheet"_ns, IgnoreErrors()); + link->SetAttr(nsGkAtoms::href, + u"resource://content-accessible/accessiblecaret.css"_ns, + IgnoreErrors()); + root->AppendChildTo(link, kNotify, IgnoreErrors()); + } auto CreateAndAppendChildElement = [&](const nsLiteralString& aElementId) { RefPtr child = doc->CreateHTMLElement(nsGkAtoms::div); diff --git a/layout/base/tests/browser_stylesheet_change_events.js b/layout/base/tests/browser_stylesheet_change_events.js index 092b2d83f289..c86719705070 100644 --- a/layout/base/tests/browser_stylesheet_change_events.js +++ b/layout/base/tests/browser_stylesheet_change_events.js @@ -41,7 +41,7 @@ async function testApplicableStateChangeEvent(testRoot) { // accessiblecaret.css might be reported, interfering with the test // assertions, so let's ignore it return ( - e.stylesheet?.href === "resource://gre-resources/accessiblecaret.css" + e.stylesheet?.href === "resource://content-accessible/accessiblecaret.css" ); } diff --git a/layout/style/BuiltInStyleSheetList.h b/layout/style/BuiltInStyleSheetList.h deleted file mode 100644 index 3b30631585ec..000000000000 --- a/layout/style/BuiltInStyleSheetList.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* list of user agent style sheets that GlobalStyleSheetCache manages */ - -/* - * STYLE_SHEET(identifier_, url_, flags_) - * - * identifier_ - * An identifier for the style sheet, suitable for use as an enum class value. - * - * url_ - * The URL of the style sheet. - * - * flags_ - * UserStyleSheetType indicating whether the sheet can be safely placed in - * shared memory, and the kind of sheet it is. - */ - -STYLE_SHEET(ContentEditable, "resource://gre/res/contenteditable.css", UA) -STYLE_SHEET(CounterStyles, "resource://gre-resources/counterstyles.css", UA) -STYLE_SHEET(Forms, "resource://gre-resources/forms.css", UA) -STYLE_SHEET(HTML, "resource://gre-resources/html.css", UA) -STYLE_SHEET(MathML, "resource://gre-resources/mathml.css", UA) -STYLE_SHEET(NoFrames, "resource://gre-resources/noframes.css", UA) -STYLE_SHEET(Quirk, "resource://gre-resources/quirk.css", UA) -STYLE_SHEET(Scrollbars, "resource://gre-resources/scrollbars.css", UA) -STYLE_SHEET(SVG, "resource://gre/res/svg.css", UA) -STYLE_SHEET(UA, "resource://gre-resources/ua.css", UA) -STYLE_SHEET(XUL, "chrome://global/content/xul.css", UAUnshared) -STYLE_SHEET(AccessibleCaret, "resource://gre-resources/accessiblecaret.css", Author) -STYLE_SHEET(Details, "resource://gre-resources/details.css", Author) diff --git a/layout/style/BuiltInStyleSheets.h b/layout/style/BuiltInStyleSheets.h deleted file mode 100644 index 078f10b65ffa..000000000000 --- a/layout/style/BuiltInStyleSheets.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* an identifier for User Agent style sheets */ - -#ifndef mozilla_BuiltInStyleSheets_h -#define mozilla_BuiltInStyleSheets_h - -#include -#include "mozilla/TypedEnumBits.h" - -namespace mozilla { - -enum class BuiltInStyleSheetFlags : uint8_t { - UA = 1, - Author = 1 << 1, - // By default sheets are shared, except xul.css which we only need in the - // parent process. - NotShared = 1 << 2, - - UAUnshared = (UA | NotShared), -}; - -MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(BuiltInStyleSheetFlags); - -enum class BuiltInStyleSheet : uint8_t { -#define STYLE_SHEET(identifier_, url_, flags_) identifier_, -#include "mozilla/BuiltInStyleSheetList.h" -#undef STYLE_SHEET - Count -}; - -} // namespace mozilla - -#endif // mozilla_BuiltInStyleSheets_h diff --git a/layout/style/GlobalStyleSheetCache.cpp b/layout/style/GlobalStyleSheetCache.cpp index 68162af0e83c..24e0e5352a3e 100644 --- a/layout/style/GlobalStyleSheetCache.cpp +++ b/layout/style/GlobalStyleSheetCache.cpp @@ -19,7 +19,6 @@ #include "mozilla/dom/SRIMetadata.h" #include "mozilla/ipc/SharedMemoryHandle.h" #include "mozilla/ipc/SharedMemoryMapping.h" -#include "mozilla/ServoBindings.h" #include "MainThreadUtils.h" #include "nsContentUtils.h" #include "nsIConsoleService.h" @@ -31,6 +30,8 @@ #include "nsServiceManagerUtils.h" #include "nsXULAppAPI.h" +#include + namespace mozilla { // The GlobalStyleSheetCache is responsible for sharing user agent style sheet @@ -129,30 +130,15 @@ nsresult GlobalStyleSheetCache::Observe(nsISupports* aSubject, return NS_OK; } -static constexpr struct { - nsLiteralCString mURL; - BuiltInStyleSheetFlags mFlags; -} kBuiltInSheetInfo[] = { -#define STYLE_SHEET(identifier_, url_, flags_) \ - {nsLiteralCString(url_), BuiltInStyleSheetFlags::flags_}, -#include "mozilla/BuiltInStyleSheetList.h" -#undef STYLE_SHEET -}; - -NotNull GlobalStyleSheetCache::BuiltInSheet( - BuiltInStyleSheet aSheet) { - auto& slot = mBuiltIns[aSheet]; - if (!slot) { - const auto& info = kBuiltInSheetInfo[size_t(aSheet)]; - const auto parsingMode = (info.mFlags & BuiltInStyleSheetFlags::UA) - ? eAgentSheetFeatures - : eAuthorSheetFeatures; - MOZ_ASSERT(info.mFlags & BuiltInStyleSheetFlags::UA || - info.mFlags & BuiltInStyleSheetFlags::Author); - slot = LoadSheetURL(info.mURL, parsingMode, eCrash); +#define STYLE_SHEET(identifier_, url_, shared_) \ + NotNull GlobalStyleSheetCache::identifier_##Sheet() { \ + if (!m##identifier_##Sheet) { \ + m##identifier_##Sheet = LoadSheetURL(url_, eAgentSheetFeatures, eCrash); \ + } \ + return WrapNotNull(m##identifier_##Sheet); \ } - return WrapNotNull(slot); -} +#include "mozilla/UserAgentStyleSheetList.h" +#undef STYLE_SHEET StyleSheet* GlobalStyleSheetCache::GetUserContentSheet() { return mUserContentSheet; @@ -208,9 +194,9 @@ size_t GlobalStyleSheetCache::SizeOfIncludingThis( #define MEASURE(s) n += s ? s->SizeOfIncludingThis(aMallocSizeOf) : 0; - for (const auto& sheet : mBuiltIns) { - MEASURE(sheet); - } +#define STYLE_SHEET(identifier_, url_, shared_) MEASURE(m##identifier_##Sheet); +#include "mozilla/UserAgentStyleSheetList.h" +#undef STYLE_SHEET MEASURE(mUserChromeSheet); MEASURE(mUserContentSheet); @@ -284,25 +270,21 @@ GlobalStyleSheetCache::GlobalStyleSheetCache() { reinterpret_cast(sSharedMemory.data())) { MOZ_RELEASE_ASSERT(header->mMagic == Header::kMagic); - for (auto kind : MakeEnumeratedRange(BuiltInStyleSheet::Count)) { - const auto& info = kBuiltInSheetInfo[size_t(kind)]; - if (info.mFlags & BuiltInStyleSheetFlags::NotShared) { - continue; - } - const auto parsingMode = (info.mFlags & BuiltInStyleSheetFlags::UA) - ? eAgentSheetFeatures - : eAuthorSheetFeatures; - LoadSheetFromSharedMemory(info.mURL, &mBuiltIns[kind], parsingMode, - header, kind); - } +#define STYLE_SHEET(identifier_, url_, shared_) \ + if (shared_) { \ + LoadSheetFromSharedMemory(url_, &m##identifier_##Sheet, \ + eAgentSheetFeatures, header, \ + UserAgentStyleSheetID::identifier_); \ + } +#include "mozilla/UserAgentStyleSheetList.h" +#undef STYLE_SHEET } } } void GlobalStyleSheetCache::LoadSheetFromSharedMemory( - const nsACString& aURL, RefPtr* aSheet, - SheetParsingMode aParsingMode, const Header* aHeader, - BuiltInStyleSheet aSheetID) { + const char* aURL, RefPtr* aSheet, SheetParsingMode aParsingMode, + const Header* aHeader, UserAgentStyleSheetID aSheetID) { auto i = size_t(aSheetID); auto sheet = @@ -395,20 +377,19 @@ void GlobalStyleSheetCache::InitSharedSheetsInParent() { // Normally calling ToShared on UA sheets should not fail. It happens // in practice in odd cases that seem like corrupted installations; see bug // 1621773. On failure, return early and fall back to non-shared sheets. - for (auto kind : MakeEnumeratedRange(BuiltInStyleSheet::Count)) { - auto i = size_t(kind); - const auto& info = kBuiltInSheetInfo[i]; - if (info.mFlags & BuiltInStyleSheetFlags::NotShared) { - continue; - } - StyleSheet* sheet = BuiltInSheet(kind); - URLExtraData::sShared[i] = sheet->URLData(); - header->mSheets[i] = sheet->ToShared(builder.get(), message); - if (!header->mSheets[i]) { - CrashReporter::AppendAppNotesToCrashReport("\n"_ns + message); - return; - } +#define STYLE_SHEET(identifier_, url_, shared_) \ + if (shared_) { \ + StyleSheet* sheet = identifier_##Sheet(); \ + size_t i = size_t(UserAgentStyleSheetID::identifier_); \ + URLExtraData::sShared[i] = sheet->URLData(); \ + header->mSheets[i] = sheet->ToShared(builder.get(), message); \ + if (!header->mSheets[i]) { \ + CrashReporter::AppendAppNotesToCrashReport("\n"_ns + message); \ + return; \ + } \ } +#include "mozilla/UserAgentStyleSheetList.h" +#undef STYLE_SHEET // Finished writing into the shared memory. Freeze it, so that a process // can't confuse other processes by changing the UA style sheet contents. @@ -498,7 +479,7 @@ void GlobalStyleSheetCache::InitFromProfile() { } RefPtr GlobalStyleSheetCache::LoadSheetURL( - const nsACString& aURL, SheetParsingMode aParsingMode, + const char* aURL, SheetParsingMode aParsingMode, FailureAction aFailureAction) { nsCOMPtr uri; NS_NewURI(getter_AddRefs(uri), aURL); diff --git a/layout/style/GlobalStyleSheetCache.h b/layout/style/GlobalStyleSheetCache.h index 1bdc58909e36..aff88d480f35 100644 --- a/layout/style/GlobalStyleSheetCache.h +++ b/layout/style/GlobalStyleSheetCache.h @@ -10,11 +10,11 @@ #include "nsIMemoryReporter.h" #include "nsIObserver.h" #include "mozilla/Attributes.h" -#include "mozilla/BuiltInStyleSheets.h" #include "mozilla/MemoryReporting.h" #include "mozilla/PreferenceSheet.h" #include "mozilla/NotNull.h" #include "mozilla/StaticPtr.h" +#include "mozilla/UserAgentStyleSheetID.h" #include "mozilla/css/Loader.h" #include "mozilla/ipc/SharedMemoryHandle.h" #include "mozilla/ipc/SharedMemoryMapping.h" @@ -43,15 +43,11 @@ class GlobalStyleSheetCache final : public nsIObserver, static GlobalStyleSheetCache* Singleton(); -#define STYLE_SHEET(identifier_, url_, flags_) \ - NotNull identifier_##Sheet() { \ - return BuiltInSheet(BuiltInStyleSheet::identifier_); \ - } -#include "mozilla/BuiltInStyleSheetList.h" +#define STYLE_SHEET(identifier_, url_, shared_) \ + NotNull identifier_##Sheet(); +#include "mozilla/UserAgentStyleSheetList.h" #undef STYLE_SHEET - NotNull BuiltInSheet(BuiltInStyleSheet); - StyleSheet* GetUserContentSheet(); StyleSheet* GetUserChromeSheet(); @@ -91,7 +87,7 @@ class GlobalStyleSheetCache final : public nsIObserver, struct Header { static constexpr uint32_t kMagic = 0x55415353; uint32_t mMagic; // Must be set to kMagic. - const StyleLockedCssRules* mSheets[size_t(BuiltInStyleSheet::Count)]; + const StyleLockedCssRules* mSheets[size_t(UserAgentStyleSheetID::Count)]; uint8_t mBuffer[1]; }; @@ -101,25 +97,25 @@ class GlobalStyleSheetCache final : public nsIObserver, void InitFromProfile(); void InitSharedSheetsInParent(); void InitMemoryReporter(); - RefPtr LoadSheetURL(const nsACString& aURL, + RefPtr LoadSheetURL(const char* aURL, css::SheetParsingMode aParsingMode, css::FailureAction aFailureAction); RefPtr LoadSheetFile(nsIFile* aFile, css::SheetParsingMode aParsingMode); RefPtr LoadSheet(nsIURI* aURI, css::SheetParsingMode aParsingMode, css::FailureAction aFailureAction); - void LoadSheetFromSharedMemory(const nsACString& aURL, - RefPtr* aSheet, + void LoadSheetFromSharedMemory(const char* aURL, RefPtr* aSheet, css::SheetParsingMode, const Header*, - BuiltInStyleSheet); + UserAgentStyleSheetID); static StaticRefPtr gStyleCache; static StaticRefPtr gCSSLoader; static StaticRefPtr gUserContentSheetURL; - EnumeratedArray, - size_t(BuiltInStyleSheet::Count)> - mBuiltIns; +#define STYLE_SHEET(identifier_, url_, shared_) \ + RefPtr m##identifier_##Sheet; +#include "mozilla/UserAgentStyleSheetList.h" +#undef STYLE_SHEET RefPtr mUserChromeSheet; RefPtr mUserContentSheet; diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index f12fb0a7e3c3..041cfaeee6fc 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1510,7 +1510,10 @@ Loader::Completed Loader::ParseSheet( } AUTO_PROFILER_LABEL_CATEGORY_PAIR_RELEVANT_FOR_JS(LAYOUT_CSSParsing); - ++mParsedSheetCount; + // TODO(emilio): fix browser_css_cache.js to deal with accessiblecaret.css. + if (!loadData->mURI || !IsPrivilegedURI(loadData->mURI)) { + ++mParsedSheetCount; + } loadData->mIsBeingParsed = true; diff --git a/layout/style/URLExtraData.cpp b/layout/style/URLExtraData.cpp index f0100521688b..730576cad39d 100644 --- a/layout/style/URLExtraData.cpp +++ b/layout/style/URLExtraData.cpp @@ -47,6 +47,6 @@ void URLExtraData::Shutdown() { URLExtraData::~URLExtraData() = default; StaticRefPtr - URLExtraData::sShared[size_t(BuiltInStyleSheet::Count)]; + URLExtraData::sShared[size_t(UserAgentStyleSheetID::Count)]; } // namespace mozilla diff --git a/layout/style/URLExtraData.h b/layout/style/URLExtraData.h index 0f79566abd41..c63cbc4ca14c 100644 --- a/layout/style/URLExtraData.h +++ b/layout/style/URLExtraData.h @@ -12,7 +12,7 @@ #include #include "mozilla/StaticPtr.h" -#include "mozilla/BuiltInStyleSheets.h" +#include "mozilla/UserAgentStyleSheetID.h" #include "nsCOMPtr.h" #include "nsIPrincipal.h" #include "nsIReferrerInfo.h" @@ -66,7 +66,8 @@ struct URLExtraData { // URLExtraData objects that shared style sheets use a sheet ID index to // refer to. - static StaticRefPtr sShared[size_t(BuiltInStyleSheet::Count)]; + static StaticRefPtr + sShared[size_t(UserAgentStyleSheetID::Count)]; private: ~URLExtraData(); diff --git a/layout/style/UserAgentStyleSheetID.h b/layout/style/UserAgentStyleSheetID.h new file mode 100644 index 000000000000..58de5cc60742 --- /dev/null +++ b/layout/style/UserAgentStyleSheetID.h @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* an identifier for User Agent style sheets */ + +#ifndef mozilla_UserAgentStyleSheetID_h +#define mozilla_UserAgentStyleSheetID_h + +namespace mozilla { + +enum class UserAgentStyleSheetID : uint8_t { +#define STYLE_SHEET(identifier_, url_, shared_) identifier_, +#include "mozilla/UserAgentStyleSheetList.h" +#undef STYLE_SHEET + Count +}; + +} // namespace mozilla + +#endif // mozilla_UserAgentStyleSheetID_h diff --git a/layout/style/UserAgentStyleSheetList.h b/layout/style/UserAgentStyleSheetList.h new file mode 100644 index 000000000000..1cf4cf283cf6 --- /dev/null +++ b/layout/style/UserAgentStyleSheetList.h @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* list of user agent style sheets that GlobalStyleSheetCache manages */ + +/* + * STYLE_SHEET(identifier_, url_, shared_) + * + * identifier_ + * An identifier for the style sheet, suitable for use as an enum class value. + * + * url_ + * The URL of the style sheet. + * + * shared_ + * A boolean indicating whether the sheet can be safely placed in shared + * memory. + */ + +STYLE_SHEET(ContentEditable, "resource://gre/res/contenteditable.css", true) +STYLE_SHEET(CounterStyles, "resource://gre-resources/counterstyles.css", true) +STYLE_SHEET(Forms, "resource://gre-resources/forms.css", true) +STYLE_SHEET(HTML, "resource://gre-resources/html.css", true) +STYLE_SHEET(MathML, "resource://gre-resources/mathml.css", true) +STYLE_SHEET(NoFrames, "resource://gre-resources/noframes.css", true) +STYLE_SHEET(Quirk, "resource://gre-resources/quirk.css", true) +STYLE_SHEET(Scrollbars, "resource://gre-resources/scrollbars.css", true) +STYLE_SHEET(SVG, "resource://gre/res/svg.css", true) +STYLE_SHEET(UA, "resource://gre-resources/ua.css", true) +STYLE_SHEET(XUL, "chrome://global/content/xul.css", false) diff --git a/layout/style/jar.mn b/layout/style/jar.mn index ae320ab4a21d..632746a6588c 100644 --- a/layout/style/jar.mn +++ b/layout/style/jar.mn @@ -10,8 +10,6 @@ toolkit.jar: res/noframes.css (res/noframes.css) res/scrollbars.css (res/scrollbars.css) res/forms.css (res/forms.css) - res/accessiblecaret.css (res/accessiblecaret.css) - res/details.css (res/details.css) #ifdef ANDROID res/accessiblecaret-normal.svg (res/accessiblecaret-normal.svg) res/accessiblecaret-tilt-left.svg (res/accessiblecaret-tilt-left.svg) diff --git a/layout/style/moz.build b/layout/style/moz.build index 4d01bfbda3d9..be46bc0685c7 100644 --- a/layout/style/moz.build +++ b/layout/style/moz.build @@ -75,8 +75,6 @@ EXPORTS.mozilla += [ "AnimatedPropertyIDSet.h", "AnimationCollection.h", "AttributeStyles.h", - "BuiltInStyleSheetList.h", - "BuiltInStyleSheets.h", "CachedInheritingStyles.h", "ComputedStyle.h", "ComputedStyleInlines.h", @@ -124,6 +122,8 @@ EXPORTS.mozilla += [ "TimelineCollection.h", "TimelineManager.h", "URLExtraData.h", + "UserAgentStyleSheetID.h", + "UserAgentStyleSheetList.h", ] EXPORTS.mozilla.dom += [ @@ -296,7 +296,9 @@ RESOURCE_FILES += [ CONTENT_ACCESSIBLE_FILES += [ "ImageDocument.css", + "res/accessiblecaret.css", "res/close-12.svg", + "res/details.css", "res/plaintext.css", "res/viewsource.css", "TopLevelImageDocument.css", diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 875434aa90f8..45e069d75b61 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -8911,6 +8911,7 @@ pub unsafe extern "C" fn Servo_SharedMemoryBuilder_AddStylesheet( ) -> *const LockedCssRules { // Assert some things we assume when we create a style sheet from shared // memory. + debug_assert_eq!(contents.origin, Origin::UserAgent); debug_assert_eq!(contents.quirks_mode, QuirksMode::NoQuirks); debug_assert!(contents.source_map_url.read().is_none()); debug_assert!(contents.source_url.read().is_none());