зеркало из 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:
Родитель
607f99b5f0
Коммит
dc2a166e28
|
@ -136,8 +136,8 @@ using namespace mozilla::dom;
|
|||
/**
|
||||
* Update or create various subclasses of TouchBarItem.
|
||||
*/
|
||||
- (NSTouchBarItem*)updateButton:(NSCustomTouchBarItem*)aButton input:(TouchBarInput*)aInput;
|
||||
- (NSTouchBarItem*)updateMainButton:(NSCustomTouchBarItem*)aMainButton input:(TouchBarInput*)aInput;
|
||||
- (void)updateButton:(NSButton*)aButton input:(TouchBarInput*)aInput;
|
||||
- (void)updateMainButton:(NSButton*)aMainButton input:(TouchBarInput*)aInput;
|
||||
- (NSTouchBarItem*)makeShareScrubberForIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
||||
|
||||
/**
|
||||
|
|
|
@ -147,9 +147,11 @@ static const NSArray<NSString*>* kAllowedInputTypes = @[
|
|||
newItem.view = button;
|
||||
|
||||
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 {
|
||||
|
@ -157,66 +159,65 @@ static const NSArray<NSString*>* kAllowedInputTypes = @[
|
|||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ([[aInput type] hasSuffix:@"button"]) {
|
||||
[self updateButton:(NSCustomTouchBarItem*)item input:aInput];
|
||||
[(NSCustomTouchBarItem*)item setCustomizationLabel:[aInput title]];
|
||||
[self updateButton:(NSButton*)item.view input:aInput];
|
||||
} else if ([[aInput type] hasSuffix:@"mainButton"]) {
|
||||
[self updateMainButton:(NSCustomTouchBarItem*)item input:aInput];
|
||||
[(NSCustomTouchBarItem*)item setCustomizationLabel:[aInput title]];
|
||||
[self updateMainButton:(NSButton*)item.view input:aInput];
|
||||
}
|
||||
|
||||
[self.mappedLayoutItems[[aInput nativeIdentifier]] release];
|
||||
self.mappedLayoutItems[[aInput nativeIdentifier]] = aInput;
|
||||
}
|
||||
|
||||
- (NSTouchBarItem*)updateButton:(NSCustomTouchBarItem*)aButton input:(TouchBarInput*)aInput {
|
||||
NSButton* button = (NSButton*)aButton.view;
|
||||
if (!button) {
|
||||
return nil;
|
||||
- (void)updateButton:(NSButton*)aButton input:(TouchBarInput*)aInput {
|
||||
if (!aButton || !aInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
button.title = [aInput title];
|
||||
aButton.title = [aInput title];
|
||||
if (![aInput isIconPositionSet]) {
|
||||
[button setImagePosition:NSImageOnly];
|
||||
[aButton setImagePosition:NSImageOnly];
|
||||
[aInput setIconPositionSet:true];
|
||||
}
|
||||
|
||||
if ([aInput imageURI]) {
|
||||
RefPtr<nsTouchBarInputIcon> icon = [aInput icon];
|
||||
if (!icon) {
|
||||
icon = new nsTouchBarInputIcon([aInput document], button);
|
||||
icon = new nsTouchBarInputIcon([aInput document], aButton);
|
||||
[aInput setIcon:icon];
|
||||
}
|
||||
icon->SetupIcon([aInput imageURI]);
|
||||
}
|
||||
[button setEnabled:![aInput isDisabled]];
|
||||
[aButton setEnabled:![aInput isDisabled]];
|
||||
|
||||
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);
|
||||
|
||||
aButton.customizationLabel = [aInput title];
|
||||
|
||||
return aButton;
|
||||
}
|
||||
|
||||
- (NSTouchBarItem*)updateMainButton:(NSCustomTouchBarItem*)aMainButton
|
||||
input:(TouchBarInput*)aInput {
|
||||
NSButton* button = (NSButton*)aMainButton.view;
|
||||
- (void)updateMainButton:(NSButton*)aMainButton input:(TouchBarInput*)aInput {
|
||||
if (!aMainButton || !aInput) {
|
||||
return;
|
||||
}
|
||||
// If empty, string is still being localized. Display a blank input instead.
|
||||
if ([[aInput title] isEqualToString:@""]) {
|
||||
[button setImagePosition:NSNoImage];
|
||||
[aMainButton setImagePosition:NSNoImage];
|
||||
} else {
|
||||
[button setImagePosition:NSImageLeft];
|
||||
[aMainButton setImagePosition:NSImageLeft];
|
||||
}
|
||||
button.imageHugsTitle = YES;
|
||||
aMainButton.imageHugsTitle = YES;
|
||||
[aInput setIconPositionSet:true];
|
||||
|
||||
aMainButton = (NSCustomTouchBarItem*)[self updateButton:aMainButton input:aInput];
|
||||
[button.widthAnchor constraintGreaterThanOrEqualToConstant:MAIN_BUTTON_WIDTH].active = YES;
|
||||
[button setContentHuggingPriority:1.0 forOrientation:NSLayoutConstraintOrientationHorizontal];
|
||||
return aMainButton;
|
||||
[self updateButton:aMainButton input:aInput];
|
||||
[aMainButton.widthAnchor constraintGreaterThanOrEqualToConstant:MAIN_BUTTON_WIDTH].active = YES;
|
||||
[aMainButton setContentHuggingPriority:1.0
|
||||
forOrientation:NSLayoutConstraintOrientationHorizontal];
|
||||
}
|
||||
|
||||
- (NSTouchBarItem*)makeShareScrubberForIdentifier:(NSTouchBarItemIdentifier)aIdentifier {
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
typedef NSString* NSTouchBarItemIdentifier;
|
||||
__attribute__((weak_import)) @interface NSTouchBarItem : NSObject
|
||||
@property(readonly) NSView* view;
|
||||
@property(readonly) NSString* customizationLabel;
|
||||
- (instancetype)initWithIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
||||
@end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче