2017-10-14 03:40:27 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#include "HeadlessKeyBindings.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#include "nsCocoaUtils.h"
|
|
|
|
#include "NativeKeyBindings.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "mozilla/WritingModes.h"
|
2017-10-14 03:40:27 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
HeadlessKeyBindings& HeadlessKeyBindings::GetInstance() {
|
|
|
|
static UniquePtr<HeadlessKeyBindings> sInstance;
|
|
|
|
if (!sInstance) {
|
|
|
|
sInstance.reset(new HeadlessKeyBindings());
|
|
|
|
ClearOnShutdown(&sInstance);
|
|
|
|
}
|
|
|
|
return *sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult HeadlessKeyBindings::AttachNativeKeyEvent(WidgetKeyboardEvent& aEvent) {
|
2021-02-17 01:55:20 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
2017-10-14 03:40:27 +03:00
|
|
|
|
|
|
|
aEvent.mNativeKeyEvent = nsCocoaUtils::MakeNewCococaEventFromWidgetEvent(aEvent, 0, nil);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
2021-02-17 01:55:20 +03:00
|
|
|
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
|
2017-10-14 03:40:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HeadlessKeyBindings::GetEditCommands(nsIWidget::NativeKeyBindingsType aType,
|
|
|
|
const WidgetKeyboardEvent& aEvent,
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
const Maybe<WritingMode>& aWritingMode,
|
2017-10-14 03:40:27 +03:00
|
|
|
nsTArray<CommandInt>& aCommands) {
|
|
|
|
// Convert the widget keyboard into a cocoa event so it can be translated
|
|
|
|
// into commands in the NativeKeyBindings.
|
|
|
|
WidgetKeyboardEvent modifiedEvent(aEvent);
|
|
|
|
modifiedEvent.mNativeKeyEvent = nsCocoaUtils::MakeNewCococaEventFromWidgetEvent(aEvent, 0, nil);
|
|
|
|
|
|
|
|
NativeKeyBindings* keyBindings = NativeKeyBindings::GetInstance(aType);
|
Bug 1685491 - part 5: Move the code remapping arrow keys in vertical content to `NativeKeyBindings` r=smaug,jfkthame
Currently, this feature is implemented only on Linux and macOS (see also
bug 1077515 and bug 1301497), and the code is really similar each other.
Additionally, it always tries to query selection to check whether the caret is
in vertical content or not if arrow keys are pressed. For avoiding a lot of
query, this patch makes `TextEventDispatcher` cache writing mode at every
selection change notification. However, unfortunately, it's not available when
non-editable content has focus, but it should be out of scope of this bug since
it requires a lot of changes.
Anyway, with this patch, we can write a mochitest only on Linux and macOS.
The following patch adds a test for this as a fix of bug 1103374.
Differential Revision: https://phabricator.services.mozilla.com/D102881
2021-02-02 06:29:31 +03:00
|
|
|
keyBindings->GetEditCommands(modifiedEvent, aWritingMode, aCommands);
|
2017-10-14 03:40:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|