use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HtmlPasswordInput method setAttributeNS.
/**
* {@inheritDoc}
*/
@Override
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners, notifyMutationObservers);
if ("value".equals(qualifiedName)) {
final SgmlPage page = getPage();
if (page != null && page.isHtmlPage()) {
int pos = 0;
if (!hasFeature(JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START)) {
pos = attributeValue.length();
}
setSelectionStart(pos);
setSelectionEnd(pos);
}
}
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HtmlTextInput method setAttributeNS.
/**
* {@inheritDoc}
*/
@Override
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners, notifyMutationObservers);
if ("value".equals(qualifiedName)) {
final SgmlPage page = getPage();
if (page != null && page.isHtmlPage()) {
int pos = 0;
if (!hasFeature(JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START)) {
pos = attributeValue.length();
}
setSelectionStart(pos);
setSelectionEnd(pos);
}
}
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class Document method createElement.
/**
* Creates a new element with the given tag name.
*
* @param tagName the tag name
* @return the new HTML element, or NOT_FOUND if the tag is not supported
*/
@JsxFunction
public Object createElement(String tagName) {
Object result = NOT_FOUND;
try {
if (tagName.contains("<") || tagName.contains(">")) {
if (LOG.isInfoEnabled()) {
LOG.info("createElement: Provided string '" + tagName + "' contains an invalid character; '<' and '>' are not allowed");
}
throw Context.reportRuntimeError("String contains an invalid character");
} else if (tagName.length() > 0 && tagName.charAt(0) == '<' && tagName.endsWith(">")) {
tagName = tagName.substring(1, tagName.length() - 1);
final Matcher matcher = TAG_NAME_PATTERN.matcher(tagName);
if (!matcher.matches()) {
if (LOG.isInfoEnabled()) {
LOG.info("createElement: Provided string '" + tagName + "' contains an invalid character");
}
throw Context.reportRuntimeError("String contains an invalid character");
}
}
final SgmlPage page = getPage();
org.w3c.dom.Node element = page.createElement(tagName);
if (element instanceof HtmlInput) {
((HtmlInput) element).markAsCreatedByJavascript();
} else if (element instanceof HtmlImage) {
((HtmlImage) element).markAsCreatedByJavascript();
} else if (element instanceof HtmlRp) {
((HtmlRp) element).markAsCreatedByJavascript();
} else if (element instanceof HtmlRt) {
((HtmlRt) element).markAsCreatedByJavascript();
} else if (element instanceof HtmlUnknownElement) {
((HtmlUnknownElement) element).markAsCreatedByJavascript();
} else if (element instanceof HtmlSvg) {
element = UnknownElementFactory.instance.createElementNS(page, "", "svg", null);
((HtmlUnknownElement) element).markAsCreatedByJavascript();
}
final Object jsElement = getScriptableFor(element);
if (jsElement == NOT_FOUND) {
if (LOG.isDebugEnabled()) {
LOG.debug("createElement(" + tagName + ") cannot return a result as there isn't a JavaScript object for the element " + element.getClass().getName());
}
} else {
result = jsElement;
}
} catch (final ElementNotFoundException e) {
// Just fall through - result is already set to NOT_FOUND
}
return result;
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class NamedAttrNodeMapImpl method doMouseEvent.
/**
* Simulates the specified mouse event, returning the page which this element's window contains after the event.
* The returned page may or may not be the same as the original page, depending on JavaScript event handlers, etc.
*
* @param eventType the mouse event type to simulate
* @param shiftKey {@code true} if SHIFT is pressed during the mouse event
* @param ctrlKey {@code true} if CTRL is pressed during the mouse event
* @param altKey {@code true} if ALT is pressed during the mouse event
* @param button the button code, must be {@link MouseEvent#BUTTON_LEFT}, {@link MouseEvent#BUTTON_MIDDLE}
* or {@link MouseEvent#BUTTON_RIGHT}
* @return the page which this element's window contains after the event
*/
private Page doMouseEvent(final String eventType, final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) {
final SgmlPage page = getPage();
if (!page.getWebClient().isJavaScriptEnabled()) {
return page;
}
final ScriptResult scriptResult;
final Event event;
if (MouseEvent.TYPE_CONTEXT_MENU.equals(eventType) && getPage().getWebClient().getBrowserVersion().hasFeature(EVENT_ONCLICK_USES_POINTEREVENT)) {
event = new PointerEvent(this, eventType, shiftKey, ctrlKey, altKey, button, 0);
} else {
event = new MouseEvent(this, eventType, shiftKey, ctrlKey, altKey, button);
}
scriptResult = fireEvent(event);
final Page currentPage;
if (scriptResult == null) {
currentPage = page;
} else {
currentPage = page.getWebClient().getCurrentWindow().getEnclosedPage();
}
final boolean mouseOver = !MouseEvent.TYPE_MOUSE_OUT.equals(eventType);
if (mouseOver_ != mouseOver) {
mouseOver_ = mouseOver;
page.clearComputedStyles();
}
return currentPage;
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class NamedAttrNodeMapImpl method click.
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
* Simulates clicking on this element, returning the page in the window that has the focus
* after the element has been clicked. Note that the returned page may or may not be the same
* as the original page, depending on the type of element being clicked, the presence of JavaScript
* action listeners, etc.
*
* @param event the click event used
* @param shiftKey {@code true} if SHIFT is pressed during the click
* @param ctrlKey {@code true} if CTRL is pressed during the click
* @param altKey {@code true} if ALT is pressed during the click
* @param ignoreVisibility whether to ignore visibility or not
* @param <P> the page type
* @return the page contained in the current window as returned by {@link WebClient#getCurrentWindow()}
* @exception IOException if an IO error occurs
*/
@SuppressWarnings("unchecked")
public <P extends Page> P click(final Event event, final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final boolean ignoreVisibility) throws IOException {
final SgmlPage page = getPage();
if ((!ignoreVisibility && !isDisplayed()) || isDisabledElementAndDisabled()) {
return (P) page;
}
if (!page.getWebClient().isJavaScriptEnabled()) {
doClickStateUpdate(shiftKey, ctrlKey);
page.getWebClient().loadDownloadedResponses();
return (P) getPage().getWebClient().getCurrentWindow().getEnclosedPage();
}
// may be different from page when working with "orphaned pages"
// (ex: clicking a link in a page that is not active anymore)
final Page contentPage = page.getEnclosingWindow().getEnclosedPage();
boolean stateUpdated = false;
boolean changed = false;
if (isStateUpdateFirst()) {
changed = doClickStateUpdate(shiftKey, ctrlKey);
stateUpdated = true;
}
final AbstractJavaScriptEngine<?> jsEngine = page.getWebClient().getJavaScriptEngine();
jsEngine.holdPosponedActions();
try {
final ScriptResult scriptResult = doClickFireClickEvent(event);
final boolean eventIsAborted = event.isAborted(scriptResult);
final boolean pageAlreadyChanged = contentPage != page.getEnclosingWindow().getEnclosedPage();
if (!pageAlreadyChanged && !stateUpdated && !eventIsAborted) {
changed = doClickStateUpdate(shiftKey, ctrlKey);
}
} finally {
jsEngine.processPostponedActions();
}
if (changed) {
doClickFireChangeEvent();
}
return (P) getPage().getWebClient().getCurrentWindow().getEnclosedPage();
}
Aggregations