dom/events/FocusEvent.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/FocusEvent.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "mozilla/dom/FocusEvent.h"
    1.10 +#include "mozilla/ContentEvents.h"
    1.11 +#include "prtime.h"
    1.12 +
    1.13 +namespace mozilla {
    1.14 +namespace dom {
    1.15 +
    1.16 +NS_IMPL_ISUPPORTS_INHERITED(FocusEvent, UIEvent, nsIDOMFocusEvent)
    1.17 +
    1.18 +FocusEvent::FocusEvent(EventTarget* aOwner,
    1.19 +                       nsPresContext* aPresContext,
    1.20 +                       InternalFocusEvent* aEvent)
    1.21 +  : UIEvent(aOwner, aPresContext,
    1.22 +            aEvent ? aEvent : new InternalFocusEvent(false, NS_FOCUS_CONTENT))
    1.23 +{
    1.24 +  if (aEvent) {
    1.25 +    mEventIsInternal = false;
    1.26 +  } else {
    1.27 +    mEventIsInternal = true;
    1.28 +    mEvent->time = PR_Now();
    1.29 +  }
    1.30 +}
    1.31 +
    1.32 +/* readonly attribute nsIDOMEventTarget relatedTarget; */
    1.33 +NS_IMETHODIMP
    1.34 +FocusEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)
    1.35 +{
    1.36 +  NS_ENSURE_ARG_POINTER(aRelatedTarget);
    1.37 +  NS_IF_ADDREF(*aRelatedTarget = GetRelatedTarget());
    1.38 +  return NS_OK;
    1.39 +}
    1.40 +
    1.41 +EventTarget*
    1.42 +FocusEvent::GetRelatedTarget()
    1.43 +{
    1.44 +  return mEvent->AsFocusEvent()->relatedTarget;
    1.45 +}
    1.46 +
    1.47 +nsresult
    1.48 +FocusEvent::InitFocusEvent(const nsAString& aType,
    1.49 +                           bool aCanBubble,
    1.50 +                           bool aCancelable,
    1.51 +                           nsIDOMWindow* aView,
    1.52 +                           int32_t aDetail,
    1.53 +                           EventTarget* aRelatedTarget)
    1.54 +{
    1.55 +  nsresult rv =
    1.56 +    UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
    1.57 +  NS_ENSURE_SUCCESS(rv, rv);
    1.58 +  mEvent->AsFocusEvent()->relatedTarget = aRelatedTarget;
    1.59 +  return NS_OK;
    1.60 +}
    1.61 +
    1.62 +already_AddRefed<FocusEvent>
    1.63 +FocusEvent::Constructor(const GlobalObject& aGlobal,
    1.64 +                        const nsAString& aType,
    1.65 +                        const FocusEventInit& aParam,
    1.66 +                        ErrorResult& aRv)
    1.67 +{
    1.68 +  nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
    1.69 +  nsRefPtr<FocusEvent> e = new FocusEvent(t, nullptr, nullptr);
    1.70 +  bool trusted = e->Init(t);
    1.71 +  aRv = e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
    1.72 +                          aParam.mDetail, aParam.mRelatedTarget);
    1.73 +  e->SetTrusted(trusted);
    1.74 +  return e.forget();
    1.75 +}
    1.76 +
    1.77 +} // namespace dom
    1.78 +} // namespace mozilla
    1.79 +
    1.80 +using namespace mozilla;
    1.81 +using namespace mozilla::dom;
    1.82 +
    1.83 +nsresult
    1.84 +NS_NewDOMFocusEvent(nsIDOMEvent** aInstancePtrResult,
    1.85 +                    EventTarget* aOwner,
    1.86 +                    nsPresContext* aPresContext,
    1.87 +                    InternalFocusEvent* aEvent)
    1.88 +{
    1.89 +  FocusEvent* it = new FocusEvent(aOwner, aPresContext, aEvent);
    1.90 +  NS_ADDREF(it);
    1.91 +  *aInstancePtrResult = static_cast<Event*>(it);
    1.92 +  return NS_OK;
    1.93 +}

mercurial