Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different rendering in SWT Browser with setText and setUrl

Tags:

css

eclipse

swt

I'm trying to write an Eclipse plugin that displays some information as an HTML page. For this I want to use SWT Browser widget. The problem is that when I set browser's content via setText, nth-child selectors do not work, but when I set the exact same content via setUrl("file://..., they work correctly. Why the rendering is different and how can I achieve the same rendering with setText as with setUrl?

I'm creating the Browser with SWT.NONE, since I do not want to force users to install Safari or Firefox.

This is the HTML where the problem is reproducible:

<!doctype html><html><head>
<style type="text/css">
    div:nth-child(2n) { background-color: #f00; }
</style>
</head><body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
</body></html>
like image 484
Fixpoint Avatar asked May 19 '12 10:05

Fixpoint


1 Answers

Having used the browser's setText() method extensively, I've not seen any behavior like what you're describing.

Is it possible that this is a local intranet quirks-mode / compatibility mode issue? IE defaults its rendering engine differently based on the source of the content - and, by default, it behaves differently when rendering intranet content versus internet content (and content on your local filesystem is treated as intranet content.) That's my recollection anyway, all I remember for sure is that there's a fair amount of voodoo unless you explicitly set the compatibility header.

Does adding the following meta tag change the behavior?

<meta http-equiv="X-UA-Compatible" content="IE=9" />

Also, do you have an appropriate DOCTYPE defined in the HTML you're adding with setText()?

like image 78
Edward Thomson Avatar answered Nov 15 '22 13:11

Edward Thomson