Skip to content
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

8268084: [macos] Disabled JMenuItem arrow is not disabled #5310

Closed
wants to merge 8 commits into from

Conversation

@prsadhuk
Copy link
Contributor

@prsadhuk prsadhuk commented Aug 31, 2021

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

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8268084: [macos] Disabled JMenuItem arrow is not disabled

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Aug 31, 2021

👋 Welcome back psadhukhan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

Loading

@openjdk openjdk bot added the rfr label Aug 31, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Aug 31, 2021

@prsadhuk The following labels will be automatically applied to this pull request:

  • 2d
  • awt
  • swing

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

Loading

@prsadhuk
Copy link
Contributor Author

@prsadhuk prsadhuk commented Aug 31, 2021

/label remove awt,2d

Loading

@openjdk openjdk bot removed awt 2d labels Aug 31, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Aug 31, 2021

@prsadhuk
The awt label was successfully removed.

The 2d label was successfully removed.

Loading

@mlbridge
Copy link

@mlbridge mlbridge bot commented Aug 31, 2021

Loading

@mrserb
Copy link
Member

@mrserb mrserb commented Aug 31, 2021

In native app, same menuitem arrow is disabled for disabled menuitem.

How it will work if the "apple.laf.useScreenMenuBar" property is set, will the arrow look the same(disabled) as after this fix?

Loading

@prsadhuk
Copy link
Contributor Author

@prsadhuk prsadhuk commented Sep 1, 2021

In native app, same menuitem arrow is disabled for disabled menuitem.

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.

Loading

if (!isEnabled && (arrowIcon instanceof ImageIcon)) {
arrowIcon = new ImageIconUIResource(GrayFilter.
createDisabledImage(((ImageIcon)arrowIcon).getImage()));
}
Copy link
Member

@mrserb mrserb Sep 1, 2021

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.

Loading

Copy link
Contributor Author

@prsadhuk prsadhuk Sep 2, 2021

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.

Loading

Copy link
Member

@mrserb mrserb Sep 2, 2021

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.

Loading

Copy link
Contributor Author

@prsadhuk prsadhuk Sep 2, 2021

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.

Loading

Copy link
Member

@mrserb mrserb Sep 2, 2021

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(),

Loading

Copy link
Contributor Author

@prsadhuk prsadhuk Sep 2, 2021

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.

Loading

Copy link
Member

@mrserb mrserb Sep 2, 2021

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.

Loading

Copy link
Contributor Author

@prsadhuk prsadhuk Sep 2, 2021

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.

Loading

disabledIcon.paintIcon(c, g, arrowIconRect.x, arrowIconRect.y);
} else {
arrowIcon.paintIcon(c, g, arrowIconRect.x, arrowIconRect.y);
}
Copy link
Member

@mrserb mrserb Sep 2, 2021

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.

Loading

Copy link
Contributor Author

@prsadhuk prsadhuk Sep 3, 2021

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

Loading

Copy link
Member

@mrserb mrserb Sep 3, 2021

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?

Loading

Copy link
Contributor Author

@prsadhuk prsadhuk Sep 4, 2021

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.

Loading

Copy link
Contributor Author

@prsadhuk prsadhuk Sep 7, 2021

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?

Loading

mrserb
mrserb approved these changes Sep 16, 2021
Copy link
Member

@mrserb mrserb left a comment

Looks fine

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Sep 16, 2021

@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:

8268084: [macos] Disabled JMenuItem arrow is not disabled

Reviewed-by: serb, jdv

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 master branch:

  • eeaf43b: 8274114: ProblemList serviceability/sa/TestJhsdbJstackMixed.java on linux-aarch64 in -Xcomp mode
  • 517405e: 8273965: some testlibrary_tests/ir_framework tests fail when c1 disabled
  • 11cddd3: 8272114: Unused _last_state in osThread_windows
  • cbe57e8: 8273684: Replace usages of java.util.Stack with ArrayDeque
  • a72c8aa: 8273921: Refactor NSK/JDI tests to create thread using factory
  • 161fdb4: 8273935: (zipfs) Files.getFileAttributeView() throws UOE instead of returning null when view not supported
  • 0fc47e9: 8266666: Implementation for snippets
  • 6d91a3e: 8269039: Disable SHA-1 Signed JARs
  • 42d5d2a: 8274056: JavaAccessibilityUtilities leaks JNI objects
  • 57df0db: 8270873: JFR: Catch DirectoryIteratorException when scanning for .jfr files
  • ... and 361 more: https://git.openjdk.java.net/jdk/compare/79a06df8113ba1da55db5c38fe34608c3507c223...master

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 master branch, type /integrate in a new comment.

Loading

@openjdk openjdk bot added the ready label Sep 16, 2021
@openjdk openjdk bot added ready and removed ready labels Sep 22, 2021
@prsadhuk
Copy link
Contributor Author

@prsadhuk prsadhuk commented Oct 4, 2021

/integrate

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Oct 4, 2021

Going to push as commit 3281102.
Since your change was applied there have been 511 commits pushed to the master branch:

  • 7957994: 8273695: Safepoint deadlock on VMOperation_lock
  • 9ca6bf0: 8274505: Too weak variable type leads to unnecessary cast in java.desktop
  • 0786d8b: 8268435: (ch) ChannelInputStream could override readAllBytes
  • bb4500d: 8274465: Fix javax/swing/text/ParagraphView/6364882/bug6364882.java failures
  • 05d3860: 8274605: Fix predicate guarantees on returned values in (Doc)SourcePositions
  • 3d7671b: 8274562: (fs) UserDefinedFileAttributeView doesn't correctly determine if supported when using OverlayFS
  • c05dc26: 8274435: EXCEPTION_ACCESS_VIOLATION in BFSClosure::closure_impl
  • cc14c6f: 8274227: Remove "impl.prefix" jdk system property usage from InetAddress
  • 292d7bb: 8274363: Transitively sealed classes not considered exhaustive in switches
  • 1887028: 8269113: Javac throws when compiling switch (null)
  • ... and 501 more: https://git.openjdk.java.net/jdk/compare/79a06df8113ba1da55db5c38fe34608c3507c223...master

Your commit was automatically rebased without conflicts.

Loading

@openjdk openjdk bot closed this Oct 4, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Oct 4, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Oct 4, 2021

@prsadhuk Pushed as commit 3281102.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Loading

@prsadhuk prsadhuk deleted the 8268084 branch Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants