Bug 855741 - Update Focus webidl from Event to FocusEvent. r=smaug

This commit is contained in:
Alfredo Yang 2013-06-05 08:02:51 -04:00
Родитель bb9e1b8d60
Коммит 5b1f01f4d8
12 изменённых файлов: 210 добавлений и 16 удалений

Просмотреть файл

@ -38,6 +38,7 @@ CPP_SOURCES += [
'nsDOMDragEvent.cpp',
'nsDOMEvent.cpp',
'nsDOMEventTargetHelper.cpp',
'nsDOMFocusEvent.cpp',
'nsDOMKeyboardEvent.cpp',
'nsDOMMessageEvent.cpp',
'nsDOMMouseEvent.cpp',

Просмотреть файл

@ -161,6 +161,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMEvent)
case NS_MUTATION_EVENT:
static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode = nullptr;
break;
case NS_FOCUS_EVENT:
static_cast<nsFocusEvent*>(tmp->mEvent)->relatedTarget = nullptr;
break;
default:
break;
}
@ -203,6 +206,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent)
cb.NoteXPCOMChild(
static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode);
break;
case NS_FOCUS_EVENT:
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
cb.NoteXPCOMChild(
static_cast<nsFocusEvent*>(tmp->mEvent)->relatedTarget);
break;
default:
break;
}

Просмотреть файл

@ -0,0 +1,87 @@
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
/* 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 "nsDOMFocusEvent.h"
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS_INHERITED1(nsDOMFocusEvent, nsDOMUIEvent, nsIDOMFocusEvent)
nsDOMFocusEvent::nsDOMFocusEvent(mozilla::dom::EventTarget* aOwner,
nsPresContext* aPresContext, nsFocusEvent* aEvent)
: nsDOMUIEvent(aOwner, aPresContext, aEvent ?
static_cast<nsGUIEvent*>(aEvent) :
static_cast<nsGUIEvent*>(new nsFocusEvent(false, NS_FOCUS_CONTENT)))
{
if (aEvent) {
mEventIsInternal = false;
} else {
mEventIsInternal = true;
mEvent->time = PR_Now();
}
SetIsDOMBinding();
}
nsDOMFocusEvent::~nsDOMFocusEvent()
{
if (mEventIsInternal && mEvent) {
delete static_cast<nsFocusEvent*>(mEvent);
mEvent = nullptr;
}
}
/* readonly attribute nsIDOMEventTarget relatedTarget; */
NS_IMETHODIMP
nsDOMFocusEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)
{
NS_ENSURE_ARG_POINTER(aRelatedTarget);
NS_IF_ADDREF(*aRelatedTarget = GetRelatedTarget());
return NS_OK;
}
mozilla::dom::EventTarget*
nsDOMFocusEvent::GetRelatedTarget()
{
return static_cast<nsFocusEvent*>(mEvent)->relatedTarget;
}
nsresult
nsDOMFocusEvent::InitFocusEvent(const nsAString& aType,
bool aCanBubble,
bool aCancelable,
nsIDOMWindow* aView,
int32_t aDetail,
mozilla::dom::EventTarget* aRelatedTarget)
{
nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
NS_ENSURE_SUCCESS(rv, rv);
static_cast<nsFocusEvent*>(mEvent)->relatedTarget = aRelatedTarget;
return NS_OK;
}
already_AddRefed<nsDOMFocusEvent>
nsDOMFocusEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal,
const nsAString& aType,
const mozilla::dom::FocusEventInit& aParam,
mozilla::ErrorResult& aRv)
{
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.Get());
nsRefPtr<nsDOMFocusEvent> e = new nsDOMFocusEvent(t, nullptr, nullptr);
bool trusted = e->Init(t);
aRv = e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
aParam.mDetail, aParam.mRelatedTarget);
e->SetTrusted(trusted);
return e.forget();
}
nsresult NS_NewDOMFocusEvent(nsIDOMEvent** aInstancePtrResult,
mozilla::dom::EventTarget* aOwner,
nsPresContext* aPresContext,
nsFocusEvent* aEvent)
{
nsDOMFocusEvent* it = new nsDOMFocusEvent(aOwner, aPresContext, aEvent);
return CallQueryInterface(it, aInstancePtrResult);
}

Просмотреть файл

@ -0,0 +1,47 @@
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
/* 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/. */
#ifndef nsDOMFocusEvent_h_
#define nsDOMFocusEvent_h_
#include "nsDOMUIEvent.h"
#include "nsIDOMFocusEvent.h"
#include "mozilla/dom/FocusEventBinding.h"
class nsDOMFocusEvent : public nsDOMUIEvent,
public nsIDOMFocusEvent
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMFOCUSEVENT
// Forward to base class
NS_FORWARD_TO_NSDOMUIEVENT
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
{
return mozilla::dom::FocusEventBinding::Wrap(aCx, aScope, this);
}
nsDOMFocusEvent(mozilla::dom::EventTarget* aOwner,
nsPresContext* aPresContext, nsFocusEvent* aEvent);
mozilla::dom::EventTarget* GetRelatedTarget();
static already_AddRefed<nsDOMFocusEvent> Constructor(const mozilla::dom::GlobalObject& aGlobal,
const nsAString& aType,
const mozilla::dom::FocusEventInit& aParam,
mozilla::ErrorResult& aRv);
protected:
nsresult InitFocusEvent(const nsAString& aType,
bool aCanBubble,
bool aCancelable,
nsIDOMWindow* aView,
int32_t aDetail,
mozilla::dom::EventTarget* aRelatedTarget);
~nsDOMFocusEvent();
};
#endif /* !defined(nsDOMFocusEvent_h_) */

Просмотреть файл

@ -730,6 +730,9 @@ nsEventDispatcher::CreateEvent(mozilla::dom::EventTarget* aOwner,
case NS_MOUSE_EVENT:
return NS_NewDOMMouseEvent(aDOMEvent, aOwner, aPresContext,
static_cast<nsInputEvent*>(aEvent));
case NS_FOCUS_EVENT:
return NS_NewDOMFocusEvent(aDOMEvent, aOwner, aPresContext,
static_cast<nsFocusEvent*>(aEvent));
case NS_MOUSE_SCROLL_EVENT:
return NS_NewDOMMouseScrollEvent(aDOMEvent, aOwner, aPresContext,
static_cast<nsInputEvent*>(aEvent));

Просмотреть файл

@ -390,6 +390,10 @@ DOMInterfaces = {
'nativeType': 'JSObject'
}],
'FocusEvent': {
'nativeType': 'nsDOMFocusEvent',
},
'GainNode': {
'resultNotAddRefed': [ 'gain' ],
},

Просмотреть файл

@ -25,6 +25,7 @@ XPIDL_SOURCES += [
'nsIDOMEvent.idl',
'nsIDOMEventListener.idl',
'nsIDOMEventTarget.idl',
'nsIDOMFocusEvent.idl',
'nsIDOMGamepadAxisMoveEvent.idl',
'nsIDOMGamepadButtonEvent.idl',
'nsIDOMGamepadEvent.idl',

Просмотреть файл

@ -280,6 +280,11 @@ NS_NewDOMMouseEvent(nsIDOMEvent** aInstancePtrResult,
nsPresContext* aPresContext,
class nsInputEvent* aEvent);
nsresult
NS_NewDOMFocusEvent(nsIDOMEvent** aInstancePtrResult,
mozilla::dom::EventTarget* aOwner,
nsPresContext* aPresContext,
class nsFocusEvent* aEvent);
nsresult
NS_NewDOMMouseScrollEvent(nsIDOMEvent** aInstancePtrResult,
mozilla::dom::EventTarget* aOwner,
nsPresContext* aPresContext,

Просмотреть файл

@ -0,0 +1,12 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "nsIDOMUIEvent.idl"
[scriptable, builtinclass, uuid(4faecbd6-1bcd-42d8-bc66-ec6b95050063)]
interface nsIDOMFocusEvent : nsIDOMUIEvent
{
readonly attribute nsIDOMEventTarget relatedTarget;
};

Просмотреть файл

@ -0,0 +1,21 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* For more information on this interface please see
* http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
[Constructor(DOMString typeArg, optional FocusEventInit focusEventInitDict)]
interface FocusEvent : UIEvent {
// Introduced in DOM Level 3:
readonly attribute EventTarget? relatedTarget;
};
dictionary FocusEventInit : UIEventInit {
EventTarget? relatedTarget = null;
};

Просмотреть файл

@ -82,6 +82,7 @@ webidl_files = \
FileReader.webidl \
FileReaderSync.webidl \
FileRequest.webidl \
FocusEvent.webidl \
FormData.webidl \
Function.webidl \
GainNode.webidl \

Просмотреть файл

@ -1552,20 +1552,6 @@ public:
};
};
class nsFocusEvent : public nsEvent
{
public:
nsFocusEvent(bool isTrusted, uint32_t msg)
: nsEvent(isTrusted, msg, NS_FOCUS_EVENT),
fromRaise(false),
isRefocus(false)
{
}
bool fromRaise;
bool isRefocus;
};
class nsSelectionEvent : public nsGUIEvent
{
private:
@ -1718,11 +1704,11 @@ public:
/**
* DOM UIEvent
*/
class nsUIEvent : public nsEvent
class nsUIEvent : public nsGUIEvent
{
public:
nsUIEvent(bool isTrusted, uint32_t msg, int32_t d)
: nsEvent(isTrusted, msg, NS_UI_EVENT),
: nsGUIEvent(isTrusted, msg, nullptr, NS_UI_EVENT),
detail(d)
{
}
@ -1730,6 +1716,24 @@ public:
int32_t detail;
};
class nsFocusEvent : public nsUIEvent
{
public:
nsFocusEvent(bool isTrusted, uint32_t msg)
: nsUIEvent(isTrusted, msg, 0),
fromRaise(false),
isRefocus(false)
{
eventStructType = NS_FOCUS_EVENT;
}
/// The possible related target
nsCOMPtr<mozilla::dom::EventTarget> relatedTarget;
bool fromRaise;
bool isRefocus;
};
/**
* Simple gesture event
*/