mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 282097 - Part 3: Add key bindings recorder to nsCocoaUtils. r=masayuki, r=smichaud
This commit is contained in:
parent
278ae6155f
commit
422f8b06fc
@ -12,6 +12,7 @@
|
||||
#include "imgIContainer.h"
|
||||
#include "nsEvent.h"
|
||||
#include "npapi.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
// This must be the last include:
|
||||
#include "nsObjCExceptions.h"
|
||||
@ -78,6 +79,26 @@ private:
|
||||
|
||||
@end
|
||||
|
||||
struct KeyBindingsCommand
|
||||
{
|
||||
SEL selector;
|
||||
id data;
|
||||
};
|
||||
|
||||
@interface NativeKeyBindingsRecorder : NSResponder
|
||||
{
|
||||
@private
|
||||
nsTArray<KeyBindingsCommand>* mCommands;
|
||||
}
|
||||
|
||||
- (void)startRecording:(nsTArray<KeyBindingsCommand>&)aCommands;
|
||||
|
||||
- (void)doCommandBySelector:(SEL)aSelector;
|
||||
|
||||
- (void)insertText:(id)aString;
|
||||
|
||||
@end // NativeKeyBindingsRecorder
|
||||
|
||||
class nsCocoaUtils
|
||||
{
|
||||
public:
|
||||
@ -286,6 +307,14 @@ class nsCocoaUtils
|
||||
* once we're comfortable with the HiDPI behavior.
|
||||
*/
|
||||
static bool HiDPIEnabled();
|
||||
|
||||
/**
|
||||
* Keys can optionally be bound by system or user key bindings to one or more
|
||||
* commands based on selectors. This collects any such commands in the
|
||||
* provided array.
|
||||
*/
|
||||
static void GetCommandsFromKeyEvent(NSEvent* aEvent,
|
||||
nsTArray<KeyBindingsCommand>& aCommands);
|
||||
};
|
||||
|
||||
#endif // nsCocoaUtils_h_
|
||||
|
@ -574,3 +574,55 @@ nsCocoaUtils::HiDPIEnabled()
|
||||
|
||||
return sHiDPIEnabled;
|
||||
}
|
||||
|
||||
void
|
||||
nsCocoaUtils::GetCommandsFromKeyEvent(NSEvent* aEvent,
|
||||
nsTArray<KeyBindingsCommand>& aCommands)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
MOZ_ASSERT(aEvent);
|
||||
|
||||
static NativeKeyBindingsRecorder* sNativeKeyBindingsRecorder;
|
||||
if (!sNativeKeyBindingsRecorder) {
|
||||
sNativeKeyBindingsRecorder = [NativeKeyBindingsRecorder new];
|
||||
}
|
||||
|
||||
[sNativeKeyBindingsRecorder startRecording:aCommands];
|
||||
|
||||
// This will trigger 0 - N calls to doCommandBySelector: and insertText:
|
||||
[sNativeKeyBindingsRecorder
|
||||
interpretKeyEvents:[NSArray arrayWithObject:aEvent]];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
@implementation NativeKeyBindingsRecorder
|
||||
|
||||
- (void)startRecording:(nsTArray<KeyBindingsCommand>&)aCommands
|
||||
{
|
||||
mCommands = &aCommands;
|
||||
mCommands->Clear();
|
||||
}
|
||||
|
||||
- (void)doCommandBySelector:(SEL)aSelector
|
||||
{
|
||||
KeyBindingsCommand command = {
|
||||
aSelector,
|
||||
nil
|
||||
};
|
||||
|
||||
mCommands->AppendElement(command);
|
||||
}
|
||||
|
||||
- (void)insertText:(id)aString
|
||||
{
|
||||
KeyBindingsCommand command = {
|
||||
@selector(insertText:),
|
||||
aString
|
||||
};
|
||||
|
||||
mCommands->AppendElement(command);
|
||||
}
|
||||
|
||||
@end // NativeKeyBindingsRecorder
|
||||
|
Loading…
x
Reference in New Issue
Block a user