Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / widget / MiscEvents.h
blob44c9d771e2f246a1f21d7b25c0f0521288d77be6
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 "mozilla/Maybe.h"
13 #include "nsCOMPtr.h"
14 #include "nsAtom.h"
15 #include "nsGkAtoms.h"
16 #include "nsITransferable.h"
17 #include "nsString.h"
19 namespace mozilla {
21 namespace dom {
22 class PBrowserParent;
23 class PBrowserChild;
24 } // namespace dom
26 /******************************************************************************
27 * mozilla::WidgetContentCommandEvent
28 ******************************************************************************/
30 class WidgetContentCommandEvent : public WidgetGUIEvent {
31 public:
32 virtual WidgetContentCommandEvent* AsContentCommandEvent() override {
33 return this;
36 WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage,
37 nsIWidget* aWidget, bool aOnlyEnabledCheck = false)
38 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget,
39 eContentCommandEventClass),
40 mOnlyEnabledCheck(aOnlyEnabledCheck),
41 mSucceeded(false),
42 mIsEnabled(false) {}
44 virtual WidgetEvent* Duplicate() const override {
45 // This event isn't an internal event of any DOM event.
46 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
47 "WidgetQueryContentEvent needs to support Duplicate()");
48 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
49 return nullptr;
52 // eContentCommandInsertText
53 mozilla::Maybe<nsString> mString; // [in]
55 // eContentCommandPasteTransferable
56 nsCOMPtr<nsITransferable> mTransferable; // [in]
58 // eContentCommandScroll
59 // for mScroll.mUnit
60 enum { eCmdScrollUnit_Line, eCmdScrollUnit_Page, eCmdScrollUnit_Whole };
62 struct ScrollInfo {
63 ScrollInfo()
64 : mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false) {}
66 int32_t mAmount; // [in]
67 uint8_t mUnit; // [in]
68 bool mIsHorizontal; // [in]
69 } mScroll;
71 bool mOnlyEnabledCheck; // [in]
73 bool mSucceeded; // [out]
74 bool mIsEnabled; // [out]
76 void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
77 bool aCopyTargets) {
78 AssignGUIEventData(aEvent, aCopyTargets);
80 mString = aEvent.mString;
81 mScroll = aEvent.mScroll;
82 mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
83 mSucceeded = aEvent.mSucceeded;
84 mIsEnabled = aEvent.mIsEnabled;
88 /******************************************************************************
89 * mozilla::WidgetCommandEvent
91 * This sends a command to chrome. If you want to request what is performed
92 * in focused content, you should use WidgetContentCommandEvent instead.
94 * XXX Should be |WidgetChromeCommandEvent|?
95 ******************************************************************************/
97 class WidgetCommandEvent : public WidgetGUIEvent {
98 public:
99 virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
101 protected:
102 WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType, nsAtom* aCommand,
103 nsIWidget* aWidget, const WidgetEventTime* aTime = nullptr)
104 : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
105 eCommandEventClass, aTime),
106 mCommand(aCommand) {
107 mSpecifiedEventType = aEventType;
110 public:
112 * Constructor to initialize an app command. This is the only case to
113 * initialize this class as a command in C++ stack.
115 WidgetCommandEvent(bool aIsTrusted, nsAtom* aCommand, nsIWidget* aWidget,
116 const WidgetEventTime* aTime = nullptr)
117 : WidgetCommandEvent(aIsTrusted, nsGkAtoms::onAppCommand, aCommand,
118 aWidget, aTime) {}
121 * Constructor to initialize as internal event of dom::CommandEvent.
123 WidgetCommandEvent()
124 : WidgetCommandEvent(false, nullptr, nullptr, nullptr, nullptr) {}
126 virtual WidgetEvent* Duplicate() const override {
127 MOZ_ASSERT(mClass == eCommandEventClass,
128 "Duplicate() must be overridden by sub class");
129 // Not copying widget, it is a weak reference.
130 WidgetCommandEvent* result = new WidgetCommandEvent(
131 false, mSpecifiedEventType, mCommand, nullptr, this);
132 result->AssignCommandEventData(*this, true);
133 result->mFlags = mFlags;
134 return result;
137 RefPtr<nsAtom> mCommand;
139 // XXX Not tested by test_assign_event_data.html
140 void AssignCommandEventData(const WidgetCommandEvent& aEvent,
141 bool aCopyTargets) {
142 AssignGUIEventData(aEvent, aCopyTargets);
144 // mCommand must have been initialized with the constructor.
148 } // namespace mozilla
150 #endif // mozilla_MiscEvents_h__