From: <rb...@us...> - 2015-09-05 11:29:40
|
Revision: 11110 http://sourceforge.net/p/htmlunit/code/11110 Author: rbri Date: 2015-09-05 11:29:37 +0000 (Sat, 05 Sep 2015) Log Message: ----------- code cleanup and simplification Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2015-09-05 11:01:31 UTC (rev 11109) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2015-09-05 11:29:37 UTC (rev 11110) @@ -1104,6 +1104,26 @@ } /** + * Returns the onload property. Note that this is not necessarily a function if something else has been set. + * @return the onload property + */ + @JsxGetter + public Object getOnload() { + final Object onload = getHandlerForJavaScript("load"); + if (onload == null) { + // NB: for IE, the onload of window is the one of the body element but not for Mozilla. + final HtmlPage page = (HtmlPage) getWebWindow().getEnclosedPage(); + final HtmlElement body = page.getBody(); + if (body != null) { + final HTMLBodyElement b = (HTMLBodyElement) body.getScriptObject(); + return b.getEventHandler("onload"); + } + return null; + } + return onload; + } + + /** * Sets the value of the onload event handler. * @param newOnload the new handler */ @@ -1117,31 +1137,22 @@ } /** - * Sets the value of the onclick event handler. - * @param newOnload the new handler - */ - @JsxSetter - public void setOnclick(final Object newOnload) { - getEventListenersContainer().setEventHandlerProp("click", newOnload); - } - - /** * Returns the onclick property (caution this is not necessary a function if something else has * been set). * @return the onclick property */ @JsxGetter public Object getOnclick() { - return getEventListenersContainer().getEventHandlerProp("click"); + return getHandlerForJavaScript("click"); } /** - * Sets the value of the ondblclick event handler. - * @param newHandler the new handler + * Sets the value of the onclick event handler. + * @param newOnload the new handler */ @JsxSetter - public void setOndblclick(final Object newHandler) { - getEventListenersContainer().setEventHandlerProp("dblclick", newHandler); + public void setOnclick(final Object newOnload) { + setHandlerForJavaScript("click", newOnload); } /** @@ -1151,27 +1162,16 @@ */ @JsxGetter public Object getOndblclick() { - return getEventListenersContainer().getEventHandlerProp("dblclick"); + return getHandlerForJavaScript("dblclick"); } /** - * Returns the onload property. Note that this is not necessarily a function if something else has been set. - * @return the onload property + * Sets the value of the ondblclick event handler. + * @param newHandler the new handler */ - @JsxGetter - public Object getOnload() { - final Object onload = getEventListenersContainer().getEventHandlerProp("load"); - if (onload == null) { - // NB: for IE, the onload of window is the one of the body element but not for Mozilla. - final HtmlPage page = (HtmlPage) getWebWindow().getEnclosedPage(); - final HtmlElement body = page.getBody(); - if (body != null) { - final HTMLBodyElement b = (HTMLBodyElement) body.getScriptObject(); - return b.getEventHandler("onload"); - } - return null; - } - return onload; + @JsxSetter + public void setOndblclick(final Object newHandler) { + setHandlerForJavaScript("dblclick", newHandler); } /** @@ -1181,7 +1181,7 @@ */ @JsxGetter public Object getOnhashchange() { - return getEventListenersContainer().getEventHandlerProp(Event.TYPE_HASH_CHANGE); + return getHandlerForJavaScript(Event.TYPE_HASH_CHANGE); } /** @@ -1190,7 +1190,7 @@ */ @JsxSetter public void setOnhashchange(final Object newHandler) { - getEventListenersContainer().setEventHandlerProp(Event.TYPE_HASH_CHANGE, newHandler); + setHandlerForJavaScript(Event.TYPE_HASH_CHANGE, newHandler); } /** @@ -2173,7 +2173,7 @@ */ @JsxGetter({@WebBrowser(FF), @WebBrowser(CHROME), @WebBrowser(value = IE, minVersion = 11) }) - public Object getSnsubmit() { + public Object getOnsubmit() { return getHandlerForJavaScript(Event.TYPE_SUBMIT); } |