2004-08-20 22:09:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +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/. */
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
#ifndef mozilla_dom_UIEvent_h_
|
|
|
|
#define mozilla_dom_UIEvent_h_
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h"
|
|
|
|
#include "mozilla/dom/UIEventBinding.h"
|
|
|
|
#include "nsDeviceContext.h"
|
2004-08-20 22:09:19 +04:00
|
|
|
#include "nsIDOMUIEvent.h"
|
2012-04-12 01:55:21 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-09-23 15:55:35 +04:00
|
|
|
#include "nsPresContext.h"
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2013-10-01 01:26:04 +04:00
|
|
|
class nsINode;
|
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
class UIEvent : public Event,
|
2014-02-28 18:58:43 +04:00
|
|
|
public nsIDOMUIEvent
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-02-28 18:58:43 +04:00
|
|
|
UIEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent);
|
2004-08-20 22:09:19 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UIEvent, Event)
|
2004-08-20 22:09:19 +04:00
|
|
|
|
|
|
|
// nsIDOMUIEvent Interface
|
|
|
|
NS_DECL_NSIDOMUIEVENT
|
2014-02-28 18:58:43 +04:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
// Forward to Event
|
|
|
|
NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION
|
2013-05-30 00:43:41 +04:00
|
|
|
NS_IMETHOD DuplicatePrivateData() MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, void** aIter) MOZ_OVERRIDE;
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2015-02-15 21:52:28 +03:00
|
|
|
static LayoutDeviceIntPoint CalculateScreenPoint(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2012-04-12 01:55:21 +04:00
|
|
|
{
|
|
|
|
if (!aEvent ||
|
2014-08-04 09:28:50 +04:00
|
|
|
(aEvent->mClass != eMouseEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
aEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
aEvent->mClass != eWheelEventClass &&
|
2014-08-04 09:28:50 +04:00
|
|
|
aEvent->mClass != eDragEventClass &&
|
2014-08-04 09:28:52 +04:00
|
|
|
aEvent->mClass != ePointerEventClass &&
|
2014-08-04 09:28:53 +04:00
|
|
|
aEvent->mClass != eSimpleGestureEventClass)) {
|
2015-02-15 21:52:28 +03:00
|
|
|
return LayoutDeviceIntPoint(0, 0);
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
WidgetGUIEvent* event = aEvent->AsGUIEvent();
|
2013-08-02 11:05:16 +04:00
|
|
|
if (!event->widget) {
|
2015-02-15 21:52:28 +03:00
|
|
|
return aEvent->refPoint;
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
LayoutDeviceIntPoint offset = aEvent->refPoint + event->widget->WidgetToScreenOffset();
|
2014-02-28 18:58:43 +04:00
|
|
|
nscoord factor =
|
2014-11-13 14:53:02 +03:00
|
|
|
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
|
2015-02-15 21:52:28 +03:00
|
|
|
return LayoutDeviceIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
|
|
|
|
2013-07-10 13:55:05 +04:00
|
|
|
static CSSIntPoint CalculateClientPoint(nsPresContext* aPresContext,
|
2014-02-28 18:58:43 +04:00
|
|
|
WidgetEvent* aEvent,
|
2013-07-10 13:55:05 +04:00
|
|
|
CSSIntPoint* aDefaultClientPoint)
|
2012-04-12 01:55:21 +04:00
|
|
|
{
|
|
|
|
if (!aEvent ||
|
2014-08-04 09:28:50 +04:00
|
|
|
(aEvent->mClass != eMouseEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
aEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
aEvent->mClass != eWheelEventClass &&
|
2014-08-04 09:28:50 +04:00
|
|
|
aEvent->mClass != eDragEventClass &&
|
2014-08-04 09:28:52 +04:00
|
|
|
aEvent->mClass != ePointerEventClass &&
|
2014-08-04 09:28:53 +04:00
|
|
|
aEvent->mClass != eSimpleGestureEventClass) ||
|
2012-04-12 01:55:21 +04:00
|
|
|
!aPresContext ||
|
2013-10-22 12:55:20 +04:00
|
|
|
!aEvent->AsGUIEvent()->widget) {
|
2013-07-10 13:55:05 +04:00
|
|
|
return aDefaultClientPoint
|
|
|
|
? *aDefaultClientPoint
|
|
|
|
: CSSIntPoint(0, 0);
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
if (!shell) {
|
2013-07-10 13:55:05 +04:00
|
|
|
return CSSIntPoint(0, 0);
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
2013-07-10 13:55:05 +04:00
|
|
|
if (!rootFrame) {
|
|
|
|
return CSSIntPoint(0, 0);
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
2013-07-10 13:55:05 +04:00
|
|
|
nsPoint pt =
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, rootFrame);
|
2012-04-12 01:55:21 +04:00
|
|
|
|
2013-07-10 13:55:05 +04:00
|
|
|
return CSSIntPoint::FromAppUnitsRounded(pt);
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
static already_AddRefed<UIEvent> Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const UIEventInit& aParam,
|
|
|
|
ErrorResult& aRv);
|
2013-03-14 00:02:32 +04:00
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) MOZ_OVERRIDE
|
2013-03-14 00:02:32 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return UIEventBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-14 00:02:32 +04:00
|
|
|
}
|
|
|
|
|
2013-05-10 11:13:45 +04:00
|
|
|
nsIDOMWindow* GetView() const
|
2013-03-14 00:02:32 +04:00
|
|
|
{
|
2013-05-10 11:13:45 +04:00
|
|
|
return mView;
|
2013-03-14 00:02:32 +04:00
|
|
|
}
|
|
|
|
|
2013-05-10 11:13:45 +04:00
|
|
|
int32_t Detail() const
|
2013-03-14 00:02:32 +04:00
|
|
|
{
|
|
|
|
return mDetail;
|
|
|
|
}
|
|
|
|
|
2013-05-10 11:13:45 +04:00
|
|
|
int32_t LayerX() const
|
2013-03-14 00:02:32 +04:00
|
|
|
{
|
|
|
|
return GetLayerPoint().x;
|
|
|
|
}
|
|
|
|
|
2013-05-10 11:13:45 +04:00
|
|
|
int32_t LayerY() const
|
2013-03-14 00:02:32 +04:00
|
|
|
{
|
|
|
|
return GetLayerPoint().y;
|
|
|
|
}
|
|
|
|
|
2013-05-10 11:13:45 +04:00
|
|
|
int32_t PageX() const;
|
|
|
|
int32_t PageY() const;
|
2013-03-14 00:02:32 +04:00
|
|
|
|
2013-04-21 03:48:55 +04:00
|
|
|
virtual uint32_t Which()
|
2013-03-14 00:02:32 +04:00
|
|
|
{
|
2014-08-04 09:28:48 +04:00
|
|
|
MOZ_ASSERT(mEvent->mClass != eKeyboardEventClass,
|
2013-05-05 11:03:16 +04:00
|
|
|
"Key events should override Which()");
|
2014-08-04 09:28:50 +04:00
|
|
|
MOZ_ASSERT(mEvent->mClass != eMouseEventClass,
|
2013-05-05 11:03:16 +04:00
|
|
|
"Mouse events should override Which()");
|
|
|
|
return 0;
|
2013-03-14 00:02:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINode> GetRangeParent();
|
|
|
|
|
2013-05-10 11:13:45 +04:00
|
|
|
int32_t RangeOffset() const;
|
2013-03-14 00:02:32 +04:00
|
|
|
|
2013-05-10 11:13:45 +04:00
|
|
|
bool CancelBubble() const
|
2013-03-14 00:02:32 +04:00
|
|
|
{
|
|
|
|
return mEvent->mFlags.mPropagationStopped;
|
|
|
|
}
|
|
|
|
|
2013-05-10 11:13:45 +04:00
|
|
|
bool IsChar() const;
|
2013-03-14 00:02:32 +04:00
|
|
|
|
2011-08-26 11:43:49 +04:00
|
|
|
protected:
|
2014-07-09 01:23:17 +04:00
|
|
|
~UIEvent() {}
|
|
|
|
|
2004-08-20 22:09:19 +04:00
|
|
|
// Internal helper functions
|
2012-04-12 01:55:21 +04:00
|
|
|
nsIntPoint GetMovementPoint();
|
2013-05-10 11:13:45 +04:00
|
|
|
nsIntPoint GetLayerPoint() const;
|
2011-08-26 11:43:49 +04:00
|
|
|
|
2011-04-24 10:54:25 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> mView;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mDetail;
|
2013-07-10 13:55:05 +04:00
|
|
|
CSSIntPoint mClientPoint;
|
2007-11-12 15:53:06 +03:00
|
|
|
// Screenpoint is mEvent->refPoint.
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntPoint mLayerPoint;
|
2013-07-10 13:55:05 +04:00
|
|
|
CSSIntPoint mPagePoint;
|
2012-05-10 02:54:18 +04:00
|
|
|
nsIntPoint mMovementPoint;
|
2012-04-12 01:55:21 +04:00
|
|
|
bool mIsPointerLocked;
|
2013-07-10 13:55:05 +04:00
|
|
|
CSSIntPoint mLastClientPoint;
|
2012-04-25 07:00:01 +04:00
|
|
|
|
|
|
|
static Modifiers ComputeModifierState(const nsAString& aModifiersList);
|
|
|
|
bool GetModifierStateInternal(const nsAString& aKey);
|
2004-08-20 22:09:19 +04:00
|
|
|
};
|
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#define NS_FORWARD_TO_UIEVENT \
|
|
|
|
NS_FORWARD_NSIDOMUIEVENT(UIEvent::) \
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \
|
2015-01-07 03:53:23 +03:00
|
|
|
NS_IMETHOD DuplicatePrivateData() MOZ_OVERRIDE \
|
2012-06-11 03:44:50 +04:00
|
|
|
{ \
|
2014-02-28 18:58:43 +04:00
|
|
|
return UIEvent::DuplicatePrivateData(); \
|
2012-06-11 03:44:50 +04:00
|
|
|
} \
|
|
|
|
NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, \
|
|
|
|
bool aSerializeInterfaceType) \
|
2015-01-07 03:53:23 +03:00
|
|
|
MOZ_OVERRIDE \
|
2012-06-11 03:44:50 +04:00
|
|
|
{ \
|
2014-02-28 18:58:43 +04:00
|
|
|
UIEvent::Serialize(aMsg, aSerializeInterfaceType); \
|
2012-06-11 03:44:50 +04:00
|
|
|
} \
|
|
|
|
NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, \
|
2015-01-07 03:53:23 +03:00
|
|
|
void** aIter) MOZ_OVERRIDE \
|
2012-06-11 03:44:50 +04:00
|
|
|
{ \
|
2014-02-28 18:58:43 +04:00
|
|
|
return UIEvent::Deserialize(aMsg, aIter); \
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
#endif // mozilla_dom_UIEvent_h_
|