Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
DOMContentLoaded event from C++
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Martin Lutken  
View profile  
 More options May 16 2011, 2:03 am
Newsgroups: mozilla.dev.tech.xul
From: Martin Lutken <mlut...@gmail.com>
Date: Sun, 15 May 2011 23:03:54 -0700 (PDT)
Local: Mon, May 16 2011 2:03 am
Subject: DOMContentLoaded event from C++
I would like to get the "DOMContentLoaded" event from C++. It works
from javascript, but not from C++. However it seems I more or less
have the correct event target since "resize" and "unload" event does
work.

My XulFile is very simple where the interesting part is this line
declaring the browser:
<browser id="mybrowser1"  src="http://www.google.dk" flex="1" />

The C++ code is like this:
void CSpecialThing::getBrowserQuestionForForum()
{
    nsString wsHrefXul      = NS_LITERAL_STRING( "chrome://xulcrawler/
content/main.xul" );
    nsString wsIDBrowser    = NS_LITERAL_STRING( "mybrowser1" );

    // --- A lot of variables ---
    nsresult rv;
    nsCOMPtr<nsIDOMWindowInternal>      pWinInt(0);
    nsCOMPtr<nsISimpleEnumerator>       pWinEnumerator;
    nsCOMPtr<nsIDOMLocation>            pDOMLocation;
    nsCOMPtr<nsIDOMWindowCollection>    pDOMWindowCollection;
    nsCOMPtr<nsIDOMWindow>              pDomWin;

    // -----------------------------
    // --- Get DomWindowInternal ---
    // -----------------------------

    nsCOMPtr<nsIWindowMediator>
pWindowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));

    nsString sWindowType( NS_LITERAL_STRING("") );
    rv = pWindowMediator->GetEnumerator( sWindowType.get(),
getter_AddRefs(pWinEnumerator));

    PRBool bHasMoreElements;
    rv = pWinEnumerator->HasMoreElements( &bHasMoreElements );

    while ( bHasMoreElements ) {
        nsCOMPtr<nsISupports> pSupportsWin;
        rv = pWinEnumerator->GetNext( getter_AddRefs(pSupportsWin) );
        nsCOMPtr<nsIDOMWindowInternal>
pWinInternal(do_QueryInterface(pSupportsWin));

        rv = pWinInternal-

>GetLocation( getter_AddRefs(pDOMLocation) );

        nsString wsHrefTest;
        rv = pDOMLocation->GetHref( wsHrefTest );

        // See if we have the correct (XUL) URI
        if ( wsHrefXul == wsHrefTest  ) pWinInt = pWinInternal;

        rv = pWinEnumerator->HasMoreElements( &bHasMoreElements );
    }

    // --- Get the "mybrowser1" element ---
    pWinInt->GetFrames( getter_AddRefs(pDOMWindowCollection) );
    pDOMWindowCollection->NamedItem( wsIDBrowser,
getter_AddRefs(pDomWin) );

    // --- Add events ---
    nsCOMPtr<nsIDOMEventTarget>
pDomEventTarget(do_QueryInterface(pDomWin));
    pDomEventTarget-

>AddEventListener(NS_LITERAL_STRING("DOMContentLoaded"), this,

PR_FALSE);
    pDomEventTarget->AddEventListener(NS_LITERAL_STRING("resize"),
this, PR_FALSE);
    pDomEventTarget->AddEventListener(NS_LITERAL_STRING("unload"),
this, PR_FALSE);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil  
View profile  
 More options May 16 2011, 4:46 am
Newsgroups: mozilla.dev.tech.xul
From: Neil <n...@parkwaycc.co.uk>
Date: Mon, 16 May 2011 09:46:30 +0100
Local: Mon, May 16 2011 4:46 am
Subject: Re: DOMContentLoaded event from C++

Martin Lutken wrote:
>I would like to get the "DOMContentLoaded" event from C++. It works from javascript, but not from C++. However it seems I more or less have the correct event target since "resize" and "unload" event does work.

Chances are you did attach the event handler to the window, but
unfortunately loading a new document clears all extant event handlers.
In JavaScript you've probably been attaching a capturing event handler
to the browser element instead.

--
Warning: May contain traces of nuts.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Martin Lutken  
View profile  
 More options May 16 2011, 8:14 am
Newsgroups: mozilla.dev.tech.xul
From: Martin Lutken <mlut...@gmail.com>
Date: Mon, 16 May 2011 05:14:28 -0700 (PDT)
Local: Mon, May 16 2011 8:14 am
Subject: Re: DOMContentLoaded event from C++
On 16 Maj, 10:46, Neil <n...@parkwaycc.co.uk> wrote:

> Martin Lutken wrote:
> >I would like to get the "DOMContentLoaded" event from C++. It works from javascript, but not from C++. However it seems I more or less have the correct event target since "resize" and "unload" event does work.

> Chances are you did attach the event handler to the window, but
> unfortunately loading a new document clears all extant event handlers.
> In JavaScript you've probably been attaching a capturing event handler
> to the browser element instead.

> --
> Warning: May contain traces of nuts.

Ok. Any idea how I get the browser element ?

Is it one of those I already have interfaces to? Anyway I found the
code in the source for Songbird, but they do not listen to the
"DOMContentLoaded" so you're probably right that I am attaching event
listneners to the wrong element.

Thanks a lot


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil  
View profile  
 More options May 17 2011, 8:05 am
Newsgroups: mozilla.dev.tech.xul
From: Neil <n...@parkwaycc.co.uk>
Date: Tue, 17 May 2011 13:05:48 +0100
Local: Tues, May 17 2011 8:05 am
Subject: Re: DOMContentLoaded event from C++

Martin Lutken wrote:
>Ok. Any idea how I get the browser element ?

(Using abbreviated variable names to save space)

nsCOMPtr<nsIDOMDocument> doc;
win->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMElement> elt;
doc->GetElementById(NS_LITERAL_STRING("browser1"), getter_AddRefs(elt));
nsCOMPtr<nsIDOMEventTarget> tgt(do_QueryInterface(elt);
tgt->AddEventListener(NS_LITERAL_STRING("DOMContentLoaded"), this, PR_TRUE);

--
Warning: May contain traces of nuts.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Martin Lutken  
View profile  
 More options May 17 2011, 11:43 am
Newsgroups: mozilla.dev.tech.xul
From: Martin Lutken <mlut...@gmail.com>
Date: Tue, 17 May 2011 08:43:07 -0700 (PDT)
Local: Tues, May 17 2011 11:43 am
Subject: Re: DOMContentLoaded event from C++
Hi Neil

I'll try your way too. Again Thanks a lot :)
Also found a way myself which seems to work:

I found the solution. Just need to get the Parent windows of the one I
wa using. Except if you want the "unload" event which seems to only
work for the window I was first using. Here goes the complete updated
code for those who might have had the same troubles as I.
Thanks again to Neil for his great help.

void CSpecialThing::getBrowserQuestionForForum()
{
    nsString wsHrefXul      = NS_LITERAL_STRING( "chrome://xulcrawler/
content/main.xul" );
    nsString wsIDBrowser    = NS_LITERAL_STRING( "mybrowser1" );

    // --- A lot of variables ---
    nsresult rv;
    nsCOMPtr<nsIDOMWindowInternal>      pWinInt(0);
    nsCOMPtr<nsISimpleEnumerator>       pWinEnumerator;
    nsCOMPtr<nsIDOMLocation>            pDOMLocation;
    nsCOMPtr<nsIDOMWindowCollection>    pDOMWindowCollection;
    nsCOMPtr<nsIDOMWindow>              pDomWin;
    nsCOMPtr<nsIDOMWindow>              pDomWinBrowser;
    nsCOMPtr<nsIDOMDocument>            pDomDoc;

    // -----------------------------
    // --- Get DomWindowInternal ---
    // -----------------------------

    nsCOMPtr<nsIWindowMediator>
pWindowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));

    nsString sWindowType( NS_LITERAL_STRING("") );
    rv = pWindowMediator->GetEnumerator( sWindowType.get(),
getter_AddRefs(pWinEnumerator));

    PRBool bHasMoreElements;
    rv = pWinEnumerator->HasMoreElements( &bHasMoreElements );

    while ( bHasMoreElements ) {
        nsCOMPtr<nsISupports> pSupportsWin;
        rv = pWinEnumerator->GetNext( getter_AddRefs(pSupportsWin) );
        nsCOMPtr<nsIDOMWindowInternal>
pWinInternal(do_QueryInterface(pSupportsWin));

        rv = pWinInternal-

>GetLocation( getter_AddRefs(pDOMLocation) );

        nsString wsHrefTest;
        rv = pDOMLocation->GetHref( wsHrefTest );

        // See if we have the correct (XUL) URI
        if ( wsHrefXul == wsHrefTest  ) pWinInt = pWinInternal;

        rv = pWinEnumerator->HasMoreElements( &bHasMoreElements );
    }

    // --- Get the "mybrowser1" element ---
    pWinInt->GetFrames( getter_AddRefs(pDOMWindowCollection) );
    pDOMWindowCollection->NamedItem( wsIDBrowser,
getter_AddRefs(pDomWin) );

    pDomWin->GetParent( getter_AddRefs(pDomWinBrowser) );

    // --- Add events ---
    nsCOMPtr<nsIDOMEventTarget>
pDomEventTargetBrowserWin(do_QueryInterface(pDomWin));
    nsCOMPtr<nsIDOMEventTarget>
pDomEventTargetBrowser(do_QueryInterface(pDomWinBrowser));
    pDomEventTargetBrowser-

>AddEventListener(NS_LITERAL_STRING("DOMContentLoaded"), this,

PR_FALSE);
    pDomEventTargetBrowser-
>AddEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);

    pDomEventTargetBrowserWin-

>AddEventListener(NS_LITERAL_STRING("unload"), this, PR_FALSE);

    // ---------------------------------------------------------------
    // --- Bonus example on how to get the current URI of the page ---
    // ---------------------------------------------------------------
    pDomWin->GetDocument( getter_AddRefs(pDomDoc) );
    nsCOMPtr<nsIDOMDocumentView>
pDomDocumentView(do_QueryInterface(pDomDoc));
    nsCOMPtr<nsIDOMAbstractView> domAbstractView =
getDefaultView(pDomDocumentView);
    nsCOMPtr<nsIWebNavigation>
webNavigation(do_GetInterface(domAbstractView));
    printf("webNavigation uri: %s\n",
getCurrentURI(webNavigation).c_str() );


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Martin Lutken  
View profile  
 More options May 17 2011, 11:44 am
Newsgroups: mozilla.dev.tech.xul
From: Martin Lutken <mlut...@gmail.com>
Date: Tue, 17 May 2011 08:44:25 -0700 (PDT)
Local: Tues, May 17 2011 11:44 am
Subject: Re: DOMContentLoaded event from C++
Hi Neil

I'll try your way too. Again Thanks a lot :)
Also found a way myself which seems to work:

I found the solution. Just need to get the Parent windows of the one I
wa using. Except if you want the "unload" event which seems to only
work for the window I was first using. Here goes the complete updated
code for those who might have had the same troubles as I.
Thanks again to Neil for his great help.

void CSpecialThing::getBrowserQuestionForForum()
{
    nsString wsHrefXul      = NS_LITERAL_STRING( "chrome://xulcrawler/
content/main.xul" );
    nsString wsIDBrowser    = NS_LITERAL_STRING( "mybrowser1" );

    // --- A lot of variables ---
    nsresult rv;
    nsCOMPtr<nsIDOMWindowInternal>      pWinInt(0);
    nsCOMPtr<nsISimpleEnumerator>       pWinEnumerator;
    nsCOMPtr<nsIDOMLocation>            pDOMLocation;
    nsCOMPtr<nsIDOMWindowCollection>    pDOMWindowCollection;
    nsCOMPtr<nsIDOMWindow>              pDomWin;
    nsCOMPtr<nsIDOMWindow>              pDomWinBrowser;
    nsCOMPtr<nsIDOMDocument>            pDomDoc;

    // -----------------------------
    // --- Get DomWindowInternal ---
    // -----------------------------

    nsCOMPtr<nsIWindowMediator>
pWindowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));

    nsString sWindowType( NS_LITERAL_STRING("") );
    rv = pWindowMediator->GetEnumerator( sWindowType.get(),
getter_AddRefs(pWinEnumerator));

    PRBool bHasMoreElements;
    rv = pWinEnumerator->HasMoreElements( &bHasMoreElements );

    while ( bHasMoreElements ) {
        nsCOMPtr<nsISupports> pSupportsWin;
        rv = pWinEnumerator->GetNext( getter_AddRefs(pSupportsWin) );
        nsCOMPtr<nsIDOMWindowInternal>
pWinInternal(do_QueryInterface(pSupportsWin));

        rv = pWinInternal-

>GetLocation( getter_AddRefs(pDOMLocation) );

        nsString wsHrefTest;
        rv = pDOMLocation->GetHref( wsHrefTest );

        // See if we have the correct (XUL) URI
        if ( wsHrefXul == wsHrefTest  ) pWinInt = pWinInternal;

        rv = pWinEnumerator->HasMoreElements( &bHasMoreElements );
    }

    // --- Get the "mybrowser1" element ---
    pWinInt->GetFrames( getter_AddRefs(pDOMWindowCollection) );
    pDOMWindowCollection->NamedItem( wsIDBrowser,
getter_AddRefs(pDomWin) );

    pDomWin->GetParent( getter_AddRefs(pDomWinBrowser) );

    // --- Add events ---
    nsCOMPtr<nsIDOMEventTarget>
pDomEventTargetBrowserWin(do_QueryInterface(pDomWin));
    nsCOMPtr<nsIDOMEventTarget>
pDomEventTargetBrowser(do_QueryInterface(pDomWinBrowser));
    pDomEventTargetBrowser-

>AddEventListener(NS_LITERAL_STRING("DOMContentLoaded"), this,

PR_FALSE);
    pDomEventTargetBrowser-
>AddEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);

    pDomEventTargetBrowserWin-

>AddEventListener(NS_LITERAL_STRING("unload"), this, PR_FALSE);

    // ---------------------------------------------------------------
    // --- Bonus example on how to get the current URI of the page ---
    // ---------------------------------------------------------------
    pDomWin->GetDocument( getter_AddRefs(pDomDoc) );
    nsCOMPtr<nsIDOMDocumentView>
pDomDocumentView(do_QueryInterface(pDomDoc));
    nsCOMPtr<nsIDOMAbstractView> domAbstractView =
getDefaultView(pDomDocumentView);
    nsCOMPtr<nsIWebNavigation>
webNavigation(do_GetInterface(domAbstractView));
    printf("webNavigation uri: %s\n",
getCurrentURI(webNavigation).c_str() );


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
YuLo  
View profile   Translate to Translated (View Original)
 More options Oct 1 2012, 8:15 am
Newsgroups: mozilla.dev.tech.xul
From: YuLo <yuloem...@gmail.com>
Date: Mon, 1 Oct 2012 05:15:15 -0700 (PDT)
Local: Mon, Oct 1 2012 8:15 am
Subject: Re: DOMContentLoaded event from C++
вторник, 17 мая 2011 г., 19:44:25 UTC+4 пользователь Martin  Lutken написал:

Hi, Martin.
A question for nubie. What function will be fired on event. The second parameter for "AddEventListener" is "this". It is the pointer to class, not function.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil  
View profile  
 More options Oct 1 2012, 11:47 am
Newsgroups: mozilla.dev.tech.xul
From: Neil <n...@parkwaycc.co.uk>
Date: Mon, 01 Oct 2012 16:47:02 +0100
Local: Mon, Oct 1 2012 11:47 am
Subject: Re: DOMContentLoaded event from C++

YuLo wrote:
>A question for nubie. What function will be fired on event. The second parameter for "AddEventListener" is "this". It is the pointer to class, not function.

The second parameter is an nsIDOMEventListener type. This has a method
called handleEvent (or HandleEvent in C++).

XPConnect magic allows script to pass a function instead of a class.

--
Warning: May contain traces of nuts.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
YuLo  
View profile   Translate to Translated (View Original)
 More options Oct 4 2012, 5:35 am
Newsgroups: mozilla.dev.tech.xul
From: YuLo <yuloem...@gmail.com>
Date: Thu, 4 Oct 2012 02:35:32 -0700 (PDT)
Local: Thurs, Oct 4 2012 5:35 am
Subject: Re: DOMContentLoaded event from C++
понедельник, 1 октября 2012 г., 19:47:03 UTC+4 пользователь Neil написал:

Thank you Neil,
now i understand.
I implemented nsIDOMEventListener class and can catch events.
Thanks again!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
YuLo  
View profile   Translate to Translated (View Original)
 More options Oct 6 2012, 8:08 am
Newsgroups: mozilla.dev.tech.xul
From: YuLo <yuloem...@gmail.com>
Date: Sat, 6 Oct 2012 05:08:51 -0700 (PDT)
Local: Sat, Oct 6 2012 8:08 am
Subject: Re: DOMContentLoaded event from C++
четверг, 4 октября 2012 г., 13:35:33 UTC+4 пользователь YuLo написал:

But my problem is not solved yet.
I can catch keyboard event but where can i get KeyCode?
The event variable of HandleEvent() is of type nsIDOMEvent.
Casting it to nsIDOMKeyEvent and using GetKeyCode() crashes XULRunner.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
YuLo  
View profile   Translate to Translated (View Original)
 More options Oct 6 2012, 8:24 am
Newsgroups: mozilla.dev.tech.xul
From: YuLo <yuloem...@gmail.com>
Date: Sat, 6 Oct 2012 05:24:21 -0700 (PDT)
Local: Sat, Oct 6 2012 8:24 am
Subject: Re: DOMContentLoaded event from C++
суббота, 6 октября 2012 г., 16:08:51 UTC+4 пользователь YuLo написал:

sorry, do_QueryInterface solved the problem.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »