Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / nsTouchBar.h
blob4d0aa28d63ee29af808a01ff08ae017343ae8db7
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsTouchBar_h_
6 #define nsTouchBar_h_
8 #import <Cocoa/Cocoa.h>
10 #include "nsITouchBarHelper.h"
11 #include "nsTouchBarInput.h"
13 const NSTouchBarItemIdentifier kTouchBarBaseIdentifier =
14 @"com.mozilla.firefox.touchbar";
16 /**
17 * Our TouchBar is its own delegate. This is adequate for our purposes,
18 * since the current implementation only defines Touch Bar buttons for the
19 * main Firefox window. If modals and other windows were to have custom
20 * Touch Bar views, each window would have to be a NSTouchBarDelegate so
21 * they could define their own custom sets of buttons.
23 @interface nsTouchBar : NSTouchBar <NSTouchBarDelegate,
24 NSSharingServicePickerTouchBarItemDelegate,
25 NSSharingServiceDelegate> {
26 /**
27 * Link to the frontend API that determines which buttons appear
28 * in the Touch Bar
30 nsCOMPtr<nsITouchBarHelper> mTouchBarHelper;
33 /**
34 * Contains TouchBarInput representations of the inputs currently in
35 * the Touch Bar. Populated in `init` and updated by nsITouchBarUpdater.
37 @property(strong) NSMutableDictionary<NSTouchBarItemIdentifier, TouchBarInput*>*
38 mappedLayoutItems;
40 /**
41 * Stores buttons displayed in a NSScrollView. They must be stored separately
42 * because they are untethered from the nsTouchBar. As such, they
43 * cannot be retrieved with [NSTouchBar itemForIdentifier].
45 @property(strong)
46 NSMutableDictionary<NSTouchBarItemIdentifier, NSCustomTouchBarItem*>*
47 scrollViewButtons;
49 /**
50 * Returns an instance of nsTouchBar based on implementation details
51 * fetched from the frontend through nsTouchBarHelper.
53 - (instancetype)init;
55 /**
56 * If aInputs is not nil, a nsTouchBar containing the inputs specified is
57 * initialized. Otherwise, a nsTouchBar is initialized containing a default set
58 * of inputs.
60 - (instancetype)initWithInputs:(NSMutableArray<TouchBarInput*>*)aInputs;
62 - (void)dealloc;
64 /**
65 * Creates a new NSTouchBarItem and adds it to the Touch Bar.
66 * Reads the passed identifier and creates the
67 * appropriate item type (eg. NSCustomTouchBarItem).
68 * Required as a member of NSTouchBarDelegate.
70 - (NSTouchBarItem*)touchBar:(NSTouchBar*)aTouchBar
71 makeItemForIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
73 /**
74 * Updates an input on the Touch Bar by redirecting to one of the specific
75 * TouchBarItem types updaters.
76 * Returns true if the input was successfully updated.
78 - (bool)updateItem:(TouchBarInput*)aInput;
80 /**
81 * Helper function for updateItem. Checks to see if a given input exists within
82 * any of this Touch Bar's popovers and updates it if it exists.
84 - (bool)maybeUpdatePopoverChild:(TouchBarInput*)aInput;
86 /**
87 * Helper function for updateItem. Checks to see if a given input exists within
88 * any of this Touch Bar's scroll views and updates it if it exists.
90 - (bool)maybeUpdateScrollViewChild:(TouchBarInput*)aInput;
92 /**
93 * Helper function for updateItem. Replaces an item in the
94 * self.mappedLayoutItems dictionary.
96 - (void)replaceMappedLayoutItem:(TouchBarInput*)aItem;
98 /**
99 * Update or create various subclasses of TouchBarItem.
101 - (void)updateButton:(NSCustomTouchBarItem*)aButton
102 withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
103 - (void)updateMainButton:(NSCustomTouchBarItem*)aMainButton
104 withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
105 - (void)updatePopover:(NSPopoverTouchBarItem*)aPopoverItem
106 withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
107 - (void)updateScrollView:(NSCustomTouchBarItem*)aScrollViewItem
108 withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
109 - (void)updateLabel:(NSTextField*)aLabel
110 withIdentifier:(NSTouchBarItemIdentifier)aIdentifier;
111 - (NSTouchBarItem*)makeShareScrubberForIdentifier:
112 (NSTouchBarItemIdentifier)aIdentifier;
115 * If aShowing is true, aPopover is shown. Otherwise, it is hidden.
117 - (void)showPopover:(TouchBarInput*)aPopover showing:(bool)aShowing;
120 * Redirects button actions to the appropriate handler.
122 - (void)touchBarAction:(id)aSender;
125 * Helper function to initialize a new nsTouchBarInputIcon and load an icon.
127 - (void)loadIconForInput:(TouchBarInput*)aInput forItem:(NSTouchBarItem*)aItem;
129 - (NSArray*)itemsForSharingServicePickerTouchBarItem:
130 (NSSharingServicePickerTouchBarItem*)aPickerTouchBarItem;
132 - (NSArray<NSSharingService*>*)
133 sharingServicePicker:(NSSharingServicePicker*)aSharingServicePicker
134 sharingServicesForItems:(NSArray*)aItems
135 proposedSharingServices:(NSArray<NSSharingService*>*)aProposedServices;
137 - (void)releaseJSObjects;
139 @end // nsTouchBar
141 #endif // nsTouchBar_h_