Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Does browser rendering occur in the Display thread?
Does browser rendering occur in the Display thread? [message #463039] Tue, 25 October 2005 14:18 Go to next message
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
I'm trying to write some tests that depend upon content being rendered
in the Browser control. Does this rendering happen in the Display
thread or does the browser have it's own? If the OS matters I'm running
on WinXP.

Thanks,
Brad
Re: Does browser rendering occur in the Display thread? [message #463041 is a reply to message #463039] Tue, 25 October 2005 15:48 Go to previous messageGo to next message
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
Here's a quick snippet that shows the problem. When I run it the
console displays "after flush events" before the status text listener fires.

public class BrowserThreading {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);

shell.setLayout(new FillLayout());

Browser browser = new Browser(shell, SWT.NONE);
browser.addStatusTextListener(new StatusTextListener() {
public void changed(StatusTextEvent event) {
if (event.text.equals("onload")) //$NON-NLS-1$
System.out.println("status event " + event.text); //$NON-NLS-1$
}
});

browser.setText("<html><body onload=\"window.status='onload';\">body
content</body></html>"); //$NON-NLS-1$

// flush all events
while (display.readAndDispatch());

System.out.println("after flush events"); //$NON-NLS-1$

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

display.dispose();
}
}

Brad Reynolds wrote:
> I'm trying to write some tests that depend upon content being rendered
> in the Browser control. Does this rendering happen in the Display
> thread or does the browser have it's own? If the OS matters I'm running
> on WinXP.
>
> Thanks,
> Brad
Re: Does browser rendering occur in the Display thread? [message #463042 is a reply to message #463039] Tue, 25 October 2005 16:38 Go to previous messageGo to next message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
I'm fairly sure it does occure in the event dispatch thread. It's fairly easy to check. Try the following snippet:

public static void main(String[] args) {
    Display display = new Display();

    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());

    Browser b = new Browser(shell);
    b.setUrl("http://www.google.com");

    GridData data = new GridData();
    data.horizontalAlignment = SWT.FILL;
    data.verticalAlignment = SWT.FILL;
    data.grabHorizontalSpace = true;
    data.grabVerticalSpace = true;
    b.setLayoutData(data);

    Button b = new Button(shell, SWT.PUSH);
    b.setText("Push Me!");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            while (true);
        }
    });

    shell.open();

    while (!shell.isDisposed())
        if (!display.readAndDispatch()) display.sleep();
}


Sorry if anything in there is wrong, I just hacked that out from memory. Anyway, push the button and then drag another window over the Shell. If the Browser repaints even when the Button doesn't, then it's a safe bet that the rendering is done in a separate thread. If the Browser doesn't repaint, then the rendering is really done in the event dispatch thread.
Re: Does browser rendering occur in the Display thread? [message #463044 is a reply to message #463042] Tue, 25 October 2005 18:17 Go to previous message
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
Thanks for the response. According to that test it's in the UI thread,
or at least the paint events are which I would think they have to be.
The thing that concerns me is that loading of content in any browser is
asynchronous, at least when doing this via javascript, and they make
callbacks to allow you to know when a page has been loaded (ready
state). So would SWT remove that behavior and force them to be
synchronous? Anyway even with that test I'm still having problems.

I think my problem is actually a little more complicated than I
initially stated. I'm trying to run javascript on load of the page.
This then sets the window.status allowing me to receive the
StatusTextEvent. But I'm having problems writing an abbott test that
allows me to inspect this as it seems that the event fires after, or
sometimes before, the flushing of all events (while
(display.readAndDispatch()) so I'm having problems asserting the
behavior. I'm going to think about this more. Thanks for the
suggestion and if you have any others I'm all ears.

Thanks,
Brad

Daniel Spiewak wrote:
> I'm fairly sure it does occure in the event dispatch thread. It's fairly easy to check. Try the following snippet:
>
>
> public static void main(String[] args) {
>     Display display = new Display();
> 
>     Shell shell = new Shell(display);
>     shell.setLayout(new GridLayout());
> 
>     Browser b = new Browser(shell);
>     b.setUrl("http://www.google.com");
> 
>     GridData data = new GridData();
>     data.horizontalAlignment = SWT.FILL;
>     data.verticalAlignment = SWT.FILL;
>     data.grabHorizontalSpace = true;
>     data.grabVerticalSpace = true;
>     b.setLayoutData(data);
> 
>     Button b = new Button(shell, SWT.PUSH);
>     b.setText("Push Me!");
>     b.addSelectionListener(new SelectionAdapter() {
>         public void widgetSelected(SelectionEvent e) {
>             while (true);
>         }
>     });
> 
>     shell.open();
> 
>     while (!shell.isDisposed())
>         if (!display.readAndDispatch()) display.sleep();
> }
> 

>
> Sorry if anything in there is wrong, I just hacked that out from memory. Anyway, push the button and then drag another window over the Shell. If the Browser repaints even when the Button doesn't, then it's a safe bet that the rendering is done in a separate thread. If the Browser doesn't repaint, then the rendering is really done in the event dispatch thread.
Previous Topic:Caret on beginning of selection
Next Topic:keylistener doesn't work
Goto Forum:
  


Current Time: Tue Apr 23 13:11:46 GMT 2024

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

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

Back to the top