Bug 531102 - [Browser] background not set via setBackground()
Summary: [Browser] background not set via setBackground()
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: Category:Browser,enhancement,theme,dark
Keywords: helpwanted, triaged
Depends on:
Blocks:
 
Reported: 2018-02-13 08:40 EST by Lars Vogel CLA
Modified: 2018-07-10 14:13 EDT (History)
3 users (show)

See Also:


Attachments
Background (37.11 KB, image/png)
2018-02-13 08:40 EST, Lars Vogel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2018-02-13 08:40:43 EST
Created attachment 272662 [details]
Background

If I open an image in the Eclipse browser in the dark theme, the remaining background is white. 

Not sure if this can be changed, but if, we should change the default background to dark in the dark theme.
Comment 1 Lars Vogel CLA 2018-02-13 08:41:09 EST
Adding Matthias, as he is interested in improving the dark theme.
Comment 2 Matthias Becker CLA 2018-02-13 08:44:49 EST
anyway if us open up a webpage in the browser that has a bright background this won't change due to the dark theme.
Comment 3 Lars Vogel CLA 2018-02-13 08:58:16 EST
(In reply to Matthias Becker from comment #2)
> anyway if us open up a webpage in the browser that has a bright background
> this won't change due to the dark theme.

True, this bug is for the empty space default.
Comment 4 Matthias Becker CLA 2018-02-14 05:00:40 EST
There is already:

.MPart Table,
.MPart Browser,
.Mpart OleFrame,
.MPart ViewForm,
.MPart ViewForm > ToolBar,
.MPart ViewForm > CLabel,
.MPart PageBook > Label,
.MPart PageBook > SashForm,
#org-eclipse-help-ui-HelpView LayoutComposite > LayoutComposite,
#org-eclipse-help-ui-HelpView LayoutComposite > LayoutComposite > * {
    background-color: #313538;
    color: #CCC;
}

in /org.eclipse.ui.themes/css/dark/e4-dark_partstyle.css
the setBackground method is called for the browser widget but (at least on macOS) this does not seem to have any effect.
On Linux this also seems to have no effect (as Lars is on Linux). I don't know how it is on Windows.

SWT Team: Can you have a look at this?
Comment 5 Lars Vogel CLA 2018-02-23 04:47:28 EST
Looks to me that the SWT Browser widgets ignores the setBackground call.

SWT team is this a known issue? Would be nice to have this? Otherwise every empty browser will look bad in the dark theme.

import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet128 {
	public static void main(String [] args) {
		Display display = new Display();
		final Shell shell = new Shell(display);
		FillLayout fillLayout = new FillLayout();
		shell.setLayout(fillLayout);
		final Browser browser= new Browser(shell, SWT.NONE);
		browser.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_CYAN));

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}
Comment 6 Leo Ufimtsev CLA 2018-02-23 11:59:49 EST
Yea, at the moment it's ignored.

The background in browser widget is HTML based. So setText() with custom html background would make the widget black. Or call execute() with javascript that makes background black.

To implement native support, we'd have to cache the setBackground() and re-apply it via javascript after every page load.

The implementation would have to tranlsate the COLOR in setBackground(COLOR) into html and do something like ~document.body.setBackground<..>

It can be done, would probably take me a a day or so to implement/test/verify.

Does the same problem occur on Win/Cocoa btw?(I haven't tested).
Comment 7 Matthias Becker CLA 2018-02-23 12:01:31 EST
(In reply to Leo Ufimtsev from comment #6)
> Does the same problem occur on Win/Cocoa btw?(I haven't tested).

On macOS the background also is white
Comment 8 Leo Ufimtsev CLA 2018-02-23 12:41:52 EST
Thanks for testing.

One problem might be that if a theme sets the background, then browsing web-pages (e.g google) might not look proper. setForeground() should also be considered in such situations.

Also not sure if webkit/I.E browsers can actually render an image with custom background for the non-image area. Would have to experiment.

I think at the moment Gtk3 bug fixes may take higher priority than fixing a theme issue. We have enough gtk3 bugs to keep us busy for a while :-) 
-> adding helpwanted tag. Patches are welcome.

A workaround at platform level would be to load html page with it's own background and embed the image in the page.
Comment 9 Lars Vogel CLA 2018-05-31 10:05:53 EDT
(In reply to Leo Ufimtsev from comment #6)
> Does the same problem occur on Win/Cocoa btw?(I haven't tested).

Same problem on Windows.
Comment 10 Lars Vogel CLA 2018-05-31 10:07:01 EDT
Nikita, would it be possible on the SWT Windows side to support setBackground for Browser? This would allow making empty browsers look better in the dark theme.
Comment 11 Leo Ufimtsev CLA 2018-05-31 11:17:29 EDT
(In reply to Lars Vogel from comment #10)
> Nikita, would it be possible on the SWT Windows side to support
> setBackground for Browser? This would allow making empty browsers look
> better in the dark theme.

This could potentially be done at common level, i.e, one implementation for gtk/cocoa/win that executes javascript when setBackground(..) is called.
Comment 12 Alexander Kurtakov CLA 2018-05-31 11:48:45 EDT
I'm not sold to the idea of setBackround for browser - it should be the actual content defining the background.
Comment 13 Lars Vogel CLA 2018-05-31 11:51:08 EDT
(In reply to Alexander Kurtakov from comment #12)
> I'm not sold to the idea of setBackround for browser - it should be the
> actual content defining the background.

Yes, this would only be useful for an empty browser.
Comment 14 Alexander Kurtakov CLA 2018-05-31 11:54:06 EDT
I have even tried with Firefox running in dark theme and the default background (e.g. about: ) is some neutral light gray .
Comment 15 Alexander Kurtakov CLA 2018-05-31 11:55:30 EDT
So what we wnat to achieve is similar to https://support.mozilla.org/en-US/questions/1106886 ?
Comment 16 Alexander Kurtakov CLA 2018-05-31 11:58:53 EDT
Overriding background for all pages is a total no-go.
But overriding for empty page is doable and webkitgtk has API for that webkit_web_view_set_background_color
Comment 17 Leo Ufimtsev CLA 2018-05-31 12:09:18 EDT
(In reply to Alexander Kurtakov from comment #16)
> Overriding background for all pages is a total no-go.
> But overriding for empty page is doable and webkitgtk has API for that
> webkit_web_view_set_background_color

This is interesting, I never knew about this API when I suggested the above. The api is definitely the better approach.