1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/ContentEvents.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,320 @@ 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_ContentEvents_h__ 1.10 +#define mozilla_ContentEvents_h__ 1.11 + 1.12 +#include <stdint.h> 1.13 + 1.14 +#include "mozilla/BasicEvents.h" 1.15 +#include "mozilla/dom/DataTransfer.h" 1.16 +#include "mozilla/dom/EventTarget.h" 1.17 +#include "nsCOMPtr.h" 1.18 +#include "nsRect.h" 1.19 +#include "nsStringGlue.h" 1.20 + 1.21 +class nsIContent; 1.22 + 1.23 +namespace mozilla { 1.24 + 1.25 +/****************************************************************************** 1.26 + * mozilla::InternalScrollPortEvent 1.27 + ******************************************************************************/ 1.28 + 1.29 +class InternalScrollPortEvent : public WidgetGUIEvent 1.30 +{ 1.31 +public: 1.32 + virtual InternalScrollPortEvent* AsScrollPortEvent() MOZ_OVERRIDE 1.33 + { 1.34 + return this; 1.35 + } 1.36 + 1.37 + enum orientType 1.38 + { 1.39 + vertical = 0, 1.40 + horizontal = 1, 1.41 + both = 2 1.42 + }; 1.43 + 1.44 + InternalScrollPortEvent(bool aIsTrusted, uint32_t aMessage, 1.45 + nsIWidget* aWidget) : 1.46 + WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLPORT_EVENT), 1.47 + orient(vertical) 1.48 + { 1.49 + } 1.50 + 1.51 + virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE 1.52 + { 1.53 + MOZ_ASSERT(eventStructType == NS_SCROLLPORT_EVENT, 1.54 + "Duplicate() must be overridden by sub class"); 1.55 + // Not copying widget, it is a weak reference. 1.56 + InternalScrollPortEvent* result = 1.57 + new InternalScrollPortEvent(false, message, nullptr); 1.58 + result->AssignScrollPortEventData(*this, true); 1.59 + result->mFlags = mFlags; 1.60 + return result; 1.61 + } 1.62 + 1.63 + orientType orient; 1.64 + 1.65 + void AssignScrollPortEventData(const InternalScrollPortEvent& aEvent, 1.66 + bool aCopyTargets) 1.67 + { 1.68 + AssignGUIEventData(aEvent, aCopyTargets); 1.69 + 1.70 + orient = aEvent.orient; 1.71 + } 1.72 +}; 1.73 + 1.74 +/****************************************************************************** 1.75 + * mozilla::InternalScrollPortEvent 1.76 + ******************************************************************************/ 1.77 + 1.78 +class InternalScrollAreaEvent : public WidgetGUIEvent 1.79 +{ 1.80 +public: 1.81 + virtual InternalScrollAreaEvent* AsScrollAreaEvent() MOZ_OVERRIDE 1.82 + { 1.83 + return this; 1.84 + } 1.85 + 1.86 + InternalScrollAreaEvent(bool aIsTrusted, uint32_t aMessage, 1.87 + nsIWidget* aWidget) : 1.88 + WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLAREA_EVENT) 1.89 + { 1.90 + } 1.91 + 1.92 + virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE 1.93 + { 1.94 + MOZ_ASSERT(eventStructType == NS_SCROLLAREA_EVENT, 1.95 + "Duplicate() must be overridden by sub class"); 1.96 + // Not copying widget, it is a weak reference. 1.97 + InternalScrollAreaEvent* result = 1.98 + new InternalScrollAreaEvent(false, message, nullptr); 1.99 + result->AssignScrollAreaEventData(*this, true); 1.100 + result->mFlags = mFlags; 1.101 + return result; 1.102 + } 1.103 + 1.104 + nsRect mArea; 1.105 + 1.106 + void AssignScrollAreaEventData(const InternalScrollAreaEvent& aEvent, 1.107 + bool aCopyTargets) 1.108 + { 1.109 + AssignGUIEventData(aEvent, aCopyTargets); 1.110 + 1.111 + mArea = aEvent.mArea; 1.112 + } 1.113 +}; 1.114 + 1.115 +/****************************************************************************** 1.116 + * mozilla::InternalFormEvent 1.117 + * 1.118 + * We hold the originating form control for form submit and reset events. 1.119 + * originator is a weak pointer (does not hold a strong reference). 1.120 + ******************************************************************************/ 1.121 + 1.122 +class InternalFormEvent : public WidgetEvent 1.123 +{ 1.124 +public: 1.125 + virtual InternalFormEvent* AsFormEvent() MOZ_OVERRIDE { return this; } 1.126 + 1.127 + InternalFormEvent(bool aIsTrusted, uint32_t aMessage) : 1.128 + WidgetEvent(aIsTrusted, aMessage, NS_FORM_EVENT), 1.129 + originator(nullptr) 1.130 + { 1.131 + } 1.132 + 1.133 + virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE 1.134 + { 1.135 + MOZ_ASSERT(eventStructType == NS_FORM_EVENT, 1.136 + "Duplicate() must be overridden by sub class"); 1.137 + InternalFormEvent* result = new InternalFormEvent(false, message); 1.138 + result->AssignFormEventData(*this, true); 1.139 + result->mFlags = mFlags; 1.140 + return result; 1.141 + } 1.142 + 1.143 + nsIContent *originator; 1.144 + 1.145 + void AssignFormEventData(const InternalFormEvent& aEvent, bool aCopyTargets) 1.146 + { 1.147 + AssignEventData(aEvent, aCopyTargets); 1.148 + 1.149 + // Don't copy originator due to a weak pointer. 1.150 + } 1.151 +}; 1.152 + 1.153 +/****************************************************************************** 1.154 + * mozilla::InternalClipboardEvent 1.155 + ******************************************************************************/ 1.156 + 1.157 +class InternalClipboardEvent : public WidgetEvent 1.158 +{ 1.159 +public: 1.160 + virtual InternalClipboardEvent* AsClipboardEvent() MOZ_OVERRIDE 1.161 + { 1.162 + return this; 1.163 + } 1.164 + 1.165 + InternalClipboardEvent(bool aIsTrusted, uint32_t aMessage) : 1.166 + WidgetEvent(aIsTrusted, aMessage, NS_CLIPBOARD_EVENT) 1.167 + { 1.168 + } 1.169 + 1.170 + virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE 1.171 + { 1.172 + MOZ_ASSERT(eventStructType == NS_CLIPBOARD_EVENT, 1.173 + "Duplicate() must be overridden by sub class"); 1.174 + InternalClipboardEvent* result = new InternalClipboardEvent(false, message); 1.175 + result->AssignClipboardEventData(*this, true); 1.176 + result->mFlags = mFlags; 1.177 + return result; 1.178 + } 1.179 + 1.180 + nsCOMPtr<dom::DataTransfer> clipboardData; 1.181 + 1.182 + void AssignClipboardEventData(const InternalClipboardEvent& aEvent, 1.183 + bool aCopyTargets) 1.184 + { 1.185 + AssignEventData(aEvent, aCopyTargets); 1.186 + 1.187 + clipboardData = aEvent.clipboardData; 1.188 + } 1.189 +}; 1.190 + 1.191 +/****************************************************************************** 1.192 + * mozilla::InternalFocusEvent 1.193 + ******************************************************************************/ 1.194 + 1.195 +class InternalFocusEvent : public InternalUIEvent 1.196 +{ 1.197 +public: 1.198 + virtual InternalFocusEvent* AsFocusEvent() MOZ_OVERRIDE { return this; } 1.199 + 1.200 + InternalFocusEvent(bool aIsTrusted, uint32_t aMessage) : 1.201 + InternalUIEvent(aIsTrusted, aMessage, NS_FOCUS_EVENT), 1.202 + fromRaise(false), isRefocus(false) 1.203 + { 1.204 + } 1.205 + 1.206 + virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE 1.207 + { 1.208 + MOZ_ASSERT(eventStructType == NS_FOCUS_EVENT, 1.209 + "Duplicate() must be overridden by sub class"); 1.210 + InternalFocusEvent* result = new InternalFocusEvent(false, message); 1.211 + result->AssignFocusEventData(*this, true); 1.212 + result->mFlags = mFlags; 1.213 + return result; 1.214 + } 1.215 + 1.216 + /// The possible related target 1.217 + nsCOMPtr<dom::EventTarget> relatedTarget; 1.218 + 1.219 + bool fromRaise; 1.220 + bool isRefocus; 1.221 + 1.222 + void AssignFocusEventData(const InternalFocusEvent& aEvent, bool aCopyTargets) 1.223 + { 1.224 + AssignUIEventData(aEvent, aCopyTargets); 1.225 + 1.226 + relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr; 1.227 + fromRaise = aEvent.fromRaise; 1.228 + isRefocus = aEvent.isRefocus; 1.229 + } 1.230 +}; 1.231 + 1.232 +/****************************************************************************** 1.233 + * mozilla::InternalTransitionEvent 1.234 + ******************************************************************************/ 1.235 + 1.236 +class InternalTransitionEvent : public WidgetEvent 1.237 +{ 1.238 +public: 1.239 + virtual InternalTransitionEvent* AsTransitionEvent() MOZ_OVERRIDE 1.240 + { 1.241 + return this; 1.242 + } 1.243 + 1.244 + InternalTransitionEvent(bool aIsTrusted, uint32_t aMessage) 1.245 + : WidgetEvent(aIsTrusted, aMessage, NS_TRANSITION_EVENT) 1.246 + , elapsedTime(0.0) 1.247 + { 1.248 + mFlags.mCancelable = false; 1.249 + } 1.250 + 1.251 + virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE 1.252 + { 1.253 + MOZ_ASSERT(eventStructType == NS_TRANSITION_EVENT, 1.254 + "Duplicate() must be overridden by sub class"); 1.255 + InternalTransitionEvent* result = 1.256 + new InternalTransitionEvent(false, message); 1.257 + result->AssignTransitionEventData(*this, true); 1.258 + result->mFlags = mFlags; 1.259 + return result; 1.260 + } 1.261 + 1.262 + nsString propertyName; 1.263 + float elapsedTime; 1.264 + nsString pseudoElement; 1.265 + 1.266 + void AssignTransitionEventData(const InternalTransitionEvent& aEvent, 1.267 + bool aCopyTargets) 1.268 + { 1.269 + AssignEventData(aEvent, aCopyTargets); 1.270 + 1.271 + propertyName = aEvent.propertyName; 1.272 + elapsedTime = aEvent.elapsedTime; 1.273 + pseudoElement = aEvent.pseudoElement; 1.274 + } 1.275 +}; 1.276 + 1.277 +/****************************************************************************** 1.278 + * mozilla::InternalAnimationEvent 1.279 + ******************************************************************************/ 1.280 + 1.281 +class InternalAnimationEvent : public WidgetEvent 1.282 +{ 1.283 +public: 1.284 + virtual InternalAnimationEvent* AsAnimationEvent() MOZ_OVERRIDE 1.285 + { 1.286 + return this; 1.287 + } 1.288 + 1.289 + InternalAnimationEvent(bool aIsTrusted, uint32_t aMessage) 1.290 + : WidgetEvent(aIsTrusted, aMessage, NS_ANIMATION_EVENT) 1.291 + , elapsedTime(0.0) 1.292 + { 1.293 + mFlags.mCancelable = false; 1.294 + } 1.295 + 1.296 + virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE 1.297 + { 1.298 + MOZ_ASSERT(eventStructType == NS_ANIMATION_EVENT, 1.299 + "Duplicate() must be overridden by sub class"); 1.300 + InternalAnimationEvent* result = new InternalAnimationEvent(false, message); 1.301 + result->AssignAnimationEventData(*this, true); 1.302 + result->mFlags = mFlags; 1.303 + return result; 1.304 + } 1.305 + 1.306 + nsString animationName; 1.307 + float elapsedTime; 1.308 + nsString pseudoElement; 1.309 + 1.310 + void AssignAnimationEventData(const InternalAnimationEvent& aEvent, 1.311 + bool aCopyTargets) 1.312 + { 1.313 + AssignEventData(aEvent, aCopyTargets); 1.314 + 1.315 + animationName = aEvent.animationName; 1.316 + elapsedTime = aEvent.elapsedTime; 1.317 + pseudoElement = aEvent.pseudoElement; 1.318 + } 1.319 +}; 1.320 + 1.321 +} // namespace mozilla 1.322 + 1.323 +#endif // mozilla_ContentEvents_h__