I posted this on the SWT newsgroup, but did not get any replies. Maybe
someone here can help me … Thanx, - Kalman.
Below is a simple class that shows how the browser widget can easily be
broken. I am assuming it has something to do with OLE,
because Internet
Explorer displays everything fine.
Any ideas?
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
* Browser Widget becomes broken (doesn't properly render HTML code) the
second time "Add" button is hit.
*
* I tried saving broken html code to a regular html file and that
displays
fine.
* I also validated the produced code against an HTML validator
*
* I believe the bug has something to do with using
<code>class</code>
attribute inside the <code>span</code> tag
*
* @author kalman hazins (kalman@xxxxxxxxx)
(November, 19th)
*
*/
public class BrowserBroken {
public static String textSoFar =
getDoctypeStuff() + "</body></html>";
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Broken Browser");
shell.setLayout(new GridLayout(2, true));
final Browser browser
= new Browser(shell, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 500;
gd.widthHint = 500;
gd.horizontalSpan = 2;
browser.setLayoutData(gd);
Label hitButton = new Label(shell, SWT.NONE);
hitButton.setText("Please, press the
\"Add\" button");
Button buttonAdd = new Button(shell, SWT.PUSH);
buttonAdd.setText("Add");
buttonAdd.addSelectionListener(new
SelectionAdapter() {
public void widgetSelected(SelectionEvent
e) {
for (int i = 0; i < 20; i++) {
int insertAt =
textSoFar.lastIndexOf("</body>");
StringBuffer buffer = new StringBuffer(textSoFar);
String input = "The browser will be broken the
next time you hit the
\"Add\" button";
buffer.insert(insertAt,
"\n<span class=\"headerText\">" + input +
"</span><br>");
textSoFar =
buffer.toString();
browser.setText(textSoFar);
}
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
private static String getDoctypeStuff() {
return "<!DOCTYPE HTML PUBLIC
\"-//W3C//DTD HTML 4.01
Transitional//EN\">\n" +
"<html>\n"
+
"<head>\n"
+
"<title>Case
Folder</title>\n" +
"<meta
http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\">\n" +
"<style
type=\"text/css\">\n" +
".headerText {font-family: Tahoma;\n" +
" font-size: 10px;\n" +
" font-style: normal;\n" +
" color: #0A246A;\n" +
"}\n" +
"</style>\n" +
"</head>\n" +
"<body>\n";
}
}