Bug 785528 - Don't allow deletion of doctype nodes in the markup panel. r=jwalker
authorDave Camp <dcamp@mozilla.com>
Fri, 24 Aug 2012 17:59:48 -0700
changeset 103449 4c3e82b3dcaf9afbac95ef95fff6b17b7fa70110
parent 103448 45ec9c8d4f272606830cf8e6841f727cb02e66bd
child 103450 5fa145ef906a778d1a1729ecbaa40884926c5ff5
push id13991
push userryanvm@gmail.com
push dateSun, 26 Aug 2012 02:29:03 +0000
treeherdermozilla-inbound@c4f20a024113 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker
bugs785528
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 785528 - Don't allow deletion of doctype nodes in the markup panel. r=jwalker
browser/devtools/markupview/MarkupView.jsm
--- a/browser/devtools/markupview/MarkupView.jsm
+++ b/browser/devtools/markupview/MarkupView.jsm
@@ -131,21 +131,17 @@ MarkupView.prototype = {
     if (aEvent.target.tagName.toLowerCase() === "input" ||
         aEvent.target.tagName.toLowerCase() === "textarea") {
       return;
     }
 
     switch(aEvent.keyCode) {
       case Ci.nsIDOMKeyEvent.DOM_VK_DELETE:
       case Ci.nsIDOMKeyEvent.DOM_VK_BACK_SPACE:
-        let node = this._selectedContainer.node;
-        let doc = nodeDocument(node);
-        if (node != doc && node != doc.documentElement) {
-          this.deleteNode(this._selectedContainer.node);
-        }
+        this.deleteNode(this._selectedContainer.node);
         break;
       case Ci.nsIDOMKeyEvent.DOM_VK_HOME:
         this.navigate(this._containers.get(this._rootNode.firstChild));
         break;
       case Ci.nsIDOMKeyEvent.DOM_VK_LEFT:
         this.collapseNode(this._selectedContainer.node);
         break;
       case Ci.nsIDOMKeyEvent.DOM_VK_RIGHT:
@@ -199,16 +195,23 @@ MarkupView.prototype = {
   },
 
   /**
    * Delete a node from the DOM.
    * This is an undoable action.
    */
   deleteNode: function MC__deleteNode(aNode)
   {
+    let doc = nodeDocument(node);
+    if (node === doc ||
+        node === doc.documentElement ||
+        node.nodeType == Ci.nsIDOMNode.DOCUMENT_TYPE_NODE) {
+      return;
+    }
+
     let parentNode = aNode.parentNode;
     let sibling = aNode.nextSibling;
 
     this.undo.do(function() {
       parentNode.removeChild(aNode);
     }, function() {
       parentNode.insertBefore(aNode, sibling);
     });