Skip to content

Commit 2ae06ca

Browse files
authored
Rollup merge of #103164 - notriddle:notriddle/media-min-width, r=GuillaumeGomez
rustdoc: remove CSS `@media (min-width: 701px)` The two rules within it can and should be done without the separate media query: * There ain't no rule saying a viewport can't be `700.5px` wide, since hardware pixels can be finer than CSS pixels. <details><summary>Screenshot</summary> ![image](https://user-images.githubusercontent.com/1593513/196283804-e946fbe3-d914-4819-ba2d-b4a6a07f190a.png) </details> * The rule for the first example-wrap child should probably apply on mobile. <details><summary>Screenshots</summary> ## Before ![rustdoc-before](https://user-images.githubusercontent.com/1593513/196282813-88b861c7-7b05-4de5-a421-914396f86a04.png) ## After ![rustdoc-after](https://user-images.githubusercontent.com/1593513/196282842-e57760c2-72d5-4dad-94f5-1d7175043326.png) </details> * The rule for the source sidebar is overriden by the mobile rule setting `max-width: 100vw`, so it can be merged with the rest of the styles.
2 parents 18431b6 + d4e4b08 commit 2ae06ca

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

src/librustdoc/html/static/css/rustdoc.css

+10-20
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ img {
437437

438438
.source-sidebar-expanded .source .sidebar {
439439
overflow-y: auto;
440+
width: 300px;
440441
}
441442

442443
.source-sidebar-expanded .source .sidebar > *:not(#sidebar-toggle) {
@@ -1692,31 +1693,20 @@ details.rustdoc-toggle[open] > summary.hideme::after {
16921693
display: inline-block;
16931694
}
16941695

1695-
/* Media Queries */
1696-
1697-
/*
1698-
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY;
1699-
If you update this line, then you also need to update the line with the same warning
1700-
in storage.js plus the media query with (max-width: 700px)
1701-
*/
1702-
@media (min-width: 701px) {
1703-
/* In case there is no documentation before a code block, we need to add some margin at the top
1704-
to prevent an overlay between the "collapse toggle" and the information tooltip.
1705-
However, it's not needed with smaller screen width because the doc/code block is always put
1706-
"one line" below. */
1707-
.docblock > .example-wrap:first-child .tooltip {
1708-
margin-top: 16px;
1709-
}
1710-
1711-
.source-sidebar-expanded .source .sidebar {
1712-
width: 300px;
1713-
}
1696+
/* In case there is no documentation before a code block, we need to add some margin at the top
1697+
to prevent an overlay between the "collapse toggle" and the information tooltip.
1698+
However, it's not needed with smaller screen width because the doc/code block is always put
1699+
"one line" below. */
1700+
.docblock > .example-wrap:first-child .tooltip {
1701+
margin-top: 16px;
17141702
}
17151703

1704+
/* Media Queries */
1705+
17161706
/*
17171707
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
17181708
If you update this line, then you also need to update the line with the same warning
1719-
in storage.js plus the media query with (min-width: 701px)
1709+
in storage.js
17201710
*/
17211711
@media (max-width: 700px) {
17221712
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,

src/librustdoc/html/static/js/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ function loadCss(cssFileName) {
737737

738738
window.rustdocMobileScrollLock = function() {
739739
const mobile_topbar = document.querySelector(".mobile-topbar");
740-
if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) {
740+
if (window.innerWidth <= window.RUSTDOC_MOBILE_BREAKPOINT) {
741741
// This is to keep the scroll position on mobile.
742742
oldSidebarScrollPosition = window.scrollY;
743743
document.body.style.width = `${document.body.offsetWidth}px`;
@@ -783,7 +783,7 @@ function loadCss(cssFileName) {
783783
}
784784

785785
window.addEventListener("resize", () => {
786-
if (window.innerWidth >= window.RUSTDOC_MOBILE_BREAKPOINT &&
786+
if (window.innerWidth > window.RUSTDOC_MOBILE_BREAKPOINT &&
787787
oldSidebarScrollPosition !== null) {
788788
// If the user opens the sidebar in "mobile" mode, and then grows the browser window,
789789
// we need to switch away from mobile mode and make the main content area scrollable.

src/librustdoc/html/static/js/storage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ window.currentTheme = document.getElementById("themeStyle");
1010
window.mainTheme = document.getElementById("mainThemeStyle");
1111

1212
// WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
13-
// If you update this line, then you also need to update the two media queries with the same
13+
// If you update this line, then you also need to update the media query with the same
1414
// warning in rustdoc.css
15-
window.RUSTDOC_MOBILE_BREAKPOINT = 701;
15+
window.RUSTDOC_MOBILE_BREAKPOINT = 700;
1616

1717
const settingsDataset = (function() {
1818
const settingsElement = document.getElementById("default-settings");

src/test/rustdoc-gui/sidebar-mobile-scroll.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// This test ensures that the mobile sidebar preserves scroll position.
22
goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
33
// Switching to "mobile view" by reducing the width to 600px.
4-
size: (600, 600)
4+
size: (700, 600)
55
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
66

77
// Scroll down.
88
scroll-to: "//h2[@id='blanket-implementations']"
9-
assert-window-property: {"pageYOffset": "651"}
9+
assert-window-property: {"pageYOffset": "627"}
1010

1111
// Open the sidebar menu.
1212
click: ".sidebar-menu-toggle"
@@ -21,11 +21,11 @@ assert-window-property: {"pageYOffset": "0"}
2121
// Close the sidebar menu. Make sure the scroll position gets restored.
2222
click: ".sidebar-menu-toggle"
2323
wait-for-css: (".sidebar", {"left": "-1000px"})
24-
assert-window-property: {"pageYOffset": "651"}
24+
assert-window-property: {"pageYOffset": "627"}
2525

2626
// Now test that scrollability returns when the browser window is just resized.
2727
click: ".sidebar-menu-toggle"
2828
wait-for-css: (".sidebar", {"left": "0px"})
2929
assert-window-property: {"pageYOffset": "0"}
3030
size: (900, 600)
31-
assert-window-property: {"pageYOffset": "651"}
31+
assert-window-property: {"pageYOffset": "627"}

0 commit comments

Comments
 (0)