1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/UIEvent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,193 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_dom_UIEvent_h_ 1.10 +#define mozilla_dom_UIEvent_h_ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "mozilla/dom/Event.h" 1.14 +#include "mozilla/dom/UIEventBinding.h" 1.15 +#include "nsDeviceContext.h" 1.16 +#include "nsIDOMUIEvent.h" 1.17 +#include "nsLayoutUtils.h" 1.18 +#include "nsPresContext.h" 1.19 + 1.20 +class nsINode; 1.21 + 1.22 +namespace mozilla { 1.23 +namespace dom { 1.24 + 1.25 +class UIEvent : public Event, 1.26 + public nsIDOMUIEvent 1.27 +{ 1.28 +public: 1.29 + UIEvent(EventTarget* aOwner, 1.30 + nsPresContext* aPresContext, 1.31 + WidgetGUIEvent* aEvent); 1.32 + 1.33 + NS_DECL_ISUPPORTS_INHERITED 1.34 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UIEvent, Event) 1.35 + 1.36 + // nsIDOMUIEvent Interface 1.37 + NS_DECL_NSIDOMUIEVENT 1.38 + 1.39 + // Forward to Event 1.40 + NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION 1.41 + NS_IMETHOD DuplicatePrivateData() MOZ_OVERRIDE; 1.42 + NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) MOZ_OVERRIDE; 1.43 + NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, void** aIter) MOZ_OVERRIDE; 1.44 + 1.45 + static nsIntPoint CalculateScreenPoint(nsPresContext* aPresContext, 1.46 + WidgetEvent* aEvent) 1.47 + { 1.48 + if (!aEvent || 1.49 + (aEvent->eventStructType != NS_MOUSE_EVENT && 1.50 + aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT && 1.51 + aEvent->eventStructType != NS_WHEEL_EVENT && 1.52 + aEvent->eventStructType != NS_DRAG_EVENT && 1.53 + aEvent->eventStructType != NS_POINTER_EVENT && 1.54 + aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT)) { 1.55 + return nsIntPoint(0, 0); 1.56 + } 1.57 + 1.58 + WidgetGUIEvent* event = aEvent->AsGUIEvent(); 1.59 + if (!event->widget) { 1.60 + return LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint); 1.61 + } 1.62 + 1.63 + LayoutDeviceIntPoint offset = aEvent->refPoint + 1.64 + LayoutDeviceIntPoint::FromUntyped(event->widget->WidgetToScreenOffset()); 1.65 + nscoord factor = 1.66 + aPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel(); 1.67 + return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor), 1.68 + nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor)); 1.69 + } 1.70 + 1.71 + static CSSIntPoint CalculateClientPoint(nsPresContext* aPresContext, 1.72 + WidgetEvent* aEvent, 1.73 + CSSIntPoint* aDefaultClientPoint) 1.74 + { 1.75 + if (!aEvent || 1.76 + (aEvent->eventStructType != NS_MOUSE_EVENT && 1.77 + aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT && 1.78 + aEvent->eventStructType != NS_WHEEL_EVENT && 1.79 + aEvent->eventStructType != NS_DRAG_EVENT && 1.80 + aEvent->eventStructType != NS_POINTER_EVENT && 1.81 + aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT) || 1.82 + !aPresContext || 1.83 + !aEvent->AsGUIEvent()->widget) { 1.84 + return aDefaultClientPoint 1.85 + ? *aDefaultClientPoint 1.86 + : CSSIntPoint(0, 0); 1.87 + } 1.88 + 1.89 + nsIPresShell* shell = aPresContext->GetPresShell(); 1.90 + if (!shell) { 1.91 + return CSSIntPoint(0, 0); 1.92 + } 1.93 + nsIFrame* rootFrame = shell->GetRootFrame(); 1.94 + if (!rootFrame) { 1.95 + return CSSIntPoint(0, 0); 1.96 + } 1.97 + nsPoint pt = 1.98 + nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, rootFrame); 1.99 + 1.100 + return CSSIntPoint::FromAppUnitsRounded(pt); 1.101 + } 1.102 + 1.103 + static already_AddRefed<UIEvent> Constructor(const GlobalObject& aGlobal, 1.104 + const nsAString& aType, 1.105 + const UIEventInit& aParam, 1.106 + ErrorResult& aRv); 1.107 + 1.108 + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE 1.109 + { 1.110 + return UIEventBinding::Wrap(aCx, this); 1.111 + } 1.112 + 1.113 + nsIDOMWindow* GetView() const 1.114 + { 1.115 + return mView; 1.116 + } 1.117 + 1.118 + int32_t Detail() const 1.119 + { 1.120 + return mDetail; 1.121 + } 1.122 + 1.123 + int32_t LayerX() const 1.124 + { 1.125 + return GetLayerPoint().x; 1.126 + } 1.127 + 1.128 + int32_t LayerY() const 1.129 + { 1.130 + return GetLayerPoint().y; 1.131 + } 1.132 + 1.133 + int32_t PageX() const; 1.134 + int32_t PageY() const; 1.135 + 1.136 + virtual uint32_t Which() 1.137 + { 1.138 + MOZ_ASSERT(mEvent->eventStructType != NS_KEY_EVENT, 1.139 + "Key events should override Which()"); 1.140 + MOZ_ASSERT(mEvent->eventStructType != NS_MOUSE_EVENT, 1.141 + "Mouse events should override Which()"); 1.142 + return 0; 1.143 + } 1.144 + 1.145 + already_AddRefed<nsINode> GetRangeParent(); 1.146 + 1.147 + int32_t RangeOffset() const; 1.148 + 1.149 + bool CancelBubble() const 1.150 + { 1.151 + return mEvent->mFlags.mPropagationStopped; 1.152 + } 1.153 + 1.154 + bool IsChar() const; 1.155 + 1.156 +protected: 1.157 + // Internal helper functions 1.158 + nsIntPoint GetMovementPoint(); 1.159 + nsIntPoint GetLayerPoint() const; 1.160 + 1.161 + nsCOMPtr<nsIDOMWindow> mView; 1.162 + int32_t mDetail; 1.163 + CSSIntPoint mClientPoint; 1.164 + // Screenpoint is mEvent->refPoint. 1.165 + nsIntPoint mLayerPoint; 1.166 + CSSIntPoint mPagePoint; 1.167 + nsIntPoint mMovementPoint; 1.168 + bool mIsPointerLocked; 1.169 + CSSIntPoint mLastClientPoint; 1.170 + 1.171 + static Modifiers ComputeModifierState(const nsAString& aModifiersList); 1.172 + bool GetModifierStateInternal(const nsAString& aKey); 1.173 +}; 1.174 + 1.175 +} // namespace dom 1.176 +} // namespace mozilla 1.177 + 1.178 +#define NS_FORWARD_TO_UIEVENT \ 1.179 + NS_FORWARD_NSIDOMUIEVENT(UIEvent::) \ 1.180 + NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \ 1.181 + NS_IMETHOD DuplicatePrivateData() \ 1.182 + { \ 1.183 + return UIEvent::DuplicatePrivateData(); \ 1.184 + } \ 1.185 + NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, \ 1.186 + bool aSerializeInterfaceType) \ 1.187 + { \ 1.188 + UIEvent::Serialize(aMsg, aSerializeInterfaceType); \ 1.189 + } \ 1.190 + NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, \ 1.191 + void** aIter) \ 1.192 + { \ 1.193 + return UIEvent::Deserialize(aMsg, aIter); \ 1.194 + } 1.195 + 1.196 +#endif // mozilla_dom_UIEvent_h_