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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
Aggregations