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