use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class BrowserTab method createExampleWidgets.
/**
* Creates the "Example" widgets.
*/
@Override
void createExampleWidgets() {
/* Compute the widget style */
int style = getDefaultStyle();
if (borderButton.getSelection())
style |= SWT.BORDER;
if (webKitButton.getSelection())
style |= SWT.WEBKIT;
/* Create the example widgets */
try {
browser = new Browser(browserGroup, style);
} catch (SWTError e) {
// Probably missing browser
try {
browser = new Browser(browserGroup, style & ~(SWT.WEBKIT));
} catch (SWTError e2) {
// Unsupported platform
errorMessage = e.getMessage();
return;
}
MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
String resourceString = "WebKitNotFound";
dialog.setMessage(ControlExample.getResourceString(resourceString, e.getMessage()));
dialog.open();
}
if (lastUrl != null) {
browser.setUrl(lastUrl);
} else if (lastText != null) {
browser.setText(lastText);
} else {
StringBuilder sb = new StringBuilder(300);
try (InputStream htmlStream = ControlExample.class.getResourceAsStream("browser-content.html");
BufferedReader br = new BufferedReader(new InputStreamReader(htmlStream))) {
int read = 0;
while ((read = br.read()) != -1) sb.append((char) read);
} catch (IOException e) {
log(e.getMessage());
}
String text = sb.toString();
browser.setText(text);
}
lastText = lastUrl = null;
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Bug497705_BrowserDragDetect method main.
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Browser b = new Browser(shell, SWT.BORDER);
b.setText("TEXT");
final Label label2 = new Label(shell, SWT.BORDER);
// doesn't seem to have an effect.
setDrag(b);
setDrop(label2);
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_LocationListener_adapter_closeShell.
@Test
public void test_LocationListener_adapter_closeShell() {
Display display = Display.getCurrent();
Shell shell = new Shell(display);
Browser browser = new Browser(shell, SWT.NONE);
LocationAdapter adapter = new LocationAdapter() {
};
// shouldn't throw
browser.addLocationListener(adapter);
shell.close();
}
use of org.eclipse.swt.browser.Browser 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);
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_OpenWindow_Progress_Listener_ValidateEventOrder.
/**
* Validate event order : Child's visibility should come before progress completed event
*/
@Test
public void test_OpenWindow_Progress_Listener_ValidateEventOrder() {
AtomicBoolean windowOpenFired = new AtomicBoolean(false);
AtomicBoolean childCompleted = new AtomicBoolean(false);
AtomicBoolean visibilityShowed = new AtomicBoolean(false);
Shell childShell = new Shell(shell, SWT.None);
childShell.setText("Child shell");
childShell.setLayout(new FillLayout());
final Browser browserChild = new Browser(childShell, SWT.NONE);
browser.addOpenWindowListener(event -> {
event.browser = browserChild;
// Validate event order.
assertFalse("OpenWindowListenr should have been fired first", visibilityShowed.get() || childCompleted.get());
windowOpenFired.set(true);
});
browserChild.addVisibilityWindowListener(showAdapter(event -> {
childShell.open();
assertTrue("Child Visibility.show should have fired before progress completed", // Validate event order.
windowOpenFired.get() && !childCompleted.get());
visibilityShowed.set(true);
}));
browserChild.addProgressListener(completedAdapter(event -> {
assertTrue("Child's Progress Completed before parent's expected events", // Validate event order.
windowOpenFired.get() && visibilityShowed.get());
// Triggers test to finish.
childCompleted.set(true);
browserChild.setText("Child Browser!");
}));
shell.open();
browser.setText("<html>" + "<script type='text/javascript'>" + // opens child window.
"var newWin = window.open();" + "</script>\n" + "<body>This test uses javascript to open a new window.</body></html>");
boolean passed = waitForPassCondition(() -> windowOpenFired.get() && visibilityShowed.get() && childCompleted.get());
String errMsg = "\nTest timed out." + "\nExpected true for the below, but have:" + "\nWindoOpenFired:" + windowOpenFired.get() + "\nVisibilityShowed:" + visibilityShowed.get() + "\nChildCompleted:" + childCompleted.get();
assertTrue(errMsg, passed);
}
Aggregations