Skip to content

Commit a45151e

Browse files
committed
rustdoc: fix font color inheritance from body, and test
1 parent 303653e commit a45151e

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,8 @@ function loadCss(cssUrl) {
860860
wrapper.style.top = (pos.top + window.scrollY) + "px";
861861
wrapper.style.left = (pos.left + window.scrollX) + "px";
862862
wrapper.style.width = pos.width + "px";
863-
document.documentElement.appendChild(wrapper);
863+
const body = document.getElementsByTagName("body")[0];
864+
body.appendChild(wrapper);
864865
window.CURRENT_NOTABLE_ELEMENT = wrapper;
865866
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE = e;
866867
wrapper.onpointerleave = function(ev) {
@@ -877,7 +878,8 @@ function loadCss(cssUrl) {
877878
function hideNotable() {
878879
if (window.CURRENT_NOTABLE_ELEMENT) {
879880
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
880-
document.documentElement.removeChild(window.CURRENT_NOTABLE_ELEMENT);
881+
const body = document.getElementsByTagName("body")[0];
882+
body.removeChild(window.CURRENT_NOTABLE_ELEMENT);
881883
window.CURRENT_NOTABLE_ELEMENT = null;
882884
}
883885
}

src/test/rustdoc-gui/notable-trait.goml

+73
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,76 @@ compare-elements-position-false: (
137137
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
138138
("y", "x"),
139139
)
140+
141+
// Now check the colors.
142+
define-function: (
143+
"check-colors",
144+
(theme, header_color, content_color, type_color, trait_color),
145+
[
146+
("goto", "file://" + |DOC_PATH| + "/test_docs/struct.NotableStructWithLongName.html"),
147+
// This is needed to ensure that the text color is computed.
148+
("show-text", true),
149+
150+
// Setting the theme.
151+
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
152+
// We reload the page so the local storage settings are being used.
153+
("reload"),
154+
155+
("move-cursor-to", "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"),
156+
("assert-count", (".notable-traits-tooltiptext", 1)),
157+
158+
("assert-css", (
159+
".notable-traits-tooltiptext h3.notable",
160+
{"color": |header_color|},
161+
ALL,
162+
)),
163+
("assert-css", (
164+
".notable-traits-tooltiptext pre.content",
165+
{"color": |content_color|},
166+
ALL,
167+
)),
168+
("assert-css", (
169+
".notable-traits-tooltiptext pre.content a.struct",
170+
{"color": |type_color|},
171+
ALL,
172+
)),
173+
("assert-css", (
174+
".notable-traits-tooltiptext pre.content a.trait",
175+
{"color": |trait_color|},
176+
ALL,
177+
)),
178+
]
179+
)
180+
181+
call-function: (
182+
"check-colors",
183+
{
184+
"theme": "ayu",
185+
"content_color": "rgb(230, 225, 207)",
186+
"header_color": "rgb(255, 255, 255)",
187+
"type_color": "rgb(255, 160, 165)",
188+
"trait_color": "rgb(57, 175, 215)",
189+
},
190+
)
191+
192+
call-function: (
193+
"check-colors",
194+
{
195+
"theme": "dark",
196+
"content_color": "rgb(221, 221, 221)",
197+
"header_color": "rgb(221, 221, 221)",
198+
"type_color": "rgb(45, 191, 184)",
199+
"trait_color": "rgb(183, 140, 242)",
200+
},
201+
)
202+
203+
call-function: (
204+
"check-colors",
205+
{
206+
"theme": "light",
207+
"content_color": "rgb(0, 0, 0)",
208+
"header_color": "rgb(0, 0, 0)",
209+
"type_color": "rgb(173, 55, 138)",
210+
"trait_color": "rgb(110, 79, 201)",
211+
},
212+
)

0 commit comments

Comments
 (0)