Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Issue 2852233002: Mac[Views]: Make native menus more responsive by pumping private runloop modes. (Closed)

Created:
3 years, 7 months ago by tapted
Modified:
3 years, 7 months ago
CC:
chromium-reviews, tfarina, mac-reviews_chromium.org, chrome-apps-syd-reviews_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Mac[Views]: Make native menus more responsive by pumping private runloop modes. Native NSMenus run a UI-thread-blocking animation to flash the selected item and fade out. This takes 300ms or more and events are only pumped in private run loop modes. This can make menus feel really laggy - <select> popups in particular. A menu run by a native NSPopUpButton feels better since it uses a different menu close animation which is opaque. Since it's opaque you don't see how laggy the interface is behind it whilst the menu becomes transparent. Using this animation is possible in MacViews, but its style is fixed with a blue bar on the right, to match the native NSPopUpButton appearance, so it looks weird. Changing any of the NSPopUpButtonCell's style will just revert to a fade-out menu animation. To get the menus feeling more responsive, "peek" at the processing on the NSMenuItem by hooking -[NSMenuItem _sendItemSelectedNote]. This is sent early in the event processing and before any animations start blocking the UI thread. MenuController can peek at this and (optionally) post the action handling as a task. Then, observe the private run loop modes that AppKit uses during menu fade and "un" highlight of the menu bar. This allows the posted task to execute and compositing tasks to run in parallel with the menu fade. BUG=602914, 640466 TEST=With chrome://flags#secondary-ui-md enabled, click the bookmark star. Changing the Folder: should be immediately visible while the menu is fading out. Review-Url: https://codereview.chromium.org/2852233002 Cr-Commit-Position: refs/heads/master@{#470769} Committed: https://chromium.googlesource.com/chromium/src/+/335d78a0e0299bda3465cb7e303b79e043f680da

Patch Set 1 : With the NSPopUpMenu animation #

Patch Set 2 : Remove NSPopUpMenu hacks #

Patch Set 3 : nits #

Patch Set 4 : Soooooo nice #

Patch Set 5 : Tweaks #

Patch Set 6 : Ignore 10.9, 10.10. Works in 10.11. More test, self target #

Patch Set 7 : Pump private run loops #

Total comments: 6

Patch Set 8 : fix tests, respond to comments, selfnits #

Total comments: 4

Patch Set 9 : base::CancelableClosure #

Patch Set 10 : Merge private categories #

Total comments: 12

Patch Set 11 : respond to comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+377 lines, -127 lines) Patch
M base/message_loop/message_pump_mac.mm View 1 2 3 4 5 6 7 8 9 10 1 chunk +31 lines, -12 lines 0 comments Download
M chrome/browser/ui/cocoa/extensions/browser_action_button_interactive_uitest.mm View 1 2 3 4 5 6 7 7 chunks +66 lines, -62 lines 0 comments Download
M ui/base/cocoa/menu_controller.h View 1 2 3 4 5 6 7 8 9 10 2 chunks +22 lines, -10 lines 0 comments Download
M ui/base/cocoa/menu_controller.mm View 1 2 3 4 5 6 7 8 9 10 8 chunks +87 lines, -24 lines 0 comments Download
M ui/base/cocoa/menu_controller_unittest.mm View 1 2 3 4 5 6 7 8 5 chunks +170 lines, -19 lines 0 comments Download
M ui/views/controls/menu/menu_runner_impl_cocoa.mm View 1 2 3 4 5 6 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 89 (76 generated)
tapted
Hi Robert - please take a look.
3 years, 7 months ago (2017-05-04 09:13:09 UTC) #46
tapted
Hi Robert, please take a look. I think this is what you had in mind? ...
3 years, 7 months ago (2017-05-08 10:22:57 UTC) #55
Robert Sesek
On 2017/05/08 10:22:57, tapted wrote: > Hi Robert, please take a look. I think this ...
3 years, 7 months ago (2017-05-08 22:42:10 UTC) #56
tapted
PTAL - figured out the test. The problem was that the test harness invokes the ...
3 years, 7 months ago (2017-05-09 04:57:43 UTC) #65
Robert Sesek
LGTM. Please also get Mark to review and add BUG=640466. https://codereview.chromium.org/2852233002/diff/300001/ui/base/cocoa/menu_controller.mm File ui/base/cocoa/menu_controller.mm (right): https://codereview.chromium.org/2852233002/diff/300001/ui/base/cocoa/menu_controller.mm#newcode42 ...
3 years, 7 months ago (2017-05-09 15:49:45 UTC) #66
tapted
Mark: can you take a look too - thanks! On 2017/05/09 15:49:45, Robert Sesek wrote: ...
3 years, 7 months ago (2017-05-10 03:49:07 UTC) #72
Robert Sesek
LGTM https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/message_pump_mac.mm File base/message_loop/message_pump_mac.mm (right): https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/message_pump_mac.mm#newcode44 base/message_loop/message_pump_mac.mm:44: void CFRunLoopAddSourceToAllModes(CFRunLoopRef rl, CFRunLoopSourceRef source) { One last ...
3 years, 7 months ago (2017-05-10 13:37:27 UTC) #75
Mark Mentovai
LGTM. Excited to try this out. https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/message_pump_mac.mm File base/message_loop/message_pump_mac.mm (right): https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/message_pump_mac.mm#newcode35 base/message_loop/message_pump_mac.mm:35: kCFRunLoopCommonModes, kMessageLoopExclusiveRunLoopMode, I ...
3 years, 7 months ago (2017-05-10 14:00:18 UTC) #76
Robert Sesek
https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/message_pump_mac.mm File base/message_loop/message_pump_mac.mm (right): https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/message_pump_mac.mm#newcode35 base/message_loop/message_pump_mac.mm:35: kCFRunLoopCommonModes, kMessageLoopExclusiveRunLoopMode, On 2017/05/10 14:00:18, Mark Mentovai wrote: > ...
3 years, 7 months ago (2017-05-10 14:02:50 UTC) #77
tapted
https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/message_pump_mac.mm File base/message_loop/message_pump_mac.mm (right): https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/message_pump_mac.mm#newcode35 base/message_loop/message_pump_mac.mm:35: kCFRunLoopCommonModes, kMessageLoopExclusiveRunLoopMode, On 2017/05/10 14:02:49, Robert Sesek wrote: > ...
3 years, 7 months ago (2017-05-11 00:24:06 UTC) #80
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2852233002/370001
3 years, 7 months ago (2017-05-11 01:11:53 UTC) #85
commit-bot: I haz the power
Committed patchset #11 (id:370001) as https://chromium.googlesource.com/chromium/src/+/335d78a0e0299bda3465cb7e303b79e043f680da
3 years, 7 months ago (2017-05-11 01:19:49 UTC) #88
Robert Sesek
3 years, 7 months ago (2017-05-11 16:12:36 UTC) #89
Message was sent while issue was closed.
https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/mess...
File base/message_loop/message_pump_mac.mm (right):

https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/mess...
base/message_loop/message_pump_mac.mm:35: kCFRunLoopCommonModes,
kMessageLoopExclusiveRunLoopMode,
On 2017/05/11 00:24:06, tapted wrote:
> On 2017/05/10 14:02:49, Robert Sesek wrote:
> > On 2017/05/10 14:00:18, Mark Mentovai wrote:
> > > I guess I’m not supposed to complain if clang-format wrote this, but the
> > second
> > > item on this line is kind of hiding.
> > 
> > I complain all the time about this because clang-format is wrong, and I'm
not
> > going to apologize for that :).
> > 
> > I've started using "// clang-format off" around lists of things to
compensate.
> 
> I added a comment, 
> 
> // Mode that only sees Chrome work sources.
> kMessageLoopExclusiveRunLoopMode,
> 
> 
> (Incidentally... and probably orthogonal, do we still need
> kMessageLoopExclusiveRunLoopMode?
> 
> `git grep` only shows it being passed to CFRunLoopAddObserver(), but then only
> in combination with kCFRunLoopCommonModes -- it looks like we only ever spin a
> run loop in the kMessageLoopExclusiveRunLoopMode in a couple of unit test
> files).

I was wondering the same thing. The Exclusive mode was added a while ago, but I
don't think it was ultimately used as intended. I can't tell if the few cases
where it's currently used are actually required, or if CommonModes are
sufficient.

https://codereview.chromium.org/2852233002/diff/350001/base/message_loop/mess...
base/message_loop/message_pump_mac.mm:44: void
CFRunLoopAddSourceToAllModes(CFRunLoopRef rl, CFRunLoopSourceRef source) {
On 2017/05/11 00:24:05, tapted wrote:
> On 2017/05/10 13:37:27, Robert Sesek wrote:
> > One last thought: it would be nice if we could limit this to the
> > MessagePumpNSApplication, but I don't see a clean way to do that since these
> are
> > installed in the MessagePumpCFRunLoopBase and the members are private, not
> > protected. Maybe Mark has an idea.
> 
> We could pass a std::vector of scoped_cftyperef<CFStringRef> to the
> MessagePumpCFRunLoopBase constructor? Or a vector<size_t> of kAllModes
indices.
> 
> I don't know enough about the message pump stuff to know how crucial this is..
> Leaving as is, but LMK if I should explore it now, or in a follow-up.

I don't think it's critical since the mode should only be used on the AppKit
main thread. Passing a vector of additional modes (in addition to CommonModes)
to the MessagePumpCFRunLoopBase constructor seems reasonable. If this CL sticks,
I think it's worth considering.

Powered by Google App Engine
This is Rietveld 408576698