Bug 968241 - Copy outerHTML using keyboard shortcut. r=pbrosset

Copy outerHTML of the currently selected node of the inspector.
Works for ELEMENT, DOCUMENT_TYPE and COMMENT node types.

- bound "copy" event in markup-view to copy outerHTML
- added doctypeString property to NodeFront in actors/inspector.js
- markup-view.js is also using this property now
- added mochitest with dedicated html
This commit is contained in:
Julian Descottes
2015-07-02 22:43:19 +02:00
parent 80c0a6bf68
commit eb82d20c8b
8 changed files with 160 additions and 18 deletions

View File

@@ -111,6 +111,9 @@ function MarkupView(aInspector, aFrame, aControllerWindow) {
this._boundKeyDown = this._onKeyDown.bind(this);
this._frame.contentWindow.addEventListener("keydown", this._boundKeyDown, false);
this._onCopy = this._onCopy.bind(this);
this._frame.contentWindow.addEventListener("copy", this._onCopy);
this._boundFocus = this._onFocus.bind(this);
this._frame.addEventListener("focus", this._boundFocus, false);
@@ -507,6 +510,20 @@ MarkupView.prototype = {
return walker;
},
_onCopy: function (evt) {
// Ignore copy events from editors
if (this._isInputOrTextarea(evt.target)) {
return;
}
let selection = this._inspector.selection;
if (selection.isNode()) {
this._inspector.copyOuterHTML();
}
evt.stopPropagation();
evt.preventDefault();
},
/**
* Key handling.
*/
@@ -514,8 +531,7 @@ MarkupView.prototype = {
let handled = true;
// Ignore keystrokes that originated in editors.
if (aEvent.target.tagName.toLowerCase() === "input" ||
aEvent.target.tagName.toLowerCase() === "textarea") {
if (this._isInputOrTextarea(aEvent.target)) {
return;
}
@@ -614,6 +630,14 @@ MarkupView.prototype = {
}
},
/**
* Check if a node is an input or textarea
*/
_isInputOrTextarea : function (element) {
let name = element.tagName.toLowerCase();
return name === "input" || name === "textarea";
},
/**
* Delete a node from the DOM.
* This is an undoable action.
@@ -1485,6 +1509,9 @@ MarkupView.prototype = {
this._boundKeyDown, false);
this._boundKeyDown = null;
this._frame.contentWindow.removeEventListener("copy", this._onCopy);
this._onCopy = null;
this._inspector.selection.off("new-node-front", this._boundOnNewSelection);
this._boundOnNewSelection = null;
@@ -2314,10 +2341,7 @@ function GenericEditor(aContainer, aNode) {
this.tag.textContent = aNode.isBeforePseudoElement ? "::before" : "::after";
} else if (aNode.nodeType == Ci.nsIDOMNode.DOCUMENT_TYPE_NODE) {
this.elt.classList.add("comment");
this.tag.textContent = '<!DOCTYPE ' + aNode.name +
(aNode.publicId ? ' PUBLIC "' + aNode.publicId + '"': '') +
(aNode.systemId ? ' "' + aNode.systemId + '"' : '') +
'>';
this.tag.textContent = aNode.doctypeString;
} else {
this.tag.textContent = aNode.nodeName;
}