зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1563349 - Part 3 - Update TouchBarInputs in-place. r=spohl
Differential Revision: https://phabricator.services.mozilla.com/D47620 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4752551daf
Коммит
18272eae11
|
@ -136,8 +136,8 @@ using namespace mozilla::dom;
|
||||||
/**
|
/**
|
||||||
* Update or create various subclasses of TouchBarItem.
|
* Update or create various subclasses of TouchBarItem.
|
||||||
*/
|
*/
|
||||||
- (NSTouchBarItem*)updateButton:(NSCustomTouchBarItem*)aButton input:(TouchBarInput*)aInput;
|
- (void)updateButton:(NSButton*)aButton input:(TouchBarInput*)aInput;
|
||||||
- (NSTouchBarItem*)updateMainButton:(NSCustomTouchBarItem*)aMainButton input:(TouchBarInput*)aInput;
|
- (void)updateMainButton:(NSButton*)aMainButton input:(TouchBarInput*)aInput;
|
||||||
- (NSTouchBarItem*)makeShareScrubberForIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
- (NSTouchBarItem*)makeShareScrubberForIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -147,9 +147,11 @@ static const NSArray<NSString*>* kAllowedInputTypes = @[
|
||||||
newItem.view = button;
|
newItem.view = button;
|
||||||
|
|
||||||
if ([[input type] hasSuffix:@"mainButton"]) {
|
if ([[input type] hasSuffix:@"mainButton"]) {
|
||||||
return [self updateMainButton:newItem input:input];
|
[self updateMainButton:button input:input];
|
||||||
|
return newItem;
|
||||||
}
|
}
|
||||||
return [self updateButton:newItem input:input];
|
[self updateButton:button input:input];
|
||||||
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateItem:(TouchBarInput*)aInput {
|
- (void)updateItem:(TouchBarInput*)aInput {
|
||||||
|
@ -157,66 +159,64 @@ static const NSArray<NSString*>* kAllowedInputTypes = @[
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item.customizationLabel = [aInput title];
|
||||||
if ([[aInput type] hasSuffix:@"button"]) {
|
if ([[aInput type] hasSuffix:@"button"]) {
|
||||||
[self updateButton:(NSCustomTouchBarItem*)item input:aInput];
|
[self updateButton:(NSButton*)item.view input:aInput];
|
||||||
} else if ([[aInput type] hasSuffix:@"mainButton"]) {
|
} else if ([[aInput type] hasSuffix:@"mainButton"]) {
|
||||||
[self updateMainButton:(NSCustomTouchBarItem*)item input:aInput];
|
[self updateMainButton:(NSButton*)item.view input:aInput];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.mappedLayoutItems[[aInput nativeIdentifier]] release];
|
[self.mappedLayoutItems[[aInput nativeIdentifier]] release];
|
||||||
self.mappedLayoutItems[[aInput nativeIdentifier]] = aInput;
|
self.mappedLayoutItems[[aInput nativeIdentifier]] = aInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBarItem*)updateButton:(NSCustomTouchBarItem*)aButton input:(TouchBarInput*)aInput {
|
- (void)updateButton:(NSButton*)aButton input:(TouchBarInput*)aInput {
|
||||||
NSButton* button = (NSButton*)aButton.view;
|
if (!aButton || !aInput) {
|
||||||
if (!button) {
|
return;
|
||||||
return nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button.title = [aInput title];
|
aButton.title = [aInput title];
|
||||||
if (![aInput isIconPositionSet]) {
|
if (![aInput isIconPositionSet]) {
|
||||||
[button setImagePosition:NSImageOnly];
|
[aButton setImagePosition:NSImageOnly];
|
||||||
[aInput setIconPositionSet:true];
|
[aInput setIconPositionSet:true];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([aInput imageURI]) {
|
if ([aInput imageURI]) {
|
||||||
RefPtr<nsTouchBarInputIcon> icon = [aInput icon];
|
RefPtr<nsTouchBarInputIcon> icon = [aInput icon];
|
||||||
if (!icon) {
|
if (!icon) {
|
||||||
icon = new nsTouchBarInputIcon([aInput document], button);
|
icon = new nsTouchBarInputIcon([aInput document], aButton);
|
||||||
[aInput setIcon:icon];
|
[aInput setIcon:icon];
|
||||||
}
|
}
|
||||||
icon->SetupIcon([aInput imageURI]);
|
icon->SetupIcon([aInput imageURI]);
|
||||||
}
|
}
|
||||||
[button setEnabled:![aInput isDisabled]];
|
[aButton setEnabled:![aInput isDisabled]];
|
||||||
|
|
||||||
if ([aInput color]) {
|
if ([aInput color]) {
|
||||||
button.bezelColor = [aInput color];
|
aButton.bezelColor = [aInput color];
|
||||||
}
|
}
|
||||||
|
|
||||||
objc_setAssociatedObject(button, &sIdentifierAssociationKey, [aInput nativeIdentifier],
|
objc_setAssociatedObject(aButton, &sIdentifierAssociationKey, [aInput nativeIdentifier],
|
||||||
OBJC_ASSOCIATION_RETAIN);
|
OBJC_ASSOCIATION_RETAIN);
|
||||||
|
|
||||||
aButton.customizationLabel = [aInput title];
|
|
||||||
|
|
||||||
return aButton;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBarItem*)updateMainButton:(NSCustomTouchBarItem*)aMainButton
|
- (void)updateMainButton:(NSButton*)aMainButton input:(TouchBarInput*)aInput {
|
||||||
input:(TouchBarInput*)aInput {
|
if (!aMainButton || !aInput) {
|
||||||
NSButton* button = (NSButton*)aMainButton.view;
|
return;
|
||||||
|
}
|
||||||
// If empty, string is still being localized. Display a blank input instead.
|
// If empty, string is still being localized. Display a blank input instead.
|
||||||
if ([[aInput title] isEqualToString:@""]) {
|
if ([[aInput title] isEqualToString:@""]) {
|
||||||
[button setImagePosition:NSNoImage];
|
[aMainButton setImagePosition:NSNoImage];
|
||||||
} else {
|
} else {
|
||||||
[button setImagePosition:NSImageLeft];
|
[aMainButton setImagePosition:NSImageLeft];
|
||||||
}
|
}
|
||||||
button.imageHugsTitle = YES;
|
aMainButton.imageHugsTitle = YES;
|
||||||
[aInput setIconPositionSet:true];
|
[aInput setIconPositionSet:true];
|
||||||
|
|
||||||
aMainButton = (NSCustomTouchBarItem*)[self updateButton:aMainButton input:aInput];
|
[self updateButton:aMainButton input:aInput];
|
||||||
[button.widthAnchor constraintGreaterThanOrEqualToConstant:MAIN_BUTTON_WIDTH].active = YES;
|
[aMainButton.widthAnchor constraintGreaterThanOrEqualToConstant:MAIN_BUTTON_WIDTH].active = YES;
|
||||||
[button setContentHuggingPriority:1.0 forOrientation:NSLayoutConstraintOrientationHorizontal];
|
[aMainButton setContentHuggingPriority:1.0
|
||||||
return aMainButton;
|
forOrientation:NSLayoutConstraintOrientationHorizontal];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBarItem*)makeShareScrubberForIdentifier:(NSTouchBarItemIdentifier)aIdentifier {
|
- (NSTouchBarItem*)makeShareScrubberForIdentifier:(NSTouchBarItemIdentifier)aIdentifier {
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
typedef NSString* NSTouchBarItemIdentifier;
|
typedef NSString* NSTouchBarItemIdentifier;
|
||||||
__attribute__((weak_import)) @interface NSTouchBarItem : NSObject
|
__attribute__((weak_import)) @interface NSTouchBarItem : NSObject
|
||||||
|
@property(readonly) NSView* view;
|
||||||
|
@property(strong) NSString* customizationLabel;
|
||||||
- (instancetype)initWithIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
- (instancetype)initWithIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -41,7 +43,6 @@ __attribute__((weak_import)) @interface NSSharingServicePickerTouchBarItem : NST
|
||||||
|
|
||||||
__attribute__((weak_import)) @interface NSCustomTouchBarItem : NSTouchBarItem
|
__attribute__((weak_import)) @interface NSCustomTouchBarItem : NSTouchBarItem
|
||||||
@property(strong) NSView* view;
|
@property(strong) NSView* view;
|
||||||
@property(strong) NSString* customizationLabel;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@protocol NSTouchBarDelegate
|
@protocol NSTouchBarDelegate
|
||||||
|
|
Загрузка…
Ссылка в новой задаче