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();
}
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);
}
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);
}
Aggregations