2011-09-22 09:17:40 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2011-09-22 09:17:40 +00:00
|
|
|
|
|
|
|
#include "nsDOMCompositionEvent.h"
|
2013-07-03 15:56:26 +00:00
|
|
|
#include "prtime.h"
|
2013-09-25 11:21:19 +00:00
|
|
|
#include "mozilla/TextEvents.h"
|
2011-09-22 09:17:40 +00:00
|
|
|
|
2013-03-09 11:34:29 +00:00
|
|
|
nsDOMCompositionEvent::nsDOMCompositionEvent(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-22 09:17:40 +00:00
|
|
|
nsCompositionEvent* aEvent)
|
2013-03-09 11:34:29 +00:00
|
|
|
: nsDOMUIEvent(aOwner, aPresContext, aEvent ? aEvent :
|
2012-07-30 14:20:58 +00:00
|
|
|
new nsCompositionEvent(false, 0, nullptr))
|
2011-09-22 09:17:40 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mEvent->eventStructType == NS_COMPOSITION_EVENT,
|
|
|
|
"event type mismatch");
|
|
|
|
|
|
|
|
if (aEvent) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = false;
|
2011-09-22 09:17:40 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
2011-09-22 09:17:40 +00:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
|
|
|
|
// XXX compositionstart is cancelable in draft of DOM3 Events.
|
|
|
|
// However, it doesn't make sence for us, we cannot cancel composition
|
|
|
|
// when we sends compositionstart event.
|
2012-12-16 01:26:03 +00:00
|
|
|
mEvent->mFlags.mCancelable = false;
|
2011-09-22 09:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mData = static_cast<nsCompositionEvent*>(mEvent)->data;
|
|
|
|
// TODO: Native event should have locale information.
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCompositionEvent::~nsDOMCompositionEvent()
|
|
|
|
{
|
|
|
|
if (mEventIsInternal) {
|
|
|
|
delete static_cast<nsCompositionEvent*>(mEvent);
|
2012-07-30 14:20:58 +00:00
|
|
|
mEvent = nullptr;
|
2011-09-22 09:17:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMCompositionEvent, nsDOMUIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMCompositionEvent, nsDOMUIEvent)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMCompositionEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCompositionEvent)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCompositionEvent::GetData(nsAString& aData)
|
|
|
|
{
|
|
|
|
aData = mData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCompositionEvent::GetLocale(nsAString& aLocale)
|
|
|
|
{
|
|
|
|
aLocale = mLocale;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCompositionEvent::InitCompositionEvent(const nsAString& aType,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2011-09-22 09:17:40 +00:00
|
|
|
nsIDOMWindow* aView,
|
|
|
|
const nsAString& aData,
|
|
|
|
const nsAString& aLocale)
|
|
|
|
{
|
|
|
|
nsresult rv =
|
|
|
|
nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mData = aData;
|
|
|
|
mLocale = aLocale;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 11:34:29 +00:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2011-09-22 09:17:40 +00:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsCompositionEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsDOMCompositionEvent* event =
|
2013-03-09 11:34:29 +00:00
|
|
|
new nsDOMCompositionEvent(aOwner, aPresContext, aEvent);
|
2011-09-22 09:17:40 +00:00
|
|
|
return CallQueryInterface(event, aInstancePtrResult);
|
|
|
|
}
|