Bug 577463 - Dynamic CSS Button:disabled breaks image display on buttons
Summary: Dynamic CSS Button:disabled breaks image display on buttons
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.21   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 4.24 M1   Edit
Assignee: Lars Vogel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-25 05:10 EST by Wiebke Timm CLA
Modified: 2022-03-30 04:53 EDT (History)
3 users (show)

See Also:


Attachments
SWT control example with dynamic CSS and additional selection listeners (114.89 KB, image/gif)
2021-11-25 05:10 EST, Wiebke Timm CLA
no flags Details
Bug manifestation in our product (561.33 KB, image/gif)
2021-11-25 05:11 EST, Wiebke Timm CLA
no flags Details
Patch to SWT controlexample (20.47 KB, text/plain)
2021-11-25 05:16 EST, Wiebke Timm CLA
no flags Details
Toy example project with dynamic CSS and all types of buttons (11.09 KB, application/x-zip-compressed)
2021-11-25 08:31 EST, Wiebke Timm CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wiebke Timm CLA 2021-11-25 05:10:09 EST
Created attachment 287567 [details]
SWT control example with dynamic CSS and additional selection listeners

When using a Button:disabled theme together with dynamic CSS flag in Eclipse SWT on Windows 10, images in buttons that use setEnabled inside the selection listener disappear when clicking the button, and sometimes their size is reduced. 

I can reproduce this behavior inside the org.swt.example.controlexample when adding a product and the corresponding css file and flag, using Eclipse 4.21 and Java 11.


In one of our applications, images are sometimes also replaced from other buttons in the same dialog or part. (Eclipse 4.14) I couldn't reproduce this image-stealing in the controlexample though. "Sometimes" means that by repeatedly clicking the button and enabling/disabling it multiple times, different behavior happens to the same button. And it does not seem to be deterministic - different icons from the same dialog are used at each program start.

It does not happen to buttons with images and a selection listener that are not enabled/disabled when clicking them.

When I remove the "Button:disabled" entry from the CSS (and leave the dynamic flag true), the bug does no longer occur. 



Steps to reproduce:
--------------------

* Use a CSS theme as described in the RCP Tutorial (via extension to the product in the plugin.xml)

* Set a Button:disabled CSS theme in 'default.css' file:

Button:disabled {
    background: #e5f0f8;
}


* Enable the dynamic CSS flag (-Dorg.eclipse.e4.ui.css.dynamic=true) as VM argument.

* Create buttons with images and add a selection listener that calls button.setEnabled(...)


Attachments:
------------

I am attaching .gifs that show the behavior. I could create a diff for the controlexample or create a branch, depending on what makes more sense (please let me know).

(In the controlexample, buttons 4, 5, and 6 call setEnabled(false) and button 7 calls setEnabled(true) on button 4, 5, 6)
Comment 1 Wiebke Timm CLA 2021-11-25 05:11:27 EST
Created attachment 287568 [details]
Bug manifestation in our product
Comment 2 Wiebke Timm CLA 2021-11-25 05:16:54 EST
Created attachment 287569 [details]
Patch to SWT controlexample

The patch adds a product and a CSS file with Button:checked, as well as a dynamic CSS VM arg. 

It adds an application and a part that contains the original example to allow it to start from the product. 

In the ButtonsTab example, I added selection listeners to the buttons 4, 5, and 6 that call setEnabled(false) on these buttons. Button 7 enables the buttons again to be able to repeat using the listeners.
Comment 3 Wiebke Timm CLA 2021-11-25 08:30:04 EST
I realized that the Button:checked CSS style has a similar problem: The images also disappear when selecting/unselecting styled buttons. For radio buttons, I could even see images disappearing when just hovering over them. I attached an example project that shows this behavior.

Disabling/enabling _other_ Buttons does not trigger the bug at first, but after a button with an image has been interacted with (even if no listener was added), disabling it changes or removes the image as well. 

see attached DynamicCssTester.zip
Comment 4 Wiebke Timm CLA 2021-11-25 08:31:58 EST
Created attachment 287571 [details]
Toy example project with dynamic CSS and all types of buttons
Comment 5 Andrey Loskutov CLA 2021-11-25 09:01:51 EST
@Lars: I assume that CSS magic is done in the platform UI code, not in SWT, right?
Comment 6 Wiebke Timm CLA 2022-03-29 07:19:36 EDT
Note: If you add 

Button {
	background: white;
	color: black;
}

to the css file as pointed out in https://bugs.eclipse.org/bugs/show_bug.cgi?id=577469 to define the states initially, the images still disappear.
Comment 7 Lars Vogel CLA 2022-03-29 11:03:36 EDT
The current implementation will call setBackgroundImage on the button if you use "background" as CSS proporty. The logic is (unfortunately) reused for multiple widgets so changing it for button alone might be efficient / desired. For background-color there is an extra path for button, and this does not set another background image on the button.

Snippet to test: 


Button {
	color:blue;
	background-color: red;
}

Does that work for you?
Comment 8 Wiebke Timm CLA 2022-03-30 03:51:06 EDT
Yes, using background-color instead of background fixes the problem.

Not sure why 'background' should be used with an image at all at CSS level. Icons are usually programmatic because every button has a different icon, so setting it for all buttons is not a use case we have.
Comment 9 Lars Vogel CLA 2022-03-30 03:57:00 EDT
(In reply to Wiebke Timm from comment #8)
> Yes, using background-color instead of background fixes the problem.
> 
> Not sure why 'background' should be used with an image at all at CSS level.
> Icons are usually programmatic because every button has a different icon, so
> setting it for all buttons is not a use case we have.

tbh. setting the background-image if background is specified looks like an undesired site-effect. Unfortunately the CSS code is ... a bit unstructured so if you have a solution I think we should go with it. If I see during Bug 577493 an way to fix this, I will also do this. But for this bug I suggest we close it as worksforme.
Comment 10 Wiebke Timm CLA 2022-03-30 04:53:21 EDT
Ok for me :)