Bug 1600356 - Part 1 - Split out TouchBarInput into its own files. r=spohl

nsTouchBar.h/.mm were getting a bit unwieldy, particularly after the TouchBarInputBaseType enum from the next part of this patch was added. This part splits out TouchBarInput into its own files. This makes the Touch Bar's file structure similar to that of the menu bar's: nsMenuBarX, nsMenuBarItemX, and nsMenuBarItemIconX contrasted with nsTouchBar, nsTouchBarInput, and nsTouchBarInputIcon.

Differential Revision: https://phabricator.services.mozilla.com/D56589

--HG--
extra : moz-landing-system : lando
This commit is contained in:
harry 2019-12-31 20:26:00 +00:00
Родитель 18799a7fc4
Коммит 02ad23c3cc
7 изменённых файлов: 363 добавлений и 341 удалений

Просмотреть файл

@ -61,6 +61,7 @@ UNIFIED_SOURCES += [
'nsSystemStatusBarCocoa.mm',
'nsToolkit.mm',
'nsTouchBar.mm',
'nsTouchBarInput.mm',
'nsTouchBarInputIcon.mm',
'nsTouchBarUpdater.mm',
'nsWidgetFactory.mm',

Просмотреть файл

@ -8,79 +8,9 @@
#import <Cocoa/Cocoa.h>
#include "nsITouchBarHelper.h"
#include "nsITouchBarInput.h"
#include "nsTouchBarInputIcon.h"
#include "nsTouchBarInput.h"
#include "nsTouchBarNativeAPIDefines.h"
using namespace mozilla::dom;
/**
* NSObject representation of nsITouchBarInput.
*/
@interface TouchBarInput : NSObject {
NSString* mKey;
NSString* mTitle;
nsCOMPtr<nsIURI> mImageURI;
RefPtr<nsTouchBarInputIcon> mIcon;
NSString* mType;
NSColor* mColor;
BOOL mDisabled;
nsCOMPtr<nsITouchBarInputCallback> mCallback;
RefPtr<Document> mDocument;
BOOL mIsIconPositionSet;
NSMutableArray<TouchBarInput*>* mChildren;
}
- (NSString*)key;
- (NSString*)title;
- (nsCOMPtr<nsIURI>)imageURI;
- (RefPtr<nsTouchBarInputIcon>)icon;
- (NSString*)type;
- (NSColor*)color;
- (BOOL)isDisabled;
- (NSTouchBarItemIdentifier)nativeIdentifier;
- (nsCOMPtr<nsITouchBarInputCallback>)callback;
- (RefPtr<Document>)document;
- (BOOL)isIconPositionSet;
- (NSMutableArray<TouchBarInput*>*)children;
- (void)setKey:(NSString*)aKey;
- (void)setTitle:(NSString*)aTitle;
- (void)setImageURI:(nsCOMPtr<nsIURI>)aImageURI;
- (void)setIcon:(RefPtr<nsTouchBarInputIcon>)aIcon;
- (void)setType:(NSString*)aType;
- (void)setColor:(NSColor*)aColor;
- (void)setDisabled:(BOOL)aDisabled;
- (void)setCallback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback;
- (void)setDocument:(RefPtr<Document>)aDocument;
- (void)setIconPositionSet:(BOOL)aIsIconPositionSet;
- (void)setChildren:(NSMutableArray<TouchBarInput*>*)aChildren;
- (id)initWithKey:(NSString*)aKey
title:(NSString*)aTitle
imageURI:(nsCOMPtr<nsIURI>)aImageURI
type:(NSString*)aType
callback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback
color:(uint32_t)aColor
disabled:(BOOL)aDisabled
document:(RefPtr<Document>)aDocument
children:(nsCOMPtr<nsIArray>)aChildren;
- (TouchBarInput*)initWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput;
- (void)releaseJSObjects;
- (void)dealloc;
/**
* We make these helper methods static so that other classes can query a
* TouchBarInput's nativeIdentifier (e.g. nsTouchBarUpdater looking up a
* popover in mappedLayoutItems).
*/
+ (NSTouchBarItemIdentifier)nativeIdentifierWithType:(NSString*)aType withKey:(NSString*)aKey;
+ (NSTouchBarItemIdentifier)nativeIdentifierWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput;
@end
/**
* Our TouchBar is its own delegate. This is adequate for our purposes,
* since the current implementation only defines Touch Bar buttons for the

Просмотреть файл

@ -9,6 +9,7 @@
#include "nsArrayUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIArray.h"
#include "nsTouchBarInputIcon.h"
@implementation nsTouchBar
@ -557,10 +558,6 @@ static const uint32_t kInputIconSize = 16;
[(nsTouchBar*)[(NSPopoverTouchBarItem*)item popoverTouchBar] releaseJSObjects];
}
[input setCallback:nil];
[input setDocument:nil];
[input setImageURI:nil];
[input releaseJSObjects];
}
}
@ -614,268 +611,3 @@ static const uint32_t kInputIconSize = 16;
}
@end
@implementation TouchBarInput
- (NSString*)key {
return mKey;
}
- (NSString*)title {
return mTitle;
}
- (nsCOMPtr<nsIURI>)imageURI {
return mImageURI;
}
- (RefPtr<nsTouchBarInputIcon>)icon {
return mIcon;
}
- (NSString*)type {
return mType;
}
- (NSColor*)color {
return mColor;
}
- (BOOL)isDisabled {
return mDisabled;
}
- (NSTouchBarItemIdentifier)nativeIdentifier {
return [TouchBarInput nativeIdentifierWithType:mType withKey:mKey];
}
- (nsCOMPtr<nsITouchBarInputCallback>)callback {
return mCallback;
}
- (RefPtr<Document>)document {
return mDocument;
}
- (BOOL)isIconPositionSet {
return mIsIconPositionSet;
}
- (NSMutableArray<TouchBarInput*>*)children {
return mChildren;
}
- (void)setKey:(NSString*)aKey {
[aKey retain];
[mKey release];
mKey = aKey;
}
- (void)setTitle:(NSString*)aTitle {
[aTitle retain];
[mTitle release];
mTitle = aTitle;
}
- (void)setImageURI:(nsCOMPtr<nsIURI>)aImageURI {
mImageURI = aImageURI;
}
- (void)setIcon:(RefPtr<nsTouchBarInputIcon>)aIcon {
mIcon = aIcon;
}
- (void)setType:(NSString*)aType {
[aType retain];
[mType release];
mType = aType;
}
- (void)setColor:(NSColor*)aColor {
[aColor retain];
[mColor release];
mColor = aColor;
}
- (void)setDisabled:(BOOL)aDisabled {
mDisabled = aDisabled;
}
- (void)setCallback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback {
mCallback = aCallback;
}
- (void)setDocument:(RefPtr<Document>)aDocument {
if (mIcon) {
mIcon->Destroy();
mIcon = nil;
}
mDocument = aDocument;
}
- (void)setIconPositionSet:(BOOL)aIsIconPositionSet {
mIsIconPositionSet = aIsIconPositionSet;
}
- (void)setChildren:(NSMutableArray<TouchBarInput*>*)aChildren {
[aChildren retain];
for (TouchBarInput* child in mChildren) {
[child releaseJSObjects];
}
[mChildren removeAllObjects];
[mChildren release];
mChildren = aChildren;
}
- (id)initWithKey:(NSString*)aKey
title:(NSString*)aTitle
imageURI:(nsCOMPtr<nsIURI>)aImageURI
type:(NSString*)aType
callback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback
color:(uint32_t)aColor
disabled:(BOOL)aDisabled
document:(RefPtr<Document>)aDocument
children:(nsCOMPtr<nsIArray>)aChildren {
if (self = [super init]) {
[self setKey:aKey];
[self setTitle:aTitle];
[self setImageURI:aImageURI];
[self setType:aType];
[self setCallback:aCallback];
[self setDocument:aDocument];
[self setIconPositionSet:false];
[self setDisabled:aDisabled];
if (aColor) {
[self setColor:[NSColor colorWithDisplayP3Red:((aColor >> 16) & 0xFF) / 255.0
green:((aColor >> 8) & 0xFF) / 255.0
blue:((aColor)&0xFF) / 255.0
alpha:1.0]];
}
if (aChildren) {
uint32_t itemCount = 0;
aChildren->GetLength(&itemCount);
NSMutableArray* orderedChildren = [NSMutableArray arrayWithCapacity:itemCount];
for (uint32_t i = 0; i < itemCount; ++i) {
nsCOMPtr<nsITouchBarInput> child = do_QueryElementAt(aChildren, i);
if (!child) {
continue;
}
TouchBarInput* convertedChild = [[TouchBarInput alloc] initWithXPCOM:child];
if (convertedChild) {
orderedChildren[i] = convertedChild;
}
}
[self setChildren:orderedChildren];
}
}
return self;
}
- (TouchBarInput*)initWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput {
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;
}
nsCOMPtr<nsIURI> imageURI;
rv = aInput->GetImage(getter_AddRefs(imageURI));
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;
}
RefPtr<Document> document;
rv = aInput->GetDocument(getter_AddRefs(document));
if (NS_FAILED(rv)) {
return nil;
}
nsCOMPtr<nsIArray> children;
rv = aInput->GetChildren(getter_AddRefs(children));
if (NS_FAILED(rv)) {
return nil;
}
return [self initWithKey:nsCocoaUtils::ToNSString(keyStr)
title:nsCocoaUtils::ToNSString(titleStr)
imageURI:imageURI
type:nsCocoaUtils::ToNSString(typeStr)
callback:callback
color:colorInt
disabled:(BOOL)disabled
document:document
children:children];
}
- (void)releaseJSObjects {
if (mIcon) {
mIcon->ReleaseJSObjects();
}
mCallback = nil;
mImageURI = nil;
mDocument = nil;
for (TouchBarInput* child in mChildren) {
[child releaseJSObjects];
}
}
- (void)dealloc {
if (mIcon) {
mIcon->Destroy();
mIcon = nil;
}
[mKey release];
[mTitle release];
[mType release];
[mColor release];
[mChildren removeAllObjects];
[mChildren release];
[super dealloc];
}
+ (NSTouchBarItemIdentifier)nativeIdentifierWithType:(NSString*)aType withKey:(NSString*)aKey {
NSTouchBarItemIdentifier identifier;
identifier = [BaseIdentifier stringByAppendingPathExtension:aType];
if (aKey) {
identifier = [identifier stringByAppendingPathExtension:aKey];
}
return identifier;
}
+ (NSTouchBarItemIdentifier)nativeIdentifierWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput {
nsAutoString keyStr;
nsresult rv = aInput->GetKey(keyStr);
if (NS_FAILED(rv)) {
return nil;
}
NSString* key = nsCocoaUtils::ToNSString(keyStr);
nsAutoString typeStr;
rv = aInput->GetType(typeStr);
if (NS_FAILED(rv)) {
return nil;
}
NSString* type = nsCocoaUtils::ToNSString(typeStr);
return [TouchBarInput nativeIdentifierWithType:type withKey:key];
}
@end

Просмотреть файл

@ -0,0 +1,84 @@
/* 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/. */
#ifndef nsTouchBarInput_h_
#define nsTouchBarInput_h_
#import <Cocoa/Cocoa.h>
#include "nsITouchBarInput.h"
#include "nsTouchBarNativeAPIDefines.h"
using namespace mozilla::dom;
class nsTouchBarInputIcon;
/**
* NSObject representation of nsITouchBarInput.
*/
@interface TouchBarInput : NSObject {
NSString* mKey;
NSString* mTitle;
nsCOMPtr<nsIURI> mImageURI;
RefPtr<nsTouchBarInputIcon> mIcon;
NSString* mType;
NSColor* mColor;
BOOL mDisabled;
nsCOMPtr<nsITouchBarInputCallback> mCallback;
RefPtr<Document> mDocument;
BOOL mIsIconPositionSet;
NSMutableArray<TouchBarInput*>* mChildren;
}
- (NSString*)key;
- (NSString*)title;
- (nsCOMPtr<nsIURI>)imageURI;
- (RefPtr<nsTouchBarInputIcon>)icon;
- (NSString*)type;
- (NSColor*)color;
- (BOOL)isDisabled;
- (NSTouchBarItemIdentifier)nativeIdentifier;
- (nsCOMPtr<nsITouchBarInputCallback>)callback;
- (RefPtr<Document>)document;
- (BOOL)isIconPositionSet;
- (NSMutableArray<TouchBarInput*>*)children;
- (void)setKey:(NSString*)aKey;
- (void)setTitle:(NSString*)aTitle;
- (void)setImageURI:(nsCOMPtr<nsIURI>)aImageURI;
- (void)setIcon:(RefPtr<nsTouchBarInputIcon>)aIcon;
- (void)setType:(NSString*)aType;
- (void)setColor:(NSColor*)aColor;
- (void)setDisabled:(BOOL)aDisabled;
- (void)setCallback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback;
- (void)setDocument:(RefPtr<Document>)aDocument;
- (void)setIconPositionSet:(BOOL)aIsIconPositionSet;
- (void)setChildren:(NSMutableArray<TouchBarInput*>*)aChildren;
- (id)initWithKey:(NSString*)aKey
title:(NSString*)aTitle
imageURI:(nsCOMPtr<nsIURI>)aImageURI
type:(NSString*)aType
callback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback
color:(uint32_t)aColor
disabled:(BOOL)aDisabled
document:(RefPtr<Document>)aDocument
children:(nsCOMPtr<nsIArray>)aChildren;
- (TouchBarInput*)initWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput;
- (void)releaseJSObjects;
- (void)dealloc;
/**
* We make these helper methods static so that other classes can query a
* TouchBarInput's nativeIdentifier (e.g. nsTouchBarUpdater looking up a
* popover in mappedLayoutItems).
*/
+ (NSTouchBarItemIdentifier)nativeIdentifierWithType:(NSString*)aType withKey:(NSString*)aKey;
+ (NSTouchBarItemIdentifier)nativeIdentifierWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput;
@end
#endif // nsTouchBarInput_h_

Просмотреть файл

@ -0,0 +1,274 @@
/* 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 "nsTouchBarInput.h"
#include "mozilla/MacStringHelpers.h"
#include "nsTouchBarInputIcon.h"
@implementation TouchBarInput
- (NSString*)key {
return mKey;
}
- (NSString*)title {
return mTitle;
}
- (nsCOMPtr<nsIURI>)imageURI {
return mImageURI;
}
- (RefPtr<nsTouchBarInputIcon>)icon {
return mIcon;
}
- (NSString*)type {
return mType;
}
- (NSColor*)color {
return mColor;
}
- (BOOL)isDisabled {
return mDisabled;
}
- (NSTouchBarItemIdentifier)nativeIdentifier {
return [TouchBarInput nativeIdentifierWithType:mType withKey:mKey];
}
- (nsCOMPtr<nsITouchBarInputCallback>)callback {
return mCallback;
}
- (RefPtr<Document>)document {
return mDocument;
}
- (BOOL)isIconPositionSet {
return mIsIconPositionSet;
}
- (NSMutableArray<TouchBarInput*>*)children {
return mChildren;
}
- (void)setKey:(NSString*)aKey {
[aKey retain];
[mKey release];
mKey = aKey;
}
- (void)setTitle:(NSString*)aTitle {
[aTitle retain];
[mTitle release];
mTitle = aTitle;
}
- (void)setImageURI:(nsCOMPtr<nsIURI>)aImageURI {
mImageURI = aImageURI;
}
- (void)setIcon:(RefPtr<nsTouchBarInputIcon>)aIcon {
mIcon = aIcon;
}
- (void)setType:(NSString*)aType {
[aType retain];
[mType release];
mType = aType;
}
- (void)setColor:(NSColor*)aColor {
[aColor retain];
[mColor release];
mColor = aColor;
}
- (void)setDisabled:(BOOL)aDisabled {
mDisabled = aDisabled;
}
- (void)setCallback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback {
mCallback = aCallback;
}
- (void)setDocument:(RefPtr<Document>)aDocument {
if (mIcon) {
mIcon->Destroy();
mIcon = nil;
}
mDocument = aDocument;
}
- (void)setIconPositionSet:(BOOL)aIsIconPositionSet {
mIsIconPositionSet = aIsIconPositionSet;
}
- (void)setChildren:(NSMutableArray<TouchBarInput*>*)aChildren {
[aChildren retain];
for (TouchBarInput* child in mChildren) {
[child releaseJSObjects];
}
[mChildren removeAllObjects];
[mChildren release];
mChildren = aChildren;
}
- (id)initWithKey:(NSString*)aKey
title:(NSString*)aTitle
imageURI:(nsCOMPtr<nsIURI>)aImageURI
type:(NSString*)aType
callback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback
color:(uint32_t)aColor
disabled:(BOOL)aDisabled
document:(RefPtr<Document>)aDocument
children:(nsCOMPtr<nsIArray>)aChildren {
if (self = [super init]) {
[self setKey:aKey];
[self setTitle:aTitle];
[self setImageURI:aImageURI];
[self setType:aType];
[self setCallback:aCallback];
[self setDocument:aDocument];
[self setIconPositionSet:false];
[self setDisabled:aDisabled];
if (aColor) {
[self setColor:[NSColor colorWithDisplayP3Red:((aColor >> 16) & 0xFF) / 255.0
green:((aColor >> 8) & 0xFF) / 255.0
blue:((aColor)&0xFF) / 255.0
alpha:1.0]];
}
if (aChildren) {
uint32_t itemCount = 0;
aChildren->GetLength(&itemCount);
NSMutableArray* orderedChildren = [NSMutableArray arrayWithCapacity:itemCount];
for (uint32_t i = 0; i < itemCount; ++i) {
nsCOMPtr<nsITouchBarInput> child = do_QueryElementAt(aChildren, i);
if (!child) {
continue;
}
TouchBarInput* convertedChild = [[TouchBarInput alloc] initWithXPCOM:child];
if (convertedChild) {
orderedChildren[i] = convertedChild;
}
}
[self setChildren:orderedChildren];
}
}
return self;
}
- (TouchBarInput*)initWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput {
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;
}
nsCOMPtr<nsIURI> imageURI;
rv = aInput->GetImage(getter_AddRefs(imageURI));
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;
}
RefPtr<Document> document;
rv = aInput->GetDocument(getter_AddRefs(document));
if (NS_FAILED(rv)) {
return nil;
}
nsCOMPtr<nsIArray> children;
rv = aInput->GetChildren(getter_AddRefs(children));
if (NS_FAILED(rv)) {
return nil;
}
return [self initWithKey:nsCocoaUtils::ToNSString(keyStr)
title:nsCocoaUtils::ToNSString(titleStr)
imageURI:imageURI
type:nsCocoaUtils::ToNSString(typeStr)
callback:callback
color:colorInt
disabled:(BOOL)disabled
document:document
children:children];
}
- (void)releaseJSObjects {
if (mIcon) {
mIcon->ReleaseJSObjects();
}
[self setCallback:nil];
[self setImageURI:nil];
[self setDocument:nil];
for (TouchBarInput* child in mChildren) {
[child releaseJSObjects];
}
}
- (void)dealloc {
if (mIcon) {
mIcon->Destroy();
mIcon = nil;
}
[mKey release];
[mTitle release];
[mType release];
[mColor release];
[mChildren removeAllObjects];
[mChildren release];
[super dealloc];
}
+ (NSTouchBarItemIdentifier)nativeIdentifierWithType:(NSString*)aType withKey:(NSString*)aKey {
NSTouchBarItemIdentifier identifier;
identifier = [BaseIdentifier stringByAppendingPathExtension:aType];
if (aKey) {
identifier = [identifier stringByAppendingPathExtension:aKey];
}
return identifier;
}
+ (NSTouchBarItemIdentifier)nativeIdentifierWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput {
nsAutoString keyStr;
nsresult rv = aInput->GetKey(keyStr);
if (NS_FAILED(rv)) {
return nil;
}
NSString* key = nsCocoaUtils::ToNSString(keyStr);
nsAutoString typeStr;
rv = aInput->GetType(typeStr);
if (NS_FAILED(rv)) {
return nil;
}
NSString* type = nsCocoaUtils::ToNSString(typeStr);
return [TouchBarInput nativeIdentifierWithType:type withKey:key];
}
@end

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/dom/Document.h"
#include "nsIconLoaderService.h"
#include "nsTouchBarInput.h"
#include "nsTouchBarNativeAPIDefines.h"
using namespace mozilla::dom;

Просмотреть файл

@ -5,7 +5,7 @@
#import <Cocoa/Cocoa.h>
#include "nsTouchBar.h"
#include "nsITouchBarInput.h"
#include "nsTouchBarInput.h"
#include "nsTouchBarUpdater.h"
#include "nsTouchBarNativeAPIDefines.h"