Bug 536087 - Coolbar drag items looking very bad in dark theme
Summary: Coolbar drag items looking very bad in dark theme
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.7.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.9 M2   Edit
Assignee: Roland Grunberg CLA
QA Contact:
URL: https://github.com/de-jcup/eclipse-as...
Whiteboard:
Keywords: ui
Depends on:
Blocks:
 
Reported: 2018-06-20 09:12 EDT by Albert Tregnaghi CLA
Modified: 2018-08-02 05:17 EDT (History)
3 users (show)

See Also:


Attachments
Zip file contains a ready to use plugin project with example code in view (13.79 KB, application/x-zip-compressed)
2018-06-20 09:12 EDT, Albert Tregnaghi CLA
no flags Details
A screenshot from the example plugin showing the problem (4.80 KB, image/png)
2018-06-20 09:13 EDT, Albert Tregnaghi CLA
no flags Details
Screenshot shows patch working on windows 7 (7.74 KB, image/png)
2018-06-22 18:53 EDT, Albert Tregnaghi CLA
no flags Details
Screenshot shows patch working on linux GTK (9.49 KB, image/png)
2018-06-22 19:04 EDT, Albert Tregnaghi CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Albert Tregnaghi CLA 2018-06-20 09:12:17 EDT
Created attachment 274556 [details]
Zip file contains a ready to use plugin project with example code in view

After starting the example plugin (see attached zip file) and showing up the "Example view" the drag rendering is having a white background in eclipse dark theme. 

(there will be an image uploaded too)

This happens (at least) on Windows 7 and on Linux (GTK) too.
Comment 1 Albert Tregnaghi CLA 2018-06-20 09:13:21 EDT
Created attachment 274557 [details]
A screenshot from the example plugin showing the problem
Comment 2 Lars Vogel CLA 2018-06-20 09:15:11 EDT
Albert, IIRC you also found the place in the code in which the color is hard-coded? If that is true, can you point us to this place?
Comment 3 Lars Vogel CLA 2018-06-21 06:35:03 EDT
Roland, as master of all color issues, can you have a look?

(In reply to Lars Vogel from comment #2)
> Albert, IIRC you also found the place in the code in which the color is
> hard-coded? If that is true, can you point us to this place?

I think the problem is in the CoolBar#onPaint method. In line 712 /* Draw gripper. */ where it goes into the following code path.

if (!nativeGripper) {
 int grabberTrim = 2;
 int grabberHeight = bounds.height - (2 * grabberTrim) - 1;
 gc.setForeground(shadowColor);


etc.

@Roland, as master of all color issues, can you please have a look?
Comment 4 Roland Grunberg CLA 2018-06-21 16:10:26 EDT
> (In reply to Lars Vogel from comment #2)
> > Albert, IIRC you also found the place in the code in which the color is
> > hard-coded? If that is true, can you point us to this place?
> 
> I think the problem is in the CoolBar#onPaint method. In line 712 /* Draw
> gripper. */ where it goes into the following code path.
> 
> if (!nativeGripper) {
>  int grabberTrim = 2;
>  int grabberHeight = bounds.height - (2 * grabberTrim) - 1;
>  gc.setForeground(shadowColor);

Does the following workaround improve things for you as well ?
In ExampleView#createToolBar() below 'CoolBar coolbar = coolBarManager.createControl(topComposite);

Color bgcolor = colorRegistry.get(JFacePreferences.INFORMATION_BACKGROUND_COLOR);
if (bgcolor == null) {
  bgcolor = JFaceColors.getInformationViewerForegroundColor(Display.getDefault());
  }
coolbar.setBackground(bgcolor);

After asking Eric about this, it seems like this is actually a bug in CoolBar, which you can see by launching into SWT's ControlExample, selecting the CoolBar tab, and attempting to set the background colour. The CoolBar separators don't seem to respect the background. This seems to be a bug on Windows and Linux GTK2 & GTK3, but for some reason works on MacOS. I can file a bug for this in SWT but there may be some more investigation needed on that side.
Comment 5 Roland Grunberg CLA 2018-06-22 10:59:03 EDT
After some more investigation, it looks like this can be fixed simply by starting to theme CoolBar like other widgets in eclipse.platform.ui/bundles/org.eclipse.ui.themes/css/dark/e4-dark_globalstyle.css . I can push a patch for this.

However, before the patch is ready to be pushed, I need to confirm that the fix that will go on the SWT side doesn't affect this one. To clarify, there are 2 issues here :

1) CoolBar not being styled
2) CoolBar items not inheriting colour from parent

We can fix (1), and that's all this bug really needs, but given that (2) is still an issue (possibly for others) it would be good to verify (2) doesn't break (1) (on all platforms).
Comment 6 Eclipse Genie CLA 2018-06-22 11:16:30 EDT
New Gerrit change created: https://git.eclipse.org/r/124907
Comment 7 Albert Tregnaghi CLA 2018-06-22 11:27:10 EDT
Lars, sorry about the late response, 

As mentioned inside https://github.com/de-jcup/eclipse-asciidoctor-editor/issues/68#issuecomment-397469714 I also recognized the onPaint method did not handle themes, but used system colors. 

But I recognized this only at debugging  org.eclipse.swt.gtk.linux.x86_64.source_3.105.3.v20170228-0512.jar

When trying to find the problem inside
org.eclipse.swt.win32.win32.x86_64_3.105.2.v20161122-0613.jar
(with decompiler jad and also fernflower) on a windows machine I did not found even a onPaint method?!?! So I was very confused about my former results on linux... and being not very familier with SWT I wanted to check my last results on my linux machine again before giving any wrong information.
Comment 8 Lars Vogel CLA 2018-06-22 11:29:50 EDT
No worries Albert. Could you test Roland's patch? You need latest I-build for that and clone eclipse.platform.ui from git.eclipse.org/r. Same setup as I described in my email for the team contribution.
Comment 9 Albert Tregnaghi CLA 2018-06-22 11:45:35 EDT
Hello Roland, does adding a CSS style really solve this?

when looking at
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/bundles/org.eclipse.swt/Eclipse%20SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.java#n697

It seems that e.g. the highlight color is directly used:

```
Color highlightColor = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
...
/* Draw gripper. */
...
gc.setForeground(highlightColor);
...
```

So I don't know if the theming does override this behaviour but ... I wouldn't expect that.
Comment 10 Albert Tregnaghi CLA 2018-06-22 11:51:13 EDT
Okay Lars, I will try to test the patch - but being an absolute beginner with testing swt changes at all I would recommend that another person should do test it  also... ;-) 

I try to test it on linux and windows this weekend.
Comment 11 Lars Vogel CLA 2018-06-22 11:57:17 EDT
(In reply to Albert Tregnaghi from comment #10)
> Okay Lars, I will try to test the patch - but being an absolute beginner
> with testing swt changes at all I would recommend that another person should
> do test it  also... ;-) 

Here is how you can test this:

1.) Download latest I-build from http://download.eclipse.org/eclipse/downloads/ or use latest 4.9 from http://download.eclipse.org/eclipse/downloads/drops4/I20180621-2000/

2.) Install EGit into this download

3.) Clone eclipse.platform.ui Clone URI can be found here: https://git.eclipse.org/r/#/admin/projects/platform/eclipse.platform.ui

4.) Import at least org.eclipse.ui.themes into your workspace

5.) Ctrl+3 -> Fetch from Gerrit -> 124907

6.) Right click org.eclipse.ui.themes and select Run-As-> Eclipse Appliation

This should start a runtime Eclipse with the patch, if you have your example in the workspace your test view should also be available.

If you have problems please let me know via this bug or via email.
Comment 12 Lars Vogel CLA 2018-06-22 11:57:54 EDT
Change is, luckily, not in SWT, as SWT testing is a bit more complex. :-)
Comment 13 Roland Grunberg CLA 2018-06-22 12:15:32 EDT
(In reply to Albert Tregnaghi from comment #9)
> Hello Roland, does adding a CSS style really solve this?

From my testing on Linux, styling the CoolBar in org.eclipse.ui.themes fixes the issue. Once a widget is themed I don't think individual setting of background colours can override that, which explains why manually setting it works even on dark theme currently. I still have to test on other platforms but am just blocked on a few other minor things.

> when looking at
> https://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/bundles/org.
> eclipse.swt/Eclipse%20SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.
> java#n697
> 
> It seems that e.g. the highlight color is directly used:
> 
> ```
> Color highlightColor =
> display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
> ...
> /* Draw gripper. */
> ...
> gc.setForeground(highlightColor);
> ...
> ```

This doesn't actually set the background colour of the separator. From my understanding (hugely thanks to Eric) the area that looks like a separator is actually just showing the underlying composite that makes up the CoolBar. The drawGripper logic simply gets the bounds of that area and draws some vertical lines on it to make it look like it protrudes and can be "gripped" / dragged. You can confirm this yourself by debugging, overriding those colours to something like red/blue.
Comment 14 Roland Grunberg CLA 2018-06-22 13:35:31 EDT
I've tested on Windows and Mac. This improves the look of the CoolBar on all of these.
Comment 15 Lars Vogel CLA 2018-06-22 14:03:37 EDT
Thanks Roland. Once Albert confirms I plan to merge.
Comment 16 Albert Tregnaghi CLA 2018-06-22 18:53:11 EDT
Created attachment 274591 [details]
Screenshot shows patch working on windows 7

Tested on windows 7 - patch looks very good (see pciture)
Comment 17 Albert Tregnaghi CLA 2018-06-22 19:04:56 EDT
Created attachment 274592 [details]
Screenshot shows patch working on linux GTK
Comment 18 Albert Tregnaghi CLA 2018-06-22 19:08:16 EDT
I tested with Windows 7 and at Linux. The patch is working well on both OS - see attached pictures.

(Just one thing: the nice looking drag icon from windows 7 is much more beautiful than icon respectively the rendering on linux - compare screenshots, but it's okay).
Comment 19 Albert Tregnaghi CLA 2018-06-22 19:10:50 EDT
Lars, I tested with
http://download.eclipse.org/eclipse/downloads/drops4/I20180611-0500/

IMHO the patch is working well and should be merged.
Comment 20 Lars Vogel CLA 2018-06-23 03:27:25 EDT
Thanks Roland for the patch and Albert for the validation.
Comment 22 Niraj Modi CLA 2018-08-02 05:17:17 EDT
Verified the fix with attachment 274556 [details] on Win7 using Build id: I20180731-2000