1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef mozilla_MiscEvents_h__ 7 #define mozilla_MiscEvents_h__ 8 9 #include <stdint.h> 10 11 #include "mozilla/BasicEvents.h" 12 #include "nsCOMPtr.h" 13 #include "nsIAtom.h" 14 #include "nsITransferable.h" 15 16 namespace mozilla { 17 18 namespace dom { 19 class PBrowserParent; 20 class PBrowserChild; 21 } // namespace dom 22 23 /****************************************************************************** 24 * mozilla::WidgetContentCommandEvent 25 ******************************************************************************/ 26 27 class WidgetContentCommandEvent : public WidgetGUIEvent 28 { 29 public: AsContentCommandEvent()30 virtual WidgetContentCommandEvent* AsContentCommandEvent() override 31 { 32 return this; 33 } 34 35 WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage, 36 nsIWidget* aWidget, 37 bool aOnlyEnabledCheck = false) WidgetGUIEvent(aIsTrusted,aMessage,aWidget,eContentCommandEventClass)38 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eContentCommandEventClass) 39 , mOnlyEnabledCheck(aOnlyEnabledCheck) 40 , mSucceeded(false) 41 , mIsEnabled(false) 42 { 43 } 44 Duplicate()45 virtual WidgetEvent* Duplicate() const override 46 { 47 // This event isn't an internal event of any DOM event. 48 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(), 49 "WidgetQueryContentEvent needs to support Duplicate()"); 50 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()"); 51 return nullptr; 52 } 53 54 // eContentCommandPasteTransferable 55 nsCOMPtr<nsITransferable> mTransferable; // [in] 56 57 // eContentCommandScroll 58 // for mScroll.mUnit 59 enum 60 { 61 eCmdScrollUnit_Line, 62 eCmdScrollUnit_Page, 63 eCmdScrollUnit_Whole 64 }; 65 66 struct ScrollInfo 67 { ScrollInfoScrollInfo68 ScrollInfo() : 69 mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false) 70 { 71 } 72 73 int32_t mAmount; // [in] 74 uint8_t mUnit; // [in] 75 bool mIsHorizontal; // [in] 76 } mScroll; 77 78 bool mOnlyEnabledCheck; // [in] 79 80 bool mSucceeded; // [out] 81 bool mIsEnabled; // [out] 82 AssignContentCommandEventData(const WidgetContentCommandEvent & aEvent,bool aCopyTargets)83 void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent, 84 bool aCopyTargets) 85 { 86 AssignGUIEventData(aEvent, aCopyTargets); 87 88 mScroll = aEvent.mScroll; 89 mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck; 90 mSucceeded = aEvent.mSucceeded; 91 mIsEnabled = aEvent.mIsEnabled; 92 } 93 }; 94 95 /****************************************************************************** 96 * mozilla::WidgetCommandEvent 97 * 98 * This sends a command to chrome. If you want to request what is performed 99 * in focused content, you should use WidgetContentCommandEvent instead. 100 * 101 * XXX Should be |WidgetChromeCommandEvent|? 102 ******************************************************************************/ 103 104 class WidgetCommandEvent : public WidgetGUIEvent 105 { 106 public: AsCommandEvent()107 virtual WidgetCommandEvent* AsCommandEvent() override { return this; } 108 WidgetCommandEvent(bool aIsTrusted,nsIAtom * aEventType,nsIAtom * aCommand,nsIWidget * aWidget)109 WidgetCommandEvent(bool aIsTrusted, nsIAtom* aEventType, 110 nsIAtom* aCommand, nsIWidget* aWidget) 111 : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget, 112 eCommandEventClass) 113 , mCommand(aCommand) 114 { 115 mSpecifiedEventType = aEventType; 116 } 117 Duplicate()118 virtual WidgetEvent* Duplicate() const override 119 { 120 MOZ_ASSERT(mClass == eCommandEventClass, 121 "Duplicate() must be overridden by sub class"); 122 // Not copying widget, it is a weak reference. 123 WidgetCommandEvent* result = 124 new WidgetCommandEvent(false, mSpecifiedEventType, mCommand, nullptr); 125 result->AssignCommandEventData(*this, true); 126 result->mFlags = mFlags; 127 return result; 128 } 129 130 nsCOMPtr<nsIAtom> mCommand; 131 132 // XXX Not tested by test_assign_event_data.html AssignCommandEventData(const WidgetCommandEvent & aEvent,bool aCopyTargets)133 void AssignCommandEventData(const WidgetCommandEvent& aEvent, 134 bool aCopyTargets) 135 { 136 AssignGUIEventData(aEvent, aCopyTargets); 137 138 // mCommand must have been initialized with the constructor. 139 } 140 }; 141 142 /****************************************************************************** 143 * mozilla::WidgetPluginEvent 144 * 145 * This event delivers only a native event to focused plugin. 146 ******************************************************************************/ 147 148 class WidgetPluginEvent : public WidgetGUIEvent 149 { 150 private: 151 friend class dom::PBrowserParent; 152 friend class dom::PBrowserChild; 153 154 public: AsPluginEvent()155 virtual WidgetPluginEvent* AsPluginEvent() override { return this; } 156 WidgetPluginEvent(bool aIsTrusted,EventMessage aMessage,nsIWidget * aWidget)157 WidgetPluginEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) 158 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, ePluginEventClass) 159 , mRetargetToFocusedDocument(false) 160 { 161 } 162 Duplicate()163 virtual WidgetEvent* Duplicate() const override 164 { 165 // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent(). 166 // So, this event needs to support Duplicate(). 167 MOZ_ASSERT(mClass == ePluginEventClass, 168 "Duplicate() must be overridden by sub class"); 169 // Not copying widget, it is a weak reference. 170 WidgetPluginEvent* result = new WidgetPluginEvent(false, mMessage, nullptr); 171 result->AssignPluginEventData(*this, true); 172 result->mFlags = mFlags; 173 return result; 174 } 175 176 // If true, this event needs to be retargeted to focused document. 177 // Otherwise, never retargeted. Defaults to false. 178 bool mRetargetToFocusedDocument; 179 AssignPluginEventData(const WidgetPluginEvent & aEvent,bool aCopyTargets)180 void AssignPluginEventData(const WidgetPluginEvent& aEvent, 181 bool aCopyTargets) 182 { 183 AssignGUIEventData(aEvent, aCopyTargets); 184 185 mRetargetToFocusedDocument = aEvent.mRetargetToFocusedDocument; 186 } 187 188 protected: WidgetPluginEvent()189 WidgetPluginEvent() 190 { 191 } 192 }; 193 194 } // namespace mozilla 195 196 #endif // mozilla_MiscEvents_h__ 197