Reviewed by Mark Rowe.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Nov 2007 08:02:49 +0000 (08:02 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Nov 2007 08:02:49 +0000 (08:02 +0000)
        Bug 12054: Ability to serialize an element subtree (into clipboard?) from the DOM inspector
        http://bugs.webkit.org/show_bug.cgi?id=12054

        - Add support code for routing copy events to the focused element.
        - Implement copying the currently selected DOM node. The node
          and it's subtree is copied to the clipboard. If the node has no
          outerHTML, the nodeValue is copied (text nodes, etc.)
        - Implement copy for the resource sidebar. The URL is copied for the
          currently selected resource.

        * page/inspector/DocumentPanel.js:
        * page/inspector/inspector.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27663 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/page/inspector/DocumentPanel.js
WebCore/page/inspector/inspector.js

index 083d0230e6aca656ee340f9020578f1e89e3d125..9ac2aea03938b82797b74935d6f3785bfc3f7b28 100644 (file)
@@ -1,3 +1,20 @@
+2007-11-09  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Mark Rowe.
+
+        Bug 12054: Ability to serialize an element subtree (into clipboard?) from the DOM inspector
+        http://bugs.webkit.org/show_bug.cgi?id=12054
+
+        - Add support code for routing copy events to the focused element.
+        - Implement copying the currently selected DOM node. The node
+          and it's subtree is copied to the clipboard. If the node has no
+          outerHTML, the nodeValue is copied (text nodes, etc.)
+        - Implement copy for the resource sidebar. The URL is copied for the
+          currently selected resource.
+
+        * page/inspector/DocumentPanel.js:
+        * page/inspector/inspector.js:
+
 2007-11-09  Antti Koivisto  <antti@apple.com>
 
         Reviewed by Adele.
index 5f8ca2d2c0d94b2dcdda2fd79e8b62ccafeb8f70..67ae286c149d019e4c5154f278571e4e9a9c23ba 100644 (file)
@@ -345,6 +345,36 @@ WebInspector.DocumentPanel.prototype = {
             this.views.dom.treeOutline.handleKeyEvent(event);
     },
 
+    handleCopyEvent: function(event)
+    {
+        if (this.currentView !== this.views.dom)
+            return;
+
+        // Don't prevent the normal copy if the user has a selection.
+        if (!window.getSelection().isCollapsed)
+            return;
+
+        switch (this.focusedDOMNode.nodeType) {
+            case Node.ELEMENT_NODE:
+                var data = this.focusedDOMNode.outerHTML;
+                break;
+
+            case Node.COMMENT_NODE:
+                var data = "<!--" + this.focusedDOMNode.nodeValue + "-->";
+                break;
+
+            default:
+            case Node.TEXT_NODE:
+                var data = this.focusedDOMNode.nodeValue;
+        }
+
+        event.clipboardData.clearData();
+        event.preventDefault();
+
+        if (data)
+            event.clipboardData.setData("text/plain", data);
+    },
+
     rightSidebarResizerDragStart: function(event)
     {
         var panel = this; 
index 8f0b6d4cd309e9b058c58f7d12c15f36cbcd1e21..c635d302e449f9600871d8f9d5a93f4c1611d6f4 100644 (file)
@@ -245,6 +245,8 @@ WebInspector.loaded = function(event)
     document.addEventListener("mousedown", function(event) { WebInspector.changeFocus(event) }, true);
     document.addEventListener("focus", function(event) { WebInspector.changeFocus(event) }, true);
     document.addEventListener("keypress", function(event) { WebInspector.documentKeypress(event) }, true);
+    document.addEventListener("beforecopy", function(event) { WebInspector.documentCanCopy(event) }, true);
+    document.addEventListener("copy", function(event) { WebInspector.documentCopy(event) }, true);
 
     document.getElementById("back").title = "Show previous panel.";
     document.getElementById("forward").title = "Show next panel.";
@@ -331,6 +333,27 @@ WebInspector.documentKeypress = function(event)
         WebInspector[this.currentFocusElement.id + "Keypress"](event);
 }
 
+WebInspector.documentCanCopy = function(event)
+{
+    if (!this.currentFocusElement)
+        return;
+    // Calling preventDefault() will say "we support copying, so enable the Copy menu".
+    if (this.currentFocusElement.handleCopyEvent)
+        event.preventDefault();
+    else if (this.currentFocusElement.id && this.currentFocusElement.id.length && WebInspector[this.currentFocusElement.id + "Copy"])
+        event.preventDefault();
+}
+
+WebInspector.documentCopy = function(event)
+{
+    if (!this.currentFocusElement)
+        return;
+    if (this.currentFocusElement.handleCopyEvent)
+        this.currentFocusElement.handleCopyEvent(event);
+    else if (this.currentFocusElement.id && this.currentFocusElement.id.length && WebInspector[this.currentFocusElement.id + "Copy"])
+        WebInspector[this.currentFocusElement.id + "Copy"](event);
+}
+
 WebInspector.sidebarKeypress = function(event)
 {
     var nextSelectedElement;
@@ -365,12 +388,30 @@ WebInspector.sidebarKeypress = function(event)
     }
 }
 
+WebInspector.sidebarCopy = function(event)
+{
+    event.clipboardData.clearData();
+    event.preventDefault();
+
+    var selectedElement = this.fileOutline.selectedTreeElement;
+    if (!selectedElement || !selectedElement.representedObject || !selectedElement.representedObject.url)
+        return;
+
+    event.clipboardData.setData("URL", this.fileOutline.selectedTreeElement.representedObject.url);
+}
+
 WebInspector.mainKeypress = function(event)
 {
     if (this.currentPanel && this.currentPanel.handleKeyEvent)
         this.currentPanel.handleKeyEvent(event);
 }
 
+WebInspector.mainCopy = function(event)
+{
+    if (this.currentPanel && this.currentPanel.handleCopyEvent)
+        this.currentPanel.handleCopyEvent(event);
+}
+
 WebInspector.searchResultsKeypress = function(event)
 {
     if (this.searchResultsTree)