Skip to content

14 files changed

+134
-130
lines changed

src/librustdoc/html/render/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1312,9 +1312,7 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
13121312
if has_notable_trait {
13131313
cx.types_with_notable_traits.insert(ty.clone());
13141314
Some(format!(
1315-
"<span class=\"notable-traits\" data-ty=\"{ty}\">\
1316-
<span class=\"notable-traits-tooltip\">ⓘ</span>\
1317-
</span>",
1315+
" <a href=\"#\" class=\"notable-traits\" data-ty=\"{ty}\">ⓘ</a>",
13181316
ty = Escape(&format!("{:#}", ty.print(cx))),
13191317
))
13201318
} else {
@@ -1343,7 +1341,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
13431341
if out.is_empty() {
13441342
write!(
13451343
&mut out,
1346-
"<h3 class=\"notable\">Notable traits for <code>{}</code></h3>\
1344+
"<h3>Notable traits for <code>{}</code></h3>\
13471345
<pre class=\"content\"><code>",
13481346
impl_.for_.print(cx)
13491347
);

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

+19-52
Original file line numberDiff line numberDiff line change
@@ -929,13 +929,14 @@ so that we can apply CSS-filters to change the arrow color in themes */
929929
border-radius: 3px;
930930
border: 1px solid var(--border-color);
931931
font-size: 1rem;
932+
--popover-arrow-offset: 11px;
932933
}
933934

934935
/* This rule is to draw the little arrow connecting the settings menu to the gear icon. */
935936
.popover::before {
936937
content: '';
937938
position: absolute;
938-
right: 11px;
939+
right: var(--popover-arrow-offset);
939940
border: solid var(--border-color);
940941
border-width: 1px 1px 0 0;
941942
display: inline-block;
@@ -952,10 +953,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
952953
/* use larger max-width for help popover, but not for help.html */
953954
#help.popover {
954955
max-width: 600px;
955-
}
956-
957-
#help.popover::before {
958-
right: 48px;
956+
--popover-arrow-offset: 48px;
959957
}
960958

961959
#help dt {
@@ -1274,54 +1272,34 @@ h3.variant {
12741272
border-right: 3px solid var(--target-border-color);
12751273
}
12761274

1277-
.notable-traits-tooltip {
1278-
display: inline-block;
1279-
cursor: pointer;
1280-
}
1281-
1282-
.notable-traits .notable-traits-tooltiptext {
1283-
display: inline-block;
1284-
visibility: hidden;
1275+
.notable-traits {
1276+
color: inherit;
1277+
margin-right: 15px;
1278+
position: relative;
12851279
}
12861280

1287-
.notable-traits-tooltiptext {
1288-
padding: 5px 3px 3px 3px;
1289-
border-radius: 6px;
1290-
margin-left: 5px;
1291-
z-index: 10;
1292-
font-size: 1rem;
1293-
cursor: default;
1281+
/* placeholder thunk so that the mouse can easily travel from "(i)" to popover
1282+
the resulting "hover tunnel" is a stepped triangle, approximating
1283+
https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown */
1284+
.notable-traits:hover::after {
12941285
position: absolute;
1295-
border: 1px solid;
1296-
}
1297-
1298-
.notable-traits-tooltip::after {
1299-
/* The margin on the tooltip does not capture hover events,
1300-
this extends the area of hover enough so that mouse hover is not
1301-
lost when moving the mouse to the tooltip */
1302-
content: "\00a0\00a0\00a0";
1303-
}
1304-
1305-
.notable-traits-tooltiptext .docblock {
1306-
margin: 0;
1286+
top: calc(100% - 10px);
1287+
left: -15px;
1288+
right: -15px;
1289+
height: 20px;
1290+
content: "\00a0";
13071291
}
13081292

1309-
.notable-traits-tooltiptext .notable {
1310-
font-size: 1.1875rem;
1311-
font-weight: 600;
1312-
display: block;
1293+
.notable .docblock {
1294+
margin: 0.25em 0.5em;
13131295
}
13141296

1315-
.notable-traits-tooltiptext pre, .notable-traits-tooltiptext code {
1297+
.notable .docblock pre, .notable .docblock code {
13161298
background: transparent;
1317-
}
1318-
1319-
.notable-traits-tooltiptext .docblock pre.content {
13201299
margin: 0;
13211300
padding: 0;
13221301
font-size: 1.25rem;
13231302
white-space: pre-wrap;
1324-
overflow: hidden;
13251303
}
13261304

13271305
.search-failed {
@@ -1364,12 +1342,6 @@ h3.variant {
13641342
font-size: 1rem;
13651343
}
13661344

1367-
.notable-traits {
1368-
cursor: pointer;
1369-
z-index: 2;
1370-
margin-left: 5px;
1371-
}
1372-
13731345
#sidebar-toggle {
13741346
position: sticky;
13751347
top: 0;
@@ -1854,11 +1826,6 @@ in storage.js
18541826
border-bottom: 1px solid;
18551827
}
18561828

1857-
.notable-traits .notable-traits-tooltiptext {
1858-
left: 0;
1859-
top: 100%;
1860-
}
1861-
18621829
/* We don't display the help button on mobile devices. */
18631830
#help-button {
18641831
display: none;

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

-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ details.rustdoc-toggle > summary::before {
169169
border-color: transparent #314559 transparent transparent;
170170
}
171171

172-
.notable-traits-tooltiptext {
173-
background-color: #314559;
174-
}
175-
176172
#titles > button.selected {
177173
background-color: #141920 !important;
178174
border-bottom: 1px solid #ffb44c !important;

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

-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ details.rustdoc-toggle > summary::before {
9292
border-color: transparent black transparent transparent;
9393
}
9494

95-
.notable-traits-tooltiptext {
96-
background-color: #111;
97-
}
98-
9995
#titles > button:not(.selected) {
10096
background-color: #252525;
10197
border-top-color: #252525;

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

-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ body.source .example-wrap pre.rust a {
8484
border-color: transparent black transparent transparent;
8585
}
8686

87-
.notable-traits-tooltiptext {
88-
background-color: #eee;
89-
}
90-
9187
#titles > button:not(.selected) {
9288
background-color: #e6e6e6;
9389
border-top-color: #e6e6e6;

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

+51-9
Original file line numberDiff line numberDiff line change
@@ -850,18 +850,33 @@ function loadCss(cssUrl) {
850850
}
851851
hideNotable();
852852
const ty = e.getAttribute("data-ty");
853-
const tooltip = e.getElementsByClassName("notable-traits-tooltip")[0];
854853
const wrapper = document.createElement("div");
855854
wrapper.innerHTML = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>";
856-
wrapper.className = "notable-traits-tooltiptext";
857-
tooltip.appendChild(wrapper);
858-
const pos = wrapper.getBoundingClientRect();
859-
tooltip.removeChild(wrapper);
860-
wrapper.style.top = (pos.top + window.scrollY) + "px";
861-
wrapper.style.left = (pos.left + window.scrollX) + "px";
862-
wrapper.style.width = pos.width + "px";
855+
wrapper.className = "notable popover";
856+
const focusCatcher = document.createElement("div");
857+
focusCatcher.setAttribute("tabindex", "0");
858+
focusCatcher.onfocus = hideNotable;
859+
wrapper.appendChild(focusCatcher);
860+
const pos = e.getBoundingClientRect();
861+
// 5px overlap so that the mouse can easily travel from place to place
862+
wrapper.style.top = (pos.top + window.scrollY + pos.height) + "px";
863+
wrapper.style.left = 0;
864+
wrapper.style.right = "auto";
865+
wrapper.style.visibility = "hidden";
863866
const body = document.getElementsByTagName("body")[0];
864867
body.appendChild(wrapper);
868+
const wrapperPos = wrapper.getBoundingClientRect();
869+
// offset so that the arrow points at the center of the "(i)"
870+
const finalPos = pos.left + window.scrollX - wrapperPos.width + 24;
871+
if (finalPos > 0) {
872+
wrapper.style.left = finalPos + "px";
873+
} else {
874+
wrapper.style.setProperty(
875+
"--popover-arrow-offset",
876+
(wrapperPos.right - pos.right + 4) + "px"
877+
);
878+
}
879+
wrapper.style.visibility = "";
865880
window.CURRENT_NOTABLE_ELEMENT = wrapper;
866881
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE = e;
867882
wrapper.onpointerleave = function(ev) {
@@ -875,9 +890,31 @@ function loadCss(cssUrl) {
875890
};
876891
}
877892

893+
function notableBlurHandler(event) {
894+
if (window.CURRENT_NOTABLE_ELEMENT &&
895+
!elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT) &&
896+
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT) &&
897+
!elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) &&
898+
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE)
899+
) {
900+
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
901+
// When I click the button on an already-opened notable trait popover, Safari
902+
// hides the popover and then immediately shows it again, while everyone else hides it
903+
// and it stays hidden.
904+
//
905+
// To work around this, make sure the click finishes being dispatched before
906+
// hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave
907+
// consistently with the other two.
908+
setTimeout(hideNotable, 0);
909+
}
910+
}
911+
878912
function hideNotable() {
879913
if (window.CURRENT_NOTABLE_ELEMENT) {
880-
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
914+
if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) {
915+
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
916+
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
917+
}
881918
const body = document.getElementsByTagName("body")[0];
882919
body.removeChild(window.CURRENT_NOTABLE_ELEMENT);
883920
window.CURRENT_NOTABLE_ELEMENT = null;
@@ -891,7 +928,11 @@ function loadCss(cssUrl) {
891928
hideNotable();
892929
} else {
893930
showNotable(this);
931+
window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0");
932+
window.CURRENT_NOTABLE_ELEMENT.focus();
933+
window.CURRENT_NOTABLE_ELEMENT.onblur = notableBlurHandler;
894934
}
935+
return false;
895936
};
896937
e.onpointerenter = function(ev) {
897938
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
@@ -1018,6 +1059,7 @@ function loadCss(cssUrl) {
10181059
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
10191060
elem.style.display = "none";
10201061
});
1062+
hideNotable();
10211063
};
10221064

10231065
/**

0 commit comments

Comments
 (0)