Search in sources :

Example 21 with Event

use of com.gargoylesoftware.htmlunit.javascript.host.event.Event in project htmlunit by HtmlUnit.

the class History method goToUrlAtCurrentIndex.

/**
 * Loads the URL at the current index into the window to which this navigation history belongs.
 * @throws IOException if an IO error occurs
 */
private void goToUrlAtCurrentIndex() throws IOException {
    final Boolean old = ignoreNewPages_.get();
    ignoreNewPages_.set(Boolean.TRUE);
    try {
        final HistoryEntry entry = entries_.get(index_);
        final Page page = entry.getPage();
        if (page == null) {
            window_.getWebClient().getPage(window_, entry.getWebRequest(), false);
        } else {
            window_.setEnclosedPage(page);
            page.getWebResponse().getWebRequest().setUrl(entry.getUrl());
        }
        final Window jsWindow = window_.getScriptableObject();
        if (jsWindow != null && jsWindow.hasEventHandlers("onpopstate")) {
            final Event event = new PopStateEvent(jsWindow, Event.TYPE_POPSTATE, entry.getState());
            jsWindow.executeEventLocally(event);
        }
    } finally {
        ignoreNewPages_.set(old);
    }
}
Also used : Window(com.gargoylesoftware.htmlunit.javascript.host.Window) PopStateEvent(com.gargoylesoftware.htmlunit.javascript.host.event.PopStateEvent) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event) PopStateEvent(com.gargoylesoftware.htmlunit.javascript.host.event.PopStateEvent)

Example 22 with Event

use of com.gargoylesoftware.htmlunit.javascript.host.event.Event in project htmlunit by HtmlUnit.

the class Location method setHash.

/**
 * Sets the hash portion of the location URL (the portion following the '#').
 *
 * @param oldURL the old URL
 * @param hash the new hash portion of the location URL
 */
public void setHash(final String oldURL, String hash) {
    // we must not hit the server just to change the hash!
    if (hash != null && !hash.isEmpty() && hash.charAt(0) == '#') {
        hash = hash.substring(1);
    }
    final boolean hasChanged = hash != null && !hash.equals(hash_);
    hash_ = hash;
    if (hasChanged) {
        final Window w = getWindow();
        final Event event;
        if (getBrowserVersion().hasFeature(EVENT_TYPE_HASHCHANGEEVENT)) {
            event = new HashChangeEvent(w, Event.TYPE_HASH_CHANGE, oldURL, getHref());
        } else {
            event = new Event(w, Event.TYPE_HASH_CHANGE);
            event.initEvent(Event.TYPE_HASH_CHANGE, false, false);
        }
        w.executeEventLocally(event);
    }
}
Also used : WebWindow(com.gargoylesoftware.htmlunit.WebWindow) HashChangeEvent(com.gargoylesoftware.htmlunit.javascript.host.event.HashChangeEvent) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event) HashChangeEvent(com.gargoylesoftware.htmlunit.javascript.host.event.HashChangeEvent)

Example 23 with Event

use of com.gargoylesoftware.htmlunit.javascript.host.event.Event in project htmlunit by HtmlUnit.

the class HTMLCollectionFrames method scrollTo.

/**
 * Scrolls to the specified location on the page.
 * @param x the horizontal position to scroll to
 * @param y the vertical position to scroll to
 */
@JsxFunction
public void scrollTo(final int x, final int y) {
    final HTMLElement body = document_.getBody();
    if (body != null) {
        body.setScrollLeft(x);
        body.setScrollTop(y);
        final Event event = new Event(body, Event.TYPE_SCROLL);
        body.fireEvent(event);
    }
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) HtmlAttributeChangeEvent(com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event) MessageEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 24 with Event

use of com.gargoylesoftware.htmlunit.javascript.host.event.Event in project htmlunit by HtmlUnit.

the class HTMLCollectionFrames method scrollByPages.

/**
 * Scrolls the window content down by the specified number of pages.
 * @param pages the number of pages to scroll down
 */
@JsxFunction({ FF, FF_ESR })
public void scrollByPages(final int pages) {
    final HTMLElement body = document_.getBody();
    if (body != null) {
        body.setScrollTop(body.getScrollTop() + (getInnerHeight() * pages));
        final Event event = new Event(body, Event.TYPE_SCROLL);
        body.fireEvent(event);
    }
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) HtmlAttributeChangeEvent(com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event) MessageEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 25 with Event

use of com.gargoylesoftware.htmlunit.javascript.host.event.Event in project htmlunit by HtmlUnit.

the class XMLHttpRequest method fireJavascriptEventIgnoreAbort.

private void fireJavascriptEventIgnoreAbort(final String eventName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Firing javascript XHR event: " + eventName);
    }
    final boolean isReadyStateChange = Event.TYPE_READY_STATE_CHANGE.equalsIgnoreCase(eventName);
    final Event event;
    if (isReadyStateChange) {
        event = new Event(this, Event.TYPE_READY_STATE_CHANGE);
    } else {
        final ProgressEvent progressEvent = new ProgressEvent(this, eventName);
        final boolean lengthComputable = getBrowserVersion().hasFeature(XHR_LENGTH_COMPUTABLE);
        if (lengthComputable) {
            progressEvent.setLengthComputable(true);
        }
        if (webResponse_ != null) {
            final long contentLength = webResponse_.getContentLength();
            progressEvent.setLoaded(contentLength);
            if (lengthComputable) {
                progressEvent.setTotal(contentLength);
            }
        }
        event = progressEvent;
    }
    executeEventLocally(event);
}
Also used : ProgressEvent(com.gargoylesoftware.htmlunit.javascript.host.event.ProgressEvent) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event) ProgressEvent(com.gargoylesoftware.htmlunit.javascript.host.event.ProgressEvent)

Aggregations

Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)25 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)11 MouseEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent)9 MessageEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent)8 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)6 WebClient (com.gargoylesoftware.htmlunit.WebClient)6 HtmlAttributeChangeEvent (com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent)6 IOException (java.io.IOException)6 ScriptResult (com.gargoylesoftware.htmlunit.ScriptResult)5 EventTarget (com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget)5 HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)5 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)4 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)4 JavaScriptEngine (com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine)4 URL (java.net.URL)4 Page (com.gargoylesoftware.htmlunit.Page)3 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)3 TopLevelWindow (com.gargoylesoftware.htmlunit.TopLevelWindow)3 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)3 JsxClass (com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass)3