1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/* 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"
#include "nsTouchBarInput.h"
#include "nsTouchBarNativeAPIDefines.h"
const NSTouchBarItemIdentifier kTouchBarBaseIdentifier = @"com.mozilla.firefox.touchbar";
/**
* 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.
*/
@property(strong) NSMutableDictionary<NSTouchBarItemIdentifier, TouchBarInput*>* mappedLayoutItems;
/**
* Stores buttons displayed in a NSScrollView. They must be stored separately
* because they are untethered from the nsTouchBar. As such, they
* cannot be retrieved with [NSTouchBar itemForIdentifier].
*/
@property(strong)
NSMutableDictionary<NSTouchBarItemIdentifier, NSCustomTouchBarItem*>* scrollViewButtons;
/**
* Returns an instance of nsTouchBar based on implementation details
* fetched from the frontend through nsTouchBarHelper.
*/
- (instancetype)init;
/**
* 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;
- (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.
* Returns true if the input was successfully updated.
*/
- (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;
/**
* 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;
/**
* Helper function for updateItem. Replaces an item in the
* self.mappedLayoutItems dictionary.
*/
- (void)replaceMappedLayoutItem:(TouchBarInput*)aItem;
/**
* Update or create various subclasses of TouchBarItem.
*/
- (void)updateButton:(NSCustomTouchBarItem*)aButton
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
- (void)updateMainButton:(NSCustomTouchBarItem*)aMainButton
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
- (void)updatePopover:(NSPopoverTouchBarItem*)aPopoverItem
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
- (void)updateScrollView:(NSCustomTouchBarItem*)aScrollViewItem
withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
- (void)updateLabel:(NSTextField*)aLabel withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
- (NSTouchBarItem*)makeShareScrubberForIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
/**
* 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.
*/
- (void)touchBarAction:(id)aSender;
/**
* Helper function to initialize a new nsTouchBarInputIcon and load an icon.
*/
- (void)loadIconForInput:(TouchBarInput*)aInput forItem:(NSTouchBarItem*)aItem;
- (NSArray*)itemsForSharingServicePickerTouchBarItem:
(NSSharingServicePickerTouchBarItem*)aPickerTouchBarItem;
- (NSArray<NSSharingService*>*)sharingServicePicker:(NSSharingServicePicker*)aSharingServicePicker
sharingServicesForItems:(NSArray*)aItems
proposedSharingServices:(NSArray<NSSharingService*>*)aProposedServices;
- (void)releaseJSObjects;
@end // nsTouchBar
#endif // nsTouchBar_h_
|