Salut Béatrice :-)

No problem, first of all have a look to this :
http://orange.kame.net/dev/cvsweb.cgi/mozilla/js/ref/README?cvsroot=mozilla6&rev=1.1.1.2
But mainly :
http://users.skynet.be/saw/SpiderMonkey.htm

And for the purpose, see a html like this
<script type="text/javascript">
    do some code...
</script>
<div id="theloading">
Loading...
</div>
<html>
<head>
<style>
#maincontent
{
    display:none;
}
</style>
 <script type="text/javascript">
function init()
{
    document.getElementById("theloading").style.display="none";
    document.getElementById("maincontent").style.display="block";
}
</script>
</head>
<body onload="init();">
<div id="maincontent">
Blablabla
</div>
</body>
</html>
Tu vois l'idée ? :-)
Basically, this is a "loading wait" effect.
I want to do some personal javascript stuff while the page is loading, 
further more BEFORE the page is loaded.
The problem comes from the moment I want to "insert" my own JS 
classes/functions. I do it with this code :
 nsCOMPtr<nsIDOMWindow>   window;
  nsCOMPtr<nsIDOMDocument>  doc;
  nsCOMPtr<nsIDocument>   theDoc;
  nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
  nsIScriptContext*    context;

  mWebBrowser->GetContentDOMWindow(getter_AddRefs(window));
  window->GetDocument(getter_AddRefs(doc));
  theDoc = do_QueryInterface(doc);
  scriptGlobalObject = theDoc->GetScriptGlobalObject();
  context = scriptGlobalObject->GetContext();
jscontext = NS_REINTERPRET_CAST(JSContext*, context->GetNativeContext());
global = JS_GetGlobalObject(jscontext);
  JSObject *obj = JSexternal::JSInit(jscontext, global,NULL);

As you can see, to "insert" I need the document. But, if the document is 
complete, all my JS code at the top of the code will cause an error.
That's why I got the moment when the document is initialized and empty to 
insert my JS classes/functions.

In french now :-)
L'idée de départ était de faire un effet "patientez pendant que ça charge". 
Mais j'avais aussi besoin d'exécuter mes fonctions/méthodes "maisons" avant 
que la page soit complètement chargée.
Le problème c'est que le code C++ qui étend le DOM a besoin du document. Le 
but du jeu c'était donc de trouver le moment où le document est initialisé 
mais pas encore chargé.
Parce que faut pas oublier que Gecko fonctionne "on stream"... Il chope le 
code au fur et à mesure et exécute. Donc faut lui donner à manger du 
comestible dès le départ.
En ce qui concerne ta question de départ : t'as un exemple tout prêt dans le 
2e lien.
Le 1er c'est surtout pour la théorie.

Si t'as besoin de détails et si on peut éventuellement s'entraider : antoine 
__AT__ antoineviau . com
En ce moment je cherche à réduire l'occupation disque des composants de 
gecko et surtout réduire l'occupation mémoire. T'as des pistes ?

Antoine


"Béatrice Philippe" <[EMAIL PROTECTED]> a écrit dans le message 
de news: [EMAIL PROTECTED]
> Hi antoine,
> could you give me a peace of your code for how to create/add a new 
> class/function, please ?
> i'm currently working on javascript functions.
>
> And my question is : what's the purpose to add javascript functions while 
> a document is loading ?
>
> Thanks.
> -- 
> Béatrice Philippe-Derbez
>
> -- 
> Béatrice Philippe-Derbez
>
> Urbilog.
> 80, rue d'Iéna.
> 59000 Lille.
> 01-69-88-08-11
> 06-77-88-92-51
> "Antoine Viau" <[EMAIL PROTECTED]> a écrit dans le message de news: 
> [EMAIL PROTECTED]
>> Finally i got a solution. Here it is :
>> You cannot add a new class/function until the document has been loaded.
>> But you cannot use your new class/function while loading.
>> So what to do ?
>> Find the "moment" where the document is initialized and empty, then add 
>> your class/function.
>> This "moment" is in OnStateChange (nsIProgressListener) when the flag is 
>> STATE_START.
>> So :
>> NS_IMETHODIMP WebBrowserChrome::OnStateChange(nsIWebProgress *progress, 
>> nsIRequest *request,
>>             PRUint32 progressStateFlags, nsresult status)
>> {
>> if ( progressStateFlags & STATE_START )
>> {
>>    CreateMyClassAndFunctions();
>> }
>> ...
>> }
>>
>> Antoine
>>
>> "Antoine Viau" <[EMAIL PROTECTED]> a écrit dans le message de news: 
>> [EMAIL PROTECTED]
>>> Hi there,
>>>
>>> I have embedded Gecko in my app and I am able do extend the Javascript 
>>> functions and classes.
>>> BUT...
>>> The functions and classes are recognized only when the page is full 
>>> loaded.
>>> Means that I cannot use my functions/classes until the onload event has 
>>> fired.
>>> I would like to call my functions/classes at "loading-runtime".
>>> This should works with something like this :
>>> <html>
>>> <body>
>>> <div>This is a div</div>
>>> <script language="javascript">
>>>    My_Function_Written_In_C(some_param);
>>> </script>
>>> </body>
>>> </html>
>>>
>>> To create classes and add functions, I read this :
>>> http://users.skynet.be/saw/SpiderMonkey.htm (classes)
>>> and this :
>>> http://orange.kame.net/dev/cvsweb.cgi/mozilla/js/ref/README?cvsroot=mozilla6&rev=1.1.1.2
>>>  
>>> (functions)
>>>
>>> I tried to put the code which initialize the new functions at 
>>> STATE_START in the Chrome::OnProgressChange handler. But it does not 
>>> work.
>>>
>>> Any idea ?
>>>
>>> Thx
>>> Antoine
>>>
>>
>>
>
> 


_______________________________________________
mozilla-embedding mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-embedding

Reply via email to