2011-09-22 02:17:40 -07: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 04:12:37 -07: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 02:17:40 -07:00
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
#include "mozilla/dom/CompositionEvent.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2014-02-25 21:23:57 -08:00
|
|
|
#include "prtime.h"
|
2011-09-22 02:17:40 -07:00
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-10-01 00:23:00 -07:00
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
CompositionEvent::CompositionEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetCompositionEvent* aEvent)
|
2014-02-28 06:58:43 -08:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
|
|
|
aEvent ? aEvent : new WidgetCompositionEvent(false, 0, nullptr))
|
2011-09-22 02:17:40 -07:00
|
|
|
{
|
2014-08-03 22:28:48 -07:00
|
|
|
NS_ASSERTION(mEvent->mClass == eCompositionEventClass,
|
2011-09-22 02:17:40 -07:00
|
|
|
"event type mismatch");
|
|
|
|
|
|
|
|
if (aEvent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = false;
|
2011-09-22 02:17:40 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
2011-09-22 02:17:40 -07: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-15 17:26:03 -08:00
|
|
|
mEvent->mFlags.mCancelable = false;
|
2011-09-22 02:17:40 -07:00
|
|
|
}
|
|
|
|
|
2013-10-17 23:10:25 -07:00
|
|
|
mData = mEvent->AsCompositionEvent()->data;
|
2011-09-22 02:17:40 -07:00
|
|
|
// TODO: Native event should have locale information.
|
|
|
|
}
|
|
|
|
|
2014-02-28 06:58:43 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CompositionEvent, UIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CompositionEvent, UIEvent)
|
2011-09-22 02:17:40 -07:00
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN(CompositionEvent)
|
2011-09-22 02:17:40 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCompositionEvent)
|
2014-02-28 06:58:43 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(UIEvent)
|
2011-09-22 02:17:40 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:57 -08:00
|
|
|
CompositionEvent::GetData(nsAString& aData)
|
2011-09-22 02:17:40 -07:00
|
|
|
{
|
|
|
|
aData = mData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:57 -08:00
|
|
|
CompositionEvent::GetLocale(nsAString& aLocale)
|
2011-09-22 02:17:40 -07:00
|
|
|
{
|
|
|
|
aLocale = mLocale;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:57 -08:00
|
|
|
CompositionEvent::InitCompositionEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
nsIDOMWindow* aView,
|
|
|
|
const nsAString& aData,
|
|
|
|
const nsAString& aLocale)
|
2011-09-22 02:17:40 -07:00
|
|
|
{
|
2014-02-28 06:58:43 -08:00
|
|
|
nsresult rv = UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
|
2011-09-22 02:17:40 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mData = aData;
|
|
|
|
mLocale = aLocale;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:23:57 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2011-09-22 02:17:40 -07:00
|
|
|
nsresult
|
|
|
|
NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult,
|
2014-02-25 21:23:57 -08:00
|
|
|
EventTarget* aOwner,
|
2011-09-22 02:17:40 -07:00
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent* aEvent)
|
2011-09-22 02:17:40 -07:00
|
|
|
{
|
2014-02-25 21:23:57 -08:00
|
|
|
CompositionEvent* event = new CompositionEvent(aOwner, aPresContext, aEvent);
|
2011-09-22 02:17:40 -07:00
|
|
|
return CallQueryInterface(event, aInstancePtrResult);
|
|
|
|
}
|