From 89ba71649f59e402a0019828223a878c06f625b1 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 8 Nov 2022 18:00:22 -0700 Subject: rustdoc: use consistent "popover" styling for notable traits --- src/test/rustdoc-gui/notable-trait.goml | 61 ++++++++++++++------------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'src/test/rustdoc-gui') diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml index d8261d8dc90..3bc1c5365e9 100644 --- a/src/test/rustdoc-gui/notable-trait.goml +++ b/src/test/rustdoc-gui/notable-trait.goml @@ -22,31 +22,26 @@ assert-position: ( ) assert-position: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - {"x": 951}, + {"x": 955}, ) -// The tooltip should be beside the `i` +// The tooltip should be below the `i` // Also, clicking the tooltip should bring its text into the DOM -assert-count: ("//*[@class='notable-traits-tooltiptext']", 0) +assert-count: ("//*[@class='notable popover']", 0) click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" -assert-count: ("//*[@class='notable-traits-tooltiptext']", 1) +assert-count: ("//*[@class='notable popover']", 1) compare-elements-position-near: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - "//*[@class='notable-traits-tooltiptext']", - {"y": 2} + "//*[@class='notable popover']", + {"y": 30} ) compare-elements-position-false: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - "//*[@class='notable-traits-tooltiptext']", + "//*[@class='notable popover']", ("x") ) -// The docblock should be flush with the border. -assert-css: ( - "//*[@class='notable-traits-tooltiptext']/*[@class='docblock']", - {"margin-left": "0px"} -) click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" move-cursor-to: "//h1" -assert-count: ("//*[@class='notable-traits-tooltiptext']", 0) +assert-count: ("//*[@class='notable popover']", 0) // Now only the `i` should be on the next line. size: (1055, 600) @@ -77,7 +72,7 @@ assert-position: ( ) assert-position: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - {"x": 519}, + {"x": 523}, ) // Checking on mobile now. @@ -101,34 +96,28 @@ assert-position: ( ) assert-position: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - {"x": 289}, + {"x": 293}, ) -// The tooltip should be below `i` +// The tooltip should STILL be below `i` click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" -assert-count: ("//*[@class='notable-traits-tooltiptext']", 1) -compare-elements-position-near-false: ( +assert-count: ("//*[@class='notable popover']", 1) +compare-elements-position-near: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - "//*[@class='notable-traits-tooltiptext']", - {"y": 2} + "//*[@class='notable popover']", + {"y": 30} ) compare-elements-position-false: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - "//*[@class='notable-traits-tooltiptext']", + "//*[@class='notable popover']", ("x") ) -compare-elements-position-near: ( - "//*[@id='method.create_an_iterator_from_read']", - "//*[@class='notable-traits-tooltiptext']", - {"x": 10} -) -// The docblock should be flush with the border. -assert-css: ( - "//*[@class='notable-traits-tooltiptext']/*[@class='docblock']", - {"margin-left": "0px"} +assert-position: ( + "//*[@class='notable popover']", + {"x": 0} ) click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" move-cursor-to: "//h1" -assert-count: ("//*[@class='notable-traits-tooltiptext']", 0) +assert-count: ("//*[@class='notable popover']", 0) // Checking on very small mobile. The `i` should be on its own line. size: (365, 600) @@ -153,25 +142,25 @@ define-function: ( ("reload"), ("move-cursor-to", "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"), - ("assert-count", (".notable-traits-tooltiptext", 1)), + ("assert-count", (".notable.popover", 1)), ("assert-css", ( - ".notable-traits-tooltiptext h3.notable", + ".notable.popover h3", {"color": |header_color|}, ALL, )), ("assert-css", ( - ".notable-traits-tooltiptext pre.content", + ".notable.popover pre", {"color": |content_color|}, ALL, )), ("assert-css", ( - ".notable-traits-tooltiptext pre.content a.struct", + ".notable.popover pre a.struct", {"color": |type_color|}, ALL, )), ("assert-css", ( - ".notable-traits-tooltiptext pre.content a.trait", + ".notable.popover pre a.trait", {"color": |trait_color|}, ALL, )), -- cgit 1.4.1-3-g733a5 From 155750dc330d0a2148cff7efadd75d821854e947 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 8 Nov 2022 17:59:03 -0700 Subject: rustdoc: make notable traits popover behavior consistent with Help and Settings --- src/librustdoc/html/static/js/main.js | 10 +++++++++- src/test/rustdoc-gui/notable-trait.goml | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src/test/rustdoc-gui') diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index b670ea3f020..0538762e44d 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -897,7 +897,15 @@ function loadCss(cssUrl) { !elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) && !elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) ) { - hideNotable(); + // Work around a difference in the focus behaviour between Firefox, Chrome, and Safari. + // When I click the button on an already-opened notable trait popover, Safari + // hides the popover and then immediately shows it again, while everyone else hides it + // and it stays hidden. + // + // To work around this, make sure the click finishes being dispatched before + // hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave + // consistently with the other two. + setTimeout(hideNotable, 0); } } diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml index 3bc1c5365e9..0b97cbae499 100644 --- a/src/test/rustdoc-gui/notable-trait.goml +++ b/src/test/rustdoc-gui/notable-trait.goml @@ -199,3 +199,31 @@ call-function: ( "trait_color": "rgb(110, 79, 201)", }, ) + +reload: + +// Check that pressing escape works +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" +move-cursor-to: "//*[@class='notable popover']" +assert-count: ("//*[@class='notable popover']", 1) +press-key: "Escape" +assert-count: ("//*[@class='notable popover']", 0) + +// Check that clicking outside works. +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" +assert-count: ("//*[@class='notable popover']", 1) +click: ".search-input" +assert-count: ("//*[@class='notable popover']", 0) + +// Check that pressing tab over and over works. +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" +move-cursor-to: "//*[@class='notable popover']" +assert-count: ("//*[@class='notable popover']", 1) +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +assert-count: ("//*[@class='notable popover']", 0) -- cgit 1.4.1-3-g733a5 From 79b6112ab53a9f5cd2b267dfbdb8bcae7049b2f7 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 8 Nov 2022 17:49:29 -0700 Subject: rustdoc: update test cases --- src/test/rustdoc-gui/notable-trait.goml | 8 -------- src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html | 2 +- src/test/rustdoc/doc-notable_trait.bare-fn.html | 2 +- src/test/rustdoc/doc-notable_trait.rs | 6 +++--- src/test/rustdoc/doc-notable_trait.some-struct-new.html | 2 +- src/test/rustdoc/doc-notable_trait.wrap-me.html | 2 +- src/test/rustdoc/spotlight-from-dependency.odd.html | 2 +- src/test/rustdoc/spotlight-from-dependency.rs | 2 +- 8 files changed, 9 insertions(+), 17 deletions(-) (limited to 'src/test/rustdoc-gui') diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml index 0b97cbae499..4c3943d8858 100644 --- a/src/test/rustdoc-gui/notable-trait.goml +++ b/src/test/rustdoc-gui/notable-trait.goml @@ -119,14 +119,6 @@ click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits move-cursor-to: "//h1" assert-count: ("//*[@class='notable popover']", 0) -// Checking on very small mobile. The `i` should be on its own line. -size: (365, 600) -compare-elements-position-false: ( - "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", - "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", - ("y", "x"), -) - // Now check the colors. define-function: ( "check-colors", diff --git a/src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html b/src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html index 6b58be7e685..f2ec8320a05 100644 --- a/src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html +++ b/src/test/rustdoc/doc-notable_trait-slice.bare_fn_matches.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/doc-notable_trait.bare-fn.html b/src/test/rustdoc/doc-notable_trait.bare-fn.html index 4e4a3f18f24..b426a4d7a8b 100644 --- a/src/test/rustdoc/doc-notable_trait.bare-fn.html +++ b/src/test/rustdoc/doc-notable_trait.bare-fn.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/doc-notable_trait.rs b/src/test/rustdoc/doc-notable_trait.rs index 1f2cd7181c3..279faf55401 100644 --- a/src/test/rustdoc/doc-notable_trait.rs +++ b/src/test/rustdoc/doc-notable_trait.rs @@ -9,7 +9,7 @@ impl SomeTrait for Wrapper {} #[doc(notable_trait)] pub trait SomeTrait { // @has doc_notable_trait/trait.SomeTrait.html - // @has - '//span[@class="notable-traits"]/@data-ty' 'Wrapper' + // @has - '//a[@class="notable-traits"]/@data-ty' 'Wrapper' // @snapshot wrap-me - '//script[@id="notable-traits-data"]' fn wrap_me(self) -> Wrapper where Self: Sized { Wrapper { @@ -23,7 +23,7 @@ impl SomeTrait for SomeStruct {} impl SomeStruct { // @has doc_notable_trait/struct.SomeStruct.html - // @has - '//span[@class="notable-traits"]/@data-ty' 'SomeStruct' + // @has - '//a[@class="notable-traits"]/@data-ty' 'SomeStruct' // @snapshot some-struct-new - '//script[@id="notable-traits-data"]' pub fn new() -> SomeStruct { SomeStruct @@ -31,7 +31,7 @@ impl SomeStruct { } // @has doc_notable_trait/fn.bare_fn.html -// @has - '//span[@class="notable-traits"]/@data-ty' 'SomeStruct' +// @has - '//a[@class="notable-traits"]/@data-ty' 'SomeStruct' // @snapshot bare-fn - '//script[@id="notable-traits-data"]' pub fn bare_fn() -> SomeStruct { SomeStruct diff --git a/src/test/rustdoc/doc-notable_trait.some-struct-new.html b/src/test/rustdoc/doc-notable_trait.some-struct-new.html index c0fd9748fd3..4f8063807e6 100644 --- a/src/test/rustdoc/doc-notable_trait.some-struct-new.html +++ b/src/test/rustdoc/doc-notable_trait.some-struct-new.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/doc-notable_trait.wrap-me.html b/src/test/rustdoc/doc-notable_trait.wrap-me.html index 9a59d5edd12..bed2a38b24a 100644 --- a/src/test/rustdoc/doc-notable_trait.wrap-me.html +++ b/src/test/rustdoc/doc-notable_trait.wrap-me.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/spotlight-from-dependency.odd.html b/src/test/rustdoc/spotlight-from-dependency.odd.html index 987a949af44..1d02c13ebfb 100644 --- a/src/test/rustdoc/spotlight-from-dependency.odd.html +++ b/src/test/rustdoc/spotlight-from-dependency.odd.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/spotlight-from-dependency.rs b/src/test/rustdoc/spotlight-from-dependency.rs index 156aedca62b..090ad187d9c 100644 --- a/src/test/rustdoc/spotlight-from-dependency.rs +++ b/src/test/rustdoc/spotlight-from-dependency.rs @@ -3,7 +3,7 @@ use std::iter::Iterator; // @has foo/struct.Odd.html -// @has - '//*[@id="method.new"]//span[@class="notable-traits"]/@data-ty' 'Odd' +// @has - '//*[@id="method.new"]//a[@class="notable-traits"]/@data-ty' 'Odd' // @snapshot odd - '//script[@id="notable-traits-data"]' pub struct Odd { current: usize, -- cgit 1.4.1-3-g733a5