NSPopover with NSPopoverBehaviorSemitransient doesn't close on mouseup if mousedown moves view it's anchored to

Originator:pflynn
Number:rdar://25860399 Date Originated:4/21/2016
Status:Open Resolved:
Product:OS X SDK Product Version:
Classification: Reproducible:
 
Summary:
Normally, NSPopoverBehaviorSemitransient causes popovers to close on a mouseup within most parts of the window. However, if the mousedown that comes before it causes the control which the popover is "anchored to" to move, then the corresponding mouseup does not hide the popover.

Steps to Reproduce:
1. Start with the sample from https://developer.apple.com/library/mac/samplecode/Popover/Introduction/Intro.html (Version 1.2, 2015-12-17)
2. Apply the attached patch file (see bottom)
3. Build & run
4. Click the Show Popover button to open the popover
5. Click the Move button to move the popover's anchor (which happens to also be the Show Popover button)

Expected Results:
Popover closes, since you've clicked on the parent window

Actual Results:
Popover remains open

The popup *does* close as expected if you do any of these things differently:
- Click anywhere else in the app's main window (instead of on the Move button)... including clicking on other buttons
- Change the Move button to trigger its action on mouseup instead of mousedown
- Comment out the `self.popoverButton.frame = frame;` line
- Change the popover to NSPopoverBehaviorTransient

Version:
Xcode 7.2.1 (7C1002)
OS X 10.11.2

Notes:
This bug is easy to hit in cases where mousedown changes selection (e.g. in a list), and changing selection causes any parts of the UI to hide/show (which can move the control the popup is anchored to).

The workaround of using NSPopoverBehaviorTransient instead isn't ideal, since it changes the behavior slightly and also exposes you to other issues (such as any remaining semi-transient popovers in the UI not closing automatically when the user opens your transient popover - per http://stackoverflow.com/a/24357644/1172352).

Comments

Patch posted here: https://gist.github.com/peterflynn/11de6d3beb48cc3fb12ec7ec0eca5173


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!