зеркало из https://github.com/mozilla/gecko-dev.git
Bug 901250 - Add scroll into view menu item for the inspector. r=bgrins
This commit is contained in:
Родитель
b64b7e1291
Коммит
7836d45e7a
|
@ -673,19 +673,27 @@ InspectorPanel.prototype = {
|
|||
deleteNode.setAttribute("disabled", "true");
|
||||
}
|
||||
|
||||
// Disable / enable "Copy Unique Selector", "Copy inner HTML" &
|
||||
// "Copy outer HTML" as appropriate
|
||||
// Disable / enable "Copy Unique Selector", "Copy inner HTML",
|
||||
// "Copy outer HTML" & "Scroll Into View" as appropriate
|
||||
let unique = this.panelDoc.getElementById("node-menu-copyuniqueselector");
|
||||
let copyInnerHTML = this.panelDoc.getElementById("node-menu-copyinner");
|
||||
let copyOuterHTML = this.panelDoc.getElementById("node-menu-copyouter");
|
||||
let scrollIntoView = this.panelDoc.getElementById("node-menu-scrollnodeintoview");
|
||||
|
||||
this._target.actorHasMethod("domnode", "scrollIntoView").then(value => {
|
||||
scrollIntoView.hidden = !value;
|
||||
});
|
||||
|
||||
if (isSelectionElement) {
|
||||
unique.removeAttribute("disabled");
|
||||
copyInnerHTML.removeAttribute("disabled");
|
||||
copyOuterHTML.removeAttribute("disabled");
|
||||
scrollIntoView.removeAttribute("disabled");
|
||||
} else {
|
||||
unique.setAttribute("disabled", "true");
|
||||
copyInnerHTML.setAttribute("disabled", "true");
|
||||
copyOuterHTML.setAttribute("disabled", "true");
|
||||
scrollIntoView.setAttribute("disabled", "true");
|
||||
}
|
||||
if (!this.canGetUniqueSelector) {
|
||||
unique.hidden = true;
|
||||
|
@ -999,6 +1007,18 @@ InspectorPanel.prototype = {
|
|||
}).then(null, console.error);
|
||||
},
|
||||
|
||||
/**
|
||||
* Scroll the node into view.
|
||||
*/
|
||||
scrollNodeIntoView: function InspectorPanel_scrollNodeIntoView()
|
||||
{
|
||||
if (!this.selection.isNode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selection.nodeFront.scrollIntoView();
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the selected node.
|
||||
*/
|
||||
|
|
|
@ -90,6 +90,11 @@
|
|||
</menupopup>
|
||||
</menu>
|
||||
<menuseparator/>
|
||||
<menuitem id="node-menu-scrollnodeintoview"
|
||||
label="&inspectorScrollNodeIntoView.label;"
|
||||
accesskey="&inspectorScrollNodeIntoView.accesskey;"
|
||||
oncommand="inspector.scrollNodeIntoView()"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="node-menu-delete"
|
||||
label="&inspectorHTMLDelete.label;"
|
||||
accesskey="&inspectorHTMLDelete.accesskey;"
|
||||
|
|
|
@ -26,7 +26,8 @@ const ALL_MENU_ITEMS = [
|
|||
"node-menu-delete",
|
||||
"node-menu-pseudo-hover",
|
||||
"node-menu-pseudo-active",
|
||||
"node-menu-pseudo-focus"
|
||||
"node-menu-pseudo-focus",
|
||||
"node-menu-scrollnodeintoview"
|
||||
].concat(PASTE_MENU_ITEMS);
|
||||
|
||||
const ITEMS_WITHOUT_SHOWDOMPROPS =
|
||||
|
|
|
@ -13,6 +13,7 @@ add_task(function* () {
|
|||
yield testShowDOMProperties();
|
||||
yield testDeleteNode();
|
||||
yield testDeleteRootNode();
|
||||
yield testScrollIntoView();
|
||||
|
||||
function* testShowDOMProperties() {
|
||||
info("Testing 'Show DOM Properties' menu item.");
|
||||
|
@ -63,6 +64,11 @@ add_task(function* () {
|
|||
});
|
||||
}
|
||||
|
||||
function* testScrollIntoView() {
|
||||
// Follow up bug to add this test - https://bugzilla.mozilla.org/show_bug.cgi?id=1154107
|
||||
todo(false, "Verify that node is scrolled into the viewport.");
|
||||
}
|
||||
|
||||
function dispatchCommandEvent(node) {
|
||||
info("Dispatching command event on " + node);
|
||||
let commandEvent = document.createEvent("XULCommandEvent");
|
||||
|
|
|
@ -68,6 +68,11 @@
|
|||
<!ENTITY inspectorHTMLPasteLastChild.label "As Last Child">
|
||||
<!ENTITY inspectorHTMLPasteLastChild.accesskey "L">
|
||||
|
||||
<!-- LOCALIZATION NOTE (inspectorScrollNodeIntoView.label): This is the label
|
||||
shown in the inspector contextual-menu for the item that lets users scroll
|
||||
the current node into view -->
|
||||
<!ENTITY inspectorScrollNodeIntoView.label "Scroll Into View">
|
||||
<!ENTITY inspectorScrollNodeIntoView.accesskey "S">
|
||||
|
||||
<!-- LOCALIZATION NOTE (inspectorHTMLDelete.label): This is the label shown in
|
||||
the inspector contextual-menu for the item that lets users delete the
|
||||
|
|
|
@ -581,6 +581,16 @@ var NodeActor = exports.NodeActor = protocol.ActorClass({
|
|||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* Scroll the selected node into view.
|
||||
*/
|
||||
scrollIntoView: method(function() {
|
||||
this.rawNode.scrollIntoView(true);
|
||||
}, {
|
||||
request: {},
|
||||
response: {}
|
||||
}),
|
||||
|
||||
/**
|
||||
* Get the node's image data if any (for canvas and img nodes).
|
||||
* Returns an imageData object with the actual data being a LongStringActor
|
||||
|
|
|
@ -53,6 +53,7 @@ skip-if = buildapp == 'mulet'
|
|||
[test_inspector-reload.html]
|
||||
[test_inspector-remove.html]
|
||||
[test_inspector-retain.html]
|
||||
[test_inspector-scroll-into-view.html]
|
||||
[test_inspector-traversal.html]
|
||||
[test_makeGlobalObjectReference.html]
|
||||
[test_styles-applied.html]
|
||||
|
|
|
@ -86,5 +86,6 @@
|
|||
<object>
|
||||
<div id="1"></div>
|
||||
</object>
|
||||
<div id="scroll-into-view" style="margin-top: 1000px;">scroll</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=901250
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 901250</title>
|
||||
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
||||
<script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
|
||||
<script type="application/javascript;version=1.8">
|
||||
Components.utils.import("resource://gre/modules/devtools/Loader.jsm");
|
||||
const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {});
|
||||
const Ci = Components.interfaces;
|
||||
const inspector = devtools.require("devtools/server/actors/inspector");
|
||||
|
||||
window.onload = function() {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
runNextTest();
|
||||
}
|
||||
|
||||
var gInspectee = null;
|
||||
var gClient = null;
|
||||
var gWalker = null;
|
||||
|
||||
function assertOwnership() {
|
||||
assertOwnershipTrees(gWalker);
|
||||
}
|
||||
|
||||
addTest(function setup() {
|
||||
let url = document.getElementById("inspectorContent").href;
|
||||
attachURL(url, function(err, client, tab, doc) {
|
||||
gInspectee = doc;
|
||||
let {InspectorFront} = devtools.require("devtools/server/actors/inspector");
|
||||
let inspector = InspectorFront(client, tab);
|
||||
promiseDone(inspector.getWalker().then(walker => {
|
||||
ok(walker, "getWalker() should return an actor.");
|
||||
gClient = client;
|
||||
gWalker = walker;
|
||||
}).then(runNextTest));
|
||||
});
|
||||
});
|
||||
|
||||
addTest(Task.async(function* testScrollIntoView() {
|
||||
let id = "#scroll-into-view";
|
||||
let rect = gInspectee.querySelector(id).getBoundingClientRect();
|
||||
let nodeFront = yield gWalker.querySelector(gWalker.rootNode, id);
|
||||
let inViewport = rect.x >= 0 &&
|
||||
rect.y >= 0 &&
|
||||
rect.y <= gInspectee.defaultView.innerHeight &&
|
||||
rect.x <= gInspectee.defaultView.innerWidth;
|
||||
|
||||
ok(!inViewport, "Element is not in viewport.");
|
||||
|
||||
yield nodeFront.scrollIntoView();
|
||||
|
||||
SimpleTest.executeSoon(() => {
|
||||
rect = gInspectee.querySelector(id).getBoundingClientRect();
|
||||
inViewport = rect.x >= 0 &&
|
||||
rect.y >= 0 &&
|
||||
rect.y <= gInspectee.defaultView.innerHeight &&
|
||||
rect.x <= gInspectee.defaultView.innerWidth;
|
||||
|
||||
ok(inViewport, "Element is in viewport.");
|
||||
|
||||
runNextTest();
|
||||
});
|
||||
}));
|
||||
|
||||
addTest(function cleanup() {
|
||||
delete gWalker;
|
||||
delete gInspectee;
|
||||
delete gClient;
|
||||
runNextTest();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=901250">Mozilla Bug 901250</a>
|
||||
<a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче