From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- ipc/chromium/src/base/chrome_application_mac.mm | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ipc/chromium/src/base/chrome_application_mac.mm (limited to 'ipc/chromium/src/base/chrome_application_mac.mm') diff --git a/ipc/chromium/src/base/chrome_application_mac.mm b/ipc/chromium/src/base/chrome_application_mac.mm new file mode 100644 index 0000000000..4df6df5593 --- /dev/null +++ b/ipc/chromium/src/base/chrome_application_mac.mm @@ -0,0 +1,64 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome_application_mac.h" + +#include "base/logging.h" + +@interface CrApplication () +@property(readwrite, getter=isHandlingSendEvent, nonatomic) BOOL handlingSendEvent; +@end + +@implementation CrApplication +@synthesize handlingSendEvent = handlingSendEvent_; + +// Initialize NSApplication using the custom subclass. Check whether NSApp +// was already initialized using another class, because that would break +// some things. ++ (NSApplication*)sharedApplication { + NSApplication* app = [super sharedApplication]; + if (![NSApp isKindOfClass:self]) { + CHROMIUM_LOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String] << ", not " + << [[NSApp className] UTF8String]; + DCHECK(false) << "NSApp is of wrong type"; + } + return app; +} + +- (id)init { + if ((self = [super init])) { + eventHooks_.reset([[NSMutableArray alloc] init]); + } + return self; +} + +- (void)sendEvent:(NSEvent*)event { + chrome_application_mac::ScopedSendingEvent sendingEventScoper; + for (id handler in eventHooks_.get()) { + [handler hookForEvent:event]; + } + [super sendEvent:event]; +} + +- (void)addEventHook:(id)handler { + [eventHooks_ addObject:handler]; +} + +- (void)removeEventHook:(id)handler { + [eventHooks_ removeObject:handler]; +} + +@end + +namespace chrome_application_mac { + +ScopedSendingEvent::ScopedSendingEvent() + : app_(static_cast([CrApplication sharedApplication])), + handling_([app_ isHandlingSendEvent]) { + [app_ setHandlingSendEvent:YES]; +} + +ScopedSendingEvent::~ScopedSendingEvent() { [app_ setHandlingSendEvent:handling_]; } + +} // namespace chrome_application_mac -- cgit v1.2.3