Bug 1053898 - Add _markContainerAsSelected() API in MarkupView;r=gl
With shadowdom support, the container will become more specific than the
nodeFront. Add a specific API to select directly a container rather than
having to use a nodeFront will make the transition easier.
MozReview-Commit-ID: DIiKJPsxEYZ
--- a/devtools/client/inspector/markup/markup.js
+++ b/devtools/client/inspector/markup/markup.js
@@ -946,18 +946,17 @@ MarkupView.prototype = {
* @param {MarkupContainer} container
* The container we're navigating to.
*/
navigate: function(container) {
if (!container) {
return;
}
- let node = container.node;
- this.markNodeAsSelected(node, "treepanel");
+ this._markContainerAsSelected(container, "treepanel");
},
/**
* Make sure a node is included in the markup tool.
*
* @param {NodeFront} node
* The node in the content document.
* @param {Boolean} flashNode
@@ -1317,19 +1316,20 @@ MarkupView.prototype = {
this._removedNodeObserver = null;
// Don't select the new node if the user has already changed the current
// selection.
if (this.inspector.selection.nodeFront === parentContainer.node ||
(this.inspector.selection.nodeFront === removedNode && isHTMLTag)) {
let childContainers = parentContainer.getChildContainers();
if (childContainers && childContainers[childIndex]) {
- this.markNodeAsSelected(childContainers[childIndex].node, reason);
- if (childContainers[childIndex].hasChildren) {
- this.expandNode(childContainers[childIndex].node);
+ let childContainer = childContainers[childIndex];
+ this._markContainerAsSelected(childContainer, reason);
+ if (childContainer.hasChildren) {
+ this.expandNode(childContainer.node);
}
this.emit("reselectedonremoved");
}
}
};
// Start listening for mutations until we find a childList change that has
// removedNode removed.
@@ -1502,21 +1502,26 @@ MarkupView.prototype = {
* The NodeFront to mark as selected.
* @param {String} reason
* The reason for marking the node as selected.
* @return {Boolean} False if the node is already marked as selected, true
* otherwise.
*/
markNodeAsSelected: function(node, reason = "nodeselected") {
let container = this.getContainer(node);
+ return this._markContainerAsSelected(container);
+ },
- if (this._selectedContainer === container) {
+ _markContainerAsSelected: function(container, reason) {
+ if (!container || this._selectedContainer === container) {
return false;
}
+ let { node } = container;
+
// Un-select and remove focus from the previous container.
if (this._selectedContainer) {
this._selectedContainer.selected = false;
this._selectedContainer.clearFocus();
}
// Select the new container.
this._selectedContainer = container;