Niky Williams wrote:
Boris Zbarsky wrote:
Niky Williams wrote:
Okay, I'm trying to dispatch a focus event to an input element.
Accessing DOM nodes from off the main thread is not ok. If you're
using a debug build you'll see all sorts of beautiful assertions when
you do this.
I've read some things on nsProxy and the nsIThread...but
can't seem to put it together on how to post this event to the main
thread. Can someone point me in the correct direction please?
Thanks in advance!
See the code at
http://lxr.mozilla.org/seamonkey/source/directory/xpcom/base/src/nsLDAPChannel.cpp#107
for an example of creating a proxy object.
-Boris
Thanks for the reply! I'll take a look into this.
Niky Williams
Boris,
Are you talking about the lovely "Not Threadsafe" assertions? I'm not
getting them on this app, but when I first started messing with this, I
got them...However, I am seeing this assertion:
###!!! ASSERTION: Frame abuses NS_FRAME_OUTSIDE_CHILDREN flag: 'Not
Reached', file c:/Dev/Source/mozilla/layout/generic/nsFrame.cpp, line 4359
Not sure what exactly it means...
BTW, I am using a debug shared build of 1.5.0.2. I traced from when I
call my "Focus" function all the way through to the event loop
itself...the debugger shows them on the same (main) thread. Maybe my
function itself is messed up. If you have a minute, I've posted my
function below. Maybe you can see something I'm not doing correctly.
Just a brief overview of how I'm trying to use this. It's a
UserName/Password type of entry. They enter in their UserName/Password
and I do a lookup in SQL, if it comes back bad, I clear out the
UserName/Password (works fine) and then try to set focus back to the
UserName...this is where it's not working. Thanks again for your time!
//---------------------------------------------------------------------------
//Sets the focus for an element
//---------------------------------------------------------------------------
void CGeckoChrome::SetElementFocus (nsString sID)
{
//Temp vars
nsCOMPtr<nsIDOMElement> pCOM_de;
nsCOMPtr<nsIDOMEvent> pCOM_deDOMEvent;
nsCOMPtr<nsIDOMEventTarget> pCOM_det;
PRBool pbResult = PR_FALSE;
//Trying to create an event
CreateDOMEvent (NS_ConvertUTF8toUTF16("HTMLEvents"), getter_AddRefs
(pCOM_deDOMEvent));
//Making sure we have something here
if (pCOM_deDOMEvent)
{
//Getting the element by it's ID first
GetDOMElement (sID, getter_AddRefs (pCOM_de));
//Now getting an event target from the element
if (pCOM_de && (pCOM_det = do_QueryInterface (pCOM_de)))
{
//Setting up to receive/init an event
if (NS_SUCCEEDED (pCOM_deDOMEvent->InitEvent
(NS_ConvertUTF8toUTF16("focus"), PR_TRUE, PR_TRUE)))
{
//Dispatching the event
pCOM_det->DispatchEvent (pCOM_deDOMEvent,
&pbResult);
}
}
}
}
//---------------------------------------------------------------------------
NOTE: THESE ARE SOME HELPER FUNCTIONS I CREATED THAT ARE USED
ABOVE...HERE FOR REFERENCE IF YOU NEED IT
//---------------------------------------------------------------------------
//Creates events on the DOM
//---------------------------------------------------------------------------
void CGeckoChrome::CreateDOMEvent (nsString sEventType, nsIDOMEvent **ppde)
{
//Temp vars
nsCOMPtr<nsIDOMWindow> pCOM_dw;
nsCOMPtr<nsIDOMDocument> pCOM_dd;
nsCOMPtr<nsIDOMDocumentEvent> pCOM_dde;
//Getting the DOM Window first
if (NS_SUCCEEDED (pwb->GetContentDOMWindow (getter_AddRefs (pCOM_dw))))
{
//Now the document
if (NS_SUCCEEDED (pCOM_dw->GetDocument (getter_AddRefs
(pCOM_dd))))
{
//Now the DOM Document event
if (pCOM_dde = do_QueryInterface (pCOM_dd))
{
//Creating the event now
pCOM_dde->CreateEvent (sEventType, ppde);
}
}
}
}
//---------------------------------------------------------------------------
NOTE: pwb is a raw pointer to the nsIWebBrowser for the nsIWebBrowserChrome
//---------------------------------------------------------------------------
//Gets the element via it's ID
//---------------------------------------------------------------------------
void CGeckoChrome::GetDOMElement (nsString sID, nsIDOMElement **ppde)
{
//Temp vars
nsCOMPtr<nsIDOMWindow> pCOM_dw;
nsCOMPtr<nsIDOMDocument> pCOM_dd;
//Getting the DOM Window first
if (NS_SUCCEEDED (pwb->GetContentDOMWindow (getter_AddRefs (pCOM_dw))))
{
//Now the document
if (NS_SUCCEEDED (pCOM_dw->GetDocument (getter_AddRefs
(pCOM_dd))))
{
//Finally getting the element
pCOM_dd->GetElementById (sID, ppde);
}
}
}
//---------------------------------------------------------------------------
Niky Williams
_______________________________________________
dev-embedding mailing list
dev-embedding@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-embedding