Bug 840247 - Entering the Inspector from the Web Console should show the <html> and <body> tag expanded. r=jwalker

This commit is contained in:
Sinduja Ramaraj 2013-06-11 08:28:00 +03:00
Родитель 9a6f3ac9cc
Коммит 2f23ac8d4c
5 изменённых файлов: 36 добавлений и 40 удалений

Просмотреть файл

@ -122,17 +122,19 @@ InspectorPanel.prototype = {
// All the components are initialized. Let's select a node.
if (this.target.isLocalTab) {
let root = this.browser.contentDocument.documentElement;
this._selection.setNode(root);
this._selection.setNode(
this._getDefaultNodeForSelection(this.browser.contentDocument));
} else if (this.target.window) {
let root = this.target.window.document.documentElement;
this._selection.setNode(root);
this._selection.setNode(
this._getDefaultNodeForSelection(this.target.window.document));
}
if (this.highlighter) {
this.highlighter.unlock();
}
this.markup.expandNode(this.selection.node);
this.emit("ready");
deferred.resolve(this);
}.bind(this));
@ -143,6 +145,16 @@ InspectorPanel.prototype = {
return deferred.promise;
},
/**
* Select node for default selection
*/
_getDefaultNodeForSelection : function(document) {
// if available set body node as default selected node
// else set documentElement
var defaultNode = document.body || document.documentElement;
return defaultNode;
},
/**
* Selection object (read only)
*/
@ -253,21 +265,26 @@ InspectorPanel.prototype = {
this.selection.setNode(null);
this._destroyMarkup();
this.isDirty = false;
let self = this;
function onDOMReady() {
let onDOMReady = function() {
newWindow.removeEventListener("DOMContentLoaded", onDOMReady, true);
if (self._destroyed) {
if (this._destroyed) {
return;
}
if (!self.selection.node) {
self.selection.setNode(newWindow.document.documentElement, "navigateaway");
if (!this.selection.node) {
let defaultNode = this._getDefaultNodeForSelection(newWindow.document);
this.selection.setNode(defaultNode, "navigateaway");
}
self._initMarkup();
self.setupSearchBox();
}
this._initMarkup();
this.once("markuploaded", () => {
this.markup.expandNode(this.selection.node);
});
this.setupSearchBox();
}.bind(this);
if (newWindow.document.readyState == "loading") {
newWindow.addEventListener("DOMContentLoaded", onDOMReady, true);

Просмотреть файл

@ -35,28 +35,16 @@ function test()
inspector = aInspector;
executeSoon(function() {
inspector.selection.once("new-node", highlightBodyNode);
inspector.selection.once("new-node", highlightHeaderNode);
// Test that navigating around without a selected node gets us to the
// body element.
node = doc.querySelector("body");
// head element.
node = doc.querySelector("h1");
let bc = inspector.breadcrumbs;
bc.nodeHierarchy[bc.currentIndex].button.focus();
EventUtils.synthesizeKey("VK_RIGHT", { });
});
}
function highlightBodyNode()
{
is(inspector.selection.node, node, "selected body element");
executeSoon(function() {
inspector.selection.once("new-node", highlightHeaderNode);
// Test that moving to the child works.
node = doc.querySelector("h1");
EventUtils.synthesizeKey("VK_RIGHT", { });
});
}
function highlightHeaderNode()
{
is(inspector.selection.node, node, "selected h1 element");

Просмотреть файл

@ -255,14 +255,7 @@ function test() {
var target = TargetFactory.forTab(gBrowser.selectedTab);
gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
inspector = toolbox.getCurrentPanel();
runTests();
});
}
function runTests() {
inspector.selection.once("new-node", startTests);
executeSoon(function() {
inspector.selection.setNode(doc.body);
startTests();
});
}

Просмотреть файл

@ -10,10 +10,10 @@ function test() {
let doc;
let keySequences = [
["right", "html"],
["pageup", "*doctype*"],
["down", "html"],
["down", "head"],
["down", "body"],
["right", "body"],
["down", "node0"],
["right", "node0"],
["down", "node1"],

Просмотреть файл

@ -18,10 +18,8 @@ function openRuleView()
// Highlight a node.
let node = content.document.getElementsByTagName("h1")[0];
inspector.selection.once("new-node", testFocus);
inspector.sidebar.once("ruleview-ready",
() => inspector.selection.setNode(doc.body));
inspector.sidebar.once("ruleview-ready", testFocus);
});
}