default HTMLElement createElement(String tagName, Consumer<HTMLElement> consumer) { HTMLElement result = createElement(tagName); consumer.accept(result); return result; }
default HTMLElement withText(String content) { clear().appendChild(getOwnerDocument().createTextNode(content)); return this; }
private static void showModal(PopupContent content, final AsyncCallback<Void> callback) { final Popup popup = new Popup(Templates.create(content)); popup.wrapper = document.createElement("div"); document.getBody().appendChild(popup.wrapper); popup.component = Templates.bind(popup, popup.wrapper); popup.callback = callback; content.setDelegate(popup::close); } }
public void dropDown() { if (dropDownElement != null) { return; } dropDownElement = HTMLDocument.current().createElement("div"); dropDownElement.setAttribute("class", "flavour-dropdown flavour-dropdown-calendar"); TextRectangle windowRect = HTMLDocument.current().getBody().getBoundingClientRect(); TextRectangle inputRect = target.getElement().getBoundingClientRect(); dropDownElement.getStyle().setProperty("right", windowRect.getWidth() - inputRect.getRight() + "px"); dropDownElement.getStyle().setProperty("top", inputRect.getBottom() + "px"); CalendarDropDown dropDown = new CalendarDropDown(this::parseValue, newValue -> { closeDropDown(); target.updateValue(cachedFormatObject.format(newValue)); }); dropDownComponent = Templates.bind(dropDown, dropDownElement); HTMLDocument.current().getBody().appendChild(dropDownElement); Window.setTimeout(() -> HTMLDocument.current().addEventListener("click", bodyListener), 0); }
public void InjectScript(String scriptText) { HTMLDocument htmlDocument = (HTMLDocument)WebBrowserControl.Document; var headElements = htmlDocument.getElementsByTagName("head"); if (headElements.length == 0) { throw new IndexOutOfRangeException("No element with tag 'head' has been found in the document"); } var headElement = headElements.item(0); IHTMLScriptElement script = (IHTMLScriptElement)htmlDocument.createElement("script"); script.text = scriptText; headElement.AppendChild(script); }
private void closeDropDown() { HTMLDocument.current().getBody().removeChild(dropDownElement); HTMLDocument.current().removeEventListener("click", bodyListener); dropDownComponent.destroy(); dropDownElement = null; dropDownComponent = null; }
public void bind(String id) { bind(HTMLDocument.current().getElementById(id)); } }
Document doc = ???; HTMLDocument htmlDoc = (HTMLDocument)doc; final HTMLBodyElement body = (HTMLBodyElement)htmlDoc.getBody(); //JS [window] access DOMWindowImpl wnd = (DOMWindowImpl)((DocumentView)htmlDoc).getDefaultView(); //Style access CSSStyleDeclaration style = wnd.getComputedStyle(body, ""); assertEquals("Style extraction", "blue", style.getPropertyValue("background-color"));
public static Component bind(Object model, String id) { return bind(model, Window.current().getDocument().getElementById(id)); }
private void hookEvents() { HTMLDocument document = canvas.getOwnerDocument(); canvas.addEventListener("mousedown", this, true); document.addEventListener("mousedown", this, true); canvas.addEventListener("mouseup", this, true); document.addEventListener("mouseup", this, true); canvas.addEventListener("mousemove", this, true); document.addEventListener("mousemove", this, true); canvas.addEventListener("mousewheel", this, true); document.addEventListener("keydown", this, false); document.addEventListener("keyup", this, false); document.addEventListener("keypress", this, false); canvas.addEventListener("touchstart", this); canvas.addEventListener("touchmove", this); canvas.addEventListener("touchcancel", this); canvas.addEventListener("touchend", this); }
private void create(int width, int height, @SuppressWarnings("unused") Pixmap.Format format2) { this.width = width; this.height = height; this.format = Format.RGBA8888; canvas = (HTMLCanvasElement) document.createElement("canvas"); canvas.getStyle().setProperty("display", "none"); document.getBody().appendChild(canvas); canvas.setWidth(width); canvas.setHeight(height); context = (CanvasRenderingContext2D) canvas.getContext("2d"); context.setGlobalCompositeOperation("source-over"); id = nextId++; pixmaps.put(id, this); }
public static Component bind(Object model, String id) { return bind(model, Window.current().getDocument().getElementById(id)); }
public TeaVMMusic(TeaVMFileHandle file) { element = (HTMLAudioElement)window.getDocument().createElement("audio"); element.setSrc("assets/" + file.path()); element.addEventListener("ended", (EventListener) evt -> { if (listener != null) { listener.onCompletion(TeaVMMusic.this); } }); window.getDocument().getBody().appendChild(element); }
default HTMLElement withChild(String tagName, Consumer<HTMLElement> consumer) { HTMLElement result = getOwnerDocument().createElement(tagName); appendChild(result); consumer.accept(result); return this; }
@Override public void render() { T computedValue = value.get(); if (cacheInitialized && Objects.equals(cachedValue, computedValue)) { return; } cacheInitialized = true; cachedValue = computedValue; if (textSlot != null) { textSlot.delete(); textSlot = null; } textSlot = new NodeHolder(Window.current().getDocument().createTextNode(String.valueOf(computedValue))); getSlot().append(textSlot); } }
@Override public void run(TaskHandler handler) { this.handler = handler; HTMLImageElement image = (HTMLImageElement)window.getDocument().createElement("img"); window.getDocument().getBody().appendChild(image); image.getStyle().setProperty("display", "none"); image.setSrc(path); image.addEventListener("load", this); entry.imageElem = image; } @Override
default HTMLElement withChild(String tagName) { HTMLElement result = getOwnerDocument().createElement(tagName); appendChild(result); return this; }
@Override public void render() { T computedValue = value.get(); if (cacheInitialized && Objects.equals(cachedValue, computedValue)) { return; } cacheInitialized = true; cachedValue = computedValue; if (textSlot != null) { textSlot.delete(); textSlot = null; } textSlot = new NodeHolder(Window.current().getDocument().createTextNode(String.valueOf(computedValue))); getSlot().append(textSlot); } }
private const string DisableScriptError = @"function noError() { return true;} window.onerror = noError;"; private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) { InjectDisableScript(); } private void InjectDisableScript() { HTMLDocumentClass doc = webBrowser1.Document as HTMLDocumentClass; HTMLDocument doc2 = webBrowser1.Document as HTMLDocument; IHTMLScriptElement scriptErrorSuppressed = (IHTMLScriptElement)doc2.createElement("SCRIPT"); scriptErrorSuppressed.type = "text/javascript"; scriptErrorSuppressed.text = DisableScriptError; IHTMLElementCollection nodes = doc.getElementsByTagName("head"); foreach (IHTMLElement elem in nodes) { HTMLHeadElementClass head = (HTMLHeadElementClass)elem; head.appendChild((IHTMLDOMNode)scriptErrorSuppressed); } }