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_MiscEvents_h__ michael@0: #define mozilla_MiscEvents_h__ michael@0: michael@0: #include michael@0: michael@0: #include "mozilla/BasicEvents.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIAtom.h" michael@0: #include "nsITransferable.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::WidgetContentCommandEvent michael@0: ******************************************************************************/ michael@0: michael@0: class WidgetContentCommandEvent : public WidgetGUIEvent michael@0: { michael@0: public: michael@0: virtual WidgetContentCommandEvent* AsContentCommandEvent() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: michael@0: WidgetContentCommandEvent(bool aIsTrusted, uint32_t aMessage, michael@0: nsIWidget* aWidget, michael@0: bool aOnlyEnabledCheck = false) : michael@0: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_CONTENT_COMMAND_EVENT), michael@0: mOnlyEnabledCheck(aOnlyEnabledCheck), mSucceeded(false), mIsEnabled(false) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: // This event isn't an internal event of any DOM event. michael@0: NS_ASSERTION(!IsAllowedToDispatchDOMEvent(), michael@0: "WidgetQueryContentEvent needs to support Duplicate()"); michael@0: MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()"); michael@0: return nullptr; michael@0: } michael@0: michael@0: // NS_CONTENT_COMMAND_PASTE_TRANSFERABLE michael@0: nsCOMPtr mTransferable; // [in] michael@0: michael@0: // NS_CONTENT_COMMAND_SCROLL michael@0: // for mScroll.mUnit michael@0: enum michael@0: { michael@0: eCmdScrollUnit_Line, michael@0: eCmdScrollUnit_Page, michael@0: eCmdScrollUnit_Whole michael@0: }; michael@0: michael@0: struct ScrollInfo michael@0: { michael@0: ScrollInfo() : michael@0: mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false) michael@0: { michael@0: } michael@0: michael@0: int32_t mAmount; // [in] michael@0: uint8_t mUnit; // [in] michael@0: bool mIsHorizontal; // [in] michael@0: } mScroll; michael@0: michael@0: bool mOnlyEnabledCheck; // [in] michael@0: michael@0: bool mSucceeded; // [out] michael@0: bool mIsEnabled; // [out] michael@0: michael@0: void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignGUIEventData(aEvent, aCopyTargets); michael@0: michael@0: mScroll = aEvent.mScroll; michael@0: mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck; michael@0: mSucceeded = aEvent.mSucceeded; michael@0: mIsEnabled = aEvent.mIsEnabled; michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::WidgetCommandEvent michael@0: * michael@0: * This sends a command to chrome. If you want to request what is performed michael@0: * in focused content, you should use WidgetContentCommandEvent instead. michael@0: * michael@0: * XXX Should be |WidgetChromeCommandEvent|? michael@0: ******************************************************************************/ michael@0: michael@0: class WidgetCommandEvent : public WidgetGUIEvent michael@0: { michael@0: public: michael@0: virtual WidgetCommandEvent* AsCommandEvent() MOZ_OVERRIDE { return this; } michael@0: michael@0: WidgetCommandEvent(bool aIsTrusted, nsIAtom* aEventType, michael@0: nsIAtom* aCommand, nsIWidget* aWidget) : michael@0: WidgetGUIEvent(aIsTrusted, NS_USER_DEFINED_EVENT, aWidget, michael@0: NS_COMMAND_EVENT), michael@0: command(aCommand) michael@0: { michael@0: userType = aEventType; michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(eventStructType == NS_COMMAND_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: // Not copying widget, it is a weak reference. michael@0: WidgetCommandEvent* result = michael@0: new WidgetCommandEvent(false, userType, command, nullptr); michael@0: result->AssignCommandEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: nsCOMPtr command; michael@0: michael@0: // XXX Not tested by test_assign_event_data.html michael@0: void AssignCommandEventData(const WidgetCommandEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignGUIEventData(aEvent, aCopyTargets); michael@0: michael@0: // command must have been initialized with the constructor. michael@0: } michael@0: }; michael@0: michael@0: /****************************************************************************** michael@0: * mozilla::WidgetPluginEvent michael@0: * michael@0: * This event delivers only a native event to focused plugin. michael@0: ******************************************************************************/ michael@0: michael@0: class WidgetPluginEvent : public WidgetGUIEvent michael@0: { michael@0: public: michael@0: virtual WidgetPluginEvent* AsPluginEvent() MOZ_OVERRIDE { return this; } michael@0: michael@0: WidgetPluginEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) : michael@0: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_PLUGIN_EVENT), michael@0: retargetToFocusedDocument(false) michael@0: { michael@0: } michael@0: michael@0: virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE michael@0: { michael@0: // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent(). michael@0: // So, this event needs to support Duplicate(). michael@0: MOZ_ASSERT(eventStructType == NS_PLUGIN_EVENT, michael@0: "Duplicate() must be overridden by sub class"); michael@0: // Not copying widget, it is a weak reference. michael@0: WidgetPluginEvent* result = new WidgetPluginEvent(false, message, nullptr); michael@0: result->AssignPluginEventData(*this, true); michael@0: result->mFlags = mFlags; michael@0: return result; michael@0: } michael@0: michael@0: // If true, this event needs to be retargeted to focused document. michael@0: // Otherwise, never retargeted. Defaults to false. michael@0: bool retargetToFocusedDocument; michael@0: michael@0: void AssignPluginEventData(const WidgetPluginEvent& aEvent, michael@0: bool aCopyTargets) michael@0: { michael@0: AssignGUIEventData(aEvent, aCopyTargets); michael@0: michael@0: retargetToFocusedDocument = aEvent.retargetToFocusedDocument; michael@0: } michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_MiscEvents_h__