From 30d49a401ab11402429c8a839f54ff3b952d10a7 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 16 Jul 2021 21:58:23 -0700 Subject: [PATCH 1/4] Rustdoc accessibility: make the sidebar headers actual headers Part of #87059 Preview it at: https://notriddle.com/notriddle-rustdoc-test/rustdoc-sidebar-header/std/index.html --- src/librustdoc/html/render/context.rs | 4 +- src/librustdoc/html/render/mod.rs | 54 +++++++++++----------- src/librustdoc/html/static/css/rustdoc.css | 5 ++ 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 61057ff515b16..b6c3220901f06 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -539,7 +539,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { }; let sidebar = if let Some(ref version) = self.cache.crate_version { format!( - "

Crate {}

\ + "

Crate {}

\
\

Version {}

\
\ @@ -567,7 +567,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { page.root_path = "./"; let mut style_files = self.shared.style_files.clone(); - let sidebar = "

Settings

"; + let sidebar = "

Settings

"; style_files.push(StylePath { path: PathBuf::from("settings.css"), disabled: false }); let v = layout::render( &self.shared.templates, diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 7de023cabeff5..68c59612ccc44 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1654,7 +1654,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { { write!( buffer, - "

{}{}

", + "

{}{}

", match *it.kind { clean::StructItem(..) => "Struct ", clean::TraitItem(..) => "Trait ", @@ -1718,7 +1718,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { // to navigate the documentation (though slightly inefficiently). if !it.is_mod() { - buffer.write_str("

Other items in
"); + buffer.write_str("

Other items in
"); for (i, name) in cx.current.iter().take(parentlen).enumerate() { if i > 0 { buffer.write_str("::"); @@ -1730,7 +1730,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { *name ); } - buffer.write_str("

"); + buffer.write_str("

"); } // Sidebar refers to the enclosing module, not this module. @@ -1841,7 +1841,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { ret.sort(); out.push_str( - "Methods\ + "

Methods

\
", ); for line in ret { @@ -1906,24 +1906,24 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { if !concrete_format.is_empty() { out.push_str( - "\ - Trait Implementations", + "

\ + Trait Implementations

", ); write_sidebar_links(out, concrete_format); } if !synthetic_format.is_empty() { out.push_str( - "\ - Auto Trait Implementations", + "

\ + Auto Trait Implementations

", ); write_sidebar_links(out, synthetic_format); } if !blanket_format.is_empty() { out.push_str( - "\ - Blanket Implementations", + "

\ + Blanket Implementations

", ); write_sidebar_links(out, blanket_format); } @@ -1975,7 +1975,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V if !ret.is_empty() { write!( out, - "Methods from {}<Target={}>", + "

Methods from {}<Target={}>

", Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print(cx))), Escape(&format!("{:#}", real_target.print(cx))), ); @@ -1998,7 +1998,7 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea if !fields.is_empty() { if let CtorKind::Fictive = s.struct_type { sidebar.push_str( - "Fields\ + "

Fields

\
", ); @@ -2075,8 +2075,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean print_sidebar_section( buf, &t.items, - "\ - Associated Types
", + "

\ + Associated Types

", |m| m.is_associated_type(), |out, sym| write!(out, "{0}", sym), "
", @@ -2085,8 +2085,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean print_sidebar_section( buf, &t.items, - "\ - Associated Constants
", + "

\ + Associated Constants

", |m| m.is_associated_const(), |out, sym| write!(out, "{0}", sym), "
", @@ -2095,8 +2095,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean print_sidebar_section( buf, &t.items, - "\ - Required Methods
", + "

\ + Required Methods

", |m| m.is_ty_method(), |out, sym| write!(out, "{0}", sym), "
", @@ -2105,8 +2105,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean print_sidebar_section( buf, &t.items, - "\ - Provided Methods
", + "

\ + Provided Methods

", |m| m.is_method(), |out, sym| write!(out, "{0}", sym), "
", @@ -2128,8 +2128,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean if !res.is_empty() { res.sort(); buf.push_str( - "\ - Implementations on Foreign Types\ + "

\ + Implementations on Foreign Types

\
", ); for (name, id) in res.into_iter() { @@ -2141,11 +2141,11 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean sidebar_assoc_items(cx, buf, it); - buf.push_str("Implementors"); + buf.push_str("

Implementors

"); if t.is_auto { buf.push_str( - "Auto Implementors", + "

Auto Implementors

", ); } @@ -2188,7 +2188,7 @@ fn sidebar_union(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, u: &clean if !fields.is_empty() { sidebar.push_str( - "Fields\ + "

Fields

\
", ); @@ -2220,7 +2220,7 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean: if !variants.is_empty() { variants.sort_unstable(); sidebar.push_str(&format!( - "Variants\ + "

Variants

\
{}
", variants.join(""), )); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b86f012c0e168..bb7582e23b4d0 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -339,9 +339,12 @@ nav.sub { .sidebar .location { border: 1px solid; font-size: 17px; + font-weight: inherit; margin: 30px 10px 20px 10px; text-align: center; word-wrap: break-word; + font-weight: inherit; + padding: 0; } .sidebar .version { @@ -394,6 +397,8 @@ nav.sub { text-align: center; font-size: 17px; margin-bottom: 5px; + font-weight: inherit; + padding: 0; } .sidebar-links { From ee97b4a52876a53f18d09571107d0c88d6f74c06 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 16 Jul 2021 22:00:22 -0700 Subject: [PATCH 2/4] Remove redundant CSS --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index bb7582e23b4d0..a7ffd8a9aea14 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -339,7 +339,6 @@ nav.sub { .sidebar .location { border: 1px solid; font-size: 17px; - font-weight: inherit; margin: 30px 10px 20px 10px; text-align: center; word-wrap: break-word; From 10bdc42be86c9b83dc6303fa4c8eb8983403e627 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 17 Jul 2021 09:45:07 -0700 Subject: [PATCH 3/4] Fix test cases for header titles in sidebar --- src/test/rustdoc/deref-typedef.rs | 2 +- src/test/rustdoc/negative-impl-sidebar.rs | 2 +- src/test/rustdoc/sidebar-items.rs | 14 +++++++------- src/test/rustdoc/sidebar-links-to-foreign-impl.rs | 2 +- src/test/rustdoc/typedef.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/rustdoc/deref-typedef.rs b/src/test/rustdoc/deref-typedef.rs index 3fc48b46d7410..d42ff384b29b8 100644 --- a/src/test/rustdoc/deref-typedef.rs +++ b/src/test/rustdoc/deref-typedef.rs @@ -6,7 +6,7 @@ // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)' // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)' // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)' -// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods"]' 'Methods from Deref' +// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods"]' 'Methods from Deref' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_a"]' 'foo_a' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_b"]' 'foo_b' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_c"]' 'foo_c' diff --git a/src/test/rustdoc/negative-impl-sidebar.rs b/src/test/rustdoc/negative-impl-sidebar.rs index 3414d9540776a..d63ab346045ee 100644 --- a/src/test/rustdoc/negative-impl-sidebar.rs +++ b/src/test/rustdoc/negative-impl-sidebar.rs @@ -4,6 +4,6 @@ pub struct Foo; // @has foo/struct.Foo.html -// @has - '//*[@class="sidebar-title"][@href="#trait-implementations"]' 'Trait Implementations' +// @has - '//*[@class="sidebar-title"]/a[@href="#trait-implementations"]' 'Trait Implementations' // @has - '//*[@class="sidebar-links"]/a' '!Sync' impl !Sync for Foo {} diff --git a/src/test/rustdoc/sidebar-items.rs b/src/test/rustdoc/sidebar-items.rs index 3ba6dbacc8d32..5da660b4df304 100644 --- a/src/test/rustdoc/sidebar-items.rs +++ b/src/test/rustdoc/sidebar-items.rs @@ -1,13 +1,13 @@ #![crate_name = "foo"] // @has foo/trait.Foo.html -// @has - '//*[@class="sidebar-title"][@href="#required-methods"]' 'Required Methods' +// @has - '//*[@class="sidebar-title"]/a[@href="#required-methods"]' 'Required Methods' // @has - '//*[@class="sidebar-links"]/a' 'bar' -// @has - '//*[@class="sidebar-title"][@href="#provided-methods"]' 'Provided Methods' +// @has - '//*[@class="sidebar-title"]/a[@href="#provided-methods"]' 'Provided Methods' // @has - '//*[@class="sidebar-links"]/a' 'foo' -// @has - '//*[@class="sidebar-title"][@href="#associated-const"]' 'Associated Constants' +// @has - '//*[@class="sidebar-title"]/a[@href="#associated-const"]' 'Associated Constants' // @has - '//*[@class="sidebar-links"]/a' 'BAR' -// @has - '//*[@class="sidebar-title"][@href="#associated-types"]' 'Associated Types' +// @has - '//*[@class="sidebar-title"]/a[@href="#associated-types"]' 'Associated Types' // @has - '//*[@class="sidebar-links"]/a' 'Output' pub trait Foo { const BAR: u32 = 0; @@ -18,7 +18,7 @@ pub trait Foo { } // @has foo/struct.Bar.html -// @has - '//*[@class="sidebar-title"][@href="#fields"]' 'Fields' +// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields' // @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f"]' 'f' // @has - '//*[@class="sidebar-links"]/a[@href="#structfield.u"]' 'u' // @!has - '//*[@class="sidebar-links"]/a' 'waza' @@ -29,7 +29,7 @@ pub struct Bar { } // @has foo/enum.En.html -// @has - '//*[@class="sidebar-title"][@href="#variants"]' 'Variants' +// @has - '//*[@class="sidebar-title"]/a[@href="#variants"]' 'Variants' // @has - '//*[@class="sidebar-links"]/a' 'foo' // @has - '//*[@class="sidebar-links"]/a' 'bar' pub enum En { @@ -38,7 +38,7 @@ pub enum En { } // @has foo/union.MyUnion.html -// @has - '//*[@class="sidebar-title"][@href="#fields"]' 'Fields' +// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields' // @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f1"]' 'f1' // @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f2"]' 'f2' // @!has - '//*[@class="sidebar-links"]/a' 'waza' diff --git a/src/test/rustdoc/sidebar-links-to-foreign-impl.rs b/src/test/rustdoc/sidebar-links-to-foreign-impl.rs index d256fbe8de08a..e73c5b4f640cf 100644 --- a/src/test/rustdoc/sidebar-links-to-foreign-impl.rs +++ b/src/test/rustdoc/sidebar-links-to-foreign-impl.rs @@ -3,7 +3,7 @@ #![crate_name = "foo"] // @has foo/trait.Foo.html -// @has - '//*[@class="sidebar-title"][@href="#foreign-impls"]' 'Implementations on Foreign Types' +// @has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' 'Implementations on Foreign Types' // @has - '//h2[@id="foreign-impls"]' 'Implementations on Foreign Types' // @has - '//*[@class="sidebar-links"]/a[@href="#impl-Foo-for-u32"]' 'u32' // @has - '//div[@id="impl-Foo-for-u32"]//code' 'impl Foo for u32' diff --git a/src/test/rustdoc/typedef.rs b/src/test/rustdoc/typedef.rs index 21a7fdda7691d..479cd91a9dc60 100644 --- a/src/test/rustdoc/typedef.rs +++ b/src/test/rustdoc/typedef.rs @@ -12,7 +12,7 @@ impl MyStruct { // @has - '//*[@class="impl has-srclink"]//code' 'impl MyAlias' // @has - '//*[@class="impl has-srclink"]//code' 'impl MyTrait for MyAlias' // @has - 'Alias docstring' -// @has - '//*[@class="sidebar"]//p[@class="location"]' 'Type Definition MyAlias' +// @has - '//*[@class="sidebar"]//*[@class="location"]' 'Type Definition MyAlias' // @has - '//*[@class="sidebar"]//a[@href="#implementations"]' 'Methods' // @has - '//*[@class="sidebar"]//a[@href="#trait-implementations"]' 'Trait Implementations' /// Alias docstring From 1941764607cf1c2f85d1301496d5e49eb3e5356a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 17 Jul 2021 11:53:59 -0700 Subject: [PATCH 4/4] Fix sidebar-mobile test to focus on an actual focusable element --- src/test/rustdoc-gui/sidebar-mobile.goml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-gui/sidebar-mobile.goml b/src/test/rustdoc-gui/sidebar-mobile.goml index f0c9361d0806b..7138f91667573 100644 --- a/src/test/rustdoc-gui/sidebar-mobile.goml +++ b/src/test/rustdoc-gui/sidebar-mobile.goml @@ -13,7 +13,7 @@ click: ".sidebar-menu" assert-css: (".sidebar-elems", {"display": "block", "left": "-246px"}) // Force the sidebar open by focusing a link inside it. // This makes it easier for keyboard users to get to it. -focus: ".sidebar-title" +focus: ".sidebar-title a" assert-css: (".sidebar-elems", {"display": "block", "left": "0px"}) // When we tab out of the sidebar, close it. focus: ".search-input"