diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-21 17:31:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-21 17:31:38 +0200 |
| commit | d034ccabe455fc10e227c7fa7c060f6ecbd53856 (patch) | |
| tree | 5b81935e84835a1e4f2e0f26951e3bb4c47dcb79 /src | |
| parent | 7b0085a613e69cb69fc9e4eb5d422fa4a39d5de1 (diff) | |
| parent | 1bd94241b756bda09c6e079f806c25440a3b2c81 (diff) | |
| download | rust-d034ccabe455fc10e227c7fa7c060f6ecbd53856.tar.gz rust-d034ccabe455fc10e227c7fa7c060f6ecbd53856.zip | |
Rollup merge of #61236 - GuillaumeGomez:system-theme, r=Mark-Simulacrum
take into account the system theme Fixes #61079. The CSS can now take into account the system theme. I used it to generate some content on the document and from there, if no theme has already been selected, it'll look at the system level theme. r? @QuietMisdreavus cc @fenhl
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/html/render.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/html/static/rustdoc.css | 15 | ||||
| -rw-r--r-- | src/librustdoc/html/static/storage.js | 16 |
3 files changed, 29 insertions, 4 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ea97cea9428..211c4157da8 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -914,7 +914,7 @@ themePicker.onblur = handleThemeButtonsBlur; var but = document.createElement('button'); but.innerHTML = item; but.onclick = function(el) {{ - switchTheme(currentTheme, mainTheme, item); + switchTheme(currentTheme, mainTheme, item, true); }}; but.onblur = handleThemeButtonsBlur; themes.appendChild(but); diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 59d10668f11..244b24af43f 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -54,6 +54,21 @@ box-sizing: border-box; } +/* This part handles the "default" theme being used depending on the system one. */ +html { + content: ""; +} +@media (prefers-color-scheme: light) { + html { + content: "light"; + } +} +@media (prefers-color-scheme: dark) { + html { + content: "dark"; + } +} + /* General structure and fonts */ body { diff --git a/src/librustdoc/html/static/storage.js b/src/librustdoc/html/static/storage.js index e3927350d11..c55b1e41443 100644 --- a/src/librustdoc/html/static/storage.js +++ b/src/librustdoc/html/static/storage.js @@ -86,7 +86,7 @@ function getCurrentValue(name) { return null; } -function switchTheme(styleElem, mainStyleElem, newTheme) { +function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) { var fullBasicCss = "rustdoc" + resourcesSuffix + ".css"; var fullNewTheme = newTheme + resourcesSuffix + ".css"; var newHref = mainStyleElem.href.replace(fullBasicCss, fullNewTheme); @@ -109,8 +109,18 @@ function switchTheme(styleElem, mainStyleElem, newTheme) { }); if (found === true) { styleElem.href = newHref; - updateLocalStorage("rustdoc-theme", newTheme); + // If this new value comes from a system setting or from the previously saved theme, no + // need to save it. + if (saveTheme === true) { + updateLocalStorage("rustdoc-theme", newTheme); + } } } -switchTheme(currentTheme, mainTheme, getCurrentValue("rustdoc-theme") || "light"); +function getSystemValue() { + return getComputedStyle(document.documentElement).getPropertyValue('content'); +} + +switchTheme(currentTheme, mainTheme, + getCurrentValue("rustdoc-theme") || getSystemValue() || "light", + false); |
