mirror of
https://github.com/zen-browser/desktop.git
synced 2025-07-07 21:49:58 +02:00
feat: Mark stylesheets as changed when updating mods, b=no-bug, c=mods
This commit is contained in:
parent
4f049111b1
commit
27b03a7675
4 changed files with 34 additions and 6 deletions
13
src/layout/base/nsStyleSheetService-h.patch
Normal file
13
src/layout/base/nsStyleSheetService-h.patch
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
diff --git a/layout/base/nsStyleSheetService.h b/layout/base/nsStyleSheetService.h
|
||||||
|
index 8c49b338bf8e6830874ace9a08e8c0713167ee58..115bf09314970fd2fe79793e9cf8e0c40eb0459b 100644
|
||||||
|
--- a/layout/base/nsStyleSheetService.h
|
||||||
|
+++ b/layout/base/nsStyleSheetService.h
|
||||||
|
@@ -50,6 +50,8 @@ class nsStyleSheetService final : public nsIStyleSheetService,
|
||||||
|
|
||||||
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||||
|
|
||||||
|
+ void ZenMarkStylesAsChanged();
|
||||||
|
+
|
||||||
|
static nsStyleSheetService* GetInstance();
|
||||||
|
static nsStyleSheetService* gInstance;
|
||||||
|
|
|
@ -42,10 +42,8 @@
|
||||||
await this.#rebuildModsStylesheet();
|
await this.#rebuildModsStylesheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
#getStylesheetURIForMod(mod) {
|
#getStylesheetPathForMod(mod) {
|
||||||
return Services.io.newFileURI(
|
return PathUtils.join(this.getModFolder(mod.id), 'chrome.css');
|
||||||
new FileUtils.File(PathUtils.join(this.getModFolder(mod.id), 'chrome.css'))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async #readStylesheet() {
|
async #readStylesheet() {
|
||||||
|
@ -223,7 +221,7 @@
|
||||||
const mods = [];
|
const mods = [];
|
||||||
|
|
||||||
for (let mod of modList) {
|
for (let mod of modList) {
|
||||||
mod._chromeURL = this.#getStylesheetURIForMod(mod).spec;
|
mod._filePath = this.#getStylesheetPathForMod(mod);
|
||||||
mods.push(mod);
|
mods.push(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +242,8 @@
|
||||||
content += `/* Readme: ${mod.readme} */\n`;
|
content += `/* Readme: ${mod.readme} */\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
content += `@import url("${mod._chromeURL}");\n`;
|
const chromeContent = await IOUtils.readUTF8(mod._filePath);
|
||||||
|
content += chromeContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
content += this.#kZenStylesheetModFooter;
|
content += this.#kZenStylesheetModFooter;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIFile.h"
|
#include "nsIFile.h"
|
||||||
|
|
||||||
|
#include "nsStyleSheetService.h"
|
||||||
|
|
||||||
#include "mozilla/css/SheetParsingMode.h"
|
#include "mozilla/css/SheetParsingMode.h"
|
||||||
#include "mozilla/GlobalStyleSheetCache.h"
|
#include "mozilla/GlobalStyleSheetCache.h"
|
||||||
|
|
||||||
|
@ -82,6 +84,9 @@ nsresult ZenStyleSheetCache::RebuildModsStylesheets(const nsACString& aContents)
|
||||||
}
|
}
|
||||||
ErrorResult aRv;
|
ErrorResult aRv;
|
||||||
sheet->ReparseSheet(aContents, aRv);
|
sheet->ReparseSheet(aContents, aRv);
|
||||||
|
if (auto sss = nsStyleSheetService::GetInstance()) {
|
||||||
|
sss->ZenMarkStylesAsChanged();
|
||||||
|
}
|
||||||
return aRv.StealNSResult();
|
return aRv.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,3 +51,14 @@ auto nsZenModsBackend::RebuildModsStyles(const nsACString& aContents) -> nsresul
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace: zen
|
} // namespace: zen
|
||||||
|
|
||||||
|
auto nsStyleSheetService::ZenMarkStylesAsChanged() -> void {
|
||||||
|
for (auto& presShell : mPresShells) {
|
||||||
|
if (presShell) {
|
||||||
|
if (auto doc = presShell->GetDocument(); doc && doc->IsInChromeDocShell()) {
|
||||||
|
// Notify the document that styles have changed.
|
||||||
|
doc->ApplicableStylesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue