Re: Increase performance

"Rajat Gogri" <[email protected]> Thu, 11 Oct 2007 00:29:28 -0400
Newsgroups gmane.comp.mozilla.jrex
Message-ID <[email protected]>
--===============0496707627==
Content-Type: multipart/alternative; 
	boundary="----=_Part_15079_935435.1192076968840"

------=_Part_15079_935435.1192076968840
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hey Crued,

Thanks a lot for this code. I will try it now itself. one more question.
How are you getting link as Node element. could you please give me that code
also.

Thanks,
Rajat


On 10/11/07, crued <[email protected]> wrote:
>
> Hello Rajat,
>
> Here's a bit of code that I use, and that works for me with no changes
> to seamonkey code.  It looks like you're doing the same things, excep
> that I pass null for the fourth parameter of initMouseEvent (I don't
> recall specifically why I chose that).  Also, at one point the
> createEvent would fail for me if I tried to call click too soon.  The
> code below tries to get the clickEvent a second time if it fails to get
> one the first time.
>
>    *protected* *synchronized* *void* doClick(Node elm) *throws*
> BrowserException {
>        EventTarget relatedEventTarget              = ((JRexNodeImpl)
> elm).getEventTarget();
>        DocumentEvent event                         =
>                ((JRexHTMLDocumentImpl) elm.getOwnerDocument
> ()).getDocumentEvent();
>        MouseEvent clickEvent = (MouseEvent) event.createEvent
> (*"MouseEvents"*);
>
>        *if* (clickEvent == *null*) {
>            _log.error(*"Error initializing the clickEvent, should not be
> null.  Will try again."*);
>            *try* {
>                Thread.sleep(retryTimeout);    /// Give things a moment to
> settle
> /            } *catch* (InterruptedException e) {
>                e.printStackTrace();
>            }
>            clickEvent = (MouseEvent) event.createEvent(*"MouseEvents"*);
>            *if* (clickEvent == *null*) {
>                /// if it is still null even after reattempt throw an
> exception
> /                *throw* *new* BrowserException(*"Error initializing the
> clickEvent"*);
>            }
>        }
>
>        clickEvent.initMouseEvent(*"click"*, *true*, *true*, *null*, 1, 1,
> 2, 1, 2, *false*, *false*, *false*, *false*, (*short*) 0,
>                relatedEventTarget);
>        relatedEventTarget.dispatchEvent(clickEvent);
>    }
>
> Some small differences (which shouldn't matter, but might anyway)
> between my code and yours:
>    1. I pass null for the fourth argument ("view") of initMouseEvent.
>    2. I call getOwnerDocument to get the document, while you call
> navigator.getDocument
>
> Hope that helps.  Let us know if you are able to solve your problem.
>
> --Chris
>
> Rajat Gogri wrote:
> > Hello Guys,
> >
> > initMouseEvent() from JRex is not working for me to simulate mouse
> > click event. Could any one please post the code.
> >
> > I am using Jrex for seamonkey version. Do I need to change anything in
> > seamonkey code??
> >
> > when I do DispatchEvent() it does not follow the link and returns false.
> >
> > Please let me know the any changes needed in JRex or Seamonkey code to
> > make this code work. It is very urgent.
> >
> > *I am pasting my code here*
> >
> > JRexHTMLDocumentImpl htmlDOM =
> > (JRexHTMLDocumentImpl)navigator.getDocument();
> > HTMLCollection links = htmlDOM.getLinks();
> >
> > JRexHTMLAnchorElementImpl link1 = (JRexHTMLAnchorElementImpl)
> > links.item(1);
> > JRexEventTargetImpl clickEvent =
> > (JRexEventTargetImpl)link1.getEventTarget();
> > JRexMouseEventImpl mouseEvent = (JRexMouseEventImpl)
> > (((JRexHTMLDocumentImpl)
> > htmlDOM).getDocumentEvent().createEvent("MouseEvents"));
> > JRexDocumentViewImpl dv = (JRexDocumentViewImpl)
> > ((JRexHTMLDocumentImpl) htmlDOM).getDocumentView();
> >
> > mouseEvent.initMouseEvent("click", true, true, dv.getDefaultView(), 1,
> > 1, 2, 1, 2, false, false, false,false, (short)0, clickEvent);
> > boolean check = clickEvent.dispatchEvent(mouseEvent);
> >
> > Thanks,
> > Rajat
> >
> >
> >
>
>
>

------=_Part_15079_935435.1192076968840
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<div>Hey Crued,</div>
<div>&nbsp;</div>
<div>Thanks a lot for this code. I will try it now itself. one more question.</div>
<div>How are you getting link as Node element. could you please give me that code also.</div>
<div>&nbsp;</div>
<div>Thanks,</div>
<div>Rajat<br><br>&nbsp;</div>
<div><span class="gmail_quote">On 10/11/07, <b class="gmail_sendername">crued</b> &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hello Rajat,<br><br>Here&#39;s a bit of code that I use, and that works for me with no changes<br>to seamonkey code.&nbsp;&nbsp;It looks like you&#39;re doing the same things, excep
<br>that I pass null for the fourth parameter of initMouseEvent (I don&#39;t<br>recall specifically why I chose that).&nbsp;&nbsp;Also, at one point the<br>createEvent would fail for me if I tried to call click too soon.&nbsp;&nbsp;The<br>code below tries to get the clickEvent a second time if it fails to get
<br>one the first time.<br><br>&nbsp;&nbsp; *protected* *synchronized* *void* doClick(Node elm) *throws* BrowserException {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EventTarget relatedEventTarget&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= ((JRexNodeImpl) elm).getEventTarget();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DocumentEvent event&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((JRexHTMLDocumentImpl) elm.getOwnerDocument()).getDocumentEvent();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MouseEvent clickEvent = (MouseEvent) event.createEvent(*&quot;MouseEvents&quot;*);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *if* (clickEvent == *null*) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _log.error(*&quot;Error initializing the clickEvent, should not be null.&nbsp;&nbsp;Will try again.&quot;*);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *try* {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.sleep(retryTimeout);&nbsp;&nbsp;&nbsp;&nbsp;/// Give things a moment to settle<br>
/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} *catch* (InterruptedException e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clickEvent = (MouseEvent) event.createEvent(*&quot;MouseEvents&quot;*);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *if* (clickEvent == *null*) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// if it is still null even after reattempt throw an exception<br>/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*throw* *new* BrowserException(*&quot;Error initializing the clickEvent&quot;*);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
clickEvent.initMouseEvent(*&quot;click&quot;*, *true*, *true*, *null*, 1, 1, 2, 1, 2, *false*, *false*, *false*, *false*, (*short*) 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; relatedEventTarget);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; relatedEventTarget.dispatchEvent(clickEvent);
<br>&nbsp;&nbsp; }<br><br>Some small differences (which shouldn&#39;t matter, but might anyway)<br>between my code and yours:<br>&nbsp;&nbsp; 1. I pass null for the fourth argument (&quot;view&quot;) of initMouseEvent.<br>&nbsp;&nbsp; 2. I call getOwnerDocument to get the document, while you call
<br>navigator.getDocument<br><br>Hope that helps.&nbsp;&nbsp;Let us know if you are able to solve your problem.<br><br>--Chris<br><br>Rajat Gogri wrote:<br>&gt; Hello Guys,<br>&gt;<br>&gt; initMouseEvent() from JRex is not working for me to simulate mouse
<br>&gt; click event. Could any one please post the code.<br>&gt;<br>&gt; I am using Jrex for seamonkey version. Do I need to change anything in<br>&gt; seamonkey code??<br>&gt;<br>&gt; when I do DispatchEvent() it does not follow the link and returns false.
<br>&gt;<br>&gt; Please let me know the any changes needed in JRex or Seamonkey code to<br>&gt; make this code work. It is very urgent.<br>&gt;<br>&gt; *I am pasting my code here*<br>&gt;<br>&gt; JRexHTMLDocumentImpl htmlDOM =
<br>&gt; (JRexHTMLDocumentImpl)navigator.getDocument();<br>&gt; HTMLCollection links = htmlDOM.getLinks();<br>&gt;<br>&gt; JRexHTMLAnchorElementImpl link1 = (JRexHTMLAnchorElementImpl)<br>&gt; links.item(1);<br>&gt; JRexEventTargetImpl clickEvent =
<br>&gt; (JRexEventTargetImpl)link1.getEventTarget();<br>&gt; JRexMouseEventImpl mouseEvent = (JRexMouseEventImpl)<br>&gt; (((JRexHTMLDocumentImpl)<br>&gt; htmlDOM).getDocumentEvent().createEvent(&quot;MouseEvents&quot;));
<br>&gt; JRexDocumentViewImpl dv = (JRexDocumentViewImpl)<br>&gt; ((JRexHTMLDocumentImpl) htmlDOM).getDocumentView();<br>&gt;<br>&gt; mouseEvent.initMouseEvent(&quot;click&quot;, true, true, dv.getDefaultView(), 1,<br>&gt; 1, 2, 1, 2, false, false, false,false, (short)0, clickEvent);
<br>&gt; boolean check = clickEvent.dispatchEvent(mouseEvent);<br>&gt;<br>&gt; Thanks,<br>&gt; Rajat<br>&gt;<br>&gt;<br>&gt;<br><br><br></blockquote></div><br>

------=_Part_15079_935435.1192076968840--

--===============0496707627==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
JRex mailing list
[email protected]
http://mozdev.org/mailman/listinfo/jrex

--===============0496707627==--