Bug 1700051: part 28) Refactor `WordSplitState<T>::GetDOMWordSeparatorOffset` to...
[gecko.git] / widget / MiscEvents.h
blob38c270756e113b12ff8de79d1c23aa2a3aa3bb1f
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/. */
6 #ifndef mozilla_MiscEvents_h__
7 #define mozilla_MiscEvents_h__
9 #include <stdint.h>
11 #include "mozilla/BasicEvents.h"
12 #include "nsCOMPtr.h"
13 #include "nsAtom.h"
14 #include "nsGkAtoms.h"
15 #include "nsITransferable.h"
17 namespace mozilla {
19 namespace dom {
20 class PBrowserParent;
21 class PBrowserChild;
22 } // namespace dom
24 /******************************************************************************
25 * mozilla::WidgetContentCommandEvent
26 ******************************************************************************/
28 class WidgetContentCommandEvent : public WidgetGUIEvent {
29 public:
30 virtual WidgetContentCommandEvent* AsContentCommandEvent() override {
31 return this;
34 WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage,
35 nsIWidget* aWidget, bool aOnlyEnabledCheck = false)
36 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget,
37 eContentCommandEventClass),
38 mOnlyEnabledCheck(aOnlyEnabledCheck),
39 mSucceeded(false),
40 mIsEnabled(false) {}
42 virtual WidgetEvent* Duplicate() const override {
43 // This event isn't an internal event of any DOM event.
44 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
45 "WidgetQueryContentEvent needs to support Duplicate()");
46 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
47 return nullptr;
50 // eContentCommandPasteTransferable
51 nsCOMPtr<nsITransferable> mTransferable; // [in]
53 // eContentCommandScroll
54 // for mScroll.mUnit
55 enum { eCmdScrollUnit_Line, eCmdScrollUnit_Page, eCmdScrollUnit_Whole };
57 struct ScrollInfo {
58 ScrollInfo()
59 : mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false) {}
61 int32_t mAmount; // [in]
62 uint8_t mUnit; // [in]
63 bool mIsHorizontal; // [in]
64 } mScroll;
66 bool mOnlyEnabledCheck; // [in]
68 bool mSucceeded; // [out]
69 bool mIsEnabled; // [out]
71 void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
72 bool aCopyTargets) {
73 AssignGUIEventData(aEvent, aCopyTargets);
75 mScroll = aEvent.mScroll;
76 mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
77 mSucceeded = aEvent.mSucceeded;
78 mIsEnabled = aEvent.mIsEnabled;
82 /******************************************************************************
83 * mozilla::WidgetCommandEvent
85 * This sends a command to chrome. If you want to request what is performed
86 * in focused content, you should use WidgetContentCommandEvent instead.
88 * XXX Should be |WidgetChromeCommandEvent|?
89 ******************************************************************************/
91 class WidgetCommandEvent : public WidgetGUIEvent {
92 public:
93 virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
95 protected:
96 WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType, nsAtom* aCommand,
97 nsIWidget* aWidget)
98 : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
99 eCommandEventClass),
100 mCommand(aCommand) {
101 mSpecifiedEventType = aEventType;
104 public:
106 * Constructor to initialize an app command. This is the only case to
107 * initialize this class as a command in C++ stack.
109 WidgetCommandEvent(bool aIsTrusted, nsAtom* aCommand, nsIWidget* aWidget)
110 : WidgetCommandEvent(aIsTrusted, nsGkAtoms::onAppCommand, aCommand,
111 aWidget) {}
114 * Constructor to initialize as internal event of dom::CommandEvent.
116 WidgetCommandEvent() : WidgetCommandEvent(false, nullptr, nullptr, nullptr) {}
118 virtual WidgetEvent* Duplicate() const override {
119 MOZ_ASSERT(mClass == eCommandEventClass,
120 "Duplicate() must be overridden by sub class");
121 // Not copying widget, it is a weak reference.
122 WidgetCommandEvent* result =
123 new WidgetCommandEvent(false, mSpecifiedEventType, mCommand, nullptr);
124 result->AssignCommandEventData(*this, true);
125 result->mFlags = mFlags;
126 return result;
129 RefPtr<nsAtom> mCommand;
131 // XXX Not tested by test_assign_event_data.html
132 void AssignCommandEventData(const WidgetCommandEvent& aEvent,
133 bool aCopyTargets) {
134 AssignGUIEventData(aEvent, aCopyTargets);
136 // mCommand must have been initialized with the constructor.
140 } // namespace mozilla
142 #endif // mozilla_MiscEvents_h__