Skip to content

Commit 4d4da57

Browse files
authored
Rollup merge of rust-lang#87663 - GuillaumeGomez:rustdoc-brace-minus-brace, r=notriddle
Rustdoc accessibility: use an icon for the [-]/[+] controls This is a reopening of rust-lang#87207 with improvement for the way of generating the `background-image` CSS property. I quote from the original PR: > This way, we can show the plus and minus buttons on screens, while voice > control will read off actual words "Collapse" and "Expand" instead of reading > "open brace minus close brace" and "open brace plus close brace". Part of rust-lang#87059 r? `@notriddle`
2 parents a53bede + 6fe0972 commit 4d4da57

File tree

7 files changed

+114
-10
lines changed

7 files changed

+114
-10
lines changed

src/librustdoc/html/render/write_shared.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,45 @@ pub(super) fn write_shared(
175175
cx.write_shared(SharedResource::InvocationSpecific { basename: p }, content, &options.emit)
176176
};
177177

178+
fn add_background_image_to_css(
179+
cx: &Context<'_>,
180+
css: &mut String,
181+
rule: &str,
182+
file: &'static str,
183+
) {
184+
css.push_str(&format!(
185+
"{} {{ background-image: url({}); }}",
186+
rule,
187+
SharedResource::ToolchainSpecific { basename: file }
188+
.path(cx)
189+
.file_name()
190+
.unwrap()
191+
.to_str()
192+
.unwrap()
193+
))
194+
}
195+
196+
// Add all the static files. These may already exist, but we just
197+
// overwrite them anyway to make sure that they're fresh and up-to-date.
198+
let mut rustdoc_css = static_files::RUSTDOC_CSS.to_owned();
199+
add_background_image_to_css(
200+
cx,
201+
&mut rustdoc_css,
202+
"details.undocumented[open] > summary::before, \
203+
details.rustdoc-toggle[open] > summary::before, \
204+
details.rustdoc-toggle[open] > summary.hideme::before",
205+
"toggle-minus.svg",
206+
);
207+
add_background_image_to_css(
208+
cx,
209+
&mut rustdoc_css,
210+
"details.undocumented > summary::before, details.rustdoc-toggle > summary::before",
211+
"toggle-plus.svg",
212+
);
213+
write_minify("rustdoc.css", &rustdoc_css)?;
214+
178215
// Add all the static files. These may already exist, but we just
179216
// overwrite them anyway to make sure that they're fresh and up-to-date.
180-
write_minify("rustdoc.css", static_files::RUSTDOC_CSS)?;
181217
write_minify("settings.css", static_files::SETTINGS_CSS)?;
182218
write_minify("noscript.css", static_files::NOSCRIPT_CSS)?;
183219

@@ -217,6 +253,8 @@ pub(super) fn write_shared(
217253
write_toolchain("wheel.svg", static_files::WHEEL_SVG)?;
218254
write_toolchain("clipboard.svg", static_files::CLIPBOARD_SVG)?;
219255
write_toolchain("down-arrow.svg", static_files::DOWN_ARROW_SVG)?;
256+
write_toolchain("toggle-minus.svg", static_files::TOGGLE_MINUS_PNG)?;
257+
write_toolchain("toggle-plus.svg", static_files::TOGGLE_PLUS_PNG)?;
220258

221259
let mut themes: Vec<&String> = themes.iter().collect();
222260
themes.sort();

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

+57-9
Original file line numberDiff line numberDiff line change
@@ -1508,11 +1508,35 @@ details.rustdoc-toggle > summary.hideme > span {
15081508
}
15091509

15101510
details.rustdoc-toggle > summary::before {
1511-
content: "[+]";
1512-
font-weight: 300;
1513-
font-size: 0.8em;
1514-
letter-spacing: 1px;
1511+
content: "";
15151512
cursor: pointer;
1513+
width: 17px;
1514+
height: max(17px, 1.1em);
1515+
background-repeat: no-repeat;
1516+
background-position: top left;
1517+
display: inline-block;
1518+
vertical-align: middle;
1519+
opacity: .5;
1520+
}
1521+
1522+
/* Screen readers see the text version at the end the line.
1523+
Visual readers see the icon at the start of the line, but small and transparent. */
1524+
details.rustdoc-toggle > summary::after {
1525+
content: "Expand";
1526+
overflow: hidden;
1527+
width: 0;
1528+
height: 0;
1529+
position: absolute;
1530+
}
1531+
1532+
details.rustdoc-toggle > summary.hideme::after {
1533+
/* "hideme" toggles already have a description when they're contracted */
1534+
content: "";
1535+
}
1536+
1537+
details.rustdoc-toggle > summary:focus::before,
1538+
details.rustdoc-toggle > summary:hover::before {
1539+
opacity: 1;
15161540
}
15171541

15181542
details.rustdoc-toggle.top-doc > summary,
@@ -1560,20 +1584,44 @@ details.rustdoc-toggle[open] > summary.hideme > span {
15601584
display: none;
15611585
}
15621586

1563-
details.rustdoc-toggle[open] > summary::before {
1564-
content: "[−]";
1565-
display: inline;
1587+
details.rustdoc-toggle[open] > summary::before,
1588+
details.rustdoc-toggle[open] > summary.hideme::before {
1589+
width: 17px;
1590+
height: max(17px, 1.1em);
1591+
background-repeat: no-repeat;
1592+
background-position: top left;
1593+
display: inline-block;
1594+
content: "";
1595+
}
1596+
1597+
details.rustdoc-toggle[open] > summary::after,
1598+
details.rustdoc-toggle[open] > summary.hideme::after {
1599+
content: "Collapse";
15661600
}
15671601

15681602
details.undocumented > summary::before {
1569-
content: "[+] Show hidden undocumented items";
1603+
padding-left: 17px;
1604+
height: max(17px, 1.1em);
1605+
background-repeat: no-repeat;
1606+
background-position: top left;
1607+
content: "Show hidden undocumented items";
15701608
cursor: pointer;
15711609
font-size: 16px;
15721610
font-weight: 300;
1611+
opacity: .5;
1612+
}
1613+
1614+
details.undocumented > summary:focus::before,
1615+
details.undocumented > summary:hover::before {
1616+
opacity: 1;
15731617
}
15741618

15751619
details.undocumented[open] > summary::before {
1576-
content: "[−] Hide undocumented items";
1620+
padding-left: 17px;
1621+
height: max(17px, 1.1em);
1622+
background-repeat: no-repeat
1623+
background-position: top left;
1624+
content: "Hide undocumented items";
15771625
}
15781626

15791627
/* Media Queries */

src/librustdoc/html/static/css/themes/ayu.css

+5
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ details.undocumented > summary::before {
229229
color: #999;
230230
}
231231

232+
details.rustdoc-toggle > summary::before,
233+
details.undocumented > summary::before {
234+
filter: invert(100%);
235+
}
236+
232237
#crate-search {
233238
color: #c5c5c5;
234239
background-color: #141920;

src/librustdoc/html/static/css/themes/dark.css

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ details.undocumented > summary::before {
194194
color: #999;
195195
}
196196

197+
details.rustdoc-toggle > summary::before,
198+
details.undocumented > summary::before {
199+
filter: invert(100%);
200+
}
201+
197202
#crate-search {
198203
color: #111;
199204
background-color: #f0f0f0;
Loading
Loading

src/librustdoc/html/static_files.rs

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ crate static CLIPBOARD_SVG: &[u8] = include_bytes!("static/images/clipboard.svg"
4747
/// The file contents of `down-arrow.svg`, the icon used for the crate choice combobox.
4848
crate static DOWN_ARROW_SVG: &[u8] = include_bytes!("static/images/down-arrow.svg");
4949

50+
/// The file contents of `toggle-minus.svg`, the icon used for opened toggles.
51+
crate static TOGGLE_MINUS_PNG: &[u8] = include_bytes!("static/images/toggle-minus.svg");
52+
53+
/// The file contents of `toggle-plus.svg`, the icon used for closed toggles.
54+
crate static TOGGLE_PLUS_PNG: &[u8] = include_bytes!("static/images/toggle-plus.svg");
55+
5056
/// The contents of `COPYRIGHT.txt`, the license listing for files distributed with documentation
5157
/// output.
5258
crate static COPYRIGHT: &[u8] = include_bytes!("static/COPYRIGHT.txt");

0 commit comments

Comments
 (0)