michael@0: /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/FocusEvent.h" michael@0: #include "mozilla/ContentEvents.h" michael@0: #include "prtime.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: NS_IMPL_ISUPPORTS_INHERITED(FocusEvent, UIEvent, nsIDOMFocusEvent) michael@0: michael@0: FocusEvent::FocusEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: InternalFocusEvent* aEvent) michael@0: : UIEvent(aOwner, aPresContext, michael@0: aEvent ? aEvent : new InternalFocusEvent(false, NS_FOCUS_CONTENT)) michael@0: { michael@0: if (aEvent) { michael@0: mEventIsInternal = false; michael@0: } else { michael@0: mEventIsInternal = true; michael@0: mEvent->time = PR_Now(); michael@0: } michael@0: } michael@0: michael@0: /* readonly attribute nsIDOMEventTarget relatedTarget; */ michael@0: NS_IMETHODIMP michael@0: FocusEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aRelatedTarget); michael@0: NS_IF_ADDREF(*aRelatedTarget = GetRelatedTarget()); michael@0: return NS_OK; michael@0: } michael@0: michael@0: EventTarget* michael@0: FocusEvent::GetRelatedTarget() michael@0: { michael@0: return mEvent->AsFocusEvent()->relatedTarget; michael@0: } michael@0: michael@0: nsresult michael@0: FocusEvent::InitFocusEvent(const nsAString& aType, michael@0: bool aCanBubble, michael@0: bool aCancelable, michael@0: nsIDOMWindow* aView, michael@0: int32_t aDetail, michael@0: EventTarget* aRelatedTarget) michael@0: { michael@0: nsresult rv = michael@0: UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: mEvent->AsFocusEvent()->relatedTarget = aRelatedTarget; michael@0: return NS_OK; michael@0: } michael@0: michael@0: already_AddRefed michael@0: FocusEvent::Constructor(const GlobalObject& aGlobal, michael@0: const nsAString& aType, michael@0: const FocusEventInit& aParam, michael@0: ErrorResult& aRv) michael@0: { michael@0: nsCOMPtr t = do_QueryInterface(aGlobal.GetAsSupports()); michael@0: nsRefPtr e = new FocusEvent(t, nullptr, nullptr); michael@0: bool trusted = e->Init(t); michael@0: aRv = e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView, michael@0: aParam.mDetail, aParam.mRelatedTarget); michael@0: e->SetTrusted(trusted); michael@0: return e.forget(); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::dom; michael@0: michael@0: nsresult michael@0: NS_NewDOMFocusEvent(nsIDOMEvent** aInstancePtrResult, michael@0: EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: InternalFocusEvent* aEvent) michael@0: { michael@0: FocusEvent* it = new FocusEvent(aOwner, aPresContext, aEvent); michael@0: NS_ADDREF(it); michael@0: *aInstancePtrResult = static_cast(it); michael@0: return NS_OK; michael@0: }