widget/MiscEvents.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial