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-02-27 14:51:13 +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/FocusEvent.h"
|
|
|
|
#include "mozilla/ContentEvents.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(FocusEvent, UIEvent, nsIDOMFocusEvent)
|
2014-02-27 14:51:13 +04:00
|
|
|
|
|
|
|
FocusEvent::FocusEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
InternalFocusEvent* aEvent)
|
2014-02-28 18:58:43 +04:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
2015-09-02 09:08:00 +03:00
|
|
|
aEvent ? aEvent : new InternalFocusEvent(false, eFocus))
|
2014-02-27 14:51:13 +04:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
|
|
|
mEventIsInternal = false;
|
|
|
|
} else {
|
|
|
|
mEventIsInternal = true;
|
2016-03-28 07:29:42 +03:00
|
|
|
mEvent->mTime = PR_Now();
|
2014-02-27 14:51:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FocusEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRelatedTarget);
|
2016-12-19 14:36:48 +03:00
|
|
|
*aRelatedTarget = GetRelatedTarget().take();
|
2014-02-27 14:51:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-19 14:36:48 +03:00
|
|
|
already_AddRefed<EventTarget>
|
2014-02-27 14:51:13 +04:00
|
|
|
FocusEvent::GetRelatedTarget()
|
|
|
|
{
|
2016-12-19 14:36:48 +03:00
|
|
|
return
|
|
|
|
EnsureWebAccessibleRelatedTarget(mEvent->AsFocusEvent()->mRelatedTarget);
|
2014-02-27 14:51:13 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void
|
2014-02-27 14:51:13 +04:00
|
|
|
FocusEvent::InitFocusEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow* aView,
|
2014-02-27 14:51:13 +04:00
|
|
|
int32_t aDetail,
|
|
|
|
EventTarget* aRelatedTarget)
|
|
|
|
{
|
2016-10-30 22:30:06 +03:00
|
|
|
MOZ_ASSERT(!mEvent->mFlags.mIsBeingDispatched);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
|
2016-03-27 08:46:48 +03:00
|
|
|
mEvent->AsFocusEvent()->mRelatedTarget = aRelatedTarget;
|
2014-02-27 14:51:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<FocusEvent>
|
|
|
|
FocusEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const FocusEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<FocusEvent> e = new FocusEvent(t, nullptr, nullptr);
|
2014-02-27 14:51:13 +04:00
|
|
|
bool trusted = e->Init(t);
|
2016-01-30 20:05:36 +03:00
|
|
|
e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
|
|
|
|
aParam.mDetail, aParam.mRelatedTarget);
|
2014-02-27 14:51:13 +04:00
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 06:16:11 +03:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2014-02-27 14:51:13 +04:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<FocusEvent>
|
|
|
|
NS_NewDOMFocusEvent(EventTarget* aOwner,
|
2014-02-27 14:51:13 +04:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
InternalFocusEvent* aEvent)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<FocusEvent> it = new FocusEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 14:39:31 +03:00
|
|
|
return it.forget();
|
2014-02-27 14:51:13 +04:00
|
|
|
}
|