2011-09-22 13:17:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 13:17:40 +04:00
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
#include "mozilla/dom/CompositionEvent.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2014-02-26 09:23:57 +04:00
|
|
|
#include "prtime.h"
|
2011-09-22 13:17:40 +04:00
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-10-01 11:23:00 +04:00
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
CompositionEvent::CompositionEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetCompositionEvent* aEvent)
|
2014-02-28 18:58:43 +04:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
2015-08-26 15:56:59 +03:00
|
|
|
aEvent ? aEvent :
|
2015-08-29 02:58:26 +03:00
|
|
|
new WidgetCompositionEvent(false, eVoidEvent, nullptr))
|
2011-09-22 13:17:40 +04:00
|
|
|
{
|
2014-08-04 09:28:48 +04:00
|
|
|
NS_ASSERTION(mEvent->mClass == eCompositionEventClass,
|
2011-09-22 13:17:40 +04:00
|
|
|
"event type mismatch");
|
|
|
|
|
|
|
|
if (aEvent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = false;
|
2011-09-22 13:17:40 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = true;
|
2016-03-28 07:29:42 +03:00
|
|
|
mEvent->mTime = PR_Now();
|
2011-09-22 13:17:40 +04:00
|
|
|
|
|
|
|
// 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 05:26:03 +04:00
|
|
|
mEvent->mFlags.mCancelable = false;
|
2011-09-22 13:17:40 +04:00
|
|
|
}
|
|
|
|
|
2014-10-07 14:01:46 +04:00
|
|
|
// XXX Do we really need to duplicate the data value?
|
|
|
|
mData = mEvent->AsCompositionEvent()->mData;
|
2011-09-22 13:17:40 +04:00
|
|
|
// TODO: Native event should have locale information.
|
|
|
|
}
|
|
|
|
|
2016-11-16 23:16:22 +03:00
|
|
|
// static
|
|
|
|
already_AddRefed<CompositionEvent>
|
|
|
|
CompositionEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const CompositionEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
RefPtr<CompositionEvent> e = new CompositionEvent(t, nullptr, nullptr);
|
|
|
|
bool trusted = e->Init(t);
|
|
|
|
e->InitCompositionEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
|
|
|
aParam.mView, aParam.mData, EmptyString());
|
|
|
|
e->mDetail = aParam.mDetail;
|
|
|
|
e->SetTrusted(trusted);
|
|
|
|
e->SetComposed(aParam.mComposed);
|
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2017-01-26 09:35:09 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(CompositionEvent, UIEvent,
|
|
|
|
mRanges)
|
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CompositionEvent, UIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CompositionEvent, UIEvent)
|
2011-09-22 13:17:40 +04:00
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CompositionEvent)
|
2014-02-28 18:58:43 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(UIEvent)
|
2011-09-22 13:17:40 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void
|
|
|
|
CompositionEvent::GetData(nsAString& aData) const
|
2011-09-22 13:17:40 +04:00
|
|
|
{
|
|
|
|
aData = mData;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void
|
|
|
|
CompositionEvent::GetLocale(nsAString& aLocale) const
|
2011-09-22 13:17:40 +04:00
|
|
|
{
|
|
|
|
aLocale = mLocale;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void
|
2014-02-26 09:23:57 +04:00
|
|
|
CompositionEvent::InitCompositionEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2017-11-07 01:52:14 +03:00
|
|
|
nsGlobalWindowInner* aView,
|
2014-02-26 09:23:57 +04:00
|
|
|
const nsAString& aData,
|
|
|
|
const nsAString& aLocale)
|
2011-09-22 13:17:40 +04:00
|
|
|
{
|
2016-10-30 22:30:06 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
|
2011-09-22 13:17:40 +04:00
|
|
|
mData = aData;
|
|
|
|
mLocale = aLocale;
|
|
|
|
}
|
|
|
|
|
2016-07-26 13:09:07 +03:00
|
|
|
void
|
|
|
|
CompositionEvent::GetRanges(TextClauseArray& aRanges)
|
|
|
|
{
|
|
|
|
// If the mRanges is not empty, we return the cached value.
|
|
|
|
if (!mRanges.IsEmpty()) {
|
|
|
|
aRanges = mRanges;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RefPtr<TextRangeArray> textRangeArray = mEvent->AsCompositionEvent()->mRanges;
|
|
|
|
if (!textRangeArray) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mOwner);
|
|
|
|
const TextRange* targetRange = textRangeArray->GetTargetClause();
|
|
|
|
for (size_t i = 0; i < textRangeArray->Length(); i++) {
|
|
|
|
const TextRange& range = textRangeArray->ElementAt(i);
|
|
|
|
mRanges.AppendElement(new TextClause(window, range, targetRange));
|
|
|
|
}
|
|
|
|
aRanges = mRanges;
|
|
|
|
}
|
|
|
|
|
2014-02-26 09:23:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<CompositionEvent>
|
|
|
|
NS_NewDOMCompositionEvent(EventTarget* aOwner,
|
2011-09-22 13:17:40 +04:00
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 11:23:00 +04:00
|
|
|
WidgetCompositionEvent* aEvent)
|
2011-09-22 13:17:40 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CompositionEvent> event =
|
2015-08-12 14:39:31 +03:00
|
|
|
new CompositionEvent(aOwner, aPresContext, aEvent);
|
|
|
|
return event.forget();
|
2011-09-22 13:17:40 +04:00
|
|
|
}
|