michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_UIEvent_h_ michael@0: #define mozilla_dom_UIEvent_h_ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/dom/Event.h" michael@0: #include "mozilla/dom/UIEventBinding.h" michael@0: #include "nsDeviceContext.h" michael@0: #include "nsIDOMUIEvent.h" michael@0: #include "nsLayoutUtils.h" michael@0: #include "nsPresContext.h" michael@0: michael@0: class nsINode; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class UIEvent : public Event, michael@0: public nsIDOMUIEvent michael@0: { michael@0: public: michael@0: UIEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetGUIEvent* aEvent); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UIEvent, Event) michael@0: michael@0: // nsIDOMUIEvent Interface michael@0: NS_DECL_NSIDOMUIEVENT michael@0: michael@0: // Forward to Event michael@0: NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION michael@0: NS_IMETHOD DuplicatePrivateData() MOZ_OVERRIDE; michael@0: NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) MOZ_OVERRIDE; michael@0: NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, void** aIter) MOZ_OVERRIDE; michael@0: michael@0: static nsIntPoint CalculateScreenPoint(nsPresContext* aPresContext, michael@0: WidgetEvent* aEvent) michael@0: { michael@0: if (!aEvent || michael@0: (aEvent->eventStructType != NS_MOUSE_EVENT && michael@0: aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT && michael@0: aEvent->eventStructType != NS_WHEEL_EVENT && michael@0: aEvent->eventStructType != NS_DRAG_EVENT && michael@0: aEvent->eventStructType != NS_POINTER_EVENT && michael@0: aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT)) { michael@0: return nsIntPoint(0, 0); michael@0: } michael@0: michael@0: WidgetGUIEvent* event = aEvent->AsGUIEvent(); michael@0: if (!event->widget) { michael@0: return LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint); michael@0: } michael@0: michael@0: LayoutDeviceIntPoint offset = aEvent->refPoint + michael@0: LayoutDeviceIntPoint::FromUntyped(event->widget->WidgetToScreenOffset()); michael@0: nscoord factor = michael@0: aPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel(); michael@0: return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor), michael@0: nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor)); michael@0: } michael@0: michael@0: static CSSIntPoint CalculateClientPoint(nsPresContext* aPresContext, michael@0: WidgetEvent* aEvent, michael@0: CSSIntPoint* aDefaultClientPoint) michael@0: { michael@0: if (!aEvent || michael@0: (aEvent->eventStructType != NS_MOUSE_EVENT && michael@0: aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT && michael@0: aEvent->eventStructType != NS_WHEEL_EVENT && michael@0: aEvent->eventStructType != NS_DRAG_EVENT && michael@0: aEvent->eventStructType != NS_POINTER_EVENT && michael@0: aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT) || michael@0: !aPresContext || michael@0: !aEvent->AsGUIEvent()->widget) { michael@0: return aDefaultClientPoint michael@0: ? *aDefaultClientPoint michael@0: : CSSIntPoint(0, 0); michael@0: } michael@0: michael@0: nsIPresShell* shell = aPresContext->GetPresShell(); michael@0: if (!shell) { michael@0: return CSSIntPoint(0, 0); michael@0: } michael@0: nsIFrame* rootFrame = shell->GetRootFrame(); michael@0: if (!rootFrame) { michael@0: return CSSIntPoint(0, 0); michael@0: } michael@0: nsPoint pt = michael@0: nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, rootFrame); michael@0: michael@0: return CSSIntPoint::FromAppUnitsRounded(pt); michael@0: } michael@0: michael@0: static already_AddRefed Constructor(const GlobalObject& aGlobal, michael@0: const nsAString& aType, michael@0: const UIEventInit& aParam, michael@0: ErrorResult& aRv); michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE michael@0: { michael@0: return UIEventBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: nsIDOMWindow* GetView() const michael@0: { michael@0: return mView; michael@0: } michael@0: michael@0: int32_t Detail() const michael@0: { michael@0: return mDetail; michael@0: } michael@0: michael@0: int32_t LayerX() const michael@0: { michael@0: return GetLayerPoint().x; michael@0: } michael@0: michael@0: int32_t LayerY() const michael@0: { michael@0: return GetLayerPoint().y; michael@0: } michael@0: michael@0: int32_t PageX() const; michael@0: int32_t PageY() const; michael@0: michael@0: virtual uint32_t Which() michael@0: { michael@0: MOZ_ASSERT(mEvent->eventStructType != NS_KEY_EVENT, michael@0: "Key events should override Which()"); michael@0: MOZ_ASSERT(mEvent->eventStructType != NS_MOUSE_EVENT, michael@0: "Mouse events should override Which()"); michael@0: return 0; michael@0: } michael@0: michael@0: already_AddRefed GetRangeParent(); michael@0: michael@0: int32_t RangeOffset() const; michael@0: michael@0: bool CancelBubble() const michael@0: { michael@0: return mEvent->mFlags.mPropagationStopped; michael@0: } michael@0: michael@0: bool IsChar() const; michael@0: michael@0: protected: michael@0: // Internal helper functions michael@0: nsIntPoint GetMovementPoint(); michael@0: nsIntPoint GetLayerPoint() const; michael@0: michael@0: nsCOMPtr mView; michael@0: int32_t mDetail; michael@0: CSSIntPoint mClientPoint; michael@0: // Screenpoint is mEvent->refPoint. michael@0: nsIntPoint mLayerPoint; michael@0: CSSIntPoint mPagePoint; michael@0: nsIntPoint mMovementPoint; michael@0: bool mIsPointerLocked; michael@0: CSSIntPoint mLastClientPoint; michael@0: michael@0: static Modifiers ComputeModifierState(const nsAString& aModifiersList); michael@0: bool GetModifierStateInternal(const nsAString& aKey); michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #define NS_FORWARD_TO_UIEVENT \ michael@0: NS_FORWARD_NSIDOMUIEVENT(UIEvent::) \ michael@0: NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \ michael@0: NS_IMETHOD DuplicatePrivateData() \ michael@0: { \ michael@0: return UIEvent::DuplicatePrivateData(); \ michael@0: } \ michael@0: NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, \ michael@0: bool aSerializeInterfaceType) \ michael@0: { \ michael@0: UIEvent::Serialize(aMsg, aSerializeInterfaceType); \ michael@0: } \ michael@0: NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, \ michael@0: void** aIter) \ michael@0: { \ michael@0: return UIEvent::Deserialize(aMsg, aIter); \ michael@0: } michael@0: michael@0: #endif // mozilla_dom_UIEvent_h_