From a3eab0ba67ee9b5c6d529ba9c50752b9f2b8a159 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 17 Oct 2022 18:08:40 +0200 Subject: [PATCH 1/5] Update browser-ui-test version to 0.12.6 --- .../docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version index 679934348d0b1..0ec9201397fe4 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version +++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version @@ -1 +1 @@ -0.12.5 \ No newline at end of file +0.12.6 \ No newline at end of file From 885d69093f34b0449cc25d18630293d26c4b89e1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 17 Oct 2022 18:08:53 +0200 Subject: [PATCH 2/5] Use named arguments to make test clearer --- src/test/rustdoc-gui/anchors.goml | 54 +++++++++++++++---------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/test/rustdoc-gui/anchors.goml b/src/test/rustdoc-gui/anchors.goml index e526fa47d156e..fb8e288fae882 100644 --- a/src/test/rustdoc-gui/anchors.goml +++ b/src/test/rustdoc-gui/anchors.goml @@ -71,37 +71,37 @@ define-function: ( call-function: ( "check-colors", - ( - "ayu", // theme - "rgb(197, 197, 197)", // main color - "rgb(255, 255, 255)", // title color - "rgb(255, 255, 255)", // fqn color - "rgb(255, 160, 165)", // fqn type color - "rgb(57, 175, 215)", // src link - "rgb(83, 177, 219)", // sidebar link - ), + { + "theme": "ayu", + "main_color": "rgb(197, 197, 197)", + "title_color": "rgb(255, 255, 255)", + "fqn_color": "rgb(255, 255, 255)", + "fqn_type_color": "rgb(255, 160, 165)", + "src_link_color": "rgb(57, 175, 215)", + "sidebar_link_color": "rgb(83, 177, 219)", + }, ) call-function: ( "check-colors", - ( - "dark", // theme - "rgb(221, 221, 221)", // main color - "rgb(221, 221, 221)", // title color - "rgb(221, 221, 221)", // fqn color - "rgb(45, 191, 184)", // fqn type color - "rgb(210, 153, 29)", // src link - "rgb(253, 191, 53)", // sidebar link - ), + { + "theme": "dark", + "main_color": "rgb(221, 221, 221)", + "title_color": "rgb(221, 221, 221)", + "fqn_color": "rgb(221, 221, 221)", + "fqn_type_color": "rgb(45, 191, 184)", + "src_link_color": "rgb(210, 153, 29)", + "sidebar_link_color": "rgb(253, 191, 53)", + }, ) call-function: ( "check-colors", - ( - "light", // theme - "rgb(0, 0, 0)", // main color - "rgb(0, 0, 0)", // title color - "rgb(0, 0, 0)", // fqn color - "rgb(173, 55, 138)", // fqn type color - "rgb(56, 115, 173)", // src link - "rgb(53, 109, 164)", // sidebar link - ), + { + "theme": "light", + "main_color": "rgb(0, 0, 0)", + "title_color": "rgb(0, 0, 0)", + "fqn_color": "rgb(0, 0, 0)", + "fqn_type_color": "rgb(173, 55, 138)", + "src_link_color": "rgb(56, 115, 173)", + "sidebar_link_color": "rgb(53, 109, 164)", + }, ) From 3932b2c21d5e2a8184739eb41df7501929f70194 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 17 Oct 2022 11:41:39 -0700 Subject: [PATCH 3/5] rustdoc: factor JS mobile scroll lock into its own function https://github.com/rust-lang/rust/pull/98775#issuecomment-1172728308 --- src/librustdoc/html/static/js/main.js | 36 +++++++++++++------ .../html/static/js/source-script.js | 33 ++--------------- 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index db1cc8e451627..3bcadcda534dc 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -733,37 +733,51 @@ function loadCss(cssFileName) { let oldSidebarScrollPosition = null; - function showSidebar() { + // Scroll locking used both here and in source-script.js + + window.rustdocMobileScrollLock = function() { const mobile_topbar = document.querySelector(".mobile-topbar"); - if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT && mobile_topbar) { + if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) { // This is to keep the scroll position on mobile. oldSidebarScrollPosition = window.scrollY; document.body.style.width = `${document.body.offsetWidth}px`; document.body.style.position = "fixed"; document.body.style.top = `-${oldSidebarScrollPosition}px`; - mobile_topbar.style.top = `${oldSidebarScrollPosition}px`; - mobile_topbar.style.position = "relative"; + if (mobile_topbar) { + mobile_topbar.style.top = `${oldSidebarScrollPosition}px`; + mobile_topbar.style.position = "relative"; + } } else { oldSidebarScrollPosition = null; } - const sidebar = document.getElementsByClassName("sidebar")[0]; - addClass(sidebar, "shown"); - } + }; - function hideSidebar() { + window.rustdocMobileScrollUnlock = function() { const mobile_topbar = document.querySelector(".mobile-topbar"); - if (oldSidebarScrollPosition !== null && mobile_topbar) { + if (oldSidebarScrollPosition !== null) { // This is to keep the scroll position on mobile. document.body.style.width = ""; document.body.style.position = ""; document.body.style.top = ""; - mobile_topbar.style.top = ""; - mobile_topbar.style.position = ""; + if (mobile_topbar) { + mobile_topbar.style.top = ""; + mobile_topbar.style.position = ""; + } // The scroll position is lost when resetting the style, hence why we store it in // `oldSidebarScrollPosition`. window.scrollTo(0, oldSidebarScrollPosition); oldSidebarScrollPosition = null; } + }; + + function showSidebar() { + window.rustdocMobileScrollLock(); + const sidebar = document.getElementsByClassName("sidebar")[0]; + addClass(sidebar, "shown"); + } + + function hideSidebar() { + window.rustdocMobileScrollUnlock(); const sidebar = document.getElementsByClassName("sidebar")[0]; removeClass(sidebar, "shown"); } diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 8286e9201e649..0b9368dd89948 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -10,7 +10,6 @@ (function() { const rootPath = document.getElementById("rustdoc-vars").attributes["data-root-path"].value; -let oldScrollPosition = null; const NAME_OFFSET = 0; const DIRS_OFFSET = 1; @@ -70,44 +69,18 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) { function toggleSidebar() { const child = this.parentNode.children[0]; if (child.innerText === ">") { - if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) { - // This is to keep the scroll position on mobile. - oldScrollPosition = window.scrollY; - document.body.style.position = "fixed"; - document.body.style.top = `-${oldScrollPosition}px`; - } else { - oldScrollPosition = null; - } + window.rustdocMobileScrollLock(); addClass(document.documentElement, "source-sidebar-expanded"); child.innerText = "<"; updateLocalStorage("source-sidebar-show", "true"); } else { - if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT && oldScrollPosition !== null) { - // This is to keep the scroll position on mobile. - document.body.style.position = ""; - document.body.style.top = ""; - // The scroll position is lost when resetting the style, hence why we store it in - // `oldScrollPosition`. - window.scrollTo(0, oldScrollPosition); - oldScrollPosition = null; - } + window.rustdocMobileScrollUnlock(); removeClass(document.documentElement, "source-sidebar-expanded"); child.innerText = ">"; updateLocalStorage("source-sidebar-show", "false"); } } -window.addEventListener("resize", () => { - if (window.innerWidth >= window.RUSTDOC_MOBILE_BREAKPOINT && oldScrollPosition !== null) { - // If the user opens the sidebar in "mobile" mode, and then grows the browser window, - // we need to switch away from mobile mode and make the main content area scrollable. - document.body.style.position = ""; - document.body.style.top = ""; - window.scrollTo(0, oldScrollPosition); - oldScrollPosition = null; - } -}); - function createSidebarToggle() { const sidebarToggle = document.createElement("div"); sidebarToggle.id = "sidebar-toggle"; @@ -125,7 +98,7 @@ function createSidebarToggle() { return sidebarToggle; } -// This function is called from "source-files.js", generated in `html/render/mod.rs`. +// This function is called from "source-files.js", generated in `html/render/write_shared.rs`. // eslint-disable-next-line no-unused-vars function createSourceSidebar() { const container = document.querySelector("nav.sidebar"); From 3aa3b8be4e7a6a361c1369d6aad5ec4ea533f31d Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 17 Oct 2022 11:53:42 -0700 Subject: [PATCH 4/5] rustdoc: remove redundant CSS on `#copy-path` The border and background were removed in 5d004c1e2020eaa9bc336f09b6b0475c0eef4d78, but not all the CSS was. --- src/librustdoc/html/static/css/rustdoc.css | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 4bfc8ada28084..cf1fcefd31330 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1431,10 +1431,7 @@ h3.variant { } #settings-menu > a, #help-button > a, #copy-path { - padding: 5px; width: 33px; - border: 1px solid var(--border-color); - border-radius: 2px; cursor: pointer; line-height: 1.5; } @@ -1444,10 +1441,18 @@ h3.variant { height: 100%; display: block; background-color: var(--button-background-color); + border: 1px solid var(--border-color); + border-radius: 2px; } #copy-path { color: var(--copy-path-button-color); + background: var(--main-background-color); + height: 34px; + margin-left: 10px; + padding: 0; + padding-left: 2px; + border: 0; } #copy-path > img { filter: var(--copy-path-img-filter); @@ -1495,15 +1500,6 @@ input:checked + .slider { padding-top: 2px; } -#copy-path { - height: 34px; - background-color: var(--main-background-color); - margin-left: 10px; - padding: 0; - padding-left: 2px; - border: 0; -} - kbd { display: inline-block; padding: 3px 5px; From 642bb0d54f03af60091e32a94709aeeb4cf82a1b Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 17 Oct 2022 12:16:40 -0700 Subject: [PATCH 5/5] rustdoc: remove redundant CSS `#crate-search { border-radius }` This is the same border-radius that's always set on that ID: https://github.com/rust-lang/rust/blob/a9d1cafa878ecc04a4aa7aaa7df0414a29a2bd0b/src/librustdoc/html/static/css/rustdoc.css#L825-L836 --- src/librustdoc/html/static/css/rustdoc.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 4bfc8ada28084..77c928c10102d 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1994,10 +1994,6 @@ in storage.js plus the media query with (min-width: 701px) } @media (max-width: 464px) { - #crate-search { - border-radius: 4px; - } - .docblock { margin-left: 12px; }