Commit b22ea1fa authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Whitelist the run loop mode that AppKit uses to animate the menu in fullscreen.

This stops UI animation and video from freezing during the animation.
Also move some constants to test-accessible location and delete the
duplicates in the tests.

Bug: 554993
Change-Id: Ie4585fa405b32e8bdae984d5a4ffac700c1375ab
Reviewed-on: https://chromium-review.googlesource.com/1166169Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583361}
parent dd9f811b
...@@ -80,6 +80,15 @@ typedef NSAutoreleasePool AutoreleasePoolType; ...@@ -80,6 +80,15 @@ typedef NSAutoreleasePool AutoreleasePoolType;
class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump { class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
public: public:
// Mask that determines which modes to use. Exposed for tests.
enum { kCommonModeMask = 0x1, kAllModesMask = 0x1f };
// Modes to use for MessagePumpNSApplication that are considered "safe".
// Currently just common and exclusive modes. Ideally, messages would be
// pumped in all modes, but that interacts badly with app modal dialogs (e.g.
// NSAlert). Exposed for tests.
enum { kNSApplicationModalSafeModeMask = 0x13 };
// MessagePump: // MessagePump:
void Run(Delegate* delegate) override; void Run(Delegate* delegate) override;
void ScheduleWork() override; void ScheduleWork() override;
...@@ -128,7 +137,7 @@ class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump { ...@@ -128,7 +137,7 @@ class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
class ScopedModeEnabler; class ScopedModeEnabler;
// The maximum number of run loop modes that can be monitored. // The maximum number of run loop modes that can be monitored.
static constexpr int kNumModes = 4; static constexpr int kNumModes = 5;
// Marking timers as invalid at the right time helps significantly reduce // Marking timers as invalid at the right time helps significantly reduce
// power use (see the comment in RunDelayedWorkTimer()), however there is no // power use (see the comment in RunDelayedWorkTimer()), however there is no
......
...@@ -30,14 +30,6 @@ const CFStringRef kMessageLoopExclusiveRunLoopMode = ...@@ -30,14 +30,6 @@ const CFStringRef kMessageLoopExclusiveRunLoopMode =
namespace { namespace {
// Mask that determines which modes to use.
enum { kCommonModeMask = 0x1, kAllModesMask = 0xf };
// Modes to use for MessagePumpNSApplication that are considered "safe".
// Currently just common and exclusive modes. Ideally, messages would be pumped
// in all modes, but that interacts badly with app modal dialogs (e.g. NSAlert).
enum { kNSApplicationModalSafeModeMask = 0x3 };
void NoOp(void* info) { void NoOp(void* info) {
} }
...@@ -156,6 +148,9 @@ class MessagePumpCFRunLoopBase::ScopedModeEnabler { ...@@ -156,6 +148,9 @@ class MessagePumpCFRunLoopBase::ScopedModeEnabler {
// Process work when AppKit is highlighting an item on the main menubar. // Process work when AppKit is highlighting an item on the main menubar.
CFSTR("NSUnhighlightMenuRunLoopMode"), CFSTR("NSUnhighlightMenuRunLoopMode"),
// Process work when AppKit is animating the menu bar.
CFSTR("NSAnimationRunLoopMode"),
}; };
static_assert(arraysize(modes) == kNumModes, "mode size mismatch"); static_assert(arraysize(modes) == kNumModes, "mode size mismatch");
static_assert((1 << kNumModes) - 1 == kAllModesMask, static_assert((1 << kNumModes) - 1 == kAllModesMask,
...@@ -762,16 +757,18 @@ void MessagePumpUIApplication::Attach(Delegate* delegate) { ...@@ -762,16 +757,18 @@ void MessagePumpUIApplication::Attach(Delegate* delegate) {
ScopedPumpMessagesInPrivateModes::ScopedPumpMessagesInPrivateModes() { ScopedPumpMessagesInPrivateModes::ScopedPumpMessagesInPrivateModes() {
DCHECK(g_app_pump); DCHECK(g_app_pump);
DCHECK_EQ(kNSApplicationModalSafeModeMask, g_app_pump->GetModeMask()); DCHECK_EQ(MessagePumpCFRunLoopBase::kNSApplicationModalSafeModeMask,
g_app_pump->GetModeMask());
// Pumping events in private runloop modes is known to interact badly with // Pumping events in private runloop modes is known to interact badly with
// app modal windows like NSAlert. // app modal windows like NSAlert.
if (![NSApp modalWindow]) if (![NSApp modalWindow])
g_app_pump->SetModeMask(kAllModesMask); g_app_pump->SetModeMask(MessagePumpCFRunLoopBase::kAllModesMask);
} }
ScopedPumpMessagesInPrivateModes::~ScopedPumpMessagesInPrivateModes() { ScopedPumpMessagesInPrivateModes::~ScopedPumpMessagesInPrivateModes() {
DCHECK(g_app_pump); DCHECK(g_app_pump);
g_app_pump->SetModeMask(kNSApplicationModalSafeModeMask); g_app_pump->SetModeMask(
MessagePumpCFRunLoopBase::kNSApplicationModalSafeModeMask);
} }
int ScopedPumpMessagesInPrivateModes::GetModeMaskForTest() { int ScopedPumpMessagesInPrivateModes::GetModeMaskForTest() {
......
...@@ -16,14 +16,6 @@ ...@@ -16,14 +16,6 @@
- (void)runTestThenCloseAlert:(NSAlert*)alert; - (void)runTestThenCloseAlert:(NSAlert*)alert;
@end @end
namespace {
// Internal constants from message_pump_mac.mm.
constexpr int kAllModesMask = 0xf;
constexpr int kNSApplicationModalSafeModeMask = 0x3;
} // namespace
namespace base { namespace base {
class TestMessagePumpCFRunLoopBase { class TestMessagePumpCFRunLoopBase {
...@@ -192,7 +184,8 @@ TEST(MessagePumpMacTest, ScopedPumpMessagesAttemptWithModalDialog) { ...@@ -192,7 +184,8 @@ TEST(MessagePumpMacTest, ScopedPumpMessagesAttemptWithModalDialog) {
{ {
base::ScopedPumpMessagesInPrivateModes allow_private; base::ScopedPumpMessagesInPrivateModes allow_private;
// No modal window, so all modes should be pumped. // No modal window, so all modes should be pumped.
EXPECT_EQ(kAllModesMask, allow_private.GetModeMaskForTest()); EXPECT_EQ(MessagePumpCFRunLoopBase::kAllModesMask,
allow_private.GetModeMaskForTest());
} }
base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
...@@ -216,7 +209,7 @@ TEST(MessagePumpMacTest, ScopedPumpMessagesAttemptWithModalDialog) { ...@@ -216,7 +209,7 @@ TEST(MessagePumpMacTest, ScopedPumpMessagesAttemptWithModalDialog) {
{ {
base::ScopedPumpMessagesInPrivateModes allow_private; base::ScopedPumpMessagesInPrivateModes allow_private;
// With a modal window, only safe modes should be pumped. // With a modal window, only safe modes should be pumped.
EXPECT_EQ(kNSApplicationModalSafeModeMask, EXPECT_EQ(base::MessagePumpCFRunLoopBase::kNSApplicationModalSafeModeMask,
allow_private.GetModeMaskForTest()); allow_private.GetModeMaskForTest());
} }
[[alert buttons][0] performClick:nil]; [[alert buttons][0] performClick:nil];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment