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 : #include "mozilla/dom/InputEvent.h"
8 : #include "mozilla/TextEvents.h"
9 : #include "prtime.h"
10 :
11 : namespace mozilla {
12 : namespace dom {
13 :
14 0 : InputEvent::InputEvent(EventTarget* aOwner,
15 : nsPresContext* aPresContext,
16 0 : InternalEditorInputEvent* aEvent)
17 : : UIEvent(aOwner, aPresContext,
18 : aEvent ? aEvent :
19 0 : new InternalEditorInputEvent(false, eVoidEvent, nullptr))
20 : {
21 0 : NS_ASSERTION(mEvent->mClass == eEditorInputEventClass,
22 : "event type mismatch");
23 :
24 0 : if (aEvent) {
25 0 : mEventIsInternal = false;
26 : } else {
27 0 : mEventIsInternal = true;
28 0 : mEvent->mTime = PR_Now();
29 : }
30 0 : }
31 :
32 0 : NS_IMPL_ADDREF_INHERITED(InputEvent, UIEvent)
33 0 : NS_IMPL_RELEASE_INHERITED(InputEvent, UIEvent)
34 :
35 0 : NS_INTERFACE_MAP_BEGIN(InputEvent)
36 0 : NS_INTERFACE_MAP_END_INHERITING(UIEvent)
37 :
38 : bool
39 0 : InputEvent::IsComposing()
40 : {
41 0 : return mEvent->AsEditorInputEvent()->mIsComposing;
42 : }
43 :
44 : already_AddRefed<InputEvent>
45 0 : InputEvent::Constructor(const GlobalObject& aGlobal,
46 : const nsAString& aType,
47 : const InputEventInit& aParam,
48 : ErrorResult& aRv)
49 : {
50 0 : nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
51 0 : RefPtr<InputEvent> e = new InputEvent(t, nullptr, nullptr);
52 0 : bool trusted = e->Init(t);
53 0 : auto* view = aParam.mView ? aParam.mView->AsInner() : nullptr;
54 0 : e->InitUIEvent(aType, aParam.mBubbles, aParam.mCancelable, view,
55 0 : aParam.mDetail);
56 0 : InternalEditorInputEvent* internalEvent = e->mEvent->AsEditorInputEvent();
57 0 : internalEvent->mIsComposing = aParam.mIsComposing;
58 0 : e->SetTrusted(trusted);
59 0 : e->SetComposed(aParam.mComposed);
60 0 : return e.forget();
61 : }
62 :
63 : } // namespace dom
64 : } // namespace mozilla
65 :
66 : using namespace mozilla;
67 : using namespace mozilla::dom;
68 :
69 : already_AddRefed<InputEvent>
70 0 : NS_NewDOMInputEvent(EventTarget* aOwner,
71 : nsPresContext* aPresContext,
72 : InternalEditorInputEvent* aEvent)
73 : {
74 0 : RefPtr<InputEvent> it = new InputEvent(aOwner, aPresContext, aEvent);
75 0 : return it.forget();
76 : }
|