Search in sources :

Example 1 with WindowEvent

use of org.eclipse.swt.browser.WindowEvent 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 WindowEvent

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

the class Test_org_eclipse_swt_browser_Browser method test_VisibilityWindowListener_multiple_shells.

/**
 * Verify that if multiple child shells are open, no duplicate visibility events are sent.
 */
@Test
public void test_VisibilityWindowListener_multiple_shells() {
    AtomicBoolean secondChildCompleted = new AtomicBoolean(false);
    AtomicInteger childCount = new AtomicInteger(0);
    browser.addOpenWindowListener(event -> {
        Shell childShell = new Shell(shell);
        childShell.setText("Child shell " + childCount.get());
        childShell.setLayout(new FillLayout());
        Browser browserChild = new Browser(childShell, SWT.NONE);
        event.browser = browserChild;
        browserChild.setText("Child window");
        browserChild.addVisibilityWindowListener(new VisibilityWindowAdapter() {

            AtomicInteger invocationCount = new AtomicInteger(1);

            AtomicInteger childID = new AtomicInteger(childCount.get());

            @Override
            public void show(WindowEvent event) {
                if (childID.get() == 0 && invocationCount.get() >= 2) {
                    // are considered 'legal' as long as they don't contain size and location information.
                    if (event.location != null || event.size != null) {
                        fail("Child browser's visibility show listener should only be fired once");
                    }
                }
                invocationCount.incrementAndGet();
            }
        });
        if (childCount.get() == 1) {
            browserChild.addProgressListener(new ProgressAdapter() {

                @Override
                public void completed(ProgressEvent event) {
                    secondChildCompleted.set(true);
                }
            });
        }
        childShell.open();
        childCount.incrementAndGet();
    });
    shell.open();
    browser.setText("<html>" + "<script type='text/javascript'>" + // opens child window.
    "window.open();" + "window.open();" + "</script>\n" + "<body>This test uses javascript to open a new window.</body></html>");
    boolean passed = waitForPassCondition(() -> secondChildCompleted.get());
    String errMsg = "\nTest timed out.";
    assertTrue(errMsg, passed);
}
Also used : VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Shell(org.eclipse.swt.widgets.Shell) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WindowEvent(org.eclipse.swt.browser.WindowEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 3 with WindowEvent

use of org.eclipse.swt.browser.WindowEvent 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 4 with WindowEvent

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

the class Test_org_eclipse_swt_browser_Browser method test_VisibilityWindowListener_newListener_closeShell.

@Test
public void test_VisibilityWindowListener_newListener_closeShell() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    Browser browser = new Browser(shell, SWT.NONE);
    browser.addVisibilityWindowListener(new VisibilityWindowListener() {

        @Override
        public void hide(WindowEvent event) {
        }

        @Override
        public void show(WindowEvent event) {
        }
    });
    shell.close();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) WindowEvent(org.eclipse.swt.browser.WindowEvent) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Aggregations

WindowEvent (org.eclipse.swt.browser.WindowEvent)4 Browser (org.eclipse.swt.browser.Browser)3 OpenWindowListener (org.eclipse.swt.browser.OpenWindowListener)2 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)2 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)2 Display (org.eclipse.swt.widgets.Display)2 Shell (org.eclipse.swt.widgets.Shell)2 Test (org.junit.Test)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 VisibilityWindowAdapter (org.eclipse.swt.browser.VisibilityWindowAdapter)1 VisibilityWindowListener (org.eclipse.swt.browser.VisibilityWindowListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Menu (org.eclipse.swt.widgets.Menu)1