Bug 1041654 - Make ElementTooltip scrollable and scroll the event handler content into view when expanded. r=miker

This commit is contained in:
Sami Jaktholm 2014-08-27 02:35:00 -04:00
parent 7d1a85924c
commit 49212ebf34
5 changed files with 117 additions and 0 deletions

View File

@ -3,6 +3,7 @@ subsuite = devtools
support-files =
doc_markup_edit.html
doc_markup_events.html
doc_markup_events-overflow.html
doc_markup_flashing.html
doc_markup_mutation.html
doc_markup_navigation.html
@ -20,6 +21,8 @@ support-files =
[browser_markupview_css_completion_style_attribute.js]
[browser_markupview_events.js]
skip-if = e10s # Bug 1040751 - CodeMirror editor.destroy() isn't e10s compatible
[browser_markupview_events-overflow.js]
skip-if = e10s # Bug 1040751 - CodeMirror editor.destroy() isn't e10s compatible
[browser_markupview_highlight_hover_01.js]
skip-if = e10s # Bug 985597 - The XUL-based highlighter isn't e10s compatible
[browser_markupview_highlight_hover_02.js]

View File

@ -0,0 +1,87 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URL = TEST_URL_ROOT + "doc_markup_events-overflow.html";
const TEST_DATA = [
{
desc: "editor overflows container",
initialScrollTop: -1, // scroll to bottom
headerToClick: 49, // last header
alignBottom: true,
alignTop: false,
},
{
desc: "header overflows the container",
initialScrollTop: 2,
headerToClick: 0,
alignBottom: false,
alignTop: true,
},
{
desc: "neither header nor editor overflows the container",
initialScrollTop: 2,
headerToClick: 5,
alignBottom: false,
alignTop: false,
},
];
let test = asyncTest(function*() {
let { inspector } = yield addTab(TEST_URL).then(openInspector);
let markupContainer = yield getContainerForSelector("#events", inspector);
let evHolder = markupContainer.elt.querySelector(".markupview-events");
let tooltip = inspector.markup.tooltip;
info("Clicking to open event tooltip.");
EventUtils.synthesizeMouseAtCenter(evHolder, {}, inspector.markup.doc.defaultView);
yield tooltip.once("shown");
info("EventTooltip visible.");
let container = tooltip.content;
let containerRect = container.getBoundingClientRect();
let headers = container.querySelectorAll(".event-header");
for (let data of TEST_DATA) {
info("Testing scrolling when " + data.desc);
if (data.initialScrollTop < 0) {
info("Scrolling container to the bottom.");
let newScrollTop = container.scrollHeight - container.clientHeight;
data.initialScrollTop = container.scrollTop = newScrollTop;
} else {
info("Scrolling container by " + data.initialScrollTop + "px");
container.scrollTop = data.initialScrollTop;
}
is(container.scrollTop, data.initialScrollTop, "Container scrolled.");
info("Clicking on header #" + data.headerToClick);
let header = headers[data.headerToClick];
let ready = tooltip.once("event-tooltip-ready");
EventUtils.synthesizeMouseAtCenter(header, {}, header.ownerGlobal);
yield ready;
info("Event handler expanded.");
if (data.alignTop) {
let headerRect = header.getBoundingClientRect();
is(headerRect.top, containerRect.top,
"Clicked header is aligned with the container top.");
} else if (data.alignBottom) {
let editorRect = header.nextElementSibling.getBoundingClientRect();
is(editorRect.bottom, containerRect.bottom,
"Clicked event handler code is aligned with the container bottom.");
} else {
is(container.scrollTop, data.initialScrollTop,
"Container did not scroll, as expected.");
}
}
});

View File

@ -0,0 +1,18 @@
<html>
<head>
<meta charset="UTF-8">
<title>doc_markup_events-overflow.html</title>
</head>
<body>
<h1>doc_markup_events-overflow.html</h1>
<span id="events">Inspect me!</span>
<script>
var el = document.getElementById("events");
for (var i = 50; i > 0; i--) {
el.addEventListener("click", function onClick() {
alert("click");
});
}
</script>
</body>
</html>

View File

@ -1265,6 +1265,14 @@ EventTooltip.prototype = {
editor.setText(tidied);
eventEditors.appended = true;
let container = header.parentElement.getBoundingClientRect();
if (header.getBoundingClientRect().top < container.top) {
header.scrollIntoView(true);
} else if (content.getBoundingClientRect().bottom > container.bottom) {
content.scrollIntoView(false);
}
this._tooltip.emit("event-tooltip-ready");
});
}

View File

@ -44,6 +44,7 @@
#devtools-tooltip-events-container {
margin: -4px; /* Compensate for the .panel-arrowcontent padding. */
max-width: 390px;
overflow: auto;
}
.event-header {