2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-04-10 11:11: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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/InputEvent.h"
|
|
|
|
#include "mozilla/TextEvents.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2014-04-10 11:11:37 +04:00
|
|
|
|
|
|
|
InputEvent::InputEvent(EventTarget* aOwner, nsPresContext* aPresContext,
|
|
|
|
InternalEditorInputEvent* aEvent)
|
|
|
|
: UIEvent(aOwner, aPresContext,
|
2015-08-26 15:56:59 +03:00
|
|
|
aEvent
|
|
|
|
? aEvent
|
2015-08-29 02:58:26 +03:00
|
|
|
: new InternalEditorInputEvent(false, eVoidEvent, nullptr)) {
|
2014-08-04 09:28:49 +04:00
|
|
|
NS_ASSERTION(mEvent->mClass == eEditorInputEventClass, "event type mismatch");
|
2014-04-10 11:11:37 +04:00
|
|
|
|
|
|
|
if (aEvent) {
|
|
|
|
mEventIsInternal = false;
|
|
|
|
} else {
|
|
|
|
mEventIsInternal = true;
|
2016-03-28 07:29:42 +03:00
|
|
|
mEvent->mTime = PR_Now();
|
2014-04-10 11:11:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 19:08:11 +03:00
|
|
|
void InputEvent::GetData(nsAString& aData, CallerType aCallerType) {
|
2019-02-19 09:27:41 +03:00
|
|
|
InternalEditorInputEvent* editorInputEvent = mEvent->AsEditorInputEvent();
|
|
|
|
MOZ_ASSERT(editorInputEvent);
|
2019-03-29 19:08:11 +03:00
|
|
|
// If clipboard event is disabled, user may not want to leak clipboard
|
|
|
|
// information via DOM events. If so, we should return empty string instead.
|
|
|
|
if (mEvent->IsTrusted() && aCallerType != CallerType::System &&
|
|
|
|
!StaticPrefs::dom_event_clipboardevents_enabled() &&
|
|
|
|
ExposesClipboardDataOrDataTransfer(editorInputEvent->mInputType)) {
|
2020-09-23 18:17:15 +03:00
|
|
|
aData = editorInputEvent->mData.IsVoid() ? VoidString() : u""_ns;
|
2019-03-29 19:08:11 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-02-19 09:27:41 +03:00
|
|
|
aData = editorInputEvent->mData;
|
|
|
|
}
|
|
|
|
|
2019-03-29 19:08:11 +03:00
|
|
|
already_AddRefed<DataTransfer> InputEvent::GetDataTransfer(
|
|
|
|
CallerType aCallerType) {
|
2019-02-19 09:32:11 +03:00
|
|
|
InternalEditorInputEvent* editorInputEvent = mEvent->AsEditorInputEvent();
|
|
|
|
MOZ_ASSERT(editorInputEvent);
|
2019-03-29 19:08:11 +03:00
|
|
|
// If clipboard event is disabled, user may not want to leak clipboard
|
|
|
|
// information via DOM events. If so, we should return DataTransfer which
|
|
|
|
// has empty string instead. The reason why we make it have empty string is,
|
|
|
|
// web apps may not expect that InputEvent.dataTransfer returns empty and
|
|
|
|
// non-null DataTransfer instance.
|
|
|
|
if (mEvent->IsTrusted() && aCallerType != CallerType::System &&
|
|
|
|
!StaticPrefs::dom_event_clipboardevents_enabled() &&
|
|
|
|
ExposesClipboardDataOrDataTransfer(editorInputEvent->mInputType)) {
|
|
|
|
if (!editorInputEvent->mDataTransfer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return do_AddRef(
|
|
|
|
new DataTransfer(editorInputEvent->mDataTransfer->GetParentObject(),
|
2020-09-23 18:17:15 +03:00
|
|
|
editorInputEvent->mMessage, u""_ns));
|
2019-03-29 19:08:11 +03:00
|
|
|
}
|
|
|
|
return do_AddRef(editorInputEvent->mDataTransfer);
|
2019-02-19 09:32:11 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 13:10:57 +03:00
|
|
|
void InputEvent::GetInputType(nsAString& aInputType) {
|
|
|
|
InternalEditorInputEvent* editorInputEvent = mEvent->AsEditorInputEvent();
|
|
|
|
MOZ_ASSERT(editorInputEvent);
|
|
|
|
if (editorInputEvent->mInputType == EditorInputType::eUnknown) {
|
|
|
|
aInputType = mInputTypeValue;
|
|
|
|
} else {
|
|
|
|
editorInputEvent->GetDOMInputTypeName(aInputType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:39:38 +03:00
|
|
|
void InputEvent::GetTargetRanges(nsTArray<RefPtr<StaticRange>>& aTargetRanges) {
|
|
|
|
MOZ_ASSERT(aTargetRanges.IsEmpty());
|
|
|
|
MOZ_ASSERT(mEvent->AsEditorInputEvent());
|
|
|
|
aTargetRanges.AppendElements(mEvent->AsEditorInputEvent()->mTargetRanges);
|
|
|
|
}
|
|
|
|
|
2014-04-10 11:11:37 +04:00
|
|
|
bool InputEvent::IsComposing() {
|
|
|
|
return mEvent->AsEditorInputEvent()->mIsComposing;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<InputEvent> InputEvent::Constructor(
|
|
|
|
const GlobalObject& aGlobal, const nsAString& aType,
|
2019-09-11 17:35:28 +03:00
|
|
|
const InputEventInit& aParam) {
|
2014-04-10 11:11:37 +04:00
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<InputEvent> e = new InputEvent(t, nullptr, nullptr);
|
2014-04-10 11:11:37 +04:00
|
|
|
bool trusted = e->Init(t);
|
2018-03-26 21:53:02 +03:00
|
|
|
e->InitUIEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
|
2016-01-30 20:05:36 +03:00
|
|
|
aParam.mDetail);
|
2014-04-10 11:11:37 +04:00
|
|
|
InternalEditorInputEvent* internalEvent = e->mEvent->AsEditorInputEvent();
|
2019-01-07 13:10:57 +03:00
|
|
|
internalEvent->mInputType =
|
|
|
|
InternalEditorInputEvent::GetEditorInputType(aParam.mInputType);
|
|
|
|
if (internalEvent->mInputType == EditorInputType::eUnknown) {
|
|
|
|
e->mInputTypeValue = aParam.mInputType;
|
|
|
|
}
|
2019-02-19 09:27:41 +03:00
|
|
|
internalEvent->mData = aParam.mData;
|
2019-02-19 09:32:11 +03:00
|
|
|
internalEvent->mDataTransfer = aParam.mDataTransfer;
|
2020-03-02 10:39:38 +03:00
|
|
|
internalEvent->mTargetRanges = aParam.mTargetRanges;
|
2014-04-10 11:11:37 +04:00
|
|
|
internalEvent->mIsComposing = aParam.mIsComposing;
|
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 06:16:11 +03:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2014-04-10 11:11:37 +04:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|
2014-04-10 11:11:37 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<InputEvent> NS_NewDOMInputEvent(
|
2014-04-10 11:11:37 +04:00
|
|
|
EventTarget* aOwner, nsPresContext* aPresContext,
|
|
|
|
InternalEditorInputEvent* aEvent) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<InputEvent> it = new InputEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 14:39:31 +03:00
|
|
|
return it.forget();
|
2014-04-10 11:11:37 +04:00
|
|
|
}
|