1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef TextInputHandler_h_
8 #define TextInputHandler_h_
10 #import <UIKit/UITextInput.h>
12 #include "mozilla/EventForwards.h"
13 #include "mozilla/TextEventDispatcherListener.h"
14 #include "mozilla/widget/IMEData.h"
19 namespace mozilla::widget
{
20 class TextEventDispatcher
;
22 // This is the temporary input class. When implementing UITextInpt protocol, we
23 // should share this class with Cocoa's version.
24 class TextInputHandler final
: public TextEventDispatcherListener
{
26 explicit TextInputHandler(nsWindow
* aWidget
);
27 TextInputHandler() = delete;
31 NS_IMETHOD
NotifyIME(TextEventDispatcher
* aTextEventDispatcher
,
32 const IMENotification
& aNotification
) override
;
33 NS_IMETHOD_(IMENotificationRequests
) GetIMENotificationRequests() override
;
35 OnRemovedFrom(TextEventDispatcher
* aTextEventDispatcher
) override
;
37 WillDispatchKeyboardEvent(TextEventDispatcher
* aTextEventDispatcher
,
38 WidgetKeyboardEvent
& aKeyboardEvent
,
39 uint32_t aIndexOfKeypress
, void* aData
) override
;
41 // UIKeyInput delegation
42 bool InsertText(NSString
* aText
);
43 bool HandleCommand(Command aCommand
);
48 virtual ~TextInputHandler() = default;
50 bool DispatchKeyDownEvent(uint32_t aKeyCode
, KeyNameIndex aKeyNameIndex
,
51 char16_t aCharCode
, nsEventStatus
& aStatus
);
52 bool DispatchKeyUpEvent(uint32_t aKeyCode
, KeyNameIndex aKeyNameIndex
,
53 char16_t aCharCode
, nsEventStatus
& aStatus
);
54 bool DispatchKeyPressEvent(uint32_t aKeyCode
, KeyNameIndex aKeyNameIndex
,
55 char16_t aCharCode
, nsEventStatus
& aStatus
);
57 bool EmulateKeyboardEvent(uint32_t aKeyCode
, KeyNameIndex aKeyNameIndex
,
60 bool Destroyed() { return !mWidget
; }
62 nsWindow
* mWidget
; // weak ref
63 RefPtr
<TextEventDispatcher
> mDispatcher
;
66 } // namespace mozilla::widget