2019-01-22 20:13:33 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "nsTouchBar.h"
|
|
|
|
|
|
|
|
#include "mozilla/MacStringHelpers.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "nsArrayUtils.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsIArray.h"
|
|
|
|
|
|
|
|
@implementation nsTouchBar
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
static NSTouchBarItemIdentifier CustomButtonIdentifier = @"com.mozilla.firefox.touchbar.button";
|
2019-01-22 20:13:33 +03:00
|
|
|
static NSTouchBarItemIdentifier CustomMainButtonIdentifier =
|
|
|
|
@"com.mozilla.firefox.touchbar.mainbutton";
|
2019-01-24 11:11:00 +03:00
|
|
|
static NSTouchBarItemIdentifier ScrubberIdentifier = @"com.mozilla.firefox.touchbar.scrubber";
|
2019-01-22 20:13:33 +03:00
|
|
|
|
|
|
|
// Non-JS scrubber implemention for the Share Scrubber,
|
|
|
|
// since it is defined by an Apple API.
|
|
|
|
static NSTouchBarItemIdentifier ShareScrubberIdentifier =
|
2019-01-24 11:11:00 +03:00
|
|
|
[ScrubberIdentifier stringByAppendingPathExtension:@"share"];
|
2019-01-22 20:13:33 +03:00
|
|
|
|
|
|
|
// Used to tie action strings to buttons.
|
|
|
|
static char sIdentifierAssociationKey;
|
|
|
|
|
|
|
|
// The system default width for Touch Bar inputs is 128px. This is double.
|
|
|
|
#define MAIN_BUTTON_WIDTH 256
|
|
|
|
|
|
|
|
#pragma mark - NSTouchBarDelegate
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (instancetype)init {
|
2019-01-22 20:13:33 +03:00
|
|
|
if ((self = [super init])) {
|
|
|
|
mTouchBarHelper = do_GetService(NS_TOUCHBARHELPER_CID);
|
|
|
|
if (!mTouchBarHelper) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.delegate = self;
|
|
|
|
self.mappedLayoutItems = [NSMutableDictionary dictionary];
|
|
|
|
nsCOMPtr<nsIArray> layoutItems;
|
|
|
|
|
|
|
|
nsresult rv = mTouchBarHelper->GetLayout(getter_AddRefs(layoutItems));
|
|
|
|
if (NS_FAILED(rv) || !layoutItems) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t itemCount = 0;
|
|
|
|
layoutItems->GetLength(&itemCount);
|
2019-01-24 11:11:00 +03:00
|
|
|
// This is copied to self.defaultItemIdentifiers. Required since
|
2019-01-22 20:13:33 +03:00
|
|
|
// [self.mappedLayoutItems allKeys] does not preserve order.
|
2019-01-24 11:11:00 +03:00
|
|
|
NSMutableArray* orderedLayoutIdentifiers = [NSMutableArray arrayWithCapacity:itemCount];
|
2019-01-22 20:13:33 +03:00
|
|
|
for (uint32_t i = 0; i < itemCount; ++i) {
|
|
|
|
nsCOMPtr<nsITouchBarInput> input = do_QueryElementAt(layoutItems, i);
|
|
|
|
if (!input) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
TouchBarInput* convertedInput = [[TouchBarInput alloc] initWithXPCOM:input];
|
2019-01-22 20:13:33 +03:00
|
|
|
|
|
|
|
// Add new input to dictionary for lookup of properties in delegate.
|
|
|
|
self.mappedLayoutItems[[convertedInput nativeIdentifier]] = convertedInput;
|
|
|
|
orderedLayoutIdentifiers[i] = [convertedInput nativeIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
self.defaultItemIdentifiers = [orderedLayoutIdentifiers copy];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)dealloc {
|
2019-01-22 20:13:33 +03:00
|
|
|
for (NSTouchBarItemIdentifier identifier in self.mappedLayoutItems) {
|
|
|
|
NSTouchBarItem* item = [self itemForIdentifier:identifier];
|
|
|
|
[item release];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.defaultItemIdentifiers release];
|
|
|
|
|
|
|
|
[self.mappedLayoutItems removeAllObjects];
|
|
|
|
[self.mappedLayoutItems release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTouchBarItem*)touchBar:(NSTouchBar*)aTouchBar
|
2019-01-24 11:11:00 +03:00
|
|
|
makeItemForIdentifier:(NSTouchBarItemIdentifier)aIdentifier {
|
2019-01-22 20:13:33 +03:00
|
|
|
if ([aIdentifier hasPrefix:ScrubberIdentifier]) {
|
|
|
|
if (![aIdentifier isEqualToString:ShareScrubberIdentifier]) {
|
|
|
|
// We're only supporting the Share scrubber for now.
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return [self makeShareScrubberForIdentifier:aIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
// The cases of a button or main button require the same setup.
|
2019-01-24 11:11:00 +03:00
|
|
|
NSButton* button = [NSButton buttonWithTitle:@"" target:self action:@selector(touchBarAction:)];
|
|
|
|
NSCustomTouchBarItem* item = [[NSCustomTouchBarItem alloc] initWithIdentifier:aIdentifier];
|
2019-01-22 20:13:33 +03:00
|
|
|
item.view = button;
|
|
|
|
|
|
|
|
TouchBarInput* input = self.mappedLayoutItems[aIdentifier];
|
|
|
|
if ([aIdentifier hasPrefix:CustomButtonIdentifier]) {
|
|
|
|
return [self updateButton:item input:input];
|
|
|
|
} else if ([aIdentifier hasPrefix:CustomMainButtonIdentifier]) {
|
|
|
|
return [self updateMainButton:item input:input];
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)updateItem:(TouchBarInput*)aInput {
|
2019-01-22 20:13:33 +03:00
|
|
|
NSTouchBarItem* item = [self itemForIdentifier:[aInput nativeIdentifier]];
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ([[aInput nativeIdentifier] hasPrefix:CustomButtonIdentifier]) {
|
2019-01-24 11:11:00 +03:00
|
|
|
[self updateButton:(NSCustomTouchBarItem*)item input:aInput];
|
2019-01-22 20:13:33 +03:00
|
|
|
} else if ([[aInput nativeIdentifier] hasPrefix:CustomMainButtonIdentifier]) {
|
2019-01-24 11:11:00 +03:00
|
|
|
[self updateMainButton:(NSCustomTouchBarItem*)item input:aInput];
|
2019-01-22 20:13:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[self.mappedLayoutItems[[aInput nativeIdentifier]] release];
|
|
|
|
self.mappedLayoutItems[[aInput nativeIdentifier]] = aInput;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (NSTouchBarItem*)updateButton:(NSCustomTouchBarItem*)aButton input:(TouchBarInput*)aInput {
|
2019-01-22 20:13:33 +03:00
|
|
|
NSButton* button = (NSButton*)aButton.view;
|
|
|
|
if (!button) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
button.title = [aInput title];
|
|
|
|
if ([aInput image]) {
|
|
|
|
button.image = [aInput image];
|
|
|
|
[button setImagePosition:NSImageOnly];
|
|
|
|
}
|
|
|
|
|
|
|
|
[button setEnabled:![aInput isDisabled]];
|
|
|
|
|
|
|
|
if ([aInput color]) {
|
|
|
|
button.bezelColor = [aInput color];
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
objc_setAssociatedObject(button, &sIdentifierAssociationKey, [aInput nativeIdentifier],
|
|
|
|
OBJC_ASSOCIATION_RETAIN);
|
2019-01-22 20:13:33 +03:00
|
|
|
|
|
|
|
aButton.customizationLabel = [aInput title];
|
|
|
|
|
|
|
|
return aButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTouchBarItem*)updateMainButton:(NSCustomTouchBarItem*)aMainButton
|
2019-01-24 11:11:00 +03:00
|
|
|
input:(TouchBarInput*)aInput {
|
|
|
|
aMainButton = (NSCustomTouchBarItem*)[self updateButton:aMainButton input:aInput];
|
2019-01-22 20:13:33 +03:00
|
|
|
NSButton* button = (NSButton*)aMainButton.view;
|
|
|
|
button.imageHugsTitle = YES;
|
|
|
|
// If empty, string is still being localized. Display a blank input instead.
|
|
|
|
if ([button.title isEqualToString:@""]) {
|
|
|
|
[button setImagePosition:NSNoImage];
|
|
|
|
} else {
|
|
|
|
[button setImagePosition:NSImageLeft];
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
[button.widthAnchor constraintGreaterThanOrEqualToConstant:MAIN_BUTTON_WIDTH].active = YES;
|
|
|
|
[button setContentHuggingPriority:1.0 forOrientation:NSLayoutConstraintOrientationHorizontal];
|
2019-01-22 20:13:33 +03:00
|
|
|
return aMainButton;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (NSTouchBarItem*)makeShareScrubberForIdentifier:(NSTouchBarItemIdentifier)aIdentifier {
|
2019-01-22 20:13:33 +03:00
|
|
|
TouchBarInput* input = self.mappedLayoutItems[aIdentifier];
|
|
|
|
// System-default share menu
|
|
|
|
NSSharingServicePickerTouchBarItem* servicesItem =
|
2019-01-24 11:11:00 +03:00
|
|
|
[[NSSharingServicePickerTouchBarItem alloc] initWithIdentifier:aIdentifier];
|
2019-01-22 20:13:33 +03:00
|
|
|
servicesItem.buttonImage = [input image];
|
|
|
|
servicesItem.delegate = self;
|
|
|
|
return servicesItem;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)touchBarAction:(id)aSender {
|
2019-01-22 20:13:33 +03:00
|
|
|
NSTouchBarItemIdentifier identifier =
|
2019-01-24 11:11:00 +03:00
|
|
|
objc_getAssociatedObject(aSender, &sIdentifierAssociationKey);
|
|
|
|
if (!identifier || [identifier isEqualToString:@""]) {
|
2019-01-22 20:13:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TouchBarInput* input = self.mappedLayoutItems[identifier];
|
|
|
|
if (!input) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITouchBarInputCallback> callback = [input callback];
|
|
|
|
callback->OnCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - TouchBar Utilities
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
+ (NSImage*)getTouchBarIconNamed:(NSString*)aImageName {
|
2019-01-22 20:13:33 +03:00
|
|
|
nsCOMPtr<nsIFile> resDir;
|
|
|
|
nsAutoCString resPath;
|
|
|
|
NSString* pathToImage;
|
|
|
|
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(resDir));
|
|
|
|
resDir->AppendNative(NS_LITERAL_CSTRING("res"));
|
|
|
|
resDir->AppendNative(NS_LITERAL_CSTRING("touchbar"));
|
|
|
|
|
|
|
|
rv = resDir->GetNativePath(resPath);
|
2019-01-24 11:11:00 +03:00
|
|
|
|
2019-01-22 20:13:33 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
pathToImage = [NSString stringWithUTF8String:(const char*)resPath.get()];
|
|
|
|
pathToImage = [pathToImage stringByAppendingPathComponent:aImageName];
|
2019-01-24 11:11:00 +03:00
|
|
|
NSImage* image = [[[NSImage alloc] initWithContentsOfFile:pathToImage] autorelease];
|
2019-01-22 20:13:33 +03:00
|
|
|
// A nil image will fail gracefully to a labelled button
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - NSSharingServicePickerTouchBarItemDelegate
|
|
|
|
|
|
|
|
- (NSArray*)itemsForSharingServicePickerTouchBarItem:
|
2019-01-24 11:11:00 +03:00
|
|
|
(NSSharingServicePickerTouchBarItem*)aPickerTouchBarItem {
|
2019-01-22 20:13:33 +03:00
|
|
|
NSURL* urlToShare = nil;
|
|
|
|
NSString* titleToShare = @"";
|
|
|
|
nsAutoString url;
|
|
|
|
nsAutoString title;
|
|
|
|
if (mTouchBarHelper) {
|
|
|
|
nsresult rv = mTouchBarHelper->GetActiveUrl(url);
|
|
|
|
if (!NS_FAILED(rv)) {
|
|
|
|
urlToShare = [NSURL URLWithString:nsCocoaUtils::ToNSString(url)];
|
|
|
|
// NSURL URLWithString returns nil if the URL is invalid. At this point,
|
|
|
|
// it is too late to simply shut down the share menu, so we default to
|
|
|
|
// about:blank if the share button is clicked when the URL is invalid.
|
|
|
|
if (urlToShare == nil) {
|
|
|
|
urlToShare = [NSURL URLWithString:@"about:blank"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mTouchBarHelper->GetActiveTitle(title);
|
|
|
|
if (!NS_FAILED(rv)) {
|
|
|
|
titleToShare = nsCocoaUtils::ToNSString(title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the user has gotten this far, they have clicked the share button so it
|
|
|
|
// is logged.
|
2019-01-24 11:11:00 +03:00
|
|
|
Telemetry::AccumulateCategorical(Telemetry::LABELS_TOUCHBAR_BUTTON_PRESSES::Share);
|
2019-01-22 20:13:33 +03:00
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
return @[ urlToShare, titleToShare ];
|
2019-01-22 20:13:33 +03:00
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (NSArray<NSSharingService*>*)sharingServicePicker:(NSSharingServicePicker*)aSharingServicePicker
|
|
|
|
sharingServicesForItems:(NSArray*)aItems
|
|
|
|
proposedSharingServices:(NSArray<NSSharingService*>*)aProposedServices {
|
2019-01-22 20:13:33 +03:00
|
|
|
// redundant services
|
|
|
|
NSArray* excludedServices = @[
|
|
|
|
@"com.apple.share.System.add-to-safari-reading-list",
|
|
|
|
];
|
|
|
|
|
|
|
|
NSArray* sharingServices = [aProposedServices
|
2019-01-24 11:11:00 +03:00
|
|
|
filteredArrayUsingPredicate:[NSPredicate
|
|
|
|
predicateWithFormat:@"NOT (name IN %@)", excludedServices]];
|
2019-01-22 20:13:33 +03:00
|
|
|
|
|
|
|
return sharingServices;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TouchBarInput
|
2019-01-24 11:11:00 +03:00
|
|
|
- (NSString*)key {
|
|
|
|
return mKey;
|
|
|
|
}
|
|
|
|
- (NSString*)title {
|
|
|
|
return mTitle;
|
|
|
|
}
|
|
|
|
- (NSImage*)image {
|
|
|
|
return mImage;
|
|
|
|
}
|
|
|
|
- (NSString*)type {
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
- (NSColor*)color {
|
|
|
|
return mColor;
|
|
|
|
}
|
|
|
|
- (BOOL)isDisabled {
|
|
|
|
return mDisabled;
|
|
|
|
}
|
|
|
|
- (NSTouchBarItemIdentifier)nativeIdentifier {
|
|
|
|
return mNativeIdentifier;
|
|
|
|
}
|
|
|
|
- (nsCOMPtr<nsITouchBarInputCallback>)callback {
|
|
|
|
return mCallback;
|
|
|
|
}
|
|
|
|
- (void)setKey:(NSString*)aKey {
|
2019-01-22 20:13:33 +03:00
|
|
|
[aKey retain];
|
|
|
|
[mKey release];
|
|
|
|
mKey = aKey;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)setTitle:(NSString*)aTitle {
|
2019-01-22 20:13:33 +03:00
|
|
|
[aTitle retain];
|
|
|
|
[mTitle release];
|
|
|
|
mTitle = aTitle;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)setImage:(NSImage*)aImage {
|
2019-01-22 20:13:33 +03:00
|
|
|
[aImage retain];
|
|
|
|
[mImage release];
|
|
|
|
mImage = aImage;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)setType:(NSString*)aType {
|
2019-01-22 20:13:33 +03:00
|
|
|
[aType retain];
|
|
|
|
[mType release];
|
|
|
|
mType = aType;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)setColor:(NSColor*)aColor {
|
2019-01-22 20:13:33 +03:00
|
|
|
[aColor retain];
|
|
|
|
[mColor release];
|
|
|
|
mColor = aColor;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)setDisabled:(BOOL)aDisabled {
|
|
|
|
mDisabled = aDisabled;
|
|
|
|
}
|
2019-01-22 20:13:33 +03:00
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)setNativeIdentifier:(NSTouchBarItemIdentifier)aNativeIdentifier {
|
2019-01-22 20:13:33 +03:00
|
|
|
[aNativeIdentifier retain];
|
|
|
|
[mNativeIdentifier release];
|
|
|
|
mNativeIdentifier = aNativeIdentifier;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)setCallback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback {
|
2019-01-22 20:13:33 +03:00
|
|
|
mCallback = aCallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithKey:(NSString*)aKey
|
|
|
|
title:(NSString*)aTitle
|
|
|
|
image:(NSString*)aImage
|
2019-01-24 11:11:00 +03:00
|
|
|
type:(NSString*)aType
|
|
|
|
callback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback
|
|
|
|
color:(uint32_t)aColor
|
|
|
|
disabled:(BOOL)aDisabled {
|
2019-01-22 20:13:33 +03:00
|
|
|
if (self = [super init]) {
|
|
|
|
[self setKey:aKey];
|
|
|
|
[self setTitle:aTitle];
|
|
|
|
[self setImage:[nsTouchBar getTouchBarIconNamed:aImage]];
|
|
|
|
[self setType:aType];
|
|
|
|
[self setCallback:aCallback];
|
|
|
|
if (aColor) {
|
2019-01-24 11:11:00 +03:00
|
|
|
[self setColor:[NSColor colorWithDisplayP3Red:((aColor >> 16) & 0xFF) / 255.0
|
|
|
|
green:((aColor >> 8) & 0xFF) / 255.0
|
|
|
|
blue:((aColor)&0xFF) / 255.0
|
|
|
|
alpha:1.0]];
|
2019-01-22 20:13:33 +03:00
|
|
|
}
|
|
|
|
[self setDisabled:aDisabled];
|
|
|
|
|
|
|
|
NSTouchBarItemIdentifier TypeIdentifier = @"";
|
|
|
|
if ([aType isEqualToString:@"scrubber"]) {
|
|
|
|
TypeIdentifier = ScrubberIdentifier;
|
|
|
|
} else if ([aType isEqualToString:@"mainButton"]) {
|
|
|
|
TypeIdentifier = CustomMainButtonIdentifier;
|
|
|
|
} else {
|
|
|
|
TypeIdentifier = CustomButtonIdentifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aKey) {
|
|
|
|
[self setNativeIdentifier:TypeIdentifier];
|
|
|
|
} else if ([aKey isEqualToString:@"share"]) {
|
2019-01-24 11:11:00 +03:00
|
|
|
[self setNativeIdentifier:[TypeIdentifier stringByAppendingPathExtension:aKey]];
|
2019-01-22 20:13:33 +03:00
|
|
|
} else {
|
2019-01-24 11:11:00 +03:00
|
|
|
[self setNativeIdentifier:[TypeIdentifier stringByAppendingPathExtension:aKey]];
|
2019-01-22 20:13:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (TouchBarInput*)initWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput {
|
2019-01-22 20:13:33 +03:00
|
|
|
nsAutoString keyStr;
|
|
|
|
nsresult rv = aInput->GetKey(keyStr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString titleStr;
|
|
|
|
rv = aInput->GetTitle(titleStr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString imageStr;
|
|
|
|
rv = aInput->GetImage(imageStr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString typeStr;
|
|
|
|
rv = aInput->GetType(typeStr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITouchBarInputCallback> callback;
|
|
|
|
rv = aInput->GetCallback(getter_AddRefs(callback));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t colorInt;
|
|
|
|
rv = aInput->GetColor(&colorInt);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool disabled = false;
|
|
|
|
rv = aInput->GetDisabled(&disabled);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self initWithKey:nsCocoaUtils::ToNSString(keyStr)
|
|
|
|
title:nsCocoaUtils::ToNSString(titleStr)
|
|
|
|
image:nsCocoaUtils::ToNSString(imageStr)
|
|
|
|
type:nsCocoaUtils::ToNSString(typeStr)
|
|
|
|
callback:callback
|
|
|
|
color:colorInt
|
|
|
|
disabled:(BOOL)disabled];
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:11:00 +03:00
|
|
|
- (void)dealloc {
|
2019-01-22 20:13:33 +03:00
|
|
|
[mKey release];
|
|
|
|
[mTitle release];
|
|
|
|
[mImage release];
|
|
|
|
[mType release];
|
|
|
|
[mColor release];
|
|
|
|
[mNativeIdentifier release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|