Bug 242729 Copy in the right-click menu in the DOM inspector nodeName/nodeValue doesn't work

patch by jason_barnabe@fastmail.fm r=timeless sr=neil
This commit is contained in:
timeless%mozdev.org 2006-03-16 06:23:03 +00:00
Родитель dda9c69abf
Коммит 1059b8a1d2
4 изменённых файлов: 71 добавлений и 83 удалений

Просмотреть файл

@ -392,6 +392,7 @@
<field name="mClipboard">null</field>
<field name="mClipboardData">null</field>
<field name="mClipboardFlavor">null</field>
<field name="mClipboardHelper">null</field>
<property name="clipboardFlavor" readonly="true"
onget="return this.mClipboardFlavor"/>
@ -407,26 +408,29 @@
return this.mClipboard;
]]></getter>
</property>
<property name="clipboardHelper" readonly="true">
<getter>
<![CDATA[
if (!this.mClipboardHelper) {
this.mClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper);
}
return this.mClipboardHelper;
]]></getter>
</property>
<method name="setClipboardData">
<parameter name="aObject"/>
<parameter name="aFlavor"/>
<parameter name="aTextRepresentation"/>
<body><![CDATA[
if (aFlavor == "text/unicode") {
var iid = Components.interfaces.nsISupportsString;
var cid = "@mozilla.org/supports-string;1";
data = Components.classes[cid].createInstance(iid);
data.data = aObject;
iid = Components.interfaces.nsITransferable;
cid = "@mozilla.org/widget/transferable;1";
var trans = Components.classes[cid].createInstance(iid);
trans.setTransferData(aFlavor, data, aObject.length*2);
const clip = Components.interfaces.nsIClipboard.kGlobalClipboard;
this.clipboard.setData(trans, null, clip);
// put the text representation on the system clipboard
if (aTextRepresentation) {
this.clipboardHelper.copyString(aTextRepresentation);
}
// store the real object internally
this.mClipboardData = aObject;
this.mClipboardFlavor = aFlavor;

Просмотреть файл

@ -20,6 +20,7 @@
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (original author)
* Jason Barnabe <jason_barnabe@fastmail.fm>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -50,6 +51,13 @@ const kInspectorNSURI = "http://www.mozilla.org/inspector#";
const kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const kHTMLNSURI = "http://www.w3.org/1999/xhtml";
const nsITransactionManager = Components.interfaces.nsITransactionManager;
var gEntityConverter;
const kCharTable = {
'&': "&amp;",
'<': "&lt;",
'>': "&gt;",
'"': "&quot;"
};
var InsUtil = {
/******************************************************************************
@ -87,6 +95,42 @@ var InsUtil = {
document.persist(aId, attrs[i]);
}
}
},
/******************************************************************************
* Convenience function for escaping HTML strings.
*******************************************************************************/
unicodeToEntity: function(text)
{
const entityVersion = Components.interfaces.nsIEntityConverter.entityW3C;
function charTableLookup(letter) {
return kCharTable[letter];
}
function convertEntity(letter) {
try {
return gEntityConverter.ConvertToEntity(letter, entityVersion);
} catch (ex) {
return letter;
}
}
if (!gEntityConverter) {
try {
gEntityConverter =
Components.classes["@mozilla.org/intl/entityconverter;1"]
.createInstance(Components.interfaces.nsIEntityConverter);
} catch (ex) { }
}
// replace chars in our charTable
text = text.replace(/[<>&"]/g, charTableLookup);
// replace chars > 0x7f via nsIEntityConverter
text = text.replace(/[^\0-\u007f]/g, convertEntity);
return text;
}
};

Просмотреть файл

@ -20,6 +20,7 @@
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (original author)
* Jason Barnabe <jason_barnabe@fastmail.fm>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -43,7 +44,6 @@
//////////// global variables /////////////////////
var viewer;
var gEntityConverter;
//////////// global constants ////////////////////
@ -383,7 +383,7 @@ DOMViewer.prototype =
for (i = 0; i < aNode.attributes.length; ++i) {
var a = aNode.attributes[i];
var attr = " " + a.localName + '="' + unicodeToEntity(a.nodeValue) + '"';
var attr = " " + a.localName + '="' + InsUtil.unicodeToEntity(a.nodeValue) + '"';
if (line.length + attr.length > 80) {
s += line + (i < aNode.attributes.length-1 ? "\n"+attrIndent : "");
line = "";
@ -402,9 +402,9 @@ DOMViewer.prototype =
s += indent + "</" + aNode.localName + ">\n";
}
} else if (aNode.nodeType == Node.TEXT_NODE) {
s += unicodeToEntity(aNode.data);
s += InsUtil.unicodeToEntity(aNode.data);
} else if (aNode.nodeType == Node.COMMENT_NODE) {
s += line + "<!--" + unicodeToEntity(aNode.data) + "-->\n";
s += line + "<!--" + InsUtil.unicodeToEntity(aNode.data) + "-->\n";
}
return s;
@ -895,7 +895,6 @@ cmdEditCut.prototype =
undoTransaction: function()
{
this.cmdDelete.undoTransaction();
this.cmdCopy.undoTransaction();
}
};
@ -903,8 +902,6 @@ function cmdEditCopy() {}
cmdEditCopy.prototype =
{
copiedNode: null,
previousData: null,
previousFlavor: null,
// remove this line for bug 179621, Phase Three
txnType: "standard",
@ -912,7 +909,7 @@ cmdEditCopy.prototype =
// required for nsITransaction
QueryInterface: txnQueryInterface,
merge: txnMerge,
isTransient: false,
isTransient: true,
redoTransaction: txnRedoTransaction,
doTransaction: function()
@ -922,18 +919,11 @@ cmdEditCopy.prototype =
copiedNode = viewer.selectedNode;
if (copiedNode) {
this.copiedNode = copiedNode;
this.previousData = viewer.pane.panelset.getClipboardData();
this.previousFlavor = viewer.pane.panelset.clipboardFlavor;
}
} else
copiedNode = this.copiedNode;
viewer.pane.panelset.setClipboardData(copiedNode, "inspector/dom-node");
},
undoTransaction: function()
{
viewer.pane.panelset.setClipboardData(this.previousData, this.previousFlavor);
viewer.pane.panelset.setClipboardData(copiedNode, "inspector/dom-node", null);
}
};
@ -1034,45 +1024,3 @@ function dumpDOM2(aNode)
{
dump(DOMViewer.prototype.toXML(aNode));
}
function unicodeToEntity(text)
{
const charTable = {
'&': "&amp;",
'<': "&lt;",
'>': "&gt;",
'"': "&quot;"
};
function charTableLookup(letter) {
return charTable[letter];
}
function convertEntity(letter) {
try {
return gEntityConverter.ConvertToEntity(letter, entityVersion);
} catch (ex) {
return letter;
}
}
if (!gEntityConverter) {
try {
gEntityConverter =
Components.classes["@mozilla.org/intl/entityconverter;1"]
.createInstance(Components.interfaces.nsIEntityConverter);
} catch (ex) { }
}
const entityVersion = Components.interfaces.nsIEntityConverter.entityW3C;
var str = text;
// replace chars in our charTable
str = str.replace(/[<>&"]/g, charTableLookup);
// replace chars > 0x7f via nsIEntityConverter
str = str.replace(/[^\0-\u007f]/g, convertEntity);
return str;
}

Просмотреть файл

@ -20,6 +20,7 @@
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (original author)
* Jason Barnabe <jason_barnabe@fastmail.fm>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -227,7 +228,6 @@ cmdEditCut.prototype =
undoCommand: function()
{
this.cmdDelete.undoCommand();
this.cmdCopy.undoCommand();
}
};
@ -235,8 +235,6 @@ function cmdEditCopy() {}
cmdEditCopy.prototype =
{
copiedAttr: null,
previousData: null,
previousFlavor: null,
doCommand: function()
{
@ -246,18 +244,12 @@ cmdEditCopy.prototype =
if (!copiedAttr)
return true;
this.copiedAttr = copiedAttr;
this.previousData = viewer.pane.panelset.getClipboardData();
this.previousFlavor = viewer.pane.panelset.clipboardFlavor;
} else
copiedAttr = this.copiedAttr;
viewer.pane.panelset.setClipboardData(copiedAttr, "inspector/dom-node");
return false;
},
undoCommand: function()
{
viewer.pane.panelset.setClipboardData(this.previousData, this.previousFlavor);
var text = copiedAttr.nodeName + "=\"" + InsUtil.unicodeToEntity(copiedAttr.nodeValue) + "\"";
viewer.pane.panelset.setClipboardData(copiedAttr, "inspector/dom-node", text);
return true;
}
};