mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 977959 part.3 Hide nsINativeKeyBindings with nsIWidget::ExecuteNativeKeyBinding() r=roc+karlt+smichaud
This commit is contained in:
parent
12f45f8af4
commit
7179f50754
@ -1516,8 +1516,6 @@ nsContentUtils::Shutdown()
|
||||
sModifierSeparator = nullptr;
|
||||
|
||||
NS_IF_RELEASE(sSameOriginChecker);
|
||||
|
||||
nsTextEditorState::ShutDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIEditorObserver.h"
|
||||
#include "nsINativeKeyBindings.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIDocumentEncoder.h"
|
||||
#include "nsISelectionPrivate.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
@ -49,9 +49,6 @@ using namespace mozilla::dom;
|
||||
|
||||
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
|
||||
|
||||
static nsINativeKeyBindings *sNativeInputBindings = nullptr;
|
||||
static nsINativeKeyBindings *sNativeTextAreaBindings = nullptr;
|
||||
|
||||
class MOZ_STACK_CLASS ValueSetter
|
||||
{
|
||||
public:
|
||||
@ -679,8 +676,6 @@ protected:
|
||||
|
||||
nsresult UpdateTextInputCommands(const nsAString& commandsToUpdate);
|
||||
|
||||
NS_HIDDEN_(nsINativeKeyBindings*) GetKeyBindings();
|
||||
|
||||
protected:
|
||||
|
||||
nsIFrame* mFrame;
|
||||
@ -864,12 +859,19 @@ nsTextInputListener::HandleEvent(nsIDOMEvent* aEvent)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsINativeKeyBindings *bindings = GetKeyBindings();
|
||||
if (!bindings) {
|
||||
return NS_OK;
|
||||
nsIWidget::NativeKeyBindingsType nativeKeyBindingsType =
|
||||
mTxtCtrlElement->IsTextArea() ?
|
||||
nsIWidget::NativeKeyBindingsForMultiLineEditor :
|
||||
nsIWidget::NativeKeyBindingsForSingleLineEditor;
|
||||
nsIWidget* widget = keyEvent->widget;
|
||||
// If the event is created by chrome script, the widget is nullptr.
|
||||
if (!widget) {
|
||||
widget = mFrame->GetNearestWidget();
|
||||
NS_ENSURE_TRUE(widget, NS_OK);
|
||||
}
|
||||
|
||||
if (bindings->KeyPress(*keyEvent, DoCommandCallback, mFrame)) {
|
||||
|
||||
if (widget->ExecuteNativeKeyBinding(nativeKeyBindingsType,
|
||||
*keyEvent, DoCommandCallback, mFrame)) {
|
||||
aEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
@ -940,37 +942,6 @@ nsTextInputListener::UpdateTextInputCommands(const nsAString& commandsToUpdate)
|
||||
return domWindow->UpdateCommands(commandsToUpdate);
|
||||
}
|
||||
|
||||
nsINativeKeyBindings*
|
||||
nsTextInputListener::GetKeyBindings()
|
||||
{
|
||||
if (mTxtCtrlElement->IsTextArea()) {
|
||||
static bool sNoTextAreaBindings = false;
|
||||
|
||||
if (!sNativeTextAreaBindings && !sNoTextAreaBindings) {
|
||||
CallGetService(NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "textarea",
|
||||
&sNativeTextAreaBindings);
|
||||
|
||||
if (!sNativeTextAreaBindings) {
|
||||
sNoTextAreaBindings = true;
|
||||
}
|
||||
}
|
||||
|
||||
return sNativeTextAreaBindings;
|
||||
}
|
||||
|
||||
static bool sNoInputBindings = false;
|
||||
if (!sNativeInputBindings && !sNoInputBindings) {
|
||||
CallGetService(NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "input",
|
||||
&sNativeInputBindings);
|
||||
|
||||
if (!sNativeInputBindings) {
|
||||
sNoInputBindings = true;
|
||||
}
|
||||
}
|
||||
|
||||
return sNativeInputBindings;
|
||||
}
|
||||
|
||||
// END nsTextInputListener
|
||||
|
||||
// nsTextEditorState
|
||||
@ -1975,13 +1946,6 @@ nsTextEditorState::InitializeKeyboardEventListeners()
|
||||
mSelCon->SetScrollableFrame(do_QueryFrame(mBoundFrame->GetFirstPrincipalChild()));
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsTextEditorState::ShutDown()
|
||||
{
|
||||
NS_IF_RELEASE(sNativeTextAreaBindings);
|
||||
NS_IF_RELEASE(sNativeInputBindings);
|
||||
}
|
||||
|
||||
void
|
||||
nsTextEditorState::ValueWasChanged(bool aNotify)
|
||||
{
|
||||
|
@ -188,9 +188,6 @@ public:
|
||||
*/
|
||||
bool GetMaxLength(int32_t* aMaxLength);
|
||||
|
||||
/* called to free up native keybinding services */
|
||||
static NS_HIDDEN_(void) ShutDown();
|
||||
|
||||
void ClearValueCache() { mCachedValue.Truncate(); }
|
||||
|
||||
void HideSelectionIfBlurred();
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "nsIFocusManager.h" // for nsIFocusManager
|
||||
#include "nsIFormControl.h" // for nsIFormControl, etc
|
||||
#include "nsIHTMLEditor.h" // for nsIHTMLEditor
|
||||
#include "nsINativeKeyBindings.h" // for nsINativeKeyBindings
|
||||
#include "nsINode.h" // for nsINode, ::NODE_IS_EDITABLE, etc
|
||||
#include "nsIPlaintextEditor.h" // for nsIPlaintextEditor, etc
|
||||
#include "nsIPresShell.h" // for nsIPresShell
|
||||
@ -47,6 +46,7 @@
|
||||
#include "nsISelectionController.h" // for nsISelectionController, etc
|
||||
#include "nsISelectionPrivate.h" // for nsISelectionPrivate
|
||||
#include "nsITransferable.h" // for kFileMime, kHTMLMime, etc
|
||||
#include "nsIWidget.h" // for nsIWidget
|
||||
#include "nsLiteralString.h" // for NS_LITERAL_STRING
|
||||
#include "nsPIWindowRoot.h" // for nsPIWindowRoot
|
||||
#include "nsServiceManagerUtils.h" // for do_GetService
|
||||
@ -61,24 +61,6 @@ class nsPresContext;
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
static nsINativeKeyBindings *sNativeEditorBindings = nullptr;
|
||||
|
||||
static nsINativeKeyBindings*
|
||||
GetEditorKeyBindings()
|
||||
{
|
||||
static bool noBindings = false;
|
||||
if (!sNativeEditorBindings && !noBindings) {
|
||||
CallGetService(NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "editor",
|
||||
&sNativeEditorBindings);
|
||||
|
||||
if (!sNativeEditorBindings) {
|
||||
noBindings = true;
|
||||
}
|
||||
}
|
||||
|
||||
return sNativeEditorBindings;
|
||||
}
|
||||
|
||||
static void
|
||||
DoCommandCallback(Command aCommand, void* aData)
|
||||
{
|
||||
@ -127,12 +109,6 @@ nsEditorEventListener::~nsEditorEventListener()
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsEditorEventListener::ShutDown()
|
||||
{
|
||||
NS_IF_RELEASE(sNativeEditorBindings);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditorEventListener::Connect(nsEditor* aEditor)
|
||||
{
|
||||
@ -528,16 +504,25 @@ nsEditorEventListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (GetEditorKeyBindings() && ShouldHandleNativeKeyBindings(aKeyEvent)) {
|
||||
if (ShouldHandleNativeKeyBindings(aKeyEvent)) {
|
||||
// Now, ask the native key bindings to handle the event.
|
||||
WidgetKeyboardEvent* keyEvent =
|
||||
aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent();
|
||||
MOZ_ASSERT(keyEvent,
|
||||
"DOM key event's internal event must be WidgetKeyboardEvent");
|
||||
nsIWidget* widget = keyEvent->widget;
|
||||
// If the event is created by chrome script, the widget is always nullptr.
|
||||
if (!widget) {
|
||||
nsCOMPtr<nsIPresShell> ps = GetPresShell();
|
||||
nsPresContext* pc = ps ? ps->GetPresContext() : nullptr;
|
||||
widget = pc ? pc->GetNearestWidget() : nullptr;
|
||||
NS_ENSURE_TRUE(widget, NS_OK);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = mEditor->GetDocument();
|
||||
bool handled = sNativeEditorBindings->KeyPress(*keyEvent,
|
||||
DoCommandCallback,
|
||||
doc);
|
||||
bool handled = widget->ExecuteNativeKeyBinding(
|
||||
nsIWidget::NativeKeyBindingsForRichTextEditor,
|
||||
*keyEvent, DoCommandCallback, doc);
|
||||
if (handled) {
|
||||
aKeyEvent->PreventDefault();
|
||||
}
|
||||
|
@ -59,8 +59,6 @@ public:
|
||||
|
||||
void SpellCheckIfNeeded();
|
||||
|
||||
static NS_HIDDEN_(void) ShutDown();
|
||||
|
||||
protected:
|
||||
nsresult InstallToEditor();
|
||||
void UninstallFromEditor();
|
||||
|
@ -352,7 +352,6 @@ nsLayoutStatics::Shutdown()
|
||||
nsGlobalWindow::ShutDown();
|
||||
nsDOMClassInfo::ShutDown();
|
||||
nsListControlFrame::Shutdown();
|
||||
nsEditorEventListener::ShutDown();
|
||||
nsXBLService::Shutdown();
|
||||
nsAutoCopyListener::Shutdown();
|
||||
FrameLayerBuilder::Shutdown();
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define NativeKeyBindings_h_
|
||||
|
||||
#include "nsINativeKeyBindings.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include "mozilla/Attributes.h"
|
||||
@ -31,19 +32,19 @@
|
||||
namespace mozilla {
|
||||
namespace widget {
|
||||
|
||||
enum NativeKeyBindingsType
|
||||
{
|
||||
eNativeKeyBindingsType_Input,
|
||||
eNativeKeyBindingsType_TextArea,
|
||||
eNativeKeyBindingsType_Editor
|
||||
};
|
||||
|
||||
typedef nsDataHashtable<nsPtrHashKey<struct objc_selector>, CommandInt>
|
||||
SelectorCommandHashtable;
|
||||
|
||||
class NativeKeyBindings MOZ_FINAL : public nsINativeKeyBindings
|
||||
{
|
||||
typedef nsIWidget::NativeKeyBindingsType NativeKeyBindingsType;
|
||||
typedef nsIWidget::DoCommandCallback DoCommandCallback;
|
||||
|
||||
public:
|
||||
static already_AddRefed<NativeKeyBindings>
|
||||
GetInstance(NativeKeyBindingsType aType);
|
||||
static void Shutdown();
|
||||
|
||||
NativeKeyBindings();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
@ -57,6 +58,9 @@ public:
|
||||
|
||||
private:
|
||||
SelectorCommandHashtable mSelectorToCommand;
|
||||
|
||||
static NativeKeyBindings* sInstanceForSingleLineEditor;
|
||||
static NativeKeyBindings* sInstanceForMultiLineEditor;
|
||||
}; // NativeKeyBindings
|
||||
|
||||
} // namespace widget
|
||||
|
@ -17,6 +17,43 @@ using namespace mozilla::widget;
|
||||
PRLogModuleInfo* gNativeKeyBindingsLog = nullptr;
|
||||
#endif
|
||||
|
||||
NativeKeyBindings* NativeKeyBindings::sInstanceForSingleLineEditor = nullptr;
|
||||
NativeKeyBindings* NativeKeyBindings::sInstanceForMultiLineEditor = nullptr;
|
||||
|
||||
// static
|
||||
already_AddRefed<NativeKeyBindings>
|
||||
NativeKeyBindings::GetInstance(NativeKeyBindingsType aType)
|
||||
{
|
||||
switch (aType) {
|
||||
case nsIWidget::NativeKeyBindingsForSingleLineEditor:
|
||||
if (!sInstanceForSingleLineEditor) {
|
||||
NS_ADDREF(sInstanceForSingleLineEditor = new NativeKeyBindings());
|
||||
sInstanceForSingleLineEditor->Init(aType);
|
||||
}
|
||||
NS_ADDREF(sInstanceForSingleLineEditor);
|
||||
return sInstanceForSingleLineEditor;
|
||||
case nsIWidget::NativeKeyBindingsForMultiLineEditor:
|
||||
case nsIWidget::NativeKeyBindingsForRichTextEditor:
|
||||
if (!sInstanceForMultiLineEditor) {
|
||||
NS_ADDREF(sInstanceForMultiLineEditor = new NativeKeyBindings());
|
||||
sInstanceForMultiLineEditor->Init(aType);
|
||||
}
|
||||
NS_ADDREF(sInstanceForMultiLineEditor);
|
||||
return sInstanceForMultiLineEditor;
|
||||
default:
|
||||
MOZ_CRASH("Not implemented");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
NativeKeyBindings::Shutdown()
|
||||
{
|
||||
NS_IF_RELEASE(sInstanceForSingleLineEditor);
|
||||
NS_IF_RELEASE(sInstanceForMultiLineEditor);
|
||||
}
|
||||
|
||||
NativeKeyBindings::NativeKeyBindings()
|
||||
{
|
||||
}
|
||||
@ -83,7 +120,7 @@ NativeKeyBindings::Init(NativeKeyBindingsType aType)
|
||||
// SEL_TO_COMMAND(lowercaseWord:, );
|
||||
SEL_TO_COMMAND(moveBackward:, CommandCharPrevious);
|
||||
SEL_TO_COMMAND(moveBackwardAndModifySelection:, CommandSelectCharPrevious);
|
||||
if (aType == eNativeKeyBindingsType_Input) {
|
||||
if (aType == nsIWidget::NativeKeyBindingsForSingleLineEditor) {
|
||||
SEL_TO_COMMAND(moveDown:, CommandEndLine);
|
||||
} else {
|
||||
SEL_TO_COMMAND(moveDown:, CommandLineNext);
|
||||
@ -118,7 +155,7 @@ NativeKeyBindings::Init(NativeKeyBindingsType aType)
|
||||
CommandSelectBeginLine);
|
||||
SEL_TO_COMMAND(moveToRightEndOfLine:, CommandEndLine);
|
||||
SEL_TO_COMMAND(moveToRightEndOfLineAndModifySelection:, CommandSelectEndLine);
|
||||
if (aType == eNativeKeyBindingsType_Input) {
|
||||
if (aType == nsIWidget::NativeKeyBindingsForSingleLineEditor) {
|
||||
SEL_TO_COMMAND(moveUp:, CommandBeginLine);
|
||||
} else {
|
||||
SEL_TO_COMMAND(moveUp:, CommandLinePrevious);
|
||||
@ -148,7 +185,7 @@ NativeKeyBindings::Init(NativeKeyBindingsType aType)
|
||||
SEL_TO_COMMAND(scrollToEndOfDocument:, CommandScrollBottom);
|
||||
SEL_TO_COMMAND(selectAll:, CommandSelectAll);
|
||||
// selectLine: is complex, see KeyDown
|
||||
if (aType == eNativeKeyBindingsType_Input) {
|
||||
if (aType == nsIWidget::NativeKeyBindingsForSingleLineEditor) {
|
||||
SEL_TO_COMMAND(selectParagraph:, CommandSelectAll);
|
||||
}
|
||||
// SEL_TO_COMMAND(selectToMark:, );
|
||||
|
@ -521,6 +521,11 @@ public:
|
||||
NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
|
||||
const InputContextAction& aAction);
|
||||
NS_IMETHOD_(InputContext) GetInputContext();
|
||||
NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
|
||||
NativeKeyBindingsType aType,
|
||||
const mozilla::WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
void* aCallbackData) MOZ_OVERRIDE;
|
||||
virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE;
|
||||
NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode,
|
||||
bool* aLEDState);
|
||||
|
@ -50,6 +50,7 @@
|
||||
#ifdef __LP64__
|
||||
#include "ComplexTextInputPanel.h"
|
||||
#endif
|
||||
#include "NativeKeyBindings.h"
|
||||
|
||||
#include "gfxContext.h"
|
||||
#include "gfxQuartzSurface.h"
|
||||
@ -1962,6 +1963,17 @@ nsChildView::GetInputContext()
|
||||
return mInputContext;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
nsChildView::ExecuteNativeKeyBinding(NativeKeyBindingsType aType,
|
||||
const WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
void* aCallbackData)
|
||||
{
|
||||
nsRefPtr<NativeKeyBindings> keyBindings =
|
||||
NativeKeyBindings::GetInstance(aType);
|
||||
return keyBindings->KeyPress(aEvent, aCallback, aCallbackData);
|
||||
}
|
||||
|
||||
nsIMEUpdatePreference
|
||||
nsChildView::GetIMEUpdatePreference()
|
||||
{
|
||||
|
@ -344,6 +344,11 @@ public:
|
||||
}
|
||||
return mInputContext;
|
||||
}
|
||||
NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
|
||||
NativeKeyBindingsType aType,
|
||||
const mozilla::WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
void* aCallbackData) MOZ_OVERRIDE;
|
||||
|
||||
void SetPopupWindowLevel();
|
||||
|
||||
|
@ -5,12 +5,13 @@
|
||||
|
||||
#include "nsCocoaWindow.h"
|
||||
|
||||
#include "NativeKeyBindings.h"
|
||||
#include "TextInputHandler.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsIRollupListener.h"
|
||||
#include "nsChildView.h"
|
||||
#include "TextInputHandler.h"
|
||||
#include "nsWindowMap.h"
|
||||
#include "nsAppShell.h"
|
||||
#include "nsIAppShellService.h"
|
||||
@ -2163,6 +2164,18 @@ nsCocoaWindow::SetInputContext(const InputContext& aContext,
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
nsCocoaWindow::ExecuteNativeKeyBinding(NativeKeyBindingsType aType,
|
||||
const WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
void* aCallbackData)
|
||||
{
|
||||
nsRefPtr<NativeKeyBindings> keyBindings =
|
||||
NativeKeyBindings::GetInstance(aType);
|
||||
return keyBindings->KeyPress(aEvent, aCallback, aCallbackData);
|
||||
}
|
||||
|
||||
|
||||
@implementation WindowDelegate
|
||||
|
||||
// We try to find a gecko menu bar to paint. If one does not exist, just paint
|
||||
|
@ -89,50 +89,31 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init)
|
||||
namespace mozilla {
|
||||
namespace widget {
|
||||
|
||||
static nsresult
|
||||
NativeKeyBindingsConstructor(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult, NativeKeyBindingsType aType)
|
||||
{
|
||||
NativeKeyBindings* inst;
|
||||
|
||||
*aResult = NULL;
|
||||
if (NULL != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
|
||||
inst = new NativeKeyBindings();
|
||||
NS_ADDREF(inst);
|
||||
nsresult rv = inst->Init(aType);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
}
|
||||
NS_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
NativeKeyBindingsInputConstructor(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult)
|
||||
{
|
||||
return NativeKeyBindingsConstructor(aOuter, aIID, aResult,
|
||||
eNativeKeyBindingsType_Input);
|
||||
*aResult = NativeKeyBindings::GetInstance(
|
||||
nsIWidget::NativeKeyBindingsForSingleLineEditor).get();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
NativeKeyBindingsTextAreaConstructor(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult)
|
||||
{
|
||||
return NativeKeyBindingsConstructor(aOuter, aIID, aResult,
|
||||
eNativeKeyBindingsType_TextArea);
|
||||
*aResult = NativeKeyBindings::GetInstance(
|
||||
nsIWidget::NativeKeyBindingsForMultiLineEditor).get();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
NativeKeyBindingsEditorConstructor(nsISupports* aOuter, REFNSIID aIID,
|
||||
void** aResult)
|
||||
{
|
||||
return NativeKeyBindingsConstructor(aOuter, aIID, aResult,
|
||||
eNativeKeyBindingsType_Editor);
|
||||
*aResult = NativeKeyBindings::GetInstance(
|
||||
nsIWidget::NativeKeyBindingsForRichTextEditor).get();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace widget
|
||||
@ -258,6 +239,7 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
|
||||
static void
|
||||
nsWidgetCocoaModuleDtor()
|
||||
{
|
||||
mozilla::widget::NativeKeyBindings::Shutdown();
|
||||
nsLookAndFeel::Shutdown();
|
||||
nsToolkit::Shutdown();
|
||||
nsAppShellShutdown();
|
||||
|
@ -24,7 +24,7 @@
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::widget;
|
||||
|
||||
static nsINativeKeyBindings::DoCommandCallback gCurrentCallback;
|
||||
static nsIWidget::DoCommandCallback gCurrentCallback;
|
||||
static void *gCurrentCallbackData;
|
||||
static bool gHandled;
|
||||
|
||||
@ -198,14 +198,54 @@ select_all_cb(GtkWidget *w, gboolean select, gpointer user_data)
|
||||
gHandled = true;
|
||||
}
|
||||
|
||||
nsNativeKeyBindings*
|
||||
nsNativeKeyBindings::sInstanceForSingleLineEditor = nullptr;
|
||||
nsNativeKeyBindings*
|
||||
nsNativeKeyBindings::sInstanceForMultiLineEditor = nullptr;
|
||||
|
||||
// static
|
||||
already_AddRefed<nsNativeKeyBindings>
|
||||
nsNativeKeyBindings::GetInstance(NativeKeyBindingsType aType)
|
||||
{
|
||||
switch (aType) {
|
||||
case nsIWidget::NativeKeyBindingsForSingleLineEditor:
|
||||
if (!sInstanceForSingleLineEditor) {
|
||||
NS_ADDREF(sInstanceForSingleLineEditor = new nsNativeKeyBindings());
|
||||
sInstanceForSingleLineEditor->Init(aType);
|
||||
}
|
||||
NS_ADDREF(sInstanceForSingleLineEditor);
|
||||
return sInstanceForSingleLineEditor;
|
||||
|
||||
default:
|
||||
// fallback to multiline editor case in release build
|
||||
MOZ_ASSERT(false, "aType is invalid or not yet implemented");
|
||||
case nsIWidget::NativeKeyBindingsForMultiLineEditor:
|
||||
case nsIWidget::NativeKeyBindingsForRichTextEditor:
|
||||
if (!sInstanceForMultiLineEditor) {
|
||||
NS_ADDREF(sInstanceForMultiLineEditor = new nsNativeKeyBindings());
|
||||
sInstanceForMultiLineEditor->Init(aType);
|
||||
}
|
||||
NS_ADDREF(sInstanceForMultiLineEditor);
|
||||
return sInstanceForMultiLineEditor;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
nsNativeKeyBindings::Shutdown()
|
||||
{
|
||||
NS_IF_RELEASE(sInstanceForSingleLineEditor);
|
||||
NS_IF_RELEASE(sInstanceForMultiLineEditor);
|
||||
}
|
||||
|
||||
void
|
||||
nsNativeKeyBindings::Init(NativeKeyBindingsType aType)
|
||||
{
|
||||
switch (aType) {
|
||||
case eKeyBindings_Input:
|
||||
case nsIWidget::NativeKeyBindingsForSingleLineEditor:
|
||||
mNativeTarget = gtk_entry_new();
|
||||
break;
|
||||
case eKeyBindings_TextArea:
|
||||
default:
|
||||
mNativeTarget = gtk_text_view_new();
|
||||
if (gtk_major_version > 2 ||
|
||||
(gtk_major_version == 2 && (gtk_minor_version > 2 ||
|
||||
|
@ -16,11 +16,6 @@
|
||||
#include "mozilla/EventForwards.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
enum NativeKeyBindingsType {
|
||||
eKeyBindings_Input,
|
||||
eKeyBindings_TextArea
|
||||
};
|
||||
|
||||
#define NS_NATIVEKEYBINDINGSINPUT_CID \
|
||||
{0x5c337258, 0xa580, 0x472e, {0x86, 0x15, 0xf2, 0x77, 0xdd, 0xc5, 0xbb, 0x06}}
|
||||
|
||||
@ -32,7 +27,14 @@ enum NativeKeyBindingsType {
|
||||
|
||||
class nsNativeKeyBindings MOZ_FINAL : public nsINativeKeyBindings
|
||||
{
|
||||
typedef nsIWidget::NativeKeyBindingsType NativeKeyBindingsType;
|
||||
typedef nsIWidget::DoCommandCallback DoCommandCallback;
|
||||
|
||||
public:
|
||||
static already_AddRefed<nsNativeKeyBindings>
|
||||
GetInstance(NativeKeyBindingsType aType);
|
||||
static void Shutdown();
|
||||
|
||||
NS_HIDDEN_(void) Init(NativeKeyBindingsType aType);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
@ -51,6 +53,9 @@ private:
|
||||
guint aKeyval);
|
||||
|
||||
GtkWidget *mNativeTarget;
|
||||
|
||||
static nsNativeKeyBindings* sInstanceForSingleLineEditor;
|
||||
static nsNativeKeyBindings* sInstanceForMultiLineEditor;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -167,48 +167,22 @@ nsColorPickerConstructor(nsISupports *aOuter, REFNSIID aIID,
|
||||
return picker->QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
static nsresult
|
||||
nsNativeKeyBindingsConstructor(nsISupports *aOuter, REFNSIID aIID,
|
||||
void **aResult,
|
||||
NativeKeyBindingsType aKeyBindingsType)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsNativeKeyBindings *inst;
|
||||
|
||||
*aResult = nullptr;
|
||||
if (nullptr != aOuter) {
|
||||
rv = NS_ERROR_NO_AGGREGATION;
|
||||
return rv;
|
||||
}
|
||||
|
||||
inst = new nsNativeKeyBindings();
|
||||
if (nullptr == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
return rv;
|
||||
}
|
||||
NS_ADDREF(inst);
|
||||
inst->Init(aKeyBindingsType);
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
nsNativeKeyBindingsInputConstructor(nsISupports *aOuter, REFNSIID aIID,
|
||||
void **aResult)
|
||||
{
|
||||
return nsNativeKeyBindingsConstructor(aOuter, aIID, aResult,
|
||||
eKeyBindings_Input);
|
||||
*aResult = nsNativeKeyBindings::GetInstance(
|
||||
nsIWidget::NativeKeyBindingsForSingleLineEditor).get();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
nsNativeKeyBindingsTextAreaConstructor(nsISupports *aOuter, REFNSIID aIID,
|
||||
void **aResult)
|
||||
{
|
||||
return nsNativeKeyBindingsConstructor(aOuter, aIID, aResult,
|
||||
eKeyBindings_TextArea);
|
||||
*aResult = nsNativeKeyBindings::GetInstance(
|
||||
nsIWidget::NativeKeyBindingsForMultiLineEditor).get();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_DEFINE_NAMED_CID(NS_WINDOW_CID);
|
||||
@ -325,6 +299,7 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
|
||||
static void
|
||||
nsWidgetGtk2ModuleDtor()
|
||||
{
|
||||
nsNativeKeyBindings::Shutdown();
|
||||
nsLookAndFeel::Shutdown();
|
||||
nsFilePicker::Shutdown();
|
||||
nsSound::Shutdown();
|
||||
|
@ -119,6 +119,7 @@ extern "C" {
|
||||
|
||||
#include "nsIDOMWheelEvent.h"
|
||||
|
||||
#include "nsNativeKeyBindings.h"
|
||||
#include "nsWindow.h"
|
||||
|
||||
using namespace mozilla;
|
||||
@ -5973,6 +5974,17 @@ nsWindow::GetInputContext()
|
||||
return context;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
nsWindow::ExecuteNativeKeyBinding(NativeKeyBindingsType aType,
|
||||
const WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
void* aCallbackData)
|
||||
{
|
||||
nsRefPtr<nsNativeKeyBindings> keyBindings =
|
||||
nsNativeKeyBindings::GetInstance(aType);
|
||||
return keyBindings->KeyPress(aEvent, aCallback, aCallbackData);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWindow::GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState)
|
||||
{
|
||||
|
@ -267,6 +267,11 @@ public:
|
||||
NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
|
||||
const InputContextAction& aAction);
|
||||
NS_IMETHOD_(InputContext) GetInputContext();
|
||||
NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
|
||||
NativeKeyBindingsType aType,
|
||||
const mozilla::WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
void* aCallbackData) MOZ_OVERRIDE;
|
||||
NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState);
|
||||
|
||||
// These methods are for toplevel windows only.
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define nsINativeKeyBindings_h_
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "mozilla/EventForwards.h"
|
||||
|
||||
#define NS_INATIVEKEYBINDINGS_IID \
|
||||
@ -28,12 +29,10 @@ NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "editor"
|
||||
class nsINativeKeyBindings : public nsISupports
|
||||
{
|
||||
public:
|
||||
typedef void (*DoCommandCallback)(mozilla::Command, void*);
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INATIVEKEYBINDINGS_IID)
|
||||
|
||||
virtual NS_HIDDEN_(bool) KeyPress(const mozilla::WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
nsIWidget::DoCommandCallback aCallback,
|
||||
void *aCallbackData) = 0;
|
||||
};
|
||||
|
||||
|
@ -100,8 +100,8 @@ typedef void* nsNativeWidget;
|
||||
#endif
|
||||
|
||||
#define NS_IWIDGET_IID \
|
||||
{ 0xb979c607, 0xf0aa, 0x4fee, \
|
||||
{ 0xb2, 0x7b, 0xd4, 0x46, 0xa2, 0xe, 0x8b, 0x27 } }
|
||||
{ 0x5d94f2d, 0x5456, 0x4436, \
|
||||
{ 0xa7, 0x2f, 0x25, 0x6f, 0x47, 0xb0, 0xb5, 0x94 } }
|
||||
|
||||
/*
|
||||
* Window shadow styles
|
||||
@ -1832,6 +1832,22 @@ public:
|
||||
*/
|
||||
NS_IMETHOD_(InputContext) GetInputContext() = 0;
|
||||
|
||||
/*
|
||||
* Execute native key bindings for aType.
|
||||
*/
|
||||
typedef void (*DoCommandCallback)(mozilla::Command, void*);
|
||||
enum NativeKeyBindingsType
|
||||
{
|
||||
NativeKeyBindingsForSingleLineEditor,
|
||||
NativeKeyBindingsForMultiLineEditor,
|
||||
NativeKeyBindingsForRichTextEditor
|
||||
};
|
||||
NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
|
||||
NativeKeyBindingsType aType,
|
||||
const mozilla::WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
void* aCallbackData) = 0;
|
||||
|
||||
/**
|
||||
* Set layers acceleration to 'True' or 'False'
|
||||
*/
|
||||
|
@ -187,6 +187,11 @@ public:
|
||||
virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
|
||||
NativeKeyBindingsType aType,
|
||||
const mozilla::WidgetKeyboardEvent& aEvent,
|
||||
DoCommandCallback aCallback,
|
||||
void* aCallbackData) MOZ_OVERRIDE { return false; }
|
||||
NS_IMETHOD SetLayersAcceleration(bool aEnabled);
|
||||
virtual bool GetLayersAcceleration() { return mUseLayersAcceleration; }
|
||||
virtual bool ComputeShouldAccelerate(bool aDefault);
|
||||
|
Loading…
Reference in New Issue
Block a user