Discussion:
XPCNativeWrapper and getData (application/x-moz-node)
rvj
2010-05-24 15:43:19 UTC
Permalink
Another basic DOM/syntax query?

I am attempting to drag and drop iframe HTML table rows using ancestor
addEventListeners

Dragstart issues setData using x-moz-node to copy the dragstart event
element (htmltablerowelement)

So ondrop node reports that an HTML table row has been passed but not as we
know it!

What then is the syntax to extract the html node in a XPCNativeWrapper so
that it can be appended after the target element?

Is it a method.| property.. or what?

........... or am I using a the wrong data transfer type????


**********************************************************************

function onDragDrop(event)
{
var node=event.dataTransfer.getData("application/x-moz-node");

alert("node"+node) // [object XPCNativeWrapper [ object
HTMLTableRowElement]]
alert(node.tagName) // undefined

}
Boris Zbarsky
2010-05-24 15:50:37 UTC
Permalink
Post by rvj
So ondrop node reports that an HTML table row has been passed but not as we
know it!
Right, you're seeing the security wrapper for it.
Post by rvj
What then is the syntax to extract the html node in a XPCNativeWrapper so
that it can be appended after the target element?
Does appending the security wrapper not work? It should...
Post by rvj
alert("node"+node) // [object XPCNativeWrapper [ object
HTMLTableRowElement]]
That seems correct.
Post by rvj
alert(node.tagName) // undefined
This, however does not.

-Boris
rvj
2010-05-25 07:10:36 UTC
Permalink
Post by Boris Zbarsky
Does appending the security wrapper not work? It should...
nope I get

// Execption ..." Could not convert Javascript argument 0
// [nsIDOMHTMLTableElement.appendChild]" nsresult: "0x80570009
// NS_ERROR_XPC_BAD_CONVERT_JS)"

**********************************************************
xulrunner code (1.9.2)
************************************************************
<?xml version="1.0"?>
<window onload="attach()"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="dragdrop4" style="background:lime;height:600px;width:600px">

<script>
<![CDATA[

function attach()
{
// 1. start

try
{
document.getElementById('source').contentWindow.document.addEventListener("dragstart",onDragStart,false)
}
catch (e)
{
alert(e)
}

// 2. enter

try
{
document.getElementById('target').contentWindow.document.addEventListener("dragenter",onDragEnter,false)
}
catch (e)
{
alert(e)
}


// 3. over

try
{
document.getElementById('target').contentWindow.document.addEventListener("dragover",onDragOver,false)
}
catch (e)
{
alert(e)
}

// 4. drop

try
{
document.getElementById('target').contentWindow.document.addEventListener("drop",onDragDrop,false)
}
catch (e)
{
alert(e)
}


}


function onDragStart(event)
{

// get reference of node to be copied
element=event.target

if (element.tagName=="TD")
{
element=element.parentNode
}

event.dataTransfer.setData('application/x-moz-node',element)
event.dataTransfer.setData('text/plain','this is some text')

event.dataTransfer.effectAllowed="copy"
event.dataTransfer.dropffect="copy"

}


function onDragEnter(event)
{
event.stopPropagation();
event.preventDefault();
}

function onDragOver(event)
{
event.stopPropagation();
event.preventDefault();
}

function onDragDrop(event)
{
element=event.target
if (element.tagName=="TD")
{
element=element.parentNode
}

node=event.dataTransfer.getData("application/x-moz-node");

//alert("node"+node) // [object XPCNativeWrapper [ object
HTMLTableRowElement]]

try
{
//alert(node.tagName)
//alert(node.localName)
//alert("$"+node.getAttribute('id'))

}


catch (e)
{
alert(e)
}

target=document.getElementById('target').contentWindow.document.getElementById('tablenode') try { target.appendChild(node) } catch (e) { alert("error"+e) // Execption ..." Could not convert Javascript argument 0 // [nsIDOMHTMLTableElement.appendChild]" nsresult: "0x80570009 // NS_ERROR_XPC_BAD_CONVERT_JS)" } event.preventDefault(); } ]]> </script> <box flex="1" orient="vertical"> <iframe id="source" type="content" flex="1" src="file2.htm" /> <iframe id="target" type="content" flex="1" src="file1.htm" /> </box> </window>"Boris Zbarsky" <***@mit.edu> wrote in messagenews:_K-***@mozilla.org...> On 5/24/10 11:43 AM, rvj wrote:>> So ondrop node reports that an HTML table row has been passed but not aswe>> know it!>> Right, you're seeing the security
wrapper for it.>>> What then is the syntax to extract the html node in a XPCNativeWrapper so>> that it can be appended after the target element?>> Does appending the security wrapper not w
ork? It should...>>> alert("node"+node) // [object XPCNativeWrapper [ object>> HTMLTableRowElement]]>> That seems correct.>>> alert(node.tagName) // undefined>> This, however does not.>> -Boris
Boris Zbarsky
2010-05-25 12:12:24 UTC
Permalink
Post by rvj
Post by Boris Zbarsky
Does appending the security wrapper not work? It should...
nope I get
// Execption ..." Could not convert Javascript argument 0
// [nsIDOMHTMLTableElement.appendChild]" nsresult: "0x80570009
// NS_ERROR_XPC_BAD_CONVERT_JS)"
Does it work if you append the node.wrappedJSObject?

-Boris
rvj
2010-05-25 14:48:08 UTC
Permalink
Post by Boris Zbarsky
Does it work if you append the node.wrappedJSObject?
nope. If I try

target.appendChild(node.wrappedJSObject)

then I get x80004003 (NS_ERROR_INVALID_POINTER)

PS I assume that the html requires no special markup?


************************************************
<html>
<body style="width:100%;height:100%;text-align:center;margin:0;padding;0" >
<table style="width:100%;background:cyan;height:100%;" >
<th style="height:40px">Source Table</th>
<tr id="row1" draggable="true" style="height:20px;background:yellow"><td
id="1a" >1a</td><td id="1b" >1b</td></tr>
<tr id="row2" draggable="true" style="height:20px;background:pink"><td
id="2a" >2a</td><td id="2b" >2b</td></tr>
<tr id="row3" draggable="true" style="background:purple"><td id="3a"
Post by Boris Zbarsky
</td><td id="3b" ></td></tr>
</table>
</body>
</html>

*********************************************
<html>
<body style="width:100%;height:100%;text-align:center;margin:0;padding;0" >
<table id="tablenode" style="width:100%;background:cyan;height:100%;" >
<th style="height:40px">Target Table</th>
<tr id="row4" draggable="true" style="height:20px;background:gold"><td
id="4a" >4a</td><td id="4b" >4b</td></tr>
<tr id="row5" draggable="true" style="height:20px;background:lime"><td
id="5a" >5a</td><td id="5b" >5b</td></tr>
<tr id="row5" draggable="true" style="background:blue"><td id="6a" ></td><td
id="6b" ></td></tr>
</table>
</body>
</html>

********************************************

</html>
Post by Boris Zbarsky
Post by rvj
Post by Boris Zbarsky
Does appending the security wrapper not work? It should...
nope I get
// Execption ..." Could not convert Javascript argument 0
// [nsIDOMHTMLTableElement.appendChild]" nsresult: "0x80570009
// NS_ERROR_XPC_BAD_CONVERT_JS)"
Does it work if you append the node.wrappedJSObject?
-Boris
rvj
2010-05-27 11:27:58 UTC
Permalink
is this officially a bug

...........or user error?
Andrei Sch
2011-04-15 21:02:51 UTC
Permalink
I'm having the same issue. "application/x-moz-node" doesn't pass nodes, it passes a sort of wrapper, and, in case of "treeitem" elements, it passes empty string. Is it a bug?
Loading...