Bug 827604 - Pseudoclass lock isn't clearing; r=dcamp

This commit is contained in:
Heather Arthur 2013-01-18 14:03:22 -08:00
parent f84ebc1e87
commit 08a6f60f02
3 changed files with 59 additions and 5 deletions

View File

@ -65,6 +65,8 @@ InspectorPanel.prototype = {
this._selection = new Selection(); this._selection = new Selection();
this.onNewSelection = this.onNewSelection.bind(this); this.onNewSelection = this.onNewSelection.bind(this);
this.selection.on("new-node", this.onNewSelection); this.selection.on("new-node", this.onNewSelection);
this.onBeforeNewSelection = this.onBeforeNewSelection.bind(this);
this.selection.on("before-new-node", this.onBeforeNewSelection);
this.onDetached = this.onDetached.bind(this); this.onDetached = this.onDetached.bind(this);
this.selection.on("detached", this.onDetached); this.selection.on("detached", this.onDetached);
@ -319,6 +321,17 @@ InspectorPanel.prototype = {
this.cancelLayoutChange(); this.cancelLayoutChange();
}, },
/**
* When a new node is selected, before the selection has changed.
*/
onBeforeNewSelection: function InspectorPanel_onBeforeNewSelection(event,
node) {
if (this.breadcrumbs.indexOf(node) == -1) {
// only clear locks if we'd have to update breadcrumbs
this.clearPseudoClasses();
}
},
/** /**
* When a node is deleted, select its parent node. * When a node is deleted, select its parent node.
*/ */
@ -367,6 +380,7 @@ InspectorPanel.prototype = {
this.nodemenu.removeEventListener("popuphiding", this._resetNodeMenu, true); this.nodemenu.removeEventListener("popuphiding", this._resetNodeMenu, true);
this.breadcrumbs.destroy(); this.breadcrumbs.destroy();
this.selection.off("new-node", this.onNewSelection); this.selection.off("new-node", this.onNewSelection);
this.selection.off("before-new-node", this.onBeforeNewSelection);
this.selection.off("detached", this.onDetached); this.selection.off("detached", this.onDetached);
this._destroyMarkup(); this._destroyMarkup();
this._selection.destroy(); this._selection.destroy();
@ -500,6 +514,15 @@ InspectorPanel.prototype = {
this.selection.emit("pseudoclass"); this.selection.emit("pseudoclass");
}, },
/**
* Clear any pseudo-class locks applied to the current hierarchy.
*/
clearPseudoClasses: function InspectorPanel_clearPseudoClasses() {
this.breadcrumbs.nodeHierarchy.forEach(function(crumb) {
DOMUtils.clearPseudoClassLocks(crumb.node);
});
},
/** /**
* Toggle the highlighter when ruleview is hovered. * Toggle the highlighter when ruleview is hovered.
*/ */

View File

@ -42,6 +42,7 @@ this.EXPORTED_SYMBOLS = ["Selection"];
* *
* Events: * Events:
* "new-node" when the inner node changed * "new-node" when the inner node changed
* "before-new-node" when the inner node is set to change
* "attribute-changed" when an attribute is changed (only if tracked) * "attribute-changed" when an attribute is changed (only if tracked)
* "detached" when the node (or one of its parents) is removed from the document (only if tracked) * "detached" when the node (or one of its parents) is removed from the document (only if tracked)
* "reparented" when the node (or one of its parents) is moved under a different node (only if tracked) * "reparented" when the node (or one of its parents) is moved under a different node (only if tracked)
@ -126,6 +127,7 @@ Selection.prototype = {
setNode: function SN_setNode(value, reason="unknown") { setNode: function SN_setNode(value, reason="unknown") {
this.reason = reason; this.reason = reason;
if (value !== this._node) { if (value !== this._node) {
this.emit("before-new-node", value, reason);
let previousNode = this._node; let previousNode = this._node;
this._detachEvents(); this._detachEvents();
this._node = value; this._node = value;

View File

@ -8,7 +8,7 @@ let TargetFactory = tempScope.TargetFactory;
let DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils); let DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
let doc; let doc;
let div; let parentDiv, div, div2;
let inspector; let inspector;
let ruleview; let ruleview;
@ -30,16 +30,24 @@ function test()
function createDocument() function createDocument()
{ {
parentDiv = doc.createElement("div");
parentDiv.textContent = "parent div";
div = doc.createElement("div"); div = doc.createElement("div");
div.textContent = "test div"; div.textContent = "test div";
div2 = doc.createElement("div");
div2.textContent = "test div2";
let head = doc.getElementsByTagName('head')[0]; let head = doc.getElementsByTagName('head')[0];
let style = doc.createElement('style'); let style = doc.createElement('style');
let rules = doc.createTextNode('div { color: red; } div:hover { color: blue; }'); let rules = doc.createTextNode('div { color: red; } div:hover { color: blue; }');
style.appendChild(rules); style.appendChild(rules);
head.appendChild(style); head.appendChild(style);
doc.body.appendChild(div); parentDiv.appendChild(div);
parentDiv.appendChild(div2);
doc.body.appendChild(parentDiv);
openInspector(selectNode); openInspector(selectNode);
} }
@ -71,10 +79,31 @@ function performTests()
// toggle it back on // toggle it back on
inspector.togglePseudoClass(pseudo); inspector.togglePseudoClass(pseudo);
testNavigate();
// close the inspector // close the inspector
finishUp(); finishUp();
} }
function testNavigate()
{
inspector.selection.setNode(parentDiv);
// make sure it's still on after naving to parent
is(DOMUtils.hasPseudoClassLock(div, pseudo), true,
"pseudo-class lock is still applied after inspecting ancestor");
inspector.selection.setNode(div2);
// make sure it's removed after naving to a non-hierarchy node
is(DOMUtils.hasPseudoClassLock(div, pseudo), false,
"pseudo-class lock is removed after inspecting sibling node");
// toggle it back on
inspector.selection.setNode(div);
inspector.togglePseudoClass(pseudo);
}
function testAdded() function testAdded()
{ {
// lock is applied to it and ancestors // lock is applied to it and ancestors