michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ 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/CompositionEvent.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: CompositionEvent::CompositionEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetCompositionEvent* aEvent) michael@0: : UIEvent(aOwner, aPresContext, michael@0: aEvent ? aEvent : new WidgetCompositionEvent(false, 0, nullptr)) michael@0: { michael@0: NS_ASSERTION(mEvent->eventStructType == NS_COMPOSITION_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: // XXX compositionstart is cancelable in draft of DOM3 Events. michael@0: // However, it doesn't make sence for us, we cannot cancel composition michael@0: // when we sends compositionstart event. michael@0: mEvent->mFlags.mCancelable = false; michael@0: } michael@0: michael@0: mData = mEvent->AsCompositionEvent()->data; michael@0: // TODO: Native event should have locale information. michael@0: } michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(CompositionEvent, UIEvent) michael@0: NS_IMPL_RELEASE_INHERITED(CompositionEvent, UIEvent) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(CompositionEvent) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMCompositionEvent) michael@0: NS_INTERFACE_MAP_END_INHERITING(UIEvent) michael@0: michael@0: NS_IMETHODIMP michael@0: CompositionEvent::GetData(nsAString& aData) michael@0: { michael@0: aData = mData; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: CompositionEvent::GetLocale(nsAString& aLocale) michael@0: { michael@0: aLocale = mLocale; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: CompositionEvent::InitCompositionEvent(const nsAString& aType, michael@0: bool aCanBubble, michael@0: bool aCancelable, michael@0: nsIDOMWindow* aView, michael@0: const nsAString& aData, michael@0: const nsAString& aLocale) michael@0: { michael@0: nsresult rv = UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: mData = aData; michael@0: mLocale = aLocale; michael@0: return NS_OK; 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_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult, michael@0: EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetCompositionEvent* aEvent) michael@0: { michael@0: CompositionEvent* event = new CompositionEvent(aOwner, aPresContext, aEvent); michael@0: return CallQueryInterface(event, aInstancePtrResult); michael@0: }