2019-01-22 17:13:33 +00: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/. */
|
|
|
|
|
|
|
|
#ifndef nsTouchBar_h_
|
|
|
|
#define nsTouchBar_h_
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include "nsITouchBarHelper.h"
|
2019-12-31 20:26:00 +00:00
|
|
|
#include "nsTouchBarInput.h"
|
2019-01-22 17:13:33 +00:00
|
|
|
|
2023-09-08 01:44:07 +00:00
|
|
|
const NSTouchBarItemIdentifier kTouchBarBaseIdentifier =
|
|
|
|
@"com.mozilla.firefox.touchbar";
|
2020-12-11 04:09:18 +00:00
|
|
|
|
2019-01-22 17:13:33 +00:00
|
|
|
/**
|
|
|
|
* Our TouchBar is its own delegate. This is adequate for our purposes,
|
|
|
|
* since the current implementation only defines Touch Bar buttons for the
|
|
|
|
* main Firefox window. If modals and other windows were to have custom
|
|
|
|
* Touch Bar views, each window would have to be a NSTouchBarDelegate so
|
|
|
|
* they could define their own custom sets of buttons.
|
|
|
|
*/
|
|
|
|
@interface nsTouchBar : NSTouchBar <NSTouchBarDelegate,
|
|
|
|
NSSharingServicePickerTouchBarItemDelegate,
|
|
|
|
NSSharingServiceDelegate> {
|
|
|
|
/**
|
|
|
|
* Link to the frontend API that determines which buttons appear
|
|
|
|
* in the Touch Bar
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsITouchBarHelper> mTouchBarHelper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains TouchBarInput representations of the inputs currently in
|
|
|
|
* the Touch Bar. Populated in `init` and updated by nsITouchBarUpdater.
|
|
|
|
*/
|
2023-09-08 01:44:07 +00:00
|
|
|
@property(strong) NSMutableDictionary<NSTouchBarItemIdentifier, TouchBarInput*>*
|
|
|
|
mappedLayoutItems;
|
2019-01-22 17:13:33 +00:00
|
|
|
|
2019-10-10 01:00:47 +00:00
|
|
|
/**
|
|
|
|
* Stores buttons displayed in a NSScrollView. They must be stored separately
|
2020-01-03 17:07:25 +00:00
|
|
|
* because they are untethered from the nsTouchBar. As such, they
|
2019-10-10 01:00:47 +00:00
|
|
|
* cannot be retrieved with [NSTouchBar itemForIdentifier].
|
|
|
|
*/
|
2020-01-03 17:07:25 +00:00
|
|
|
@property(strong)
|
2023-09-08 01:44:07 +00:00
|
|
|
NSMutableDictionary<NSTouchBarItemIdentifier, NSCustomTouchBarItem*>*
|
|
|
|
scrollViewButtons;
|
2019-10-10 01:00:47 +00:00
|
|
|
|
2019-01-22 17:13:33 +00:00
|
|
|
/**
|
|
|
|
* Returns an instance of nsTouchBar based on implementation details
|
|
|
|
* fetched from the frontend through nsTouchBarHelper.
|
|
|
|
*/
|
|
|
|
- (instancetype)init;
|
|
|
|
|
2019-10-09 15:25:43 +00:00
|
|
|
/**
|
|
|
|
* If aInputs is not nil, a nsTouchBar containing the inputs specified is
|
|
|
|
* initialized. Otherwise, a nsTouchBar is initialized containing a default set
|
|
|
|
* of inputs.
|
|
|
|
*/
|
|
|
|
- (instancetype)initWithInputs:(NSMutableArray<TouchBarInput*>*)aInputs;
|
|
|
|
|
2019-01-22 17:13:33 +00:00
|
|
|
- (void)dealloc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new NSTouchBarItem and adds it to the Touch Bar.
|
|
|
|
* Reads the passed identifier and creates the
|
|
|
|
* appropriate item type (eg. NSCustomTouchBarItem).
|
|
|
|
* Required as a member of NSTouchBarDelegate.
|
|
|
|
*/
|
|
|
|
- (NSTouchBarItem*)touchBar:(NSTouchBar*)aTouchBar
|
|
|
|
makeItemForIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates an input on the Touch Bar by redirecting to one of the specific
|
|
|
|
* TouchBarItem types updaters.
|
2019-10-09 17:55:15 +00:00
|
|
|
* Returns true if the input was successfully updated.
|
2019-01-22 17:13:33 +00:00
|
|
|
*/
|
2019-10-09 17:55:15 +00:00
|
|
|
- (bool)updateItem:(TouchBarInput*)aInput;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for updateItem. Checks to see if a given input exists within
|
|
|
|
* any of this Touch Bar's popovers and updates it if it exists.
|
|
|
|
*/
|
|
|
|
- (bool)maybeUpdatePopoverChild:(TouchBarInput*)aInput;
|
|
|
|
|
2019-10-10 01:00:47 +00:00
|
|
|
/**
|
|
|
|
* Helper function for updateItem. Checks to see if a given input exists within
|
|
|
|
* any of this Touch Bar's scroll views and updates it if it exists.
|
|
|
|
*/
|
|
|
|
- (bool)maybeUpdateScrollViewChild:(TouchBarInput*)aInput;
|
|
|
|
|
2019-10-09 17:55:15 +00:00
|
|
|
/**
|
|
|
|
* Helper function for updateItem. Replaces an item in the
|
|
|
|
* self.mappedLayoutItems dictionary.
|
|
|
|
*/
|
|
|
|
- (void)replaceMappedLayoutItem:(TouchBarInput*)aItem;
|
2019-01-22 17:13:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update or create various subclasses of TouchBarItem.
|
|
|
|
*/
|
2020-01-03 17:07:25 +00:00
|
|
|
- (void)updateButton:(NSCustomTouchBarItem*)aButton
|
|
|
|
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
|
|
|
- (void)updateMainButton:(NSCustomTouchBarItem*)aMainButton
|
2019-11-10 19:39:12 +00:00
|
|
|
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
|
|
|
- (void)updatePopover:(NSPopoverTouchBarItem*)aPopoverItem
|
|
|
|
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
|
|
|
- (void)updateScrollView:(NSCustomTouchBarItem*)aScrollViewItem
|
|
|
|
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
2023-09-08 01:44:07 +00:00
|
|
|
- (void)updateLabel:(NSTextField*)aLabel
|
|
|
|
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
|
|
|
|
- (NSTouchBarItem*)makeShareScrubberForIdentifier:
|
|
|
|
(NSTouchBarItemIdentifier)aIdentifier;
|
2019-01-22 17:13:33 +00:00
|
|
|
|
|
|
|
/**
|
2019-10-09 17:55:15 +00:00
|
|
|
* If aShowing is true, aPopover is shown. Otherwise, it is hidden.
|
|
|
|
*/
|
|
|
|
- (void)showPopover:(TouchBarInput*)aPopover showing:(bool)aShowing;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects button actions to the appropriate handler.
|
2019-01-22 17:13:33 +00:00
|
|
|
*/
|
|
|
|
- (void)touchBarAction:(id)aSender;
|
|
|
|
|
2020-01-03 17:07:25 +00:00
|
|
|
/**
|
|
|
|
* Helper function to initialize a new nsTouchBarInputIcon and load an icon.
|
|
|
|
*/
|
|
|
|
- (void)loadIconForInput:(TouchBarInput*)aInput forItem:(NSTouchBarItem*)aItem;
|
|
|
|
|
2019-01-22 17:13:33 +00:00
|
|
|
- (NSArray*)itemsForSharingServicePickerTouchBarItem:
|
|
|
|
(NSSharingServicePickerTouchBarItem*)aPickerTouchBarItem;
|
|
|
|
|
2023-09-08 01:44:07 +00:00
|
|
|
- (NSArray<NSSharingService*>*)
|
|
|
|
sharingServicePicker:(NSSharingServicePicker*)aSharingServicePicker
|
|
|
|
sharingServicesForItems:(NSArray*)aItems
|
|
|
|
proposedSharingServices:(NSArray<NSSharingService*>*)aProposedServices;
|
2019-01-22 17:13:33 +00:00
|
|
|
|
2019-02-13 19:16:39 +00:00
|
|
|
- (void)releaseJSObjects;
|
|
|
|
|
2019-01-22 17:13:33 +00:00
|
|
|
@end // nsTouchBar
|
|
|
|
|
|
|
|
#endif // nsTouchBar_h_
|