michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/InputEvent.h" michael@0: #include "mozilla/TextEvents.h" michael@0: #include "prtime.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: InputEvent::InputEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: InternalEditorInputEvent* aEvent) michael@0: : UIEvent(aOwner, aPresContext, michael@0: aEvent ? aEvent : new InternalEditorInputEvent(false, 0, nullptr)) michael@0: { michael@0: NS_ASSERTION(mEvent->eventStructType == NS_EDITOR_INPUT_EVENT, michael@0: "event type mismatch"); michael@0: michael@0: if (aEvent) { michael@0: mEventIsInternal = false; michael@0: } else { michael@0: mEventIsInternal = true; michael@0: mEvent->time = PR_Now(); michael@0: } michael@0: } michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(InputEvent, UIEvent) michael@0: NS_IMPL_RELEASE_INHERITED(InputEvent, UIEvent) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(InputEvent) michael@0: NS_INTERFACE_MAP_END_INHERITING(UIEvent) michael@0: michael@0: bool michael@0: InputEvent::IsComposing() michael@0: { michael@0: return mEvent->AsEditorInputEvent()->mIsComposing; michael@0: } michael@0: michael@0: already_AddRefed michael@0: InputEvent::Constructor(const GlobalObject& aGlobal, michael@0: const nsAString& aType, michael@0: const InputEventInit& aParam, michael@0: ErrorResult& aRv) michael@0: { michael@0: nsCOMPtr t = do_QueryInterface(aGlobal.GetAsSupports()); michael@0: nsRefPtr e = new InputEvent(t, nullptr, nullptr); michael@0: bool trusted = e->Init(t); michael@0: aRv = e->InitUIEvent(aType, aParam.mBubbles, aParam.mCancelable, michael@0: aParam.mView, aParam.mDetail); michael@0: InternalEditorInputEvent* internalEvent = e->mEvent->AsEditorInputEvent(); michael@0: internalEvent->mIsComposing = aParam.mIsComposing; michael@0: e->SetTrusted(trusted); michael@0: return e.forget(); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::dom; michael@0: michael@0: nsresult michael@0: NS_NewDOMInputEvent(nsIDOMEvent** aInstancePtrResult, michael@0: EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: InternalEditorInputEvent* aEvent) michael@0: { michael@0: InputEvent* it = new InputEvent(aOwner, aPresContext, aEvent); michael@0: NS_ADDREF(it); michael@0: *aInstancePtrResult = static_cast(it); michael@0: return NS_OK; michael@0: }