[prev in list] [next in list] [prev in thread] [next in thread] 

List:       htmlunit-develop
Subject:    [HtmlUnit] SVN: [12520] branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware /htmlunit
From:       asashour () users ! sourceforge ! net
Date:       2016-04-28 22:17:26
Message-ID: E1avuFV-000156-O4 () sfs-ml-1 ! v29 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 12520
          http://sourceforge.net/p/htmlunit/code/12520
Author:   asashour
Date:     2016-04-28 22:17:26 +0000 (Thu, 28 Apr 2016)
Log Message:
-----------
hu3: fix executing events

Modified Paths:
--------------
    branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/InteractivePage.java
  branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java
  branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java


Modified: branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/InteractivePage.java
 ===================================================================
--- branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/InteractivePage.java	2016-04-28 \
                21:24:41 UTC (rev 12519)
+++ branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/InteractivePage.java	2016-04-28 \
22:17:26 UTC (rev 12520) @@ -33,6 +33,9 @@
 import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
 import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
 import com.gargoylesoftware.htmlunit.javascript.host.event.Event;
+import com.gargoylesoftware.js.nashorn.internal.runtime.ScriptFunction;
+import com.gargoylesoftware.js.nashorn.internal.runtime.ScriptObject;
+import com.gargoylesoftware.js.nashorn.internal.runtime.ScriptRuntime;
 
 /**
  * An interactive SGML page, which is able to handle JavaScript events.
@@ -219,6 +222,31 @@
     }
 
     /**
+     * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT \
YOUR OWN RISK.</span><br> +     *
+     * Execute a Function in the given context.
+     *
+     * @param function the JavaScript Function to call
+     * @param thisObject the "this" object to be used during invocation
+     * @param args the arguments to pass into the call
+     * @param htmlElementScope the HTML element for which this script is being \
executed +     * This element will be the context during the JavaScript execution. If \
null, +     * the context will default to the page.
+     * @return a ScriptResult which will contain both the current page (which may be \
different than +     * the previous page and a JavaScript result object.
+     */
+    public ScriptResult executeJavaScriptFunctionIfPossible(final ScriptFunction \
function, final ScriptObject thisObject, +            final Object[] args, final \
DomNode htmlElementScope) { +
+        if (!getWebClient().getOptions().isJavaScriptEnabled()) {
+            return new ScriptResult(null, this);
+        }
+
+        final Object result = ScriptRuntime.apply(function, thisObject, args);
+        return new ScriptResult(result, \
getWebClient().getCurrentWindow().getEnclosedPage()); +    }
+
+    /**
      * {@inheritDoc}
      */
     @Override

Modified: branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java
 ===================================================================
--- branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java	2016-04-28 \
                21:24:41 UTC (rev 12519)
+++ branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java	2016-04-28 \
22:17:26 UTC (rev 12520) @@ -32,10 +32,6 @@
 import java.util.NoSuchElementException;
 import java.util.Set;
 
-import net.sourceforge.htmlunit.corejs.javascript.Context;
-import net.sourceforge.htmlunit.corejs.javascript.ContextAction;
-import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Attr;
@@ -53,12 +49,17 @@
 import com.gargoylesoftware.htmlunit.WebClient;
 import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
 import com.gargoylesoftware.htmlunit.javascript.host.event.Event;
-import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget;
+import com.gargoylesoftware.htmlunit.javascript.host.event.Event2;
+import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget2;
 import com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent;
 import com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent;
 import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement;
 import com.gargoylesoftware.htmlunit.util.StringUtils;
 
+import net.sourceforge.htmlunit.corejs.javascript.Context;
+import net.sourceforge.htmlunit.corejs.javascript.ContextAction;
+import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
+
 /**
  * @author Ahmed Ashour
  * @author Marc Guillemot
@@ -1144,7 +1145,7 @@
      * @return the execution result, or {@code null} if nothing is executed
      */
     public ScriptResult fireEvent(final String eventType) {
-        return fireEvent(new Event(this, eventType));
+        return fireEvent(new Event2(this, eventType));
     }
 
     /**
@@ -1155,31 +1156,45 @@
      * @return the execution result, or {@code null} if nothing is executed
      */
     public ScriptResult fireEvent(final Event event) {
+        System.out.println("Fire Event is empty");
+        return null;
+    }
+
+    /**
+     * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT \
YOUR OWN RISK.</span><br> +     *
+     * Fires the event on the element. Nothing is done if JavaScript is disabled.
+     * @param event the event to fire
+     * @return the execution result, or {@code null} if nothing is executed
+     */
+    public ScriptResult fireEvent(final Event2 event) {
         final WebClient client = getPage().getWebClient();
         if (!client.getOptions().isJavaScriptEnabled()) {
             return null;
         }
 
-        if (!handles(event)) {
-            return null;
-        }
+//        if (!handles(event)) {
+//            return null;
+//        }
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("Firing " + event);
         }
-        final EventTarget jsElt = (EventTarget) getScriptableObject();
-        final ContextAction action = new ContextAction() {
-            @Override
-            public Object run(final Context cx) {
-                return jsElt.fireEvent(event);
-            }
-        };
+        final EventTarget2 jsElt = (EventTarget2) getScriptObject2();
 
-        final ContextFactory cf = client.getJavaScriptEngine().getContextFactory();
-        final ScriptResult result = (ScriptResult) cf.call(action);
-        if (event.isAborted(result)) {
-            preventDefault();
-        }
+        final ScriptResult result = jsElt.fireEvent(event);
+//        final ContextAction action = new ContextAction() {
+//            @Override
+//            public Object run(final Context cx) {
+//                return jsElt.fireEvent(event);
+//            }
+//        };
+//
+//        final ContextFactory cf = \
client.getJavaScriptEngine().getContextFactory(); +//        final ScriptResult \
result = (ScriptResult) cf.call(action); +//        if (event.isAborted(result)) {
+//            preventDefault();
+//        }
         return result;
     }
 

Modified: branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java
 ===================================================================
--- branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java	2016-04-28 \
                21:24:41 UTC (rev 12519)
+++ branches/htmlunit3/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java	2016-04-28 \
22:17:26 UTC (rev 12520) @@ -73,7 +73,9 @@
 import com.gargoylesoftware.htmlunit.javascript.host.Window;
 import com.gargoylesoftware.htmlunit.javascript.host.dom.Node;
 import com.gargoylesoftware.htmlunit.javascript.host.event.BeforeUnloadEvent;
+import com.gargoylesoftware.htmlunit.javascript.host.event.BeforeUnloadEvent2;
 import com.gargoylesoftware.htmlunit.javascript.host.event.Event;
+import com.gargoylesoftware.htmlunit.javascript.host.event.Event2;
 import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument;
 import com.gargoylesoftware.htmlunit.protocol.javascript.JavaScriptURLConnection;
 
@@ -1207,22 +1209,22 @@
 
         // Execute the specified event on the document element.
         final WebWindow window = getEnclosingWindow();
-        if (window.getScriptableObject() != null) {
+        if (window.getScriptObject2() != null) {
             final HtmlElement element = getDocumentElement();
             if (element == null) { // happens for instance if \
document.documentElement has been removed from parent  return true;
             }
-            final Event event;
+            final Event2 event;
             if (eventType.equals(Event.TYPE_BEFORE_UNLOAD)) {
-                event = new BeforeUnloadEvent(element, eventType);
+                event = new BeforeUnloadEvent2(element, eventType);
             }
             else {
-                event = new Event(element, eventType);
+                event = new Event2(element, eventType);
             }
             element.fireEvent(event);
-            if (!isOnbeforeunloadAccepted(this, event)) {
-                return false;
-            }
+//            if (!isOnbeforeunloadAccepted(this, event)) {
+//                return false;
+//            }
         }
 
         // If this page was loaded in a frame, execute the version of the event \
specified on the frame tag.


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
HtmlUnit-develop mailing list
HtmlUnit-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic