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_ContentEvents_h__ michael@0: #define mozilla_ContentEvents_h__ michael@0: michael@0: #include michael@0: michael@0: #include "mozilla/BasicEvents.h" michael@0: #include "mozilla/dom/DataTransfer.h" michael@0: #include "mozilla/dom/EventTarget.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsRect.h" michael@0: #include "nsStringGlue.h" michael@0: michael@0: class nsIContent; michael@0: michael@0: namespace mozilla { michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::InternalScrollPortEvent michael@0: ******************************************************************************/ michael@0: michael@0: class InternalScrollPortEvent : public WidgetGUIEvent michael@0: { michael@0: public: michael@0: virtual InternalScrollPortEvent* AsScrollPortEvent() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: michael@0: enum orientType michael@0: { michael@0: vertical = 0, michael@0: horizontal = 1, michael@0: both = 2 michael@0: }; michael@0: michael@0: InternalScrollPortEvent(bool aIsTrusted, uint32_t aMessage, michael@0: nsIWidget* aWidget) : michael@0: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLPORT_EVENT), michael@0: orient(vertical) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_SCROLLPORT_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: // Not copying widget, it is a weak reference. michael@0: InternalScrollPortEvent* result = michael@0: new InternalScrollPortEvent(false, message, nullptr); michael@0: result->AssignScrollPortEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: orientType orient; michael@0: michael@0: void AssignScrollPortEventData(const InternalScrollPortEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignGUIEventData(aEvent, aCopyTargets); michael@0: michael@0: orient = aEvent.orient; michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::InternalScrollPortEvent michael@0: ******************************************************************************/ michael@0: michael@0: class InternalScrollAreaEvent : public WidgetGUIEvent michael@0: { michael@0: public: michael@0: virtual InternalScrollAreaEvent* AsScrollAreaEvent() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: michael@0: InternalScrollAreaEvent(bool aIsTrusted, uint32_t aMessage, michael@0: nsIWidget* aWidget) : michael@0: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLAREA_EVENT) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_SCROLLAREA_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: // Not copying widget, it is a weak reference. michael@0: InternalScrollAreaEvent* result = michael@0: new InternalScrollAreaEvent(false, message, nullptr); michael@0: result->AssignScrollAreaEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: nsRect mArea; michael@0: michael@0: void AssignScrollAreaEventData(const InternalScrollAreaEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignGUIEventData(aEvent, aCopyTargets); michael@0: michael@0: mArea = aEvent.mArea; michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::InternalFormEvent michael@0: * michael@0: * We hold the originating form control for form submit and reset events. michael@0: * originator is a weak pointer (does not hold a strong reference). michael@0: ******************************************************************************/ michael@0: michael@0: class InternalFormEvent : public WidgetEvent michael@0: { michael@0: public: michael@0: virtual InternalFormEvent* AsFormEvent() MOZ_OVERRIDE { return this; } michael@0: michael@0: InternalFormEvent(bool aIsTrusted, uint32_t aMessage) : michael@0: WidgetEvent(aIsTrusted, aMessage, NS_FORM_EVENT), michael@0: originator(nullptr) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_FORM_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: InternalFormEvent* result = new InternalFormEvent(false, message); michael@0: result->AssignFormEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: nsIContent *originator; michael@0: michael@0: void AssignFormEventData(const InternalFormEvent& aEvent, bool aCopyTargets) michael@0: { michael@0: AssignEventData(aEvent, aCopyTargets); michael@0: michael@0: // Don't copy originator due to a weak pointer. michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::InternalClipboardEvent michael@0: ******************************************************************************/ michael@0: michael@0: class InternalClipboardEvent : public WidgetEvent michael@0: { michael@0: public: michael@0: virtual InternalClipboardEvent* AsClipboardEvent() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: michael@0: InternalClipboardEvent(bool aIsTrusted, uint32_t aMessage) : michael@0: WidgetEvent(aIsTrusted, aMessage, NS_CLIPBOARD_EVENT) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_CLIPBOARD_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: InternalClipboardEvent* result = new InternalClipboardEvent(false, message); michael@0: result->AssignClipboardEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: nsCOMPtr clipboardData; michael@0: michael@0: void AssignClipboardEventData(const InternalClipboardEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignEventData(aEvent, aCopyTargets); michael@0: michael@0: clipboardData = aEvent.clipboardData; michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::InternalFocusEvent michael@0: ******************************************************************************/ michael@0: michael@0: class InternalFocusEvent : public InternalUIEvent michael@0: { michael@0: public: michael@0: virtual InternalFocusEvent* AsFocusEvent() MOZ_OVERRIDE { return this; } michael@0: michael@0: InternalFocusEvent(bool aIsTrusted, uint32_t aMessage) : michael@0: InternalUIEvent(aIsTrusted, aMessage, NS_FOCUS_EVENT), michael@0: fromRaise(false), isRefocus(false) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_FOCUS_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: InternalFocusEvent* result = new InternalFocusEvent(false, message); michael@0: result->AssignFocusEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: /// The possible related target michael@0: nsCOMPtr relatedTarget; michael@0: michael@0: bool fromRaise; michael@0: bool isRefocus; michael@0: michael@0: void AssignFocusEventData(const InternalFocusEvent& aEvent, bool aCopyTargets) michael@0: { michael@0: AssignUIEventData(aEvent, aCopyTargets); michael@0: michael@0: relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr; michael@0: fromRaise = aEvent.fromRaise; michael@0: isRefocus = aEvent.isRefocus; michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::InternalTransitionEvent michael@0: ******************************************************************************/ michael@0: michael@0: class InternalTransitionEvent : public WidgetEvent michael@0: { michael@0: public: michael@0: virtual InternalTransitionEvent* AsTransitionEvent() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: michael@0: InternalTransitionEvent(bool aIsTrusted, uint32_t aMessage) michael@0: : WidgetEvent(aIsTrusted, aMessage, NS_TRANSITION_EVENT) michael@0: , elapsedTime(0.0) michael@0: { michael@0: mFlags.mCancelable = false; michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_TRANSITION_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: InternalTransitionEvent* result = michael@0: new InternalTransitionEvent(false, message); michael@0: result->AssignTransitionEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: nsString propertyName; michael@0: float elapsedTime; michael@0: nsString pseudoElement; michael@0: michael@0: void AssignTransitionEventData(const InternalTransitionEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignEventData(aEvent, aCopyTargets); michael@0: michael@0: propertyName = aEvent.propertyName; michael@0: elapsedTime = aEvent.elapsedTime; michael@0: pseudoElement = aEvent.pseudoElement; michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::InternalAnimationEvent michael@0: ******************************************************************************/ michael@0: michael@0: class InternalAnimationEvent : public WidgetEvent michael@0: { michael@0: public: michael@0: virtual InternalAnimationEvent* AsAnimationEvent() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: michael@0: InternalAnimationEvent(bool aIsTrusted, uint32_t aMessage) michael@0: : WidgetEvent(aIsTrusted, aMessage, NS_ANIMATION_EVENT) michael@0: , elapsedTime(0.0) michael@0: { michael@0: mFlags.mCancelable = false; michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_ANIMATION_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: InternalAnimationEvent* result = new InternalAnimationEvent(false, message); michael@0: result->AssignAnimationEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: nsString animationName; michael@0: float elapsedTime; michael@0: nsString pseudoElement; michael@0: michael@0: void AssignAnimationEventData(const InternalAnimationEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignEventData(aEvent, aCopyTargets); michael@0: michael@0: animationName = aEvent.animationName; michael@0: elapsedTime = aEvent.elapsedTime; michael@0: pseudoElement = aEvent.pseudoElement; michael@0: } michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_ContentEvents_h__