Commit ea89623b authored by timothy@apple.com's avatar 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:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27663 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 37198feb
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.
......
......@@ -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;
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment