Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Browser Widget broken?
Browser Widget broken? [message #446185] Fri, 19 November 2004 16:36 Go to next message
Kalman Hazins is currently offline Kalman HazinsFriend
Messages: 76
Registered: July 2009
Member
Hi, group.

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 display everything fine.

Any ideas?

Thanx,
- Kalman

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@zikal.com) (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";

}
}
Re: Browser Widget broken? [message #446245 is a reply to message #446185] Mon, 22 November 2004 15:21 Go to previous messageGo to next message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
Hi Kalman,

You should comment out the meta charset tag in the snippet below:
"<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\">\n" +

The javadoc of Browser.setText explains why:
* The html parameter is Unicode encoded since it is a java
<code>String</code>.
* As a result, the HTML meta tag charset should not be set. The charset is
implied
* by the <code>String</code> itself.

If this does not fix it for you, please open a bug report.

Thanks,
Chris
Re: Browser Widget broken? [message #446247 is a reply to message #446245] Mon, 22 November 2004 15:40 Go to previous message
Kalman Hazins is currently offline Kalman HazinsFriend
Messages: 76
Registered: July 2009
Member
This seems to fix the problem!

Thanx,
- Kalman

"Christophe Cornu" <christophe_cornu@ca.ibm.com> wrote in message
news:cnt06u$ke6$1@www.eclipse.org...
> Hi Kalman,
>
> You should comment out the meta charset tag in the snippet below:
> "<meta http-equiv=\"Content-Type\" content=\"text/html;
> charset=iso-8859-1\">\n" +
>
> The javadoc of Browser.setText explains why:
> * The html parameter is Unicode encoded since it is a java
> <code>String</code>.
> * As a result, the HTML meta tag charset should not be set. The charset
is
> implied
> * by the <code>String</code> itself.
>
> If this does not fix it for you, please open a bug report.
>
> Thanks,
> Chris
>
>
Previous Topic:How to SWT TableColumn remove
Next Topic:Why is SWT.SMOOTH not possible in a SashForm?
Goto Forum:
  


Current Time: Fri Apr 26 19:41:34 GMT 2024

Powered by FUDForum. Page generated in 0.03148 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top