Search in sources :

Example 1 with OpenWindowListener

use of org.eclipse.swt.browser.OpenWindowListener in project eclipse.platform.text by eclipse.

the class BrowserInformationControl method createContent.

@Override
protected void createContent(Composite parent) {
    fBrowser = new Browser(parent, SWT.NONE);
    fBrowser.setJavascriptEnabled(false);
    Display display = getShell().getDisplay();
    fBrowser.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    fBrowser.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    fBrowser.addProgressListener(new ProgressAdapter() {

        @Override
        public void completed(ProgressEvent event) {
            fCompleted = true;
        }
    });
    fBrowser.addOpenWindowListener(new OpenWindowListener() {

        @Override
        public void open(WindowEvent event) {
            // Cancel opening of new windows
            event.required = true;
        }
    });
    // Replace browser's built-in context menu with none
    fBrowser.setMenu(new Menu(getShell(), SWT.NONE));
    createTextLayout();
}
Also used : WindowEvent(org.eclipse.swt.browser.WindowEvent) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Menu(org.eclipse.swt.widgets.Menu) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) Browser(org.eclipse.swt.browser.Browser) Display(org.eclipse.swt.widgets.Display)

Example 2 with OpenWindowListener

use of org.eclipse.swt.browser.OpenWindowListener in project translationstudio8 by heartsome.

the class BrowserTab method hookOpenListner.

public void hookOpenListner() {
    openLisenter = new OpenWindowListener() {

        @Override
        public void open(WindowEvent event) {
            event.required = true;
            BrowserComponent app = new BrowserComponent(false);
            event.browser = app.getBrowser();
        }
    };
    browser.addOpenWindowListener(openLisenter);
}
Also used : WindowEvent(org.eclipse.swt.browser.WindowEvent) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener)

Example 3 with OpenWindowListener

use of org.eclipse.swt.browser.OpenWindowListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_VisibilityWindowListener_eventSize.

/**
 *  Validate that when javascript opens a new window and specifies size,
 *  it's size is passed to the visibility event correctly.
 */
@Test
public void test_VisibilityWindowListener_eventSize() {
    shell.setSize(200, 300);
    AtomicBoolean childCompleted = new AtomicBoolean(false);
    AtomicReference<Point> result = new AtomicReference<>(new Point(0, 0));
    Shell childShell = new Shell(shell);
    childShell.setSize(250, 350);
    childShell.setText("Child shell");
    childShell.setLayout(new FillLayout());
    final Browser browserChild = new Browser(childShell, SWT.NONE);
    browser.addOpenWindowListener(event -> {
        event.browser = browserChild;
        testLog.append("openWindowListener fired");
    });
    browserChild.addVisibilityWindowListener(showAdapter(event -> {
        testLog.append("Visibilty show eventfired.\nEvent size: " + event.size);
        result.set(event.size);
        childShell.open();
        childCompleted.set(true);
    }));
    shell.open();
    browser.setText("<html>" + "<script type='text/javascript'>" + "window.open('javascript:\"Child Window\"','', \"height=200,width=300\")\n" + "</script>\n" + "<body>This test uses javascript to open a new window.</body></html>");
    boolean finishedWithoutTimeout = waitForPassCondition(() -> childCompleted.get());
    browserChild.dispose();
    boolean passed = false;
    if (isWebkit1 || SwtTestUtil.isCocoa) {
        // On webkit1, event.size doesn't work properly. Fields are differently. Solution: Webkit2.
        // On Cocoa, event height/width aren't respected if declared by javascript.
        passed = finishedWithoutTimeout && result.get().x != 0 && result.get().y != 0;
    } else
        passed = finishedWithoutTimeout && result.get().x == 300 && result.get().y == 200;
    String errMsg = finishedWithoutTimeout ? "Incorrect size received:" + "\nexpected width=300, actual:" + result.get().x + "\nexpected height=100, actual:" + result.get().y : "test timed out. Child's visibility Window listener didn't trigger";
    assertTrue(errMsg + testLog.toString(), passed);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) URL(java.net.URL) Assume.assumeFalse(org.junit.Assume.assumeFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) TitleListener(org.eclipse.swt.browser.TitleListener) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Point(org.eclipse.swt.graphics.Point) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) TestName(org.junit.rules.TestName) LocationListener.changedAdapter(org.eclipse.swt.browser.LocationListener.changedAdapter) VisibilityWindowListener.showAdapter(org.eclipse.swt.browser.VisibilityWindowListener.showAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressListener.completedAdapter(org.eclipse.swt.browser.ProgressListener.completedAdapter) Assert.fail(org.junit.Assert.fail) SWTException(org.eclipse.swt.SWTException) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Before(org.junit.Before) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) LocationListener.changingAdapter(org.eclipse.swt.browser.LocationListener.changingAdapter) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) LocationEvent(org.eclipse.swt.browser.LocationEvent) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Shell(org.eclipse.swt.widgets.Shell) AtomicReference(java.util.concurrent.atomic.AtomicReference) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Aggregations

OpenWindowListener (org.eclipse.swt.browser.OpenWindowListener)3 WindowEvent (org.eclipse.swt.browser.WindowEvent)3 Browser (org.eclipse.swt.browser.Browser)2 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)2 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)2 Display (org.eclipse.swt.widgets.Display)2 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Instant (java.time.Instant)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AtomicReferenceArray (java.util.concurrent.atomic.AtomicReferenceArray)1 Supplier (java.util.function.Supplier)1 SWT (org.eclipse.swt.SWT)1 SWTException (org.eclipse.swt.SWTException)1 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)1