On Mon, 19 Sep 2022 21:31:48 GMT, Harshitha Onkar <[email protected]> wrote:

>> 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
>
> Harshitha Onkar has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   updated fix to get the right insets for Non-Resizable frame

In AwtWindow::UpdateInsets, insets are obtained in two ways: 

1. **By subtracting Client rect from Non-Client rect:** If the insets obtained 
by this approach returns a negative value for either top, bottom, left or right 
it means that the window isn't sized yet and we need to get the associated 
default native insets through approach 2.

2. **Through Default native insets**  - Obtained using 
GetSystemMetrics(<appropriate_metric>) on Windows. Once the frame is sized, the 
insets obtained by step 1 are taken as final insets and cached in the 
respective peers.

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.

-------------

PR: https://git.openjdk.org/jdk/pull/9954

Reply via email to