-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8268084: [macos] Disabled JMenuItem arrow is not disabled #5310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back psadhukhan! A progress list of the required criteria for merging this PR into |
/label remove awt,2d |
@prsadhuk The |
Webrevs
|
How it will work if the "apple.laf.useScreenMenuBar" property is set, will the arrow look the same(disabled) as after this fix? |
Yes, it is disabled. |
if (!isEnabled && (arrowIcon instanceof ImageIcon)) { | ||
arrowIcon = new ImageIconUIResource(GrayFilter. | ||
createDisabledImage(((ImageIcon)arrowIcon).getImage())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we do not need to duplicate LookAndFeel.getDisabledIcon() here and create a new disabled icon on each call for each menu item?
What about tweak the aqua arrow icon, so it will paint itself correctly for enabled/disabled states. Similar to how the MenuArrowIcon from the WindowsLookAndFeel and MetalLookAndFeel works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In MenuArrowIcon, the arrow icon is drawn there itself using drawPolygon but in Aqua, it is drawn via imageicon image so it will be a change in design and will make it more complex and it might introduce bug in hidpi/retina. I will like to keep it simple following the current design in aqua.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On windows it is painted via skin, I guess in GTK as well. But it really does not matter how it is drawn, the important part is that the icon itself knows how to draw proper appearance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other L&Fs, it creates their own icon
for ex, MetalLookAndFeel
"MenuItem.arrowIcon",(LazyValue) t -> MetalIconFactory.getMenuItemArrowIcon(),
and WindowsLookAndFeel
"MenuItem.arrowIcon", menuItemArrowIcon,
but for AquaL&F it does not create it's own factory icon and rely on BasicIconFactory$MenuItemArrowIcon, so tweaking aqua arrow icon inline with how other do will cause design change, so I think this fix caters to the problem in view of this aqua limitation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but for AquaL&F it does not create it's own factory icon and rely on BasicIconFactory$MenuItemArrowIcon, so tweaking aqua arrow icon inline with how other do will cause design change, so I think this fix caters to the problem in view of this aqua limitation.
Are you sure that the Aqua does not have its own factory? the BasicIconFactory$MenuItemArrowIcon is an empty class.
AquaLookAndFeel.java:
"Menu.arrowIcon",(LazyValue) t -> AquaImageFactory.getMenuArrowIcon(),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is for MenuArrowIcon which is also there for Metal and Windows L&F in addition with MenuItemArrowIcon(). Aqua does not have it for MenuItem.
The control for aqua menuitem goes via ImageIcon#paintIcon for menuitem arrow which does not have enabled/disabled parameter so it was done the way it is now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is for MenuArrowIcon which is also there for Metal and Windows L&F in addition with MenuItemArrowIcon(). Aqua does not have it for MenuItem.
But this icon is used for the menuitem as well, isn't it? You can add this line to the test and check:
UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
+ UIManager.getDefaults().put("Menu.arrowIcon", "");
The control for aqua menuitem goes via ImageIcon#paintIcon for menuitem arrow which does not have enabled/disabled parameter so it was done the way it is now.
I guess it is go via Icon.paintIcon() at AquaMenuPainter:408 , this is similar to metal and windows L&Fs. The first parameter of paintIcon is a component, so all information can be read there. And depending on the state that icon can draws default arrow, or creates/caches the disabled icon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is for MenuArrowIcon which is also there for Metal and Windows L&F in addition with MenuItemArrowIcon(). Aqua
And depending on the state that icon can draws default arrow, or creates/caches the disabled icon.
I guess that is what it is being done, no? Instead of inside paintArrow() method, I am creating the disabled icon outside.
disabledIcon.paintIcon(c, g, arrowIconRect.x, arrowIconRect.y); | ||
} else { | ||
arrowIcon.paintIcon(c, g, arrowIconRect.x, arrowIconRect.y); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be even better to implement it in the same way as done in other L&fs like windows/metal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will like to know how because as it is pointed out, paintArrow delegates drawing to ImageIcon#paintIcon which is in shared code and this is mac specific issue so it needs to be handled before we call ImageIcon#paintIcon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to override the paintIcon method in the InvertableImageIcon returned by the AquaImageFactory.getMenuArrowIcon() or you can create class MenuArrowIcon extends InvertableImageIcon,
and override it there.
Also take a look to another usage of InvertableImageIcon for "MenuItemCheckIcon", should we disable it as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MenuItemCheckIcon disable-ness is also solved along with this fix.
JCheckBoxMenuItem component for MenuItemCheckIcon test is added additionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any more comments on this?
src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java
Outdated
Show resolved
Hide resolved
src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java
Outdated
Show resolved
Hide resolved
test/jdk/javax/swing/plaf/aqua/JMenuItemDisableArrowButtonTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine
@prsadhuk This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 371 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit 3281102.
Your commit was automatically rebased without conflicts. |
It is seen in macos disabled JMenuItem arrow is not disabled even though JMenuItem itself is disabled.
In native app, same menuitem arrow is disabled for disabled menuitem.
Issue is when AquaMenuPainter#paintMenuItem() is called, it tries to draw a ImageIcon image of the arrow via ImageIcon#paintIcon which tries to generate MultiResolutionCachedImage via getResolutionVariant() by calling AquaUtils#generateFilteredImage.
It does not take into account if disabled arrow icon image needs to be drawn or not, so it is always enabled.
Proposed fix is to generate a disabled ImageIcon image of the same arrow icon and use it for disabled state.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5310/head:pull/5310
$ git checkout pull/5310
Update a local copy of the PR:
$ git checkout pull/5310
$ git pull https://git.openjdk.java.net/jdk pull/5310/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5310
View PR using the GUI difftool:
$ git pr show -t 5310
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5310.diff