Search in sources :

Example 1 with Document

use of elemental2.dom.Document in project gwtproject by treblereel.

the class FormPanelTest method testWrappedForm.

public void testWrappedForm() {
    // Create a form and frame in the document we can wrap.
    final String iframeId = Document.get().createUniqueId();
    final String iframeName = Document.get().createUniqueId();
    final Element container = Document.get().createDivElement();
    container.setInnerHTML("<form method='post' target='" + iframeName + "' action='" + "formHandler?sendHappyHtml'>" + "<input type='hidden' name='foo' value='bar'></input></form>" + "<iframe src=\"javascript:\'\'\" id='" + iframeId + "' " + "name='" + iframeName + "'></iframe>");
    Document.get().getBody().appendChild(container);
    // Wrap the form and make sure its target frame is intact.
    FormPanel form = FormPanel.wrap(container.getFirstChildElement());
    assertEquals(iframeName, form.getTarget());
    // Ensure that no synthesized iframe was created.
    assertNull(form.getSynthesizedIFrame());
    // Submit the form and make sure the target frame comes back with the right
    // stuff (give it 2.5 s to complete).
    delayTestFinish(TEST_DELAY);
    form.submit();
    new Timer() {

        @Override
        public void run() {
            // Get the targeted frame and make sure it contains the requested
            // 'happyElem'.
            Frame frame = Frame.wrap(Document.get().getElementById(iframeId));
            assertTrue(isHappyDivPresent(frame.getElement()));
            finishTest();
        }
    }.schedule(TEST_DELAY - 2000);
}
Also used : Timer(org.gwtproject.timer.client.Timer) HTMLIFrameElement(elemental2.dom.HTMLIFrameElement) InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element)

Example 2 with Document

use of elemental2.dom.Document in project gwtproject by treblereel.

the class FormPanelTest method testWrappedFormWithIFrame.

public void testWrappedFormWithIFrame() {
    // Create a form and frame in the document we can wrap.
    final Element container = Document.get().createDivElement();
    container.setInnerHTML("<form method='get' " + "encoding='application/x-www-form-urlencoded' action='" + "formHandler'>" + "<input type='text' name='tb' value='text'></input></form>");
    Document.get().getBody().appendChild(container);
    // Wrap the form, asking for an iframe to be created.
    FormPanel form = FormPanel.wrap(container.getFirstChildElement(), true);
    // Give the submit 5s to complete.
    delayTestFinish(TEST_DELAY);
    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {
            // Make sure we get our results back.
            assertTrue(event.getResults().equals("tb=text"));
            finishTest();
        }
    });
    form.submit();
}
Also used : HTMLIFrameElement(elemental2.dom.HTMLIFrameElement) InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) SubmitCompleteEvent(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler)

Example 3 with Document

use of elemental2.dom.Document in project gwtproject by treblereel.

the class Element method isRTLSafari.

@JsOverlay
private boolean isRTLSafari() {
    HTMLElement e = Js.uncheckedCast(this);
    // TODO when Document has defaultView, clean this up
    // TODO also see about not referencing a class which doesn't exist in the browser (ViewCSS)
    ViewCSS defaultView = Js.uncheckedCast(Js.<JsPropertyMap<?>>uncheckedCast(e.ownerDocument).get("defaultView"));
    return Objects.equals(defaultView.getComputedStyle(e, "").direction, "rtl");
}
Also used : HTMLElement(elemental2.dom.HTMLElement) ViewCSS(elemental2.dom.ViewCSS) JsPropertyMap(jsinterop.base.JsPropertyMap) JsOverlay(jsinterop.annotations.JsOverlay)

Example 4 with Document

use of elemental2.dom.Document in project gwtproject by treblereel.

the class RichTextAreaImplStandard method execCommandAssumingFocus.

void execCommandAssumingFocus(String cmd, String param) {
    HTMLIFrameElement iframe = Js.uncheckedCast(elem);
    Document document = Js.uncheckedCast(Js.asPropertyMap(iframe.contentWindow).get("document"));
    ((ExecCommand) Js.uncheckedCast(Js.asPropertyMap(document).get("execCommand"))).onInvoke(cmd, false, param);
}
Also used : HTMLIFrameElement(elemental2.dom.HTMLIFrameElement) Document(org.gwtproject.dom.client.Document)

Example 5 with Document

use of elemental2.dom.Document in project gwtproject by treblereel.

the class RichTextAreaImplStandard method initElement.

@Override
public void initElement() {
    // Most browsers don"t like setting designMode until slightly _after_
    // the iframe becomes attached to the DOM. Any non-zero timeout will do
    // just fine.
    RichTextAreaImplStandard _this = this;
    _this.onElementInitializing();
    DomGlobal.setTimeout((ignore) -> {
        if (_this.elem != null) {
            HTMLIFrameElement iframe = Js.uncheckedCast(_this.elem);
            if (iframe.contentWindow != null) {
                ((JsPropertyMap) ((JsPropertyMap) iframe.contentWindow).get("document")).set("designMode", "On");
                _this.onElementInitialized();
            }
        }
    }, 1.0D, new Object[0]);
}
Also used : HTMLIFrameElement(elemental2.dom.HTMLIFrameElement) JsPropertyMap(jsinterop.base.JsPropertyMap)

Aggregations

Document (org.apache.tapestry5.dom.Document)20 Test (org.testng.annotations.Test)17 PageTester (org.apache.tapestry5.test.PageTester)11 Test (org.junit.Test)10 HTMLDocument (elemental2.dom.HTMLDocument)9 HTMLElement (elemental2.dom.HTMLElement)9 HTMLIFrameElement (elemental2.dom.HTMLIFrameElement)9 HTMLBodyElement (elemental2.dom.HTMLBodyElement)5 Element (elemental2.dom.Element)4 Element (org.apache.tapestry5.dom.Element)4 DOMTokenList (elemental2.dom.DOMTokenList)3 JsPropertyMap (jsinterop.base.JsPropertyMap)3 Document (org.gwtproject.dom.client.Document)3 Element (org.gwtproject.dom.client.Element)3 InputElement (org.gwtproject.dom.client.InputElement)3 Document (elemental2.dom.Document)2 File (elemental2.dom.File)2 Window (elemental2.dom.Window)2 Field (java.lang.reflect.Field)2 List (java.util.List)2