Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 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/. */
6 :
7 : #ifndef mozilla_dom_KeyboardEvent_h_
8 : #define mozilla_dom_KeyboardEvent_h_
9 :
10 : #include "mozilla/dom/UIEvent.h"
11 : #include "mozilla/dom/KeyboardEventBinding.h"
12 : #include "mozilla/EventForwards.h"
13 : #include "nsIDOMKeyEvent.h"
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 : class KeyboardEvent : public UIEvent,
19 : public nsIDOMKeyEvent
20 : {
21 : public:
22 : KeyboardEvent(EventTarget* aOwner,
23 : nsPresContext* aPresContext,
24 : WidgetKeyboardEvent* aEvent);
25 :
26 : NS_DECL_ISUPPORTS_INHERITED
27 :
28 : // nsIDOMKeyEvent Interface
29 : NS_DECL_NSIDOMKEYEVENT
30 :
31 : // Forward to base class
32 0 : NS_FORWARD_TO_UIEVENT
33 :
34 : static already_AddRefed<KeyboardEvent> Constructor(
35 : const GlobalObject& aGlobal,
36 : const nsAString& aType,
37 : const KeyboardEventInit& aParam,
38 : ErrorResult& aRv);
39 :
40 0 : virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
41 : {
42 0 : return KeyboardEventBinding::Wrap(aCx, this, aGivenProto);
43 : }
44 :
45 : bool AltKey();
46 : bool CtrlKey();
47 : bool ShiftKey();
48 : bool MetaKey();
49 :
50 0 : bool GetModifierState(const nsAString& aKey)
51 : {
52 0 : return GetModifierStateInternal(aKey);
53 : }
54 :
55 : bool Repeat();
56 : bool IsComposing();
57 : uint32_t CharCode();
58 : uint32_t KeyCode();
59 : virtual uint32_t Which() override;
60 : uint32_t Location();
61 :
62 : void GetCode(nsAString& aCode);
63 : void GetInitDict(KeyboardEventInit& aParam);
64 :
65 0 : void InitKeyEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
66 : nsGlobalWindow* aView, bool aCtrlKey, bool aAltKey,
67 : bool aShiftKey, bool aMetaKey,
68 : uint32_t aKeyCode, uint32_t aCharCode)
69 : {
70 0 : auto* view = aView ? aView->AsInner() : nullptr;
71 0 : InitKeyEvent(aType, aCanBubble, aCancelable, view, aCtrlKey, aAltKey,
72 0 : aShiftKey, aMetaKey, aKeyCode, aCharCode);
73 0 : }
74 :
75 : protected:
76 0 : ~KeyboardEvent() {}
77 :
78 : void InitWithKeyboardEventInit(EventTarget* aOwner,
79 : const nsAString& aType,
80 : const KeyboardEventInit& aParam,
81 : ErrorResult& aRv);
82 :
83 : private:
84 : // True, if the instance is created with Constructor().
85 : bool mInitializedByCtor;
86 :
87 : // If the instance is created with Constructor(), which may have independent
88 : // value. mInitializedWhichValue stores it. I.e., this is invalid when
89 : // mInitializedByCtor is false.
90 : uint32_t mInitializedWhichValue;
91 : };
92 :
93 : } // namespace dom
94 : } // namespace mozilla
95 :
96 : already_AddRefed<mozilla::dom::KeyboardEvent>
97 : NS_NewDOMKeyboardEvent(mozilla::dom::EventTarget* aOwner,
98 : nsPresContext* aPresContext,
99 : mozilla::WidgetKeyboardEvent* aEvent);
100 :
101 : #endif // mozilla_dom_KeyboardEvent_h_
|