use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HtmlForm method reset.
/**
* Resets this form to its initial values, returning the page contained by this form's window after the
* reset. Note that the returned page may or may not be the same as the original page, based on JavaScript
* event handlers, etc.
*
* @return the page contained by this form's window after the reset
*/
public Page reset() {
final SgmlPage htmlPage = getPage();
final ScriptResult scriptResult = fireEvent(Event.TYPE_RESET);
if (ScriptResult.isFalse(scriptResult)) {
return htmlPage.getWebClient().getCurrentWindow().getEnclosedPage();
}
for (final HtmlElement next : getHtmlElementDescendants()) {
if (next instanceof SubmittableElement) {
((SubmittableElement) next).reset();
}
}
return htmlPage;
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HtmlNumberInput 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 Range method createContextualFragment.
/**
* Parses an HTML snippet.
* @param valueAsString text that contains text and tags to be converted to a document fragment
* @return a document fragment
* @see <a href="https://developer.mozilla.org/en-US/docs/DOM/range.createContextualFragment">Mozilla
* documentation</a>
*/
@JsxFunction
public Object createContextualFragment(final String valueAsString) {
final SgmlPage page = startContainer_.getDomNodeOrDie().getPage();
final DomDocumentFragment fragment = new DomDocumentFragment(page);
try {
page.getWebClient().getPageCreator().getHtmlParser().parseFragment(fragment, startContainer_.getDomNodeOrDie(), valueAsString, false);
} catch (final Exception e) {
LogFactory.getLog(Range.class).error("Unexpected exception occurred in createContextualFragment", e);
throw Context.reportRuntimeError("Unexpected exception occurred in createContextualFragment: " + e.getMessage());
}
return fragment.getScriptableObject();
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HTMLAnchorElement method getDefaultValue.
static String getDefaultValue(final HtmlElement element) {
String href = element.getAttributeDirect("href");
if (ATTRIBUTE_NOT_DEFINED == href) {
// for example for named anchors
return "";
}
href = href.trim();
final SgmlPage page = element.getPage();
if (page == null || !page.isHtmlPage()) {
return href;
}
try {
return HtmlAnchor.getTargetUrl(href, (HtmlPage) page).toExternalForm();
} catch (final MalformedURLException e) {
return href;
}
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HTMLInputElement method setType.
/**
* Sets the value of the attribute {@code type}.
* Note: this replace the DOM node with a new one.
* @param newType the new type to set
* @param setThroughAttribute set type value through setAttribute()
*/
private void setType(String newType, final boolean setThroughAttribute) {
HtmlInput input = getDomNodeOrDie();
final String currentType = input.getAttributeDirect("type");
final BrowserVersion browser = getBrowserVersion();
if (!currentType.equalsIgnoreCase(newType)) {
if (newType != null && browser.hasFeature(JS_INPUT_SET_TYPE_LOWERCASE)) {
newType = newType.toLowerCase(Locale.ROOT);
}
if (!isSupported(newType.toLowerCase(Locale.ROOT), browser)) {
if (setThroughAttribute) {
newType = "text";
} else if (browser.hasFeature(JS_INPUT_SET_UNSUPORTED_TYPE_EXCEPTION)) {
throw Context.reportRuntimeError("Invalid argument '" + newType + "' for setting property type.");
}
}
final AttributesImpl attributes = readAttributes(input);
final int index = attributes.getIndex("type");
if (index > -1) {
attributes.setValue(index, newType);
} else {
attributes.addAttribute(null, "type", "type", null, newType);
}
// create a new one only if we have a new type
if (ATTRIBUTE_NOT_DEFINED != currentType || !"text".equalsIgnoreCase(newType)) {
final SgmlPage page = input.getPage();
final HtmlInput newInput = (HtmlInput) page.getWebClient().getPageCreator().getHtmlParser().getFactory(HtmlInput.TAG_NAME).createElement(page, HtmlInput.TAG_NAME, attributes);
if (input.wasCreatedByJavascript()) {
newInput.markAsCreatedByJavascript();
}
if (input.getParentNode() == null) {
// the input hasn't yet been inserted into the DOM tree (likely has been
// created via document.createElement()), so simply replace it with the
// new Input instance created in the code above
input = newInput;
} else {
input.getParentNode().replaceChild(newInput, input);
}
input.setScriptableObject(null);
setDomNode(newInput, true);
} else {
super.setAttribute("type", newType);
}
}
}
Aggregations