Changeset 27663 in webkit


Ignore:
Timestamp:
Nov 10, 2007 12:02:49 AM (16 years ago)
Author:
timothy@apple.com
Message:

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:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r27659 r27663  
     12007-11-09  Timothy Hatcher  <timothy@apple.com>
     2
     3        Reviewed by Mark Rowe.
     4
     5        Bug 12054: Ability to serialize an element subtree (into clipboard?) from the DOM inspector
     6        http://bugs.webkit.org/show_bug.cgi?id=12054
     7
     8        - Add support code for routing copy events to the focused element.
     9        - Implement copying the currently selected DOM node. The node
     10          and it's subtree is copied to the clipboard. If the node has no
     11          outerHTML, the nodeValue is copied (text nodes, etc.)
     12        - Implement copy for the resource sidebar. The URL is copied for the
     13          currently selected resource.
     14
     15        * page/inspector/DocumentPanel.js:
     16        * page/inspector/inspector.js:
     17
    1182007-11-09  Antti Koivisto  <antti@apple.com>
    219
  • trunk/WebCore/page/inspector/DocumentPanel.js

    r27575 r27663  
    346346    },
    347347
     348    handleCopyEvent: function(event)
     349    {
     350        if (this.currentView !== this.views.dom)
     351            return;
     352
     353        // Don't prevent the normal copy if the user has a selection.
     354        if (!window.getSelection().isCollapsed)
     355            return;
     356
     357        switch (this.focusedDOMNode.nodeType) {
     358            case Node.ELEMENT_NODE:
     359                var data = this.focusedDOMNode.outerHTML;
     360                break;
     361
     362            case Node.COMMENT_NODE:
     363                var data = "<!--" + this.focusedDOMNode.nodeValue + "-->";
     364                break;
     365
     366            default:
     367            case Node.TEXT_NODE:
     368                var data = this.focusedDOMNode.nodeValue;
     369        }
     370
     371        event.clipboardData.clearData();
     372        event.preventDefault();
     373
     374        if (data)
     375            event.clipboardData.setData("text/plain", data);
     376    },
     377
    348378    rightSidebarResizerDragStart: function(event)
    349379    {
  • trunk/WebCore/page/inspector/inspector.js

    r27575 r27663  
    246246    document.addEventListener("focus", function(event) { WebInspector.changeFocus(event) }, true);
    247247    document.addEventListener("keypress", function(event) { WebInspector.documentKeypress(event) }, true);
     248    document.addEventListener("beforecopy", function(event) { WebInspector.documentCanCopy(event) }, true);
     249    document.addEventListener("copy", function(event) { WebInspector.documentCopy(event) }, true);
    248250
    249251    document.getElementById("back").title = "Show previous panel.";
     
    332334}
    333335
     336WebInspector.documentCanCopy = function(event)
     337{
     338    if (!this.currentFocusElement)
     339        return;
     340    // Calling preventDefault() will say "we support copying, so enable the Copy menu".
     341    if (this.currentFocusElement.handleCopyEvent)
     342        event.preventDefault();
     343    else if (this.currentFocusElement.id && this.currentFocusElement.id.length && WebInspector[this.currentFocusElement.id + "Copy"])
     344        event.preventDefault();
     345}
     346
     347WebInspector.documentCopy = function(event)
     348{
     349    if (!this.currentFocusElement)
     350        return;
     351    if (this.currentFocusElement.handleCopyEvent)
     352        this.currentFocusElement.handleCopyEvent(event);
     353    else if (this.currentFocusElement.id && this.currentFocusElement.id.length && WebInspector[this.currentFocusElement.id + "Copy"])
     354        WebInspector[this.currentFocusElement.id + "Copy"](event);
     355}
     356
    334357WebInspector.sidebarKeypress = function(event)
    335358{
     
    366389}
    367390
     391WebInspector.sidebarCopy = function(event)
     392{
     393    event.clipboardData.clearData();
     394    event.preventDefault();
     395
     396    var selectedElement = this.fileOutline.selectedTreeElement;
     397    if (!selectedElement || !selectedElement.representedObject || !selectedElement.representedObject.url)
     398        return;
     399
     400    event.clipboardData.setData("URL", this.fileOutline.selectedTreeElement.representedObject.url);
     401}
     402
    368403WebInspector.mainKeypress = function(event)
    369404{
    370405    if (this.currentPanel && this.currentPanel.handleKeyEvent)
    371406        this.currentPanel.handleKeyEvent(event);
     407}
     408
     409WebInspector.mainCopy = function(event)
     410{
     411    if (this.currentPanel && this.currentPanel.handleCopyEvent)
     412        this.currentPanel.handleCopyEvent(event);
    372413}
    373414
Note: See TracChangeset for help on using the changeset viewer.