com.gargoylesoftware.htmlunit.javascript.host.event.UIEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of htmlunit Show documentation
Show all versions of htmlunit Show documentation
A headless browser intended for use in testing web-based applications.
/*
* Copyright (c) 2002-2018 Gargoyle Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gargoylesoftware.htmlunit.javascript.host.event;
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE;
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF;
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter;
/**
* JavaScript object representing a UI event. For general information on which properties and functions should be
* supported, see DOM Level 3 Events.
*
* @author Daniel Gredler
* @author Ahmed Ashour
* @author Frank Danek
*/
@JsxClass
public class UIEvent extends Event {
/** Constant. */
@JsxConstant(FF)
public static final int SCROLL_PAGE_DOWN = 0x8000;
/** Constant. */
@JsxConstant(FF)
public static final short SCROLL_PAGE_UP = 0xFFFF8000;
/** Specifies some detail information about the event. */
private long detail_;
/** Whether or not the "meta" key was pressed during the firing of the event. */
private boolean metaKey_;
/**
* Creates a new UI event instance.
*/
@JsxConstructor({CHROME, FF, EDGE})
public UIEvent() {
}
/**
* Creates a new UI event instance.
*
* @param domNode the DOM node that triggered the event
* @param type the event type
*/
public UIEvent(final DomNode domNode, final String type) {
super(domNode, type);
}
/**
* Creates a new event instance.
* @param target the event target
* @param type the event type
*/
public UIEvent(final EventTarget target, final String type) {
super(target, type);
}
/**
* Returns some detail information about the event, depending on the event type. For mouse events,
* the detail property indicates how many times the mouse has been clicked in the same location for
* this event.
*
* @return some detail information about the event, depending on the event type
*/
@JsxGetter
public long getDetail() {
return detail_;
}
/**
* Sets the detail information for this event.
*
* @param detail the detail information for this event
*/
protected void setDetail(final long detail) {
detail_ = detail;
}
/**
* @return indicates if event propagation is stopped
*/
@Override
@JsxGetter
public boolean isCancelBubble() {
return super.isCancelBubble();
}
/**
* @param newValue indicates if event propagation is stopped
*/
@Override
@JsxSetter
public void setCancelBubble(final boolean newValue) {
super.setCancelBubble(newValue);
}
/**
* Returns the view from which the event was generated. In browsers, this is the originating window.
*
* @return the view from which the event was generated
*/
@JsxGetter
public Object getView() {
return getWindow();
}
/**
* Implementation of the DOM Level 3 Event method for initializing the UI event.
*
* @param type the event type
* @param bubbles can the event bubble
* @param cancelable can the event be canceled
* @param view the view to use for this event
* @param detail the detail to set for the event
*/
@JsxFunction({CHROME, FF, IE})
public void initUIEvent(
final String type,
final boolean bubbles,
final boolean cancelable,
final Object view,
final int detail) {
initEvent(type, bubbles, cancelable);
// Ignore the view parameter; we always use the window.
setDetail(detail);
}
/**
* Returns whether or not the "meta" key was pressed during the event firing.
* @return whether or not the "meta" key was pressed during the event firing
*/
@JsxGetter
public boolean getMetaKey() {
return metaKey_;
}
/**
* @param metaKey whether Meta has been pressed during this event or not
*/
protected void setMetaKey(final boolean metaKey) {
metaKey_ = metaKey;
}
}