-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
8288325: [windows] Actual and Preferred Size of AWT Non-resizable frame are different #9954
Conversation
👋 Welcome back honkar! A progress list of the required criteria for merging this PR into |
@honkar-jdk The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
m_insets.right < 0 || m_insets.bottom < 0 || | ||
JNU_IsInstanceOfByName(env, target, "java/awt/Frame") > 0) { |
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.
Does it mean that now we will always request the insets from the platform?
Was this code run before the frame was changed from resizeable to non-resizeable? Therefore the insets weren't updated correctly.
Is this applicable to windows?
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.
Does it mean that now we will always request the insets from the platform?
Yes the following block of code runs when window isn't sized yet (first time) or when the incoming taget is a frame to obtain platform insets
Was this code run before the frame was changed from resizeable to non-resizeable? Therefore the insets weren't updated correctly.
Previously this block of code was executed for resizable frame only for the first time (when frame is being sized for the first time). The issue was with the cached insets. The first time when frame,pack() is called on non-resizable frame the correct insets associated with it is returned and the frame is sized accordingly. But any subsequent calls to frame.getInsets() or frame.getPreferredSize() which gets the cached insets from WPanelPeer was returning the cached insets of Resizable frame and not that of the Non-Resizable frame
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.
And this is unclear to me. The frame is set to non-resizeable, frame.pack()
is called. This, I assume, results in this code block being executed, so the calculated insets should be cached.
Why do the following calls to getInsets
or getPreferredSize
return the resizeable insets if the cached ones are non-resizeable?
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.
Is this applicable to windows?
I mean to Window
objects.
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.
And this is unclear to me. The frame is set to non-resizeable,
frame.pack()
is called. This, I assume, results in this code block being executed, so the calculated insets should be cached.Why do the following calls to
getInsets
orgetPreferredSize
return the resizeable insets if the cached ones are non-resizeable?
Initially the cause for swapping of insets was unclear to me as well. After looking closely at the native debug logs, it was found that the insets calculated using Client & Non-Client Rects were different in comparison to the native insets obtained from system metrics for Non-Resizable frame.
In AwtWindow::UpdateInsets, insets are obtained in two ways:
For the Non-Resizable Frame these two approaches returned different values, because of which the actual size and preferred size differed when frame.pack() is called. Earlier the metric used for Non-Resizable frame was SM_CXDLGFRAME/ SM_CXFIXEDFRAME, which returned slightly smaller inset values compared to that returned by Client and Non-Client rects. To match the insets returned in both the cases, SM_CXSIZEFRAME/ SM_CYSIZEFRAME is used as system metric for both - Resizable/ Non-Resizable frames in the updated fix. This ensures that the same inset values are returned for Non-Resizable frame. Debug logs added to the JBS issue - JDK-8288325 |
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.
Final version looks good to me.
@honkar-jdk 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 12 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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@azuev-java, @aivanov-jdk) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
m_insets.right < 0 || m_insets.bottom < 0) | ||
{ | ||
m_insets.right < 0 || m_insets.bottom < 0) { |
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.
No strong opinion here, yet I'd rather leave these lines unchanged. Having the opening brace on its own line avoids the confusion between the condition and the code in the body; on the other hand, it starts with a comment which visually separates the condition from the code inside the if-block.
m_insets.left = m_insets.right = | ||
::GetSystemMetrics(SM_CXSIZEFRAME) + extraPaddedBorderInsets; | ||
m_insets.top = m_insets.bottom = | ||
::GetSystemMetrics(SM_CYSIZEFRAME) + extraPaddedBorderInsets; |
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.
Is it worth adding a comment clarifying why the style isn't checked? Maybe not, since now it's gone from the code. On the other hand, a reader may wonder why we always uses the sizing frame insets even for non-resizeable frames.
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.
@aivanov-jdk I agree, comment would add more clarity. Additionally instead of using SM_CXSIZEFRAME (the name can be ambiguous too) can we change it to SM_CXFRAME ? Since both are mentioned to be same metrics in the documentation https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics
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.
Additionally instead of using SM_CXSIZEFRAME (the name can be ambiguous too) can we change it to SM_CXFRAME ?
Yes, SM_CXFRAME
is neutral, it doesn't refer to either resizeable or non-resizeable frame.
@@ -1479,7 +1475,6 @@ BOOL AwtWindow::UpdateInsets(jobject insets) | |||
// to reflect that change | |||
env->CallVoidMethod(peer, AwtComponent::replaceSurfaceDataLaterMID); | |||
} | |||
|
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.
Probably, this line could remain.
// SM_CXFRAME is the width of the horizontal border in pixels. | ||
// SM_CYFRAME is the height of the vertical border in pixels. |
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 guess the meaning of CX/CYFRAME
is quite obvious.
The first sentence about the metrics being the same is helpful.
@honkar-jdk |
/integrate |
@honkar-jdk |
/sponsor |
Going to push as commit eca9749.
Your commit was automatically rebased without conflicts. |
@aivanov-jdk @honkar-jdk Pushed as commit eca9749. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
On Windows, the insets obtained for a Non-Resizable AWT Frame was different when frame.pack() was called and subsequent call to frame.getInsets() or frame.getPreferredSize(). Due to this, the actual and preferred size differed when frame.pack() was called for Non-Resizable frame (on Windows).
Earlier the insets returned when frame.getInsets() was called, was that of a Resizable frame and not the correct insets associated with Non-Resizable frame. Fix is added to native code to get the correct insets. The test - AwtFramePackTest.java has been updated to test actual and expected/preferred size for both Resizable and Non-Resizable Frames.
The test is generic though the issue and fix is on Windows platform because the condition
frame.getSize() == frame.getPreferredSize()
should be true on all platforms when frame.pack() is called.Following is the link to Windows System Metrics (used for native insets) - https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9954/head:pull/9954
$ git checkout pull/9954
Update a local copy of the PR:
$ git checkout pull/9954
$ git pull https://git.openjdk.org/jdk pull/9954/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9954
View PR using the GUI difftool:
$ git pr show -t 9954
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9954.diff