зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1031051: Part 17 - Manually implement CustomEvent. r=smaug
CustomEvent can't be generated because we still need the XPCOM interface which is used by a11y among others.
This commit is contained in:
Родитель
0f7b974094
Коммит
21d8fc32e7
|
@ -143,7 +143,7 @@
|
||||||
#include "nsIDOMXULControlElement.h"
|
#include "nsIDOMXULControlElement.h"
|
||||||
#include "nsMenuPopupFrame.h"
|
#include "nsMenuPopupFrame.h"
|
||||||
#endif
|
#endif
|
||||||
#include "nsIDOMCustomEvent.h"
|
#include "mozilla/dom/CustomEvent.h"
|
||||||
#include "nsIFrameRequestCallback.h"
|
#include "nsIFrameRequestCallback.h"
|
||||||
#include "nsIJARChannel.h"
|
#include "nsIJARChannel.h"
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,11 @@
|
||||||
#include "mozilla/EventDispatcher.h"
|
#include "mozilla/EventDispatcher.h"
|
||||||
#include "mozilla/dom/HTMLIFrameElement.h"
|
#include "mozilla/dom/HTMLIFrameElement.h"
|
||||||
#include "mozilla/dom/ToJSValue.h"
|
#include "mozilla/dom/ToJSValue.h"
|
||||||
#include "nsIDOMCustomEvent.h"
|
|
||||||
#include "nsIInterfaceRequestorUtils.h"
|
#include "nsIInterfaceRequestorUtils.h"
|
||||||
#include "nsVariant.h"
|
#include "nsVariant.h"
|
||||||
#include "mozilla/dom/BrowserElementDictionariesBinding.h"
|
#include "mozilla/dom/BrowserElementDictionariesBinding.h"
|
||||||
#include "nsCxPusher.h"
|
#include "nsCxPusher.h"
|
||||||
#include "GeneratedEventClasses.h"
|
#include "mozilla/dom/CustomEvent.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
/* 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 "CustomEvent.h"
|
||||||
|
#include "mozilla/dom/CustomEventBinding.h"
|
||||||
|
|
||||||
|
#include "mozilla/dom/BindingUtils.h"
|
||||||
|
#include "nsContentUtils.h"
|
||||||
|
#include "nsIXPConnect.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
using namespace mozilla::dom;
|
||||||
|
|
||||||
|
CustomEvent::CustomEvent(mozilla::dom::EventTarget* aOwner,
|
||||||
|
nsPresContext* aPresContext,
|
||||||
|
mozilla::WidgetEvent* aEvent)
|
||||||
|
: Event(aOwner, aPresContext, aEvent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomEvent::~CustomEvent() {}
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CustomEvent)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CustomEvent, Event)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDetail)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CustomEvent, Event)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDetail)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF_INHERITED(CustomEvent, Event)
|
||||||
|
NS_IMPL_RELEASE_INHERITED(CustomEvent, Event)
|
||||||
|
|
||||||
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CustomEvent)
|
||||||
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCustomEvent)
|
||||||
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
||||||
|
|
||||||
|
already_AddRefed<CustomEvent>
|
||||||
|
CustomEvent::Constructor(const GlobalObject& aGlobal,
|
||||||
|
const nsAString& aType,
|
||||||
|
const CustomEventInit& aParam,
|
||||||
|
ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
||||||
|
nsRefPtr<CustomEvent> e = new CustomEvent(t, nullptr, nullptr);
|
||||||
|
bool trusted = e->Init(t);
|
||||||
|
JS::Rooted<JS::Value> detail(aGlobal.Context(), aParam.mDetail);
|
||||||
|
e->InitCustomEvent(aGlobal.Context(), aType, aParam.mBubbles, aParam.mCancelable, detail, aRv);
|
||||||
|
e->SetTrusted(trusted);
|
||||||
|
return e.forget();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSObject*
|
||||||
|
CustomEvent::WrapObject(JSContext* aCx)
|
||||||
|
{
|
||||||
|
return mozilla::dom::CustomEventBinding::Wrap(aCx, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CustomEvent::InitCustomEvent(const nsAString& aType,
|
||||||
|
bool aCanBubble,
|
||||||
|
bool aCancelable,
|
||||||
|
nsIVariant* aDetail)
|
||||||
|
{
|
||||||
|
nsresult rv = Event::InitEvent(aType, aCanBubble, aCancelable);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
mDetail = aDetail;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CustomEvent::InitCustomEvent(JSContext* aCx,
|
||||||
|
const nsAString& aType,
|
||||||
|
bool aCanBubble,
|
||||||
|
bool aCancelable,
|
||||||
|
JS::Handle<JS::Value> aDetail,
|
||||||
|
ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIVariant> detail;
|
||||||
|
if (nsIXPConnect* xpc = nsContentUtils::XPConnect()) {
|
||||||
|
xpc->JSToVariant(aCx, aDetail, getter_AddRefs(detail));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!detail) {
|
||||||
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
aRv = InitCustomEvent(aType, aCanBubble, aCancelable, detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
CustomEvent::GetDetail(nsIVariant** aDetail)
|
||||||
|
{
|
||||||
|
NS_IF_ADDREF(*aDetail = mDetail);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CustomEvent::GetDetail(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JS::Value> aRetval)
|
||||||
|
{
|
||||||
|
VariantToJsval(aCx, mDetail, aRetval);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
NS_NewDOMCustomEvent(nsIDOMEvent** aInstancePtrResult,
|
||||||
|
mozilla::dom::EventTarget* aOwner,
|
||||||
|
nsPresContext* aPresContext,
|
||||||
|
mozilla::WidgetEvent* aEvent)
|
||||||
|
{
|
||||||
|
CustomEvent* it = new CustomEvent(aOwner, aPresContext, aEvent);
|
||||||
|
NS_ADDREF(it);
|
||||||
|
*aInstancePtrResult = static_cast<Event*>(it);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* 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 CustomEvent_h__
|
||||||
|
#define CustomEvent_h__
|
||||||
|
|
||||||
|
#include "mozilla/dom/Event.h"
|
||||||
|
#include "nsIDOMCustomEvent.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
struct CustomEventInit;
|
||||||
|
|
||||||
|
class CustomEvent MOZ_FINAL : public Event,
|
||||||
|
public nsIDOMCustomEvent
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
virtual ~CustomEvent();
|
||||||
|
|
||||||
|
nsCOMPtr<nsIVariant> mDetail;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CustomEvent(mozilla::dom::EventTarget* aOwner,
|
||||||
|
nsPresContext* aPresContext = nullptr,
|
||||||
|
mozilla::WidgetEvent* aEvent = nullptr);
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CustomEvent, Event)
|
||||||
|
NS_FORWARD_TO_EVENT
|
||||||
|
NS_DECL_NSIDOMCUSTOMEVENT
|
||||||
|
|
||||||
|
static already_AddRefed<CustomEvent>
|
||||||
|
Constructor(const GlobalObject& aGlobal,
|
||||||
|
const nsAString& aType,
|
||||||
|
const CustomEventInit& aParam,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
virtual JSObject*
|
||||||
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
||||||
|
|
||||||
|
void
|
||||||
|
GetDetail(JSContext* aCx,
|
||||||
|
JS::MutableHandle<JS::Value> aRetval);
|
||||||
|
|
||||||
|
void
|
||||||
|
InitCustomEvent(JSContext* aCx,
|
||||||
|
const nsAString& aType,
|
||||||
|
bool aCanBubble,
|
||||||
|
bool aCancelable,
|
||||||
|
JS::Handle<JS::Value> aDetail,
|
||||||
|
ErrorResult& aRv);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dom
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif // CustomEvent_h__
|
|
@ -36,6 +36,7 @@ EXPORTS.mozilla.dom += [
|
||||||
'ClipboardEvent.h',
|
'ClipboardEvent.h',
|
||||||
'CommandEvent.h',
|
'CommandEvent.h',
|
||||||
'CompositionEvent.h',
|
'CompositionEvent.h',
|
||||||
|
'CustomEvent.h',
|
||||||
'DataContainerEvent.h',
|
'DataContainerEvent.h',
|
||||||
'DataTransfer.h',
|
'DataTransfer.h',
|
||||||
'DeviceMotionEvent.h',
|
'DeviceMotionEvent.h',
|
||||||
|
@ -112,6 +113,7 @@ UNIFIED_SOURCES += [
|
||||||
|
|
||||||
# nsEventStateManager.cpp should be built separately because of Mac OS X headers.
|
# nsEventStateManager.cpp should be built separately because of Mac OS X headers.
|
||||||
SOURCES += [
|
SOURCES += [
|
||||||
|
'CustomEvent.cpp',
|
||||||
'EventStateManager.cpp',
|
'EventStateManager.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -365,4 +365,9 @@ NS_NewDOMTouchEvent(nsIDOMEvent** aInstancePtrResult,
|
||||||
mozilla::dom::EventTarget* aOwner,
|
mozilla::dom::EventTarget* aOwner,
|
||||||
nsPresContext* aPresContext,
|
nsPresContext* aPresContext,
|
||||||
mozilla::WidgetTouchEvent* aEvent);
|
mozilla::WidgetTouchEvent* aEvent);
|
||||||
|
nsresult
|
||||||
|
NS_NewDOMCustomEvent(nsIDOMEvent** aInstancePtrResult,
|
||||||
|
mozilla::dom::EventTarget* aOwner,
|
||||||
|
nsPresContext* aPresContext,
|
||||||
|
mozilla::WidgetEvent* aEvent);
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -10,10 +10,9 @@
|
||||||
* liability, trademark and document use rules apply.
|
* liability, trademark and document use rules apply.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[Constructor(DOMString type, optional CustomEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
|
[Constructor(DOMString type, optional CustomEventInit eventInitDict)]
|
||||||
interface CustomEvent : Event
|
interface CustomEvent : Event
|
||||||
{
|
{
|
||||||
[Throws]
|
|
||||||
readonly attribute any detail;
|
readonly attribute any detail;
|
||||||
|
|
||||||
// initCustomEvent is a Gecko specific deprecated method.
|
// initCustomEvent is a Gecko specific deprecated method.
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
<name>Init dictionary for the event constructor. """
|
<name>Init dictionary for the event constructor. """
|
||||||
|
|
||||||
simple_events = [
|
simple_events = [
|
||||||
'CustomEvent',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
""" include file names """
|
""" include file names """
|
||||||
|
|
Загрузка…
Ссылка в новой задаче