2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-23 23:54:25 -07:00
|
|
|
#ifndef nsDOMUIEvent_h
|
|
|
|
#define nsDOMUIEvent_h
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMUIEvent.h"
|
|
|
|
#include "nsDOMEvent.h"
|
2012-04-11 14:55:21 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-03-13 13:02:32 -07:00
|
|
|
#include "mozilla/dom/UIEventBinding.h"
|
2013-09-23 04:55:35 -07:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsDeviceContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-09-30 14:26:04 -07:00
|
|
|
class nsINode;
|
|
|
|
|
2009-10-21 02:38:39 -07:00
|
|
|
class nsDOMUIEvent : public nsDOMEvent,
|
2011-08-26 00:43:49 -07:00
|
|
|
public nsIDOMUIEvent
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-10 02:55:05 -07:00
|
|
|
typedef mozilla::CSSIntPoint CSSIntPoint;
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMUIEvent(mozilla::dom::EventTarget* aOwner,
|
2013-10-01 20:46:03 -07:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
mozilla::WidgetGUIEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMUIEvent, nsDOMEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMUIEvent Interface
|
|
|
|
NS_DECL_NSIDOMUIEVENT
|
|
|
|
|
|
|
|
// Forward to nsDOMEvent
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_FORWARD_TO_NSDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION
|
2013-05-29 13:43:41 -07: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-02 00:05:16 -07:00
|
|
|
static nsIntPoint
|
2013-10-01 20:46:04 -07:00
|
|
|
CalculateScreenPoint(nsPresContext* aPresContext,
|
|
|
|
mozilla::WidgetEvent* aEvent)
|
2012-04-11 14:55:21 -07:00
|
|
|
{
|
|
|
|
if (!aEvent ||
|
|
|
|
(aEvent->eventStructType != NS_MOUSE_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
|
2012-08-11 18:42:34 -07:00
|
|
|
aEvent->eventStructType != NS_WHEEL_EVENT &&
|
2012-04-11 14:55:21 -07:00
|
|
|
aEvent->eventStructType != NS_DRAG_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT)) {
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:55:20 -07:00
|
|
|
mozilla::WidgetGUIEvent* event = aEvent->AsGUIEvent();
|
2013-08-02 00:05:16 -07:00
|
|
|
if (!event->widget) {
|
|
|
|
return mozilla::LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint);
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:05:16 -07:00
|
|
|
mozilla::LayoutDeviceIntPoint offset = aEvent->refPoint +
|
|
|
|
mozilla::LayoutDeviceIntPoint::FromUntyped(event->widget->WidgetToScreenOffset());
|
2012-04-11 14:55:21 -07:00
|
|
|
nscoord factor = aPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
|
|
|
|
return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
|
|
|
|
}
|
|
|
|
|
2013-07-10 02:55:05 -07:00
|
|
|
static CSSIntPoint CalculateClientPoint(nsPresContext* aPresContext,
|
2013-10-01 20:46:04 -07:00
|
|
|
mozilla::WidgetEvent* aEvent,
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint* aDefaultClientPoint)
|
2012-04-11 14:55:21 -07:00
|
|
|
{
|
|
|
|
if (!aEvent ||
|
|
|
|
(aEvent->eventStructType != NS_MOUSE_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
|
2012-08-11 18:42:34 -07:00
|
|
|
aEvent->eventStructType != NS_WHEEL_EVENT &&
|
2012-04-11 14:55:21 -07:00
|
|
|
aEvent->eventStructType != NS_DRAG_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT) ||
|
|
|
|
!aPresContext ||
|
2013-10-22 01:55:20 -07:00
|
|
|
!aEvent->AsGUIEvent()->widget) {
|
2013-07-10 02:55:05 -07:00
|
|
|
return aDefaultClientPoint
|
|
|
|
? *aDefaultClientPoint
|
|
|
|
: CSSIntPoint(0, 0);
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
if (!shell) {
|
2013-07-10 02:55:05 -07:00
|
|
|
return CSSIntPoint(0, 0);
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
2013-07-10 02:55:05 -07:00
|
|
|
if (!rootFrame) {
|
|
|
|
return CSSIntPoint(0, 0);
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
2013-07-10 02:55:05 -07:00
|
|
|
nsPoint pt =
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, rootFrame);
|
2012-04-11 14:55:21 -07:00
|
|
|
|
2013-07-10 02:55:05 -07:00
|
|
|
return CSSIntPoint::FromAppUnitsRounded(pt);
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
|
2013-03-13 13:02:32 -07:00
|
|
|
static already_AddRefed<nsDOMUIEvent> Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const mozilla::dom::UIEventInit& aParam,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
|
2013-03-13 13:02:32 -07:00
|
|
|
{
|
|
|
|
return mozilla::dom::UIEventBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
|
|
|
|
2013-05-10 00:13:45 -07:00
|
|
|
nsIDOMWindow* GetView() const
|
2013-03-13 13:02:32 -07:00
|
|
|
{
|
2013-05-10 00:13:45 -07:00
|
|
|
return mView;
|
2013-03-13 13:02:32 -07:00
|
|
|
}
|
|
|
|
|
2013-05-10 00:13:45 -07:00
|
|
|
int32_t Detail() const
|
2013-03-13 13:02:32 -07:00
|
|
|
{
|
|
|
|
return mDetail;
|
|
|
|
}
|
|
|
|
|
2013-05-10 00:13:45 -07:00
|
|
|
int32_t LayerX() const
|
2013-03-13 13:02:32 -07:00
|
|
|
{
|
|
|
|
return GetLayerPoint().x;
|
|
|
|
}
|
|
|
|
|
2013-05-10 00:13:45 -07:00
|
|
|
int32_t LayerY() const
|
2013-03-13 13:02:32 -07:00
|
|
|
{
|
|
|
|
return GetLayerPoint().y;
|
|
|
|
}
|
|
|
|
|
2013-05-10 00:13:45 -07:00
|
|
|
int32_t PageX() const;
|
|
|
|
int32_t PageY() const;
|
2013-03-13 13:02:32 -07:00
|
|
|
|
2013-04-20 16:48:55 -07:00
|
|
|
virtual uint32_t Which()
|
2013-03-13 13:02:32 -07:00
|
|
|
{
|
2013-05-05 00:03:16 -07:00
|
|
|
MOZ_ASSERT(mEvent->eventStructType != NS_KEY_EVENT,
|
|
|
|
"Key events should override Which()");
|
|
|
|
MOZ_ASSERT(mEvent->eventStructType != NS_MOUSE_EVENT,
|
|
|
|
"Mouse events should override Which()");
|
|
|
|
return 0;
|
2013-03-13 13:02:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINode> GetRangeParent();
|
|
|
|
|
2013-05-10 00:13:45 -07:00
|
|
|
int32_t RangeOffset() const;
|
2013-03-13 13:02:32 -07:00
|
|
|
|
2013-05-10 00:13:45 -07:00
|
|
|
bool CancelBubble() const
|
2013-03-13 13:02:32 -07:00
|
|
|
{
|
|
|
|
return mEvent->mFlags.mPropagationStopped;
|
|
|
|
}
|
|
|
|
|
2013-05-10 00:13:45 -07:00
|
|
|
bool IsChar() const;
|
2013-03-13 13:02:32 -07:00
|
|
|
|
2011-08-26 00:43:49 -07:00
|
|
|
protected:
|
2007-03-22 10:30:00 -07:00
|
|
|
// Internal helper functions
|
2012-04-11 14:55:21 -07:00
|
|
|
nsIntPoint GetMovementPoint();
|
2013-05-10 00:13:45 -07:00
|
|
|
nsIntPoint GetLayerPoint() const;
|
2011-08-26 00:43:49 -07:00
|
|
|
|
2011-04-23 23:54:25 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> mView;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mDetail;
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint mClientPoint;
|
2007-11-12 04:53:06 -08:00
|
|
|
// Screenpoint is mEvent->refPoint.
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntPoint mLayerPoint;
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint mPagePoint;
|
2012-05-09 15:54:18 -07:00
|
|
|
nsIntPoint mMovementPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
bool mIsPointerLocked;
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint mLastClientPoint;
|
2012-04-24 20:00:01 -07:00
|
|
|
|
2013-09-13 19:39:41 -07:00
|
|
|
typedef mozilla::Modifiers Modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
static Modifiers ComputeModifierState(const nsAString& aModifiersList);
|
|
|
|
bool GetModifierStateInternal(const nsAString& aKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
#define NS_FORWARD_TO_NSDOMUIEVENT \
|
|
|
|
NS_FORWARD_NSIDOMUIEVENT(nsDOMUIEvent::) \
|
|
|
|
NS_FORWARD_TO_NSDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION \
|
|
|
|
NS_IMETHOD DuplicatePrivateData() \
|
|
|
|
{ \
|
|
|
|
return nsDOMUIEvent::DuplicatePrivateData(); \
|
|
|
|
} \
|
|
|
|
NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, \
|
|
|
|
bool aSerializeInterfaceType) \
|
|
|
|
{ \
|
|
|
|
nsDOMUIEvent::Serialize(aMsg, aSerializeInterfaceType); \
|
|
|
|
} \
|
|
|
|
NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, \
|
|
|
|
void** aIter) \
|
|
|
|
{ \
|
|
|
|
return nsDOMUIEvent::Deserialize(aMsg, aIter); \
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-23 23:54:25 -07:00
|
|
|
#endif // nsDOMUIEvent_h
|