Backed out changeset 4aead1eca8c6 (bug 1521893) to fix crashes (bug 1568862)

--HG--
extra : rebase_source : 55caf819b464734c29515f81eca41a6cbba4d5b4
This commit is contained in:
Sebastian Hengst 2019-07-29 17:11:19 +02:00
Родитель 5f6066ee8d
Коммит 14f4125565
30 изменённых файлов: 196 добавлений и 400 удалений

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

@ -11,7 +11,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
AppConstants: "resource://gre/modules/AppConstants.jsm",
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
});
/**
@ -58,25 +57,25 @@ function hexToInt(hexString) {
const kBuiltInInputs = {
Back: {
title: "back",
image: "chrome://browser/skin/back.svg",
image: "back.pdf",
type: "button",
callback: () => execCommand("Browser:Back", "Back"),
},
Forward: {
title: "forward",
image: "chrome://browser/skin/forward.svg",
image: "forward.pdf",
type: "button",
callback: () => execCommand("Browser:Forward", "Forward"),
},
Reload: {
title: "reload",
image: "chrome://browser/skin/reload.svg",
image: "refresh.pdf",
type: "button",
callback: () => execCommand("Browser:Reload", "Reload"),
},
Home: {
title: "home",
image: "chrome://browser/skin/home.svg",
image: "home.pdf",
type: "button",
callback: () => {
let win = BrowserWindowTracker.getTopWindow();
@ -89,25 +88,25 @@ const kBuiltInInputs = {
},
Fullscreen: {
title: "fullscreen",
image: "chrome://browser/skin/fullscreen.svg",
image: "fullscreen.pdf",
type: "button",
callback: () => execCommand("View:FullScreen", "Fullscreen"),
},
Find: {
title: "find",
image: "chrome://browser/skin/search-glass.svg",
image: "search.pdf",
type: "button",
callback: () => execCommand("cmd_find", "Find"),
},
NewTab: {
title: "new-tab",
image: "chrome://browser/skin/add.svg",
image: "new.pdf",
type: "button",
callback: () => execCommand("cmd_newNavigatorTabNoEvent", "NewTab"),
},
Sidebar: {
title: "open-sidebar",
image: "chrome://browser/skin/sidebars.svg",
image: "sidebar-left.pdf",
type: "button",
callback: () => {
let win = BrowserWindowTracker.getTopWindow();
@ -120,20 +119,20 @@ const kBuiltInInputs = {
},
AddBookmark: {
title: "add-bookmark",
image: "chrome://browser/skin/bookmark-hollow.svg",
image: "bookmark.pdf",
type: "button",
callback: () => execCommand("Browser:AddBookmarkAs", "AddBookmark"),
},
ReaderView: {
title: "reader-view",
image: "chrome://browser/skin/readerMode.svg",
image: "reader-mode.pdf",
type: "button",
callback: () => execCommand("View:ReaderView", "ReaderView"),
disabled: true, // Updated when the page is found to be Reader View-able.
},
OpenLocation: {
title: "open-location",
image: "chrome://browser/skin/search-glass.svg",
image: "search.pdf",
type: "mainButton",
callback: () => execCommand("Browser:OpenLocation", "OpenLocation"),
},
@ -143,7 +142,7 @@ const kBuiltInInputs = {
Share: {
title: "share",
type: "scrubber",
image: "chrome://browser/skin/share.svg",
image: "share.pdf",
callback: () => execCommand("cmd_share", "Share"),
},
};
@ -294,10 +293,8 @@ class TouchBarHelper {
break;
case "bookmark-icon-updated":
data == "starred"
? (kBuiltInInputs.AddBookmark.image =
"chrome://browser/skin/bookmark.svg")
: (kBuiltInInputs.AddBookmark.image =
"chrome://browser/skin/bookmark-hollow.svg");
? (kBuiltInInputs.AddBookmark.image = "bookmark-filled.pdf")
: (kBuiltInInputs.AddBookmark.image = "bookmark.pdf");
this._updateTouchBarInputs("AddBookmark");
break;
case "reader-mode-available":
@ -368,7 +365,7 @@ class TouchBarInput {
this._title = title;
}
get image() {
return PlacesUtils.toURI(this._image);
return this._image;
}
set image(image) {
this._image = image;
@ -397,10 +394,6 @@ class TouchBarInput {
set disabled(disabled) {
this._disabled = disabled;
}
// Required as context to load our input icons.
get document() {
return BrowserWindowTracker.getTopWindow().document;
}
}
const inputProto = TouchBarInput.prototype;

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

@ -37,22 +37,22 @@ add_task(async function updateBookmarkButton() {
// nsITouchBarHelper to load on Macs without Touch Bars so that it will be
// listening for "bookmark-icon-updated".
Assert.equal(
TouchBarHelper.getTouchBarInput("AddBookmark").image.spec,
"chrome://browser/skin/bookmark-hollow.svg",
TouchBarHelper.getTouchBarInput("AddBookmark").image,
"bookmark.pdf",
"AddBookmark image should be unfilled bookmark after event."
);
Services.obs.notifyObservers(null, "bookmark-icon-updated", "starred");
Assert.equal(
TouchBarHelper.getTouchBarInput("AddBookmark").image.spec,
"chrome://browser/skin/bookmark.svg",
TouchBarHelper.getTouchBarInput("AddBookmark").image,
"bookmark-filled.pdf",
"AddBookmark image should be filled bookmark after event."
);
Services.obs.notifyObservers(null, "bookmark-icon-updated", "unstarred");
Assert.equal(
TouchBarHelper.getTouchBarInput("AddBookmark").image.spec,
"chrome://browser/skin/bookmark-hollow.svg",
TouchBarHelper.getTouchBarInput("AddBookmark").image,
"bookmark.pdf",
"AddBookmark image should be unfilled bookmark after event."
);
});

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

@ -331,6 +331,7 @@
@RESPATH@/res/grabber.gif
#ifdef XP_MACOSX
@RESPATH@/res/cursors/*
@RESPATH@/res/touchbar/*
#endif
@RESPATH@/res/fonts/*
@RESPATH@/res/dtd/*

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

@ -58,7 +58,6 @@ UNIFIED_SOURCES += [
'nsSystemStatusBarCocoa.mm',
'nsToolkit.mm',
'nsTouchBar.mm',
'nsTouchBarInputIcon.mm',
'nsTouchBarUpdater.mm',
'nsWidgetFactory.mm',
'nsWindowMap.mm',
@ -142,6 +141,22 @@ RESOURCE_FILES.cursors += [
'cursors/zoomOut@2x.png',
]
RESOURCE_FILES.touchbar += [
'touchbar/back.pdf',
'touchbar/bookmark-filled.pdf',
'touchbar/bookmark.pdf',
'touchbar/forward.pdf',
'touchbar/fullscreen.pdf',
'touchbar/home.pdf',
'touchbar/new.pdf',
'touchbar/reader-mode.pdf',
'touchbar/refresh.pdf',
'touchbar/search.pdf',
'touchbar/share.pdf',
'touchbar/sidebar-left.pdf',
'touchbar/sidebar-right.pdf',
]
# These resources go in $(DIST)/bin/res/MainMenu.nib, but we can't use a magic
# RESOURCE_FILES.MainMenu.nib attribute, since that would put the files in
# $(DIST)/bin/res/MainMenu/nib. Instead, we call __setattr__ directly to create

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

@ -21,7 +21,6 @@
#include "nsIInterfaceRequestorUtils.h"
#include "nsIXULWindow.h"
#include "nsToolkit.h"
#include "nsTouchBarNativeAPIDefines.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsThreadUtils.h"

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

@ -17,13 +17,13 @@
#include "nsIContentPolicy.h"
class nsIURI;
class nsINode;
class nsIContent;
class nsIPrincipal;
class imgRequestProxy;
class nsIconLoaderService : public imgINotificationObserver {
public:
nsIconLoaderService(nsINode* aContent, nsIntRect* aImageRegionRect,
nsIconLoaderService(nsIContent* aContent, nsIntRect* aImageRegionRect,
RefPtr<nsIconLoaderObserver> aObserver,
uint32_t aIconHeight, uint32_t aIconWidth);
@ -31,12 +31,10 @@ class nsIconLoaderService : public imgINotificationObserver {
NS_DECL_ISUPPORTS
NS_DECL_IMGINOTIFICATIONOBSERVER
// LoadIcon will start a load request for the icon.
// The request may not complete until after LoadIcon returns.
// LoadIcon will set a placeholder image and start a load request for the
// icon. The request may not complete until after LoadIcon returns.
nsresult LoadIcon(nsIURI* aIconURI);
NSImage* GetNativeIconImage();
// Unless we take precautions, we may outlive the object that created us
// (mMenuObject, which owns our native menu item (mNativeMenuItem)).
// Destroy() should be called from mMenuObject's destructor to prevent
@ -49,7 +47,7 @@ class nsIconLoaderService : public imgINotificationObserver {
private:
nsresult OnFrameComplete(imgIRequest* aRequest);
nsCOMPtr<nsINode> mContent;
nsCOMPtr<nsIContent> mContent;
nsContentPolicyType mContentType;
RefPtr<imgRequestProxy> mIconRequest;
nsIntRect* mImageRegionRect;
@ -59,4 +57,5 @@ class nsIconLoaderService : public imgINotificationObserver {
uint32_t mIconWidth;
RefPtr<nsIconLoaderObserver> mCompletionHandler;
};
#endif // nsIconLoaderService_h_

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

@ -30,6 +30,7 @@
#include "nsContentUtils.h"
#include "nsIconLoaderService.h"
#include "nsIContent.h"
#include "nsIContentPolicy.h"
#include "nsNameSpaceManager.h"
#include "nsNetUtil.h"
#include "nsObjCExceptions.h"
@ -42,19 +43,17 @@ using mozilla::gfx::SourceSurface;
NS_IMPL_ISUPPORTS(nsIconLoaderService, imgINotificationObserver)
nsIconLoaderService::nsIconLoaderService(nsINode* aContent, nsIntRect* aImageRegionRect,
nsIconLoaderService::nsIconLoaderService(nsIContent* aContent, nsIntRect* aImageRegionRect,
RefPtr<nsIconLoaderObserver> aObserver,
uint32_t aIconHeight, uint32_t aIconWidth)
: mContent(aContent),
mContentType(nsIContentPolicy::TYPE_INTERNAL_IMAGE),
mImageRegionRect(aImageRegionRect),
mLoadedIcon(false),
mNativeIconImage(nil),
mIconHeight(aIconHeight),
mIconWidth(aIconWidth),
mCompletionHandler(aObserver) {
// Placeholder icon, which will later be replaced.
mNativeIconImage = [[NSImage alloc] initWithSize:NSMakeSize(mIconHeight, mIconWidth)];
}
mCompletionHandler(aObserver) {}
nsIconLoaderService::~nsIconLoaderService() { Destroy(); }
@ -66,8 +65,8 @@ void nsIconLoaderService::Destroy() {
mIconRequest->CancelAndForgetObserver(NS_BINDING_ABORTED);
mIconRequest = nullptr;
}
mNativeIconImage = nil;
mImageRegionRect = nullptr;
mNativeIconImage = nil;
mCompletionHandler = nil;
}
@ -111,8 +110,6 @@ nsresult nsIconLoaderService::LoadIcon(nsIURI* aIconURI) {
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NSImage* nsIconLoaderService::GetNativeIconImage() { return mNativeIconImage; }
//
// imgINotificationObserver
//
@ -245,11 +242,7 @@ nsresult nsIconLoaderService::OnFrameComplete(imgIRequest* aRequest) {
[newImage setTemplate:isEntirelyBlack];
[newImage setSize:NSMakeSize(mIconWidth, mIconHeight)];
NSImage* placeholderImage = mNativeIconImage;
mNativeIconImage = newImage;
[placeholderImage release];
placeholderImage = nil;
::CGImageRelease(finalImage);

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

@ -18,7 +18,6 @@
#include "nsGkAtoms.h"
#include "nsObjCExceptions.h"
#include "nsThreadUtils.h"
#include "nsTouchBarNativeAPIDefines.h"
#include "nsIContent.h"
#include "nsITouchBarUpdater.h"
@ -855,6 +854,12 @@ static BOOL gMenuItemsExecuteCommands = YES;
@end
#if !defined(MAC_OS_X_VERSION_10_12_2) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12_2
@interface NSApplication (TouchBarMenu)
- (IBAction)toggleTouchBarCustomizationPalette:(id)sender;
@end
#endif
//
// Objective-C class used as action target for menu items
//

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

@ -10,6 +10,9 @@
#ifndef nsMenuItemIconX_h_
#define nsMenuItemIconX_h_
#include "mozilla/RefPtr.h"
#include "nsCOMPtr.h"
#include "imgINotificationObserver.h"
#include "nsIContentPolicy.h"
#include "nsIconLoaderService.h"
@ -50,6 +53,7 @@ class nsMenuItemIconX : public nsIconLoaderObserver {
protected:
nsCOMPtr<nsIContent> mContent;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
nsContentPolicyType mContentType;
nsMenuObjectX* mMenuObject; // [weak]
nsIntRect mImageRegionRect;

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

@ -42,6 +42,7 @@ static const uint32_t kIconSize = 16;
nsMenuItemIconX::nsMenuItemIconX(nsMenuObjectX* aMenuItem, nsIContent* aContent,
NSMenuItem* aNativeMenuItem)
: mContent(aContent),
mTriggeringPrincipal(aContent->NodePrincipal()),
mContentType(nsIContentPolicy::TYPE_INTERNAL_IMAGE),
mMenuObject(aMenuItem),
mSetIcon(false),
@ -62,6 +63,7 @@ void nsMenuItemIconX::Destroy() {
mIconLoader->Destroy();
mIconLoader = nullptr;
}
mMenuObject = nullptr;
mNativeMenuItem = nil;
}
@ -85,6 +87,29 @@ nsresult nsMenuItemIconX::SetupIcon() {
return NS_OK;
}
if (!mSetIcon) {
// Set a completely transparent 16x16 image as the icon on this menu item
// as a placeholder. This keeps the menu item text displayed in the same
// position that it will be displayed when the real icon is loaded, and
// prevents it from jumping around or looking misaligned.
static bool sInitializedPlaceholder;
static NSImage* sPlaceholderIconImage;
if (!sInitializedPlaceholder) {
sInitializedPlaceholder = true;
// Note that we only create the one and reuse it forever, so this is not a leak.
sPlaceholderIconImage = [[NSImage alloc] initWithSize:NSMakeSize(kIconSize, kIconSize)];
}
if (!sPlaceholderIconImage) {
return NS_ERROR_FAILURE;
}
if (mNativeMenuItem) {
[mNativeMenuItem setImage:sPlaceholderIconImage];
}
}
if (!mIconLoader) {
mIconLoader = new nsIconLoaderService(mContent, &mImageRegionRect, this, kIconSize, kIconSize);
if (!mIconLoader) {
@ -92,11 +117,6 @@ nsresult nsMenuItemIconX::SetupIcon() {
}
}
if (!mSetIcon) {
// Load placeholder icon.
[mNativeMenuItem setImage:mIconLoader->GetNativeIconImage()];
}
rv = mIconLoader->LoadIcon(iconURI);
if (NS_FAILED(rv)) {
// There is no icon for this menu item, as an error occurred while loading it.
@ -156,9 +176,8 @@ nsresult nsMenuItemIconX::GetIconURI(nsIURI** aIconURI) {
}
} else {
uint64_t dummy = 0;
nsCOMPtr<nsIPrincipal> triggeringPrincipal = mContent->NodePrincipal();
nsContentUtils::GetContentPolicyTypeForUIImageLoading(
mContent, getter_AddRefs(triggeringPrincipal), mContentType, &dummy);
mContent, getter_AddRefs(mTriggeringPrincipal), mContentType, &dummy);
// If this menu item shouldn't have an icon, the string will be empty,
// and NS_NewURI will fail.

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

@ -7,12 +7,59 @@
#import <Cocoa/Cocoa.h>
#include "mozilla/RefPtr.h"
#include "nsITouchBarHelper.h"
#include "nsITouchBarInput.h"
#include "nsTouchBarInputIcon.h"
#include "nsTouchBarNativeAPIDefines.h"
using namespace mozilla::dom;
#if !defined(MAC_OS_X_VERSION_10_12) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
@interface NSButton (NewConstructors)
@property(nonatomic) BOOL imageHugsTitle;
+ (NSButton*)buttonWithTitle:(NSString*)title target:(id)target action:(SEL)action;
@end
@interface NSColor (DisplayP3Colors)
+ (NSColor*)colorWithDisplayP3Red:(CGFloat)red
green:(CGFloat)green
blue:(CGFloat)blue
alpha:(CGFloat)alpha;
@end
#endif
#if !defined(MAC_OS_X_VERSION_10_12_2) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12_2
typedef NSString* NSTouchBarItemIdentifier;
__attribute__((weak_import)) @interface NSTouchBarItem : NSObject
- (instancetype)initWithIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
@end
__attribute__((weak_import)) @interface NSCustomTouchBarItem : NSTouchBarItem
@property(strong) NSView* view;
@property(strong) NSString* customizationLabel;
@end
@protocol NSTouchBarDelegate
@end
typedef NSString* NSTouchBarCustomizationIdentifier;
__attribute__((weak_import)) @interface NSTouchBar : NSObject
@property(strong) NSArray<NSTouchBarItemIdentifier>* defaultItemIdentifiers;
@property(strong) id<NSTouchBarDelegate> delegate;
@property(strong) NSTouchBarCustomizationIdentifier customizationIdentifier;
@property(strong) NSArray<NSTouchBarItemIdentifier>* customizationAllowedItemIdentifiers;
- (NSTouchBarItem*)itemForIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
@end
@protocol NSSharingServicePickerTouchBarItemDelegate
@end
__attribute__((weak_import)) @interface NSSharingServicePickerTouchBarItem : NSTouchBarItem
@property(strong) id<NSSharingServicePickerTouchBarItemDelegate> delegate;
@property(strong) NSImage* buttonImage;
@end
@interface NSButton (TouchBarButton)
@property(strong) NSColor* bezelColor;
@end
#endif
/**
* NSObject representation of nsITouchBarInput.
@ -20,48 +67,38 @@ using namespace mozilla::dom;
@interface TouchBarInput : NSObject {
NSString* mKey;
NSString* mTitle;
nsCOMPtr<nsIURI> mImageURI;
RefPtr<nsTouchBarInputIcon> mIcon;
NSImage* mImage;
NSString* mType;
NSColor* mColor;
BOOL mDisabled;
NSTouchBarItemIdentifier mNativeIdentifier;
nsCOMPtr<nsITouchBarInputCallback> mCallback;
RefPtr<Document> mDocument;
BOOL mIsIconPositionSet;
}
- (NSString*)key;
- (NSString*)title;
- (nsCOMPtr<nsIURI>)imageURI;
- (RefPtr<nsTouchBarInputIcon>)icon;
- (NSImage*)image;
- (NSString*)type;
- (NSColor*)color;
- (BOOL)isDisabled;
- (NSTouchBarItemIdentifier)nativeIdentifier;
- (nsCOMPtr<nsITouchBarInputCallback>)callback;
- (RefPtr<Document>)document;
- (BOOL)isIconPositionSet;
- (void)setKey:(NSString*)aKey;
- (void)setTitle:(NSString*)aTitle;
- (void)setImageURI:(nsCOMPtr<nsIURI>)aImageURI;
- (void)setIcon:(RefPtr<nsTouchBarInputIcon>)aIcon;
- (void)setImage:(NSImage*)aImage;
- (void)setType:(NSString*)aType;
- (void)setColor:(NSColor*)aColor;
- (void)setDisabled:(BOOL)aDisabled;
- (void)setNativeIdentifier:(NSString*)aNativeIdentifier;
- (void)setCallback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback;
- (void)setDocument:(RefPtr<Document>)aDocument;
- (void)setIconPositionSet:(BOOL)aIsIconPositionSet;
- (id)initWithKey:(NSString*)aKey
title:(NSString*)aTitle
imageURI:(nsCOMPtr<nsIURI>)aImageURI
image:(NSString*)aImage
type:(NSString*)aType
callback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback
color:(uint32_t)aColor
disabled:(BOOL)aDisabled
document:(RefPtr<Document>)aDocument;
disabled:(BOOL)aDisabled;
- (TouchBarInput*)initWithXPCOM:(nsCOMPtr<nsITouchBarInput>)aInput;
@ -134,6 +171,11 @@ using namespace mozilla::dom;
sharingServicesForItems:(NSArray*)aItems
proposedSharingServices:(NSArray<NSSharingService*>*)aProposedServices;
/**
* Retrieves TouchBarInput icons.
*/
+ (NSImage*)getTouchBarIconNamed:(NSString*)aImageName;
- (void)releaseJSObjects;
@end // nsTouchBar

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

@ -143,18 +143,9 @@ static char sIdentifierAssociationKey;
}
button.title = [aInput title];
if (![aInput isIconPositionSet]) {
if ([aInput image]) {
button.image = [aInput image];
[button setImagePosition:NSImageOnly];
[aInput setIconPositionSet:true];
}
if ([aInput imageURI]) {
RefPtr<nsTouchBarInputIcon> icon = [aInput icon];
if (!icon) {
icon = new nsTouchBarInputIcon([aInput document], button);
[aInput setIcon:icon];
}
icon->SetupIcon([aInput imageURI]);
}
[button setEnabled:![aInput isDisabled]];
@ -173,17 +164,16 @@ static char sIdentifierAssociationKey;
- (NSTouchBarItem*)updateMainButton:(NSCustomTouchBarItem*)aMainButton
input:(TouchBarInput*)aInput {
aMainButton = (NSCustomTouchBarItem*)[self updateButton:aMainButton input:aInput];
NSButton* button = (NSButton*)aMainButton.view;
button.imageHugsTitle = YES;
// If empty, string is still being localized. Display a blank input instead.
if ([[aInput title] isEqualToString:@""]) {
if ([button.title isEqualToString:@""]) {
[button setImagePosition:NSNoImage];
} else {
[button setImagePosition:NSImageLeft];
}
button.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;
@ -194,20 +184,7 @@ static char sIdentifierAssociationKey;
// System-default share menu
NSSharingServicePickerTouchBarItem* servicesItem =
[[NSSharingServicePickerTouchBarItem alloc] initWithIdentifier:aIdentifier];
// buttonImage needs to be set to nil while we wait for our icon to load.
// Otherwise, the default Apple share icon is automatically loaded.
servicesItem.buttonImage = nil;
if ([input imageURI]) {
RefPtr<nsTouchBarInputIcon> icon = [input icon];
if (!icon) {
icon = new nsTouchBarInputIcon([input document], nil, servicesItem);
[input setIcon:icon];
}
icon->SetupIcon([input imageURI]);
}
servicesItem.buttonImage = [input image];
servicesItem.delegate = self;
return servicesItem;
}
@ -238,16 +215,35 @@ static char sIdentifierAssociationKey;
for (NSTouchBarItemIdentifier identifier in self.mappedLayoutItems) {
TouchBarInput* input = self.mappedLayoutItems[identifier];
RefPtr<nsTouchBarInputIcon> icon = [input icon];
if (icon) {
icon->ReleaseJSObjects();
}
[input setCallback:nil];
[input setDocument:nil];
[input setImageURI:nil];
}
}
#pragma mark - TouchBar Utilities
+ (NSImage*)getTouchBarIconNamed:(NSString*)aImageName {
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);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nil;
}
pathToImage = [NSString stringWithUTF8String:(const char*)resPath.get()];
pathToImage = [pathToImage stringByAppendingPathComponent:aImageName];
NSImage* image = [[[NSImage alloc] initWithContentsOfFile:pathToImage] autorelease];
// A nil image will fail gracefully to a labelled button
return image;
}
#pragma mark - NSSharingServicePickerTouchBarItemDelegate
- (NSArray*)itemsForSharingServicePickerTouchBarItem:
@ -305,11 +301,8 @@ static char sIdentifierAssociationKey;
- (NSString*)title {
return mTitle;
}
- (nsCOMPtr<nsIURI>)imageURI {
return mImageURI;
}
- (RefPtr<nsTouchBarInputIcon>)icon {
return mIcon;
- (NSImage*)image {
return mImage;
}
- (NSString*)type {
return mType;
@ -326,12 +319,6 @@ static char sIdentifierAssociationKey;
- (nsCOMPtr<nsITouchBarInputCallback>)callback {
return mCallback;
}
- (RefPtr<Document>)document {
return mDocument;
}
- (BOOL)isIconPositionSet {
return mIsIconPositionSet;
}
- (void)setKey:(NSString*)aKey {
[aKey retain];
[mKey release];
@ -344,12 +331,10 @@ static char sIdentifierAssociationKey;
mTitle = aTitle;
}
- (void)setImageURI:(nsCOMPtr<nsIURI>)aImageURI {
mImageURI = aImageURI;
}
- (void)setIcon:(RefPtr<nsTouchBarInputIcon>)aIcon {
mIcon = aIcon;
- (void)setImage:(NSImage*)aImage {
[aImage retain];
[mImage release];
mImage = aImage;
}
- (void)setType:(NSString*)aType {
@ -378,34 +363,19 @@ static char sIdentifierAssociationKey;
mCallback = aCallback;
}
- (void)setDocument:(RefPtr<Document>)aDocument {
if (mIcon) {
mIcon->Destroy();
mIcon = nil;
}
mDocument = aDocument;
}
- (void)setIconPositionSet:(BOOL)aIsIconPositionSet {
mIsIconPositionSet = aIsIconPositionSet;
}
- (id)initWithKey:(NSString*)aKey
title:(NSString*)aTitle
imageURI:(nsCOMPtr<nsIURI>)aImageURI
image:(NSString*)aImage
type:(NSString*)aType
callback:(nsCOMPtr<nsITouchBarInputCallback>)aCallback
color:(uint32_t)aColor
disabled:(BOOL)aDisabled
document:(RefPtr<Document>)aDocument {
disabled:(BOOL)aDisabled {
if (self = [super init]) {
[self setKey:aKey];
[self setTitle:aTitle];
[self setImageURI:aImageURI];
[self setImage:[nsTouchBar getTouchBarIconNamed:aImage]];
[self setType:aType];
[self setCallback:aCallback];
[self setDocument:aDocument];
[self setIconPositionSet:false];
if (aColor) {
[self setColor:[NSColor colorWithDisplayP3Red:((aColor >> 16) & 0xFF) / 255.0
green:((aColor >> 8) & 0xFF) / 255.0
@ -448,8 +418,8 @@ static char sIdentifierAssociationKey;
return nil;
}
nsCOMPtr<nsIURI> imageURI;
rv = aInput->GetImage(getter_AddRefs(imageURI));
nsAutoString imageStr;
rv = aInput->GetImage(imageStr);
if (NS_FAILED(rv)) {
return nil;
}
@ -478,29 +448,19 @@ static char sIdentifierAssociationKey;
return nil;
}
RefPtr<Document> document;
rv = aInput->GetDocument(getter_AddRefs(document));
if (NS_FAILED(rv)) {
return nil;
}
return [self initWithKey:nsCocoaUtils::ToNSString(keyStr)
title:nsCocoaUtils::ToNSString(titleStr)
imageURI:imageURI
image:nsCocoaUtils::ToNSString(imageStr)
type:nsCocoaUtils::ToNSString(typeStr)
callback:callback
color:colorInt
disabled:(BOOL)disabled
document:document];
disabled:(BOOL)disabled];
}
- (void)dealloc {
if (mIcon) {
mIcon->Destroy();
mIcon = nil;
}
[mKey release];
[mTitle release];
[mImage release];
[mType release];
[mColor release];
[mNativeIdentifier release];

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

@ -1,65 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
/*
* Retrieves and displays icons on the macOS Touch Bar.
*/
#ifndef nsTouchBarInputIcon_h_
#define nsTouchBarInputIcon_h_
#import <Cocoa/Cocoa.h>
#include "mozilla/dom/Document.h"
#include "nsIconLoaderService.h"
#include "nsTouchBarNativeAPIDefines.h"
using namespace mozilla::dom;
class nsIconLoaderService;
class nsIURI;
class nsIPrincipal;
class imgRequestProxy;
class nsTouchBarInputIcon : public nsIconLoaderObserver {
public:
nsTouchBarInputIcon(RefPtr<Document> aDocument, NSButton* aButton,
NSSharingServicePickerTouchBarItem* aShareScrubber = nil);
private:
virtual ~nsTouchBarInputIcon();
public:
// SetupIcon succeeds if it was able to set up the icon, or if there should
// be no icon, in which case it clears any existing icon but still succeeds.
nsresult SetupIcon(nsCOMPtr<nsIURI> aIconURI);
// Overrides nsIconLoaderObserver::OnComplete. Handles the NSImage* created
// by nsIconLoaderService.
nsresult OnComplete(NSImage* aImage) override;
void ReleaseJSObjects() { mDocument = nil; }
// Unless we take precautions, we may outlive the object that created us
// (mTouchBar, which owns our native menu item (mTouchBarInput)).
// Destroy() should be called from mTouchBar's destructor to prevent
// this from happening.
void Destroy();
protected:
RefPtr<Document> mDocument;
nsIntRect mImageRegionRect;
bool mSetIcon;
NSButton* mButton;
// We accept a mShareScrubber only as a special case since
// NSSharingServicePickerTouchBarItem does not expose an NSButton* on which we
// can set the `image` property.
NSSharingServicePickerTouchBarItem* mShareScrubber;
// The icon loader object should never outlive its creating
// nsTouchBarInputIcon object.
RefPtr<nsIconLoaderService> mIconLoader;
};
#endif // nsTouchBarInputIcon_h_

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

@ -1,100 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
/*
* Retrieves and displays icons on the macOS Touch Bar.
*/
#include "nsTouchBarInputIcon.h"
#include "nsCocoaUtils.h"
#include "nsComputedDOMStyle.h"
#include "nsContentUtils.h"
#include "nsGkAtoms.h"
#include "nsINode.h"
#include "nsNameSpaceManager.h"
#include "nsObjCExceptions.h"
using namespace mozilla;
static const uint32_t kIconSize = 16;
nsTouchBarInputIcon::nsTouchBarInputIcon(RefPtr<mozilla::dom::Document> aDocument,
NSButton* aButton,
NSSharingServicePickerTouchBarItem* aShareScrubber)
: mDocument(aDocument), mSetIcon(false), mButton(aButton), mShareScrubber(aShareScrubber) {
MOZ_COUNT_CTOR(nsTouchBarInputIcon);
}
nsTouchBarInputIcon::~nsTouchBarInputIcon() {
Destroy();
MOZ_COUNT_DTOR(nsTouchBarInputIcon);
}
// Called from nsTouchBar's destructor, to prevent us from outliving it
// (as might otherwise happen if calls to our imgINotificationObserver methods
// are still outstanding). nsTouchBar owns our mTouchBarInput.
void nsTouchBarInputIcon::Destroy() {
if (mIconLoader) {
mIconLoader->Destroy();
mIconLoader = nullptr;
}
mButton = nil;
}
nsresult nsTouchBarInputIcon::SetupIcon(nsCOMPtr<nsIURI> aIconURI) {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
// Still don't have one, then something is wrong, get out of here.
if (!(mButton || mShareScrubber)) {
NS_ERROR("No Touch Bar button");
return NS_ERROR_FAILURE;
}
if (!mIconLoader) {
mIconLoader = new nsIconLoaderService(mDocument, &mImageRegionRect, this, kIconSize, kIconSize);
if (!mIconLoader) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
if (!mSetIcon) {
// Load placeholder icon.
[mButton setImage:mIconLoader->GetNativeIconImage()];
}
nsresult rv = mIconLoader->LoadIcon(aIconURI);
if (NS_FAILED(rv)) {
// There is no icon for this menu item, as an error occurred while loading it.
// An icon might have been set earlier or the place holder icon may have
// been set. Clear it.
[mButton setImage:nil];
}
mSetIcon = true;
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
//
// nsIconLoaderObserver
//
nsresult nsTouchBarInputIcon::OnComplete(NSImage* aImage) {
// Apple's share scrubber requires special handling since it does not expose
// a NSButton* view like a regular TouchBarItem*.
if (mShareScrubber) {
mShareScrubber.buttonImage = aImage;
} else {
// If image is nil, this fails gracefully to a text label.
[mButton setImage:aImage];
}
[aImage release];
return NS_OK;
}

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

@ -1,63 +0,0 @@
/* 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 nsTouchBarNativeAPIDefines_h
#define nsTouchBarNativeAPIDefines_h
#import <Cocoa/Cocoa.h>
#if !defined(MAC_OS_X_VERSION_10_12) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
@interface NSButton (NewConstructors)
@property(nonatomic) BOOL imageHugsTitle;
+ (NSButton*)buttonWithTitle:(NSString*)title target:(id)target action:(SEL)action;
@end
@interface NSColor (DisplayP3Colors)
+ (NSColor*)colorWithDisplayP3Red:(CGFloat)red
green:(CGFloat)green
blue:(CGFloat)blue
alpha:(CGFloat)alpha;
@end
#endif // !defined(MAC_OS_X_VERSION_10_12)
#if !defined(MAC_OS_X_VERSION_10_12_2) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12_2
@interface NSApplication (TouchBarMenu)
- (IBAction)toggleTouchBarCustomizationPalette:(id)sender;
@end
typedef NSString* NSTouchBarItemIdentifier;
__attribute__((weak_import)) @interface NSTouchBarItem : NSObject
- (instancetype)initWithIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
@end
@protocol NSSharingServicePickerTouchBarItemDelegate
@end
__attribute__((weak_import)) @interface NSSharingServicePickerTouchBarItem : NSTouchBarItem
@property(strong) id<NSSharingServicePickerTouchBarItemDelegate> delegate;
@property(strong) NSImage* buttonImage;
@end
__attribute__((weak_import)) @interface NSCustomTouchBarItem : NSTouchBarItem
@property(strong) NSView* view;
@property(strong) NSString* customizationLabel;
@end
@protocol NSTouchBarDelegate
@end
typedef NSString* NSTouchBarCustomizationIdentifier;
__attribute__((weak_import)) @interface NSTouchBar : NSObject
@property(strong) NSArray<NSTouchBarItemIdentifier>* defaultItemIdentifiers;
@property(strong) id<NSTouchBarDelegate> delegate;
@property(strong) NSTouchBarCustomizationIdentifier customizationIdentifier;
@property(strong) NSArray<NSTouchBarItemIdentifier>* customizationAllowedItemIdentifiers;
- (NSTouchBarItem*)itemForIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
@end
@interface NSButton (TouchBarButton)
@property(strong) NSColor* bezelColor;
@end
#endif // !defined(MAC_OS_X_VERSION_10_12_2)
#endif // nsTouchBarNativeAPIDefines_h

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

@ -7,7 +7,6 @@
#include "nsTouchBar.h"
#include "nsITouchBarInput.h"
#include "nsTouchBarUpdater.h"
#include "nsTouchBarNativeAPIDefines.h"
#include "nsCocoaWindow.h"
#include "nsIArray.h"
@ -21,6 +20,9 @@ extern BOOL sTouchBarIsInitialized;
@interface BaseWindow (NSTouchBarProvider)
@property(strong) NSTouchBar* touchBar;
@end
@interface NSApplication (TouchBarMenu)
- (IBAction)toggleTouchBarCustomizationPalette:(id)sender;
@end
#endif
NS_IMPL_ISUPPORTS(nsTouchBarUpdater, nsITouchBarUpdater);

Двоичные данные
widget/cocoa/touchbar/back.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/bookmark-filled.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/bookmark.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/forward.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/fullscreen.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/home.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/new.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/reader-mode.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/refresh.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/search.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/share.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/sidebar-left.pdf Executable file

Двоичный файл не отображается.

Двоичные данные
widget/cocoa/touchbar/sidebar-right.pdf Executable file

Двоичный файл не отображается.

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

@ -4,9 +4,6 @@
#include "nsIArray.idl"
#include "nsISupports.idl"
#include "nsIURI.idl"
webidl Document;
[scriptable, function, uuid(001ab07c-1b3a-4dbf-a657-fada0065ff55)]
interface nsITouchBarInputCallback : nsISupports
@ -29,9 +26,10 @@ interface nsITouchBarInput : nsISupports
attribute AString title;
/**
* The URI of an icon file.
* The name of a icon file added to
* /widget/cocoa/touchbar.
*/
attribute nsIURI image;
attribute AString image;
/**
* The type of the input.
@ -59,10 +57,4 @@ interface nsITouchBarInput : nsISupports
* If `true`, the Touch Bar input is greyed out and inoperable.
*/
attribute boolean disabled;
/**
* The context in which this nsITouchBarInput exists. Required to create an
* imgLoader to load our image URI.
*/
readonly attribute Document document;
};