clang-format objc files (#12673)
This commit is contained in:
parent
94236bf4eb
commit
12a57ff1c2
54 changed files with 1298 additions and 1033 deletions
|
@ -1,17 +1,19 @@
|
|||
#import "brightray/browser/browser_main_parts.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#import "base/logging.h"
|
||||
#import "base/mac/bundle_locations.h"
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
namespace brightray {
|
||||
|
||||
void BrowserMainParts::OverrideAppLogsPath() {
|
||||
base::FilePath path;
|
||||
NSString* bundleName = [[[NSBundle mainBundle] infoDictionary]
|
||||
objectForKey:@"CFBundleName"];
|
||||
NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName];
|
||||
NSString* libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:logsPath];
|
||||
NSString* bundleName =
|
||||
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
|
||||
NSString* logsPath =
|
||||
[NSString stringWithFormat:@"Library/Logs/%@", bundleName];
|
||||
NSString* libraryPath =
|
||||
[NSHomeDirectory() stringByAppendingPathComponent:logsPath];
|
||||
|
||||
PathService::Override(DIR_APP_LOGS, base::FilePath([libraryPath UTF8String]));
|
||||
}
|
||||
|
@ -20,11 +22,13 @@ void BrowserMainParts::OverrideAppLogsPath() {
|
|||
void BrowserMainParts::InitializeMainNib() {
|
||||
auto infoDictionary = base::mac::OuterBundle().infoDictionary;
|
||||
|
||||
auto principalClass = NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]);
|
||||
auto principalClass =
|
||||
NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]);
|
||||
auto application = [principalClass sharedApplication];
|
||||
|
||||
NSString *mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"];
|
||||
auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName bundle:base::mac::FrameworkBundle()];
|
||||
NSString* mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"];
|
||||
auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName
|
||||
bundle:base::mac::FrameworkBundle()];
|
||||
[mainNib instantiateWithOwner:application topLevelObjects:nil];
|
||||
[mainNib release];
|
||||
}
|
||||
|
|
|
@ -9,14 +9,16 @@
|
|||
|
||||
namespace brightray {
|
||||
|
||||
InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) {
|
||||
InspectableWebContentsView* CreateInspectableContentsView(
|
||||
InspectableWebContentsImpl* inspectable_web_contents) {
|
||||
return new InspectableWebContentsViewMac(inspectable_web_contents);
|
||||
}
|
||||
|
||||
InspectableWebContentsViewMac::InspectableWebContentsViewMac(InspectableWebContentsImpl* inspectable_web_contents)
|
||||
InspectableWebContentsViewMac::InspectableWebContentsViewMac(
|
||||
InspectableWebContentsImpl* inspectable_web_contents)
|
||||
: inspectable_web_contents_(inspectable_web_contents),
|
||||
view_([[BRYInspectableWebContentsView alloc] initWithInspectableWebContentsViewMac:this]) {
|
||||
}
|
||||
view_([[BRYInspectableWebContentsView alloc]
|
||||
initWithInspectableWebContentsViewMac:this]) {}
|
||||
|
||||
InspectableWebContentsViewMac::~InspectableWebContentsViewMac() {
|
||||
[view_ removeObservers];
|
||||
|
@ -48,7 +50,7 @@ void InspectableWebContentsViewMac::SetIsDocked(bool docked) {
|
|||
}
|
||||
|
||||
void InspectableWebContentsViewMac::SetContentsResizingStrategy(
|
||||
const DevToolsContentsResizingStrategy& strategy) {
|
||||
const DevToolsContentsResizingStrategy& strategy) {
|
||||
[view_ setContentsResizingStrategy:strategy];
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
@implementation BRYInspectableWebContentsView
|
||||
|
||||
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view {
|
||||
- (instancetype)initWithInspectableWebContentsViewMac:
|
||||
(InspectableWebContentsViewMac*)view {
|
||||
self = [super init];
|
||||
if (!self)
|
||||
return nil;
|
||||
|
@ -20,18 +21,19 @@
|
|||
devtools_is_first_responder_ = NO;
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(viewDidBecomeFirstResponder:)
|
||||
name:kViewDidBecomeFirstResponder
|
||||
object:nil];
|
||||
addObserver:self
|
||||
selector:@selector(viewDidBecomeFirstResponder:)
|
||||
name:kViewDidBecomeFirstResponder
|
||||
object:nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(parentWindowBecameMain:)
|
||||
name:NSWindowDidBecomeMainNotification
|
||||
object:nil];
|
||||
addObserver:self
|
||||
selector:@selector(parentWindowBecameMain:)
|
||||
name:NSWindowDidBecomeMainNotification
|
||||
object:nil];
|
||||
|
||||
auto* contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents();
|
||||
auto* contents =
|
||||
inspectableWebContentsView_->inspectable_web_contents()->GetWebContents();
|
||||
auto contentsView = contents->GetNativeView();
|
||||
[contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
[self addSubview:contentsView];
|
||||
|
@ -63,9 +65,11 @@
|
|||
if (visible == devtools_visible_)
|
||||
return;
|
||||
|
||||
auto* inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents();
|
||||
auto* inspectable_web_contents =
|
||||
inspectableWebContentsView_->inspectable_web_contents();
|
||||
auto* webContents = inspectable_web_contents->GetWebContents();
|
||||
auto* devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents();
|
||||
auto* devToolsWebContents =
|
||||
inspectable_web_contents->GetDevToolsWebContents();
|
||||
auto devToolsView = devToolsWebContents->GetNativeView();
|
||||
|
||||
if (visible && devtools_docked_) {
|
||||
|
@ -120,8 +124,10 @@
|
|||
// Switch to new state.
|
||||
devtools_docked_ = docked;
|
||||
if (!docked) {
|
||||
auto* inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents();
|
||||
auto* devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents();
|
||||
auto* inspectable_web_contents =
|
||||
inspectableWebContentsView_->inspectable_web_contents();
|
||||
auto* devToolsWebContents =
|
||||
inspectable_web_contents->GetDevToolsWebContents();
|
||||
auto devToolsView = devToolsWebContents->GetNativeView();
|
||||
|
||||
auto styleMask = NSTitledWindowMask | NSClosableWindowMask |
|
||||
|
@ -137,7 +143,8 @@
|
|||
[devtools_window_ setFrameAutosaveName:@"brightray.devtools"];
|
||||
[devtools_window_ setTitle:@"Developer Tools"];
|
||||
[devtools_window_ setReleasedWhenClosed:NO];
|
||||
[devtools_window_ setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
|
||||
[devtools_window_ setAutorecalculatesContentBorderThickness:NO
|
||||
forEdge:NSMaxYEdge];
|
||||
[devtools_window_ setContentBorderThickness:24 forEdge:NSMaxYEdge];
|
||||
|
||||
NSView* contentView = [devtools_window_ contentView];
|
||||
|
@ -149,7 +156,8 @@
|
|||
[self setDevToolsVisible:YES];
|
||||
}
|
||||
|
||||
- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy {
|
||||
- (void)setContentsResizingStrategy:
|
||||
(const DevToolsContentsResizingStrategy&)strategy {
|
||||
strategy_.CopyFrom(strategy);
|
||||
[self adjustSubviews];
|
||||
}
|
||||
|
@ -184,7 +192,8 @@
|
|||
}
|
||||
|
||||
- (void)viewDidBecomeFirstResponder:(NSNotification*)notification {
|
||||
auto* inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents();
|
||||
auto* inspectable_web_contents =
|
||||
inspectableWebContentsView_->inspectable_web_contents();
|
||||
if (!inspectable_web_contents)
|
||||
return;
|
||||
auto* webContents = inspectable_web_contents->GetWebContents();
|
||||
|
@ -196,7 +205,8 @@
|
|||
return;
|
||||
}
|
||||
|
||||
auto* devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents();
|
||||
auto* devToolsWebContents =
|
||||
inspectable_web_contents->GetDevToolsWebContents();
|
||||
if (!devToolsWebContents)
|
||||
return;
|
||||
auto devToolsView = devToolsWebContents->GetNativeView();
|
||||
|
@ -209,7 +219,8 @@
|
|||
|
||||
- (void)parentWindowBecameMain:(NSNotification*)notification {
|
||||
NSWindow* parentWindow = [notification object];
|
||||
if ([self window] == parentWindow && devtools_docked_ && devtools_is_first_responder_)
|
||||
if ([self window] == parentWindow && devtools_docked_ &&
|
||||
devtools_is_first_responder_)
|
||||
[self notifyDevToolsFocused];
|
||||
}
|
||||
|
||||
|
@ -221,7 +232,8 @@
|
|||
|
||||
- (void)windowDidBecomeMain:(NSNotification*)notification {
|
||||
content::WebContents* web_contents =
|
||||
inspectableWebContentsView_->inspectable_web_contents()->GetDevToolsWebContents();
|
||||
inspectableWebContentsView_->inspectable_web_contents()
|
||||
->GetDevToolsWebContents();
|
||||
if (!web_contents)
|
||||
return;
|
||||
|
||||
|
@ -236,7 +248,8 @@
|
|||
|
||||
- (void)windowDidResignMain:(NSNotification*)notification {
|
||||
content::WebContents* web_contents =
|
||||
inspectableWebContentsView_->inspectable_web_contents()->GetDevToolsWebContents();
|
||||
inspectableWebContentsView_->inspectable_web_contents()
|
||||
->GetDevToolsWebContents();
|
||||
if (!web_contents)
|
||||
return;
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@ int g_identifier_ = 1;
|
|||
|
||||
CocoaNotification::CocoaNotification(NotificationDelegate* delegate,
|
||||
NotificationPresenter* presenter)
|
||||
: Notification(delegate, presenter) {
|
||||
}
|
||||
: Notification(delegate, presenter) {}
|
||||
|
||||
CocoaNotification::~CocoaNotification() {
|
||||
if (notification_)
|
||||
|
@ -29,7 +28,8 @@ CocoaNotification::~CocoaNotification() {
|
|||
void CocoaNotification::Show(const NotificationOptions& options) {
|
||||
notification_.reset([[NSUserNotification alloc] init]);
|
||||
|
||||
NSString* identifier = [NSString stringWithFormat:@"ElectronNotification%d", g_identifier_++];
|
||||
NSString* identifier =
|
||||
[NSString stringWithFormat:@"ElectronNotification%d", g_identifier_++];
|
||||
|
||||
[notification_ setTitle:base::SysUTF16ToNSString(options.title)];
|
||||
[notification_ setSubtitle:base::SysUTF16ToNSString(options.subtitle)];
|
||||
|
@ -58,23 +58,28 @@ void CocoaNotification::Show(const NotificationOptions& options) {
|
|||
|
||||
int i = 0;
|
||||
action_index_ = UINT_MAX;
|
||||
NSMutableArray* additionalActions = [[[NSMutableArray alloc] init] autorelease];
|
||||
NSMutableArray* additionalActions =
|
||||
[[[NSMutableArray alloc] init] autorelease];
|
||||
for (const auto& action : options.actions) {
|
||||
if (action.type == base::ASCIIToUTF16("button")) {
|
||||
if (action_index_ == UINT_MAX) {
|
||||
// First button observed is the displayed action
|
||||
[notification_ setHasActionButton:true];
|
||||
[notification_ setActionButtonTitle:base::SysUTF16ToNSString(action.text)];
|
||||
[notification_
|
||||
setActionButtonTitle:base::SysUTF16ToNSString(action.text)];
|
||||
action_index_ = i;
|
||||
} else {
|
||||
// All of the rest are appended to the list of additional actions
|
||||
NSString* actionIdentifier = [NSString stringWithFormat:@"%@Action%d", identifier, i];
|
||||
NSString* actionIdentifier =
|
||||
[NSString stringWithFormat:@"%@Action%d", identifier, i];
|
||||
if (@available(macOS 10.10, *)) {
|
||||
NSUserNotificationAction* notificationAction =
|
||||
[NSUserNotificationAction actionWithIdentifier:actionIdentifier
|
||||
title:base::SysUTF16ToNSString(action.text)];
|
||||
[NSUserNotificationAction
|
||||
actionWithIdentifier:actionIdentifier
|
||||
title:base::SysUTF16ToNSString(action.text)];
|
||||
[additionalActions addObject:notificationAction];
|
||||
additional_action_indices_.insert(std::make_pair(base::SysNSStringToUTF8(actionIdentifier), i));
|
||||
additional_action_indices_.insert(
|
||||
std::make_pair(base::SysNSStringToUTF8(actionIdentifier), i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,12 +93,14 @@ void CocoaNotification::Show(const NotificationOptions& options) {
|
|||
}
|
||||
|
||||
if (options.has_reply) {
|
||||
[notification_ setResponsePlaceholder:base::SysUTF16ToNSString(options.reply_placeholder)];
|
||||
[notification_ setResponsePlaceholder:base::SysUTF16ToNSString(
|
||||
options.reply_placeholder)];
|
||||
[notification_ setHasReplyButton:true];
|
||||
}
|
||||
|
||||
if (!options.close_button_text.empty()) {
|
||||
[notification_ setOtherButtonTitle:base::SysUTF16ToNSString(options.close_button_text)];
|
||||
[notification_ setOtherButtonTitle:base::SysUTF16ToNSString(
|
||||
options.close_button_text)];
|
||||
}
|
||||
|
||||
[NSUserNotificationCenter.defaultUserNotificationCenter
|
||||
|
@ -131,7 +138,8 @@ void CocoaNotification::NotificationActivated() {
|
|||
this->LogAction("button clicked");
|
||||
}
|
||||
|
||||
void CocoaNotification::NotificationActivated(NSUserNotificationAction* action) {
|
||||
void CocoaNotification::NotificationActivated(
|
||||
NSUserNotificationAction* action) {
|
||||
if (delegate()) {
|
||||
unsigned index = action_index_;
|
||||
std::string identifier = base::SysNSStringToUTF8(action.identifier);
|
||||
|
@ -151,7 +159,8 @@ void CocoaNotification::NotificationActivated(NSUserNotificationAction* action)
|
|||
void CocoaNotification::LogAction(const char* action) {
|
||||
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
||||
NSString* identifier = [notification_ valueForKey:@"identifier"];
|
||||
LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String] << ")";
|
||||
LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String]
|
||||
<< ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
return NO;
|
||||
else
|
||||
return [super performKeyEquivalent:event];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)redispatchKeyEvent:(NSEvent*)event {
|
||||
NSEventType eventType = [event type];
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
@implementation NotificationCenterDelegate
|
||||
|
||||
- (instancetype)initWithPresenter:(brightray::NotificationPresenterMac*)presenter {
|
||||
- (instancetype)initWithPresenter:
|
||||
(brightray::NotificationPresenterMac*)presenter {
|
||||
self = [super init];
|
||||
if (!self)
|
||||
return nil;
|
||||
|
@ -26,25 +27,32 @@
|
|||
}
|
||||
|
||||
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
||||
didActivateNotification:(NSUserNotification *)notif {
|
||||
didActivateNotification:(NSUserNotification*)notif {
|
||||
auto* notification = presenter_->GetNotification(notif);
|
||||
|
||||
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
||||
LOG(INFO) << "Notification activated (" << [notif.identifier UTF8String] << ")";
|
||||
LOG(INFO) << "Notification activated (" << [notif.identifier UTF8String]
|
||||
<< ")";
|
||||
}
|
||||
|
||||
if (notification) {
|
||||
// Ref: https://developer.apple.com/documentation/foundation/nsusernotificationactivationtype?language=objc
|
||||
if (notif.activationType == NSUserNotificationActivationTypeContentsClicked) {
|
||||
// Ref:
|
||||
// https://developer.apple.com/documentation/foundation/nsusernotificationactivationtype?language=objc
|
||||
if (notif.activationType ==
|
||||
NSUserNotificationActivationTypeContentsClicked) {
|
||||
notification->NotificationClicked();
|
||||
} else if (notif.activationType == NSUserNotificationActivationTypeActionButtonClicked) {
|
||||
} else if (notif.activationType ==
|
||||
NSUserNotificationActivationTypeActionButtonClicked) {
|
||||
notification->NotificationActivated();
|
||||
} else if (notif.activationType == NSUserNotificationActivationTypeReplied) {
|
||||
} else if (notif.activationType ==
|
||||
NSUserNotificationActivationTypeReplied) {
|
||||
notification->NotificationReplied([notif.response.string UTF8String]);
|
||||
} else {
|
||||
if (@available(macOS 10.10, *)) {
|
||||
if (notif.activationType == NSUserNotificationActivationTypeAdditionalActionClicked) {
|
||||
notification->NotificationActivated([notif additionalActivationAction]);
|
||||
if (notif.activationType ==
|
||||
NSUserNotificationActivationTypeAdditionalActionClicked) {
|
||||
notification->NotificationActivated(
|
||||
[notif additionalActivationAction]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,13 @@ CocoaNotification* NotificationPresenterMac::GetNotification(
|
|||
for (Notification* notification : notifications()) {
|
||||
auto* native_notification = static_cast<CocoaNotification*>(notification);
|
||||
if ([native_notification->notification().identifier
|
||||
isEqual:ns_notification.identifier])
|
||||
isEqual:ns_notification.identifier])
|
||||
return native_notification;
|
||||
}
|
||||
|
||||
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
||||
LOG(INFO) << "Could not find notification for " << [ns_notification.identifier UTF8String];
|
||||
LOG(INFO) << "Could not find notification for "
|
||||
<< [ns_notification.identifier UTF8String];
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue