summaryrefslogtreecommitdiffstats
path: root/widget/uikit/TextInputHandler.h
blob: 1f27bf11f0ca99917d4d81073b9d3afedbac34aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et tw=80: */
/* 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/. */

#ifndef TextInputHandler_h_
#define TextInputHandler_h_

#import <UIKit/UITextInput.h>

#include "mozilla/EventForwards.h"
#include "mozilla/TextEventDispatcherListener.h"
#include "mozilla/widget/IMEData.h"
#include "nsCOMPtr.h"

class nsWindow;

namespace mozilla::widget {
class TextEventDispatcher;

// This is the temporary input class. When implementing UITextInpt protocol, we
// should share this class with Cocoa's version.
class TextInputHandler final : public TextEventDispatcherListener {
 public:
  explicit TextInputHandler(nsWindow* aWidget);
  TextInputHandler() = delete;

  NS_DECL_ISUPPORTS

  NS_IMETHOD NotifyIME(TextEventDispatcher* aTextEventDispatcher,
                       const IMENotification& aNotification) override;
  NS_IMETHOD_(IMENotificationRequests) GetIMENotificationRequests() override;
  NS_IMETHOD_(void)
  OnRemovedFrom(TextEventDispatcher* aTextEventDispatcher) override;
  NS_IMETHOD_(void)
  WillDispatchKeyboardEvent(TextEventDispatcher* aTextEventDispatcher,
                            WidgetKeyboardEvent& aKeyboardEvent,
                            uint32_t aIndexOfKeypress, void* aData) override;

  // UIKeyInput delegation
  bool InsertText(NSString* aText);
  bool HandleCommand(Command aCommand);

  void OnDestroyed();

 private:
  virtual ~TextInputHandler() = default;

  bool DispatchKeyDownEvent(uint32_t aKeyCode, KeyNameIndex aKeyNameIndex,
                            char16_t aCharCode, nsEventStatus& aStatus);
  bool DispatchKeyUpEvent(uint32_t aKeyCode, KeyNameIndex aKeyNameIndex,
                          char16_t aCharCode, nsEventStatus& aStatus);
  bool DispatchKeyPressEvent(uint32_t aKeyCode, KeyNameIndex aKeyNameIndex,
                             char16_t aCharCode, nsEventStatus& aStatus);

  bool EmulateKeyboardEvent(uint32_t aKeyCode, KeyNameIndex aKeyNameIndex,
                            char16_t charCode);

  bool Destroyed() { return !mWidget; }

  nsWindow* mWidget;  // weak ref
  RefPtr<TextEventDispatcher> mDispatcher;
};

}  // namespace mozilla::widget
#endif