clang-format objc files (#12673)
This commit is contained in:
parent
94236bf4eb
commit
12a57ff1c2
54 changed files with 1298 additions and 1033 deletions
|
@ -4,13 +4,13 @@
|
|||
|
||||
#include "atom/browser/ui/tray_icon_cocoa.h"
|
||||
|
||||
#include "atom/browser/ui/cocoa/atom_menu_controller.h"
|
||||
#include "atom/browser/ui/cocoa/NSString+ANSI.h"
|
||||
#include "atom/browser/ui/cocoa/atom_menu_controller.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/events/cocoa/cocoa_event_utils.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/gfx/mac/coordinate_conversion.h"
|
||||
#include "ui/display/screen.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -22,8 +22,8 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
} // namespace
|
||||
|
||||
@interface StatusItemView : NSView {
|
||||
atom::TrayIconCocoa* trayIcon_; // weak
|
||||
AtomMenuController* menuController_; // weak
|
||||
atom::TrayIconCocoa* trayIcon_; // weak
|
||||
AtomMenuController* menuController_; // weak
|
||||
atom::TrayIcon::HighlightMode highlight_mode_;
|
||||
BOOL forceHighlight_;
|
||||
BOOL inMouseEventSequence_;
|
||||
|
@ -47,24 +47,26 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
forceHighlight_ = NO;
|
||||
inMouseEventSequence_ = NO;
|
||||
|
||||
if ((self = [super initWithFrame: CGRectZero])) {
|
||||
[self registerForDraggedTypes: @[
|
||||
if ((self = [super initWithFrame:CGRectZero])) {
|
||||
[self registerForDraggedTypes:@[
|
||||
NSFilenamesPboardType,
|
||||
NSStringPboardType,
|
||||
]];
|
||||
|
||||
// Create the status item.
|
||||
NSStatusItem * item = [[NSStatusBar systemStatusBar]
|
||||
statusItemWithLength:NSVariableStatusItemLength];
|
||||
NSStatusItem* item = [[NSStatusBar systemStatusBar]
|
||||
statusItemWithLength:NSVariableStatusItemLength];
|
||||
statusItem_.reset([item retain]);
|
||||
[statusItem_ setView:self];
|
||||
// Finalize setup by sizing our views
|
||||
[self updateDimensions];
|
||||
|
||||
// Add NSTrackingArea for listening to mouseEnter, mouseExit, and mouseMove events
|
||||
// Add NSTrackingArea for listening to mouseEnter, mouseExit, and mouseMove
|
||||
// events
|
||||
trackingArea_.reset([[NSTrackingArea alloc]
|
||||
initWithRect:[self bounds]
|
||||
options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways
|
||||
options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
|
||||
NSTrackingActiveAlways
|
||||
owner:self
|
||||
userInfo:nil]);
|
||||
[self addTrackingArea:trackingArea_];
|
||||
|
@ -73,8 +75,8 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
}
|
||||
|
||||
- (void)updateDimensions {
|
||||
NSStatusBar * bar = [NSStatusBar systemStatusBar];
|
||||
[self setFrame: NSMakeRect(0, 0, [self fullWidth], [bar thickness])];
|
||||
NSStatusBar* bar = [NSStatusBar systemStatusBar];
|
||||
[self setFrame:NSMakeRect(0, 0, [self fullWidth], [bar thickness])];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
|
@ -110,25 +112,23 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
if ([image isTemplate] == YES) {
|
||||
NSImage* imageWithColor = [[image copy] autorelease];
|
||||
[imageWithColor lockFocus];
|
||||
[[self colorWithHighlight: [self isHighlighted]] set];
|
||||
CGRect imageBounds = CGRectMake(0,0, image.size.width, image.size.height);
|
||||
[[self colorWithHighlight:[self isHighlighted]] set];
|
||||
CGRect imageBounds = CGRectMake(0, 0, image.size.width, image.size.height);
|
||||
NSRectFillUsingOperation(imageBounds, NSCompositeSourceAtop);
|
||||
[imageWithColor unlockFocus];
|
||||
image = imageWithColor;
|
||||
}
|
||||
|
||||
// Draw the image
|
||||
[image drawInRect: CGRectMake(
|
||||
roundf(([self iconWidth] - image.size.width) / 2),
|
||||
roundf((thickness - image.size.height) / 2),
|
||||
image.size.width,
|
||||
image.size.height
|
||||
)];
|
||||
[image
|
||||
drawInRect:CGRectMake(roundf(([self iconWidth] - image.size.width) / 2),
|
||||
roundf((thickness - image.size.height) / 2),
|
||||
image.size.width, image.size.height)];
|
||||
|
||||
if (title_) {
|
||||
// Draw title.
|
||||
NSRect titleDrawRect = NSMakeRect(
|
||||
[self iconWidth], -kVerticalTitleMargin, [self titleWidth], thickness);
|
||||
NSRect titleDrawRect = NSMakeRect([self iconWidth], -kVerticalTitleMargin,
|
||||
[self titleWidth], thickness);
|
||||
[attributedTitle_ drawInRect:titleDrawRect];
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,6 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
return mode && [mode isEqualToString:@"Dark"];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)isHighlighted {
|
||||
BOOL highlight = [self shouldHighlight];
|
||||
return highlight | [self isDarkMode];
|
||||
|
@ -184,9 +183,11 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
}
|
||||
|
||||
- (NSColor*)colorWithHighlight:(BOOL)highlight {
|
||||
return highlight ?
|
||||
[NSColor whiteColor] :
|
||||
[NSColor colorWithRed:0.265625 green:0.25390625 blue:0.234375 alpha:1.0];
|
||||
return highlight ? [NSColor whiteColor]
|
||||
: [NSColor colorWithRed:0.265625
|
||||
green:0.25390625
|
||||
blue:0.234375
|
||||
alpha:1.0];
|
||||
}
|
||||
|
||||
- (void)setImage:(NSImage*)image {
|
||||
|
@ -215,11 +216,9 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
[self updateDimensions];
|
||||
}
|
||||
|
||||
|
||||
- (void)updateAttributedTitle {
|
||||
NSDictionary* attributes = @{
|
||||
NSFontAttributeName:[NSFont menuBarFontOfSize:0]
|
||||
};
|
||||
NSDictionary* attributes =
|
||||
@{NSFontAttributeName : [NSFont menuBarFontOfSize:0]};
|
||||
|
||||
if (ANSI_) {
|
||||
NSCharacterSet* whites = [NSCharacterSet whitespaceCharacterSet];
|
||||
|
@ -231,20 +230,20 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
}
|
||||
|
||||
// check title_ being nil
|
||||
NSString *title = @"";
|
||||
NSString* title = @"";
|
||||
if (title_)
|
||||
title = title_;
|
||||
|
||||
attributedTitle_.reset([[NSMutableAttributedString alloc]
|
||||
initWithString:title
|
||||
attributes:attributes]);
|
||||
initWithString:title
|
||||
attributes:attributes]);
|
||||
|
||||
//NSFontAttributeName:[NSFont menuBarFontOfSize:0],
|
||||
//NSForegroundColorAttributeName:[self colorWithHighlight: highlight]
|
||||
// NSFontAttributeName:[NSFont menuBarFontOfSize:0],
|
||||
// NSForegroundColorAttributeName:[self colorWithHighlight: highlight]
|
||||
[attributedTitle_ addAttributes:attributes
|
||||
range:NSMakeRange(0, [attributedTitle_ length])];
|
||||
[attributedTitle_ addAttribute:NSForegroundColorAttributeName
|
||||
value:[self colorWithHighlight: [self isHighlighted]]
|
||||
value:[self colorWithHighlight:[self isHighlighted]]
|
||||
range:NSMakeRange(0, [attributedTitle_ length])];
|
||||
}
|
||||
|
||||
|
@ -259,10 +258,10 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
|
||||
- (void)mouseUp:(NSEvent*)event {
|
||||
if (!inMouseEventSequence_) {
|
||||
// If the menu is showing, when user clicked the tray icon, the `mouseDown`
|
||||
// event will be dissmissed, we need to close the menu at this time.
|
||||
[self setNeedsDisplay:YES];
|
||||
return;
|
||||
// If the menu is showing, when user clicked the tray icon, the `mouseDown`
|
||||
// event will be dissmissed, we need to close the menu at this time.
|
||||
[self setNeedsDisplay:YES];
|
||||
return;
|
||||
}
|
||||
inMouseEventSequence_ = NO;
|
||||
|
||||
|
@ -299,9 +298,9 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
- (void)popUpContextMenu:(atom::AtomMenuModel*)menu_model {
|
||||
// Show a custom menu.
|
||||
if (menu_model) {
|
||||
base::scoped_nsobject<AtomMenuController> menuController(
|
||||
[[AtomMenuController alloc] initWithModel:menu_model
|
||||
useDefaultAccelerator:NO]);
|
||||
base::scoped_nsobject<AtomMenuController> menuController([
|
||||
[AtomMenuController alloc] initWithModel:menu_model
|
||||
useDefaultAccelerator:NO]);
|
||||
forceHighlight_ = YES; // Should highlight when showing menu.
|
||||
[self setNeedsDisplay:YES];
|
||||
[statusItem_ popUpStatusItemMenu:[menuController menu]];
|
||||
|
@ -326,7 +325,7 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
ui::EventFlagsFromModifiers([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
|
||||
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
||||
trayIcon_->NotifyDragEntered();
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
|
@ -349,11 +348,11 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
ui::EventFlagsFromModifiers([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)draggingExited:(id <NSDraggingInfo>)sender {
|
||||
- (void)draggingExited:(id<NSDraggingInfo>)sender {
|
||||
trayIcon_->NotifyDragExited();
|
||||
}
|
||||
|
||||
- (void)draggingEnded:(id <NSDraggingInfo>)sender {
|
||||
- (void)draggingEnded:(id<NSDraggingInfo>)sender {
|
||||
trayIcon_->NotifyDragEnded();
|
||||
|
||||
if (NSPointInRect([sender draggingLocation], self.frame)) {
|
||||
|
@ -361,7 +360,7 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)handleDrop:(id <NSDraggingInfo>)sender {
|
||||
- (BOOL)handleDrop:(id<NSDraggingInfo>)sender {
|
||||
NSPasteboard* pboard = [sender draggingPasteboard];
|
||||
|
||||
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
|
||||
|
@ -380,11 +379,11 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
|
||||
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
|
||||
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
|
||||
[self handleDrop:sender];
|
||||
return YES;
|
||||
}
|
||||
|
@ -405,8 +404,7 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
|
||||
namespace atom {
|
||||
|
||||
TrayIconCocoa::TrayIconCocoa() : menu_model_(nullptr) {
|
||||
}
|
||||
TrayIconCocoa::TrayIconCocoa() : menu_model_(nullptr) {}
|
||||
|
||||
TrayIconCocoa::~TrayIconCocoa() {
|
||||
[status_item_view_ removeItem];
|
||||
|
@ -419,8 +417,7 @@ void TrayIconCocoa::SetImage(const gfx::Image& image) {
|
|||
[status_item_view_ setImage:image.AsNSImage()];
|
||||
} else {
|
||||
status_item_view_.reset(
|
||||
[[StatusItemView alloc] initWithImage:image.AsNSImage()
|
||||
icon:this]);
|
||||
[[StatusItemView alloc] initWithImage:image.AsNSImage() icon:this]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue