Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/MiscEvents.h
Line
Count
Source (jump to first uncovered line)
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 "nsAtom.h"
14
#include "nsGkAtoms.h"
15
#include "nsITransferable.h"
16
17
namespace mozilla {
18
19
namespace dom {
20
  class PBrowserParent;
21
  class PBrowserChild;
22
} // namespace dom
23
24
/******************************************************************************
25
 * mozilla::WidgetContentCommandEvent
26
 ******************************************************************************/
27
28
class WidgetContentCommandEvent : public WidgetGUIEvent
29
{
30
public:
31
  virtual WidgetContentCommandEvent* AsContentCommandEvent() override
32
0
  {
33
0
    return this;
34
0
  }
35
36
  WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage,
37
                            nsIWidget* aWidget,
38
                            bool aOnlyEnabledCheck = false)
39
    : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eContentCommandEventClass)
40
    , mOnlyEnabledCheck(aOnlyEnabledCheck)
41
    , mSucceeded(false)
42
    , mIsEnabled(false)
43
0
  {
44
0
  }
45
46
  virtual WidgetEvent* Duplicate() const override
47
0
  {
48
0
    // This event isn't an internal event of any DOM event.
49
0
    NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
50
0
      "WidgetQueryContentEvent needs to support Duplicate()");
51
0
    MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
52
0
    return nullptr;
53
0
  }
54
55
  // eContentCommandPasteTransferable
56
  nsCOMPtr<nsITransferable> mTransferable; // [in]
57
58
  // eContentCommandScroll
59
  // for mScroll.mUnit
60
  enum
61
  {
62
    eCmdScrollUnit_Line,
63
    eCmdScrollUnit_Page,
64
    eCmdScrollUnit_Whole
65
  };
66
67
  struct ScrollInfo
68
  {
69
    ScrollInfo() :
70
      mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false)
71
0
    {
72
0
    }
73
74
    int32_t mAmount;    // [in]
75
    uint8_t mUnit;      // [in]
76
    bool mIsHorizontal; // [in]
77
  } mScroll;
78
79
  bool mOnlyEnabledCheck; // [in]
80
81
  bool mSucceeded; // [out]
82
  bool mIsEnabled; // [out]
83
84
  void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
85
                                     bool aCopyTargets)
86
0
  {
87
0
    AssignGUIEventData(aEvent, aCopyTargets);
88
0
89
0
    mScroll = aEvent.mScroll;
90
0
    mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
91
0
    mSucceeded = aEvent.mSucceeded;
92
0
    mIsEnabled = aEvent.mIsEnabled;
93
0
  }
94
};
95
96
/******************************************************************************
97
 * mozilla::WidgetCommandEvent
98
 *
99
 * This sends a command to chrome.  If you want to request what is performed
100
 * in focused content, you should use WidgetContentCommandEvent instead.
101
 *
102
 * XXX Should be |WidgetChromeCommandEvent|?
103
 ******************************************************************************/
104
105
class WidgetCommandEvent : public WidgetGUIEvent
106
{
107
public:
108
0
  virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
109
110
protected:
111
  WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType,
112
                     nsAtom* aCommand, nsIWidget* aWidget)
113
    : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
114
                     eCommandEventClass)
115
    , mCommand(aCommand)
116
0
  {
117
0
    mSpecifiedEventType = aEventType;
118
0
  }
119
120
public:
121
  /**
122
   * Constructor to initialize an app command.  This is the only case to
123
   * initialize this class as a command in C++ stack.
124
   */
125
  WidgetCommandEvent(bool aIsTrusted, nsAtom* aCommand, nsIWidget* aWidget)
126
    : WidgetCommandEvent(aIsTrusted, nsGkAtoms::onAppCommand,
127
                         aCommand, aWidget)
128
0
  {
129
0
  }
130
131
  /**
132
   * Constructor to initialize as internal event of dom::CommandEvent.
133
   */
134
  WidgetCommandEvent()
135
    : WidgetCommandEvent(false, nullptr, nullptr, nullptr)
136
0
  {
137
0
  }
138
139
  virtual WidgetEvent* Duplicate() const override
140
0
  {
141
0
    MOZ_ASSERT(mClass == eCommandEventClass,
142
0
               "Duplicate() must be overridden by sub class");
143
0
    // Not copying widget, it is a weak reference.
144
0
    WidgetCommandEvent* result =
145
0
      new WidgetCommandEvent(false, mSpecifiedEventType, mCommand, nullptr);
146
0
    result->AssignCommandEventData(*this, true);
147
0
    result->mFlags = mFlags;
148
0
    return result;
149
0
  }
150
151
  RefPtr<nsAtom> mCommand;
152
153
  // XXX Not tested by test_assign_event_data.html
154
  void AssignCommandEventData(const WidgetCommandEvent& aEvent,
155
                              bool aCopyTargets)
156
0
  {
157
0
    AssignGUIEventData(aEvent, aCopyTargets);
158
0
159
0
    // mCommand must have been initialized with the constructor.
160
0
  }
161
};
162
163
/******************************************************************************
164
 * mozilla::WidgetPluginEvent
165
 *
166
 * This event delivers only a native event to focused plugin.
167
 ******************************************************************************/
168
169
class WidgetPluginEvent : public WidgetGUIEvent
170
{
171
private:
172
  friend class dom::PBrowserParent;
173
  friend class dom::PBrowserChild;
174
175
public:
176
0
  virtual WidgetPluginEvent* AsPluginEvent() override { return this; }
177
178
  WidgetPluginEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
179
    : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, ePluginEventClass)
180
    , mRetargetToFocusedDocument(false)
181
0
  {
182
0
  }
183
184
  virtual WidgetEvent* Duplicate() const override
185
0
  {
186
0
    // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
187
0
    //       So, this event needs to support Duplicate().
188
0
    MOZ_ASSERT(mClass == ePluginEventClass,
189
0
               "Duplicate() must be overridden by sub class");
190
0
    // Not copying widget, it is a weak reference.
191
0
    WidgetPluginEvent* result = new WidgetPluginEvent(false, mMessage, nullptr);
192
0
    result->AssignPluginEventData(*this, true);
193
0
    result->mFlags = mFlags;
194
0
    return result;
195
0
  }
196
197
  // If true, this event needs to be retargeted to focused document.
198
  // Otherwise, never retargeted. Defaults to false.
199
  bool mRetargetToFocusedDocument;
200
201
  void AssignPluginEventData(const WidgetPluginEvent& aEvent,
202
                             bool aCopyTargets)
203
0
  {
204
0
    AssignGUIEventData(aEvent, aCopyTargets);
205
0
206
0
    mRetargetToFocusedDocument = aEvent.mRetargetToFocusedDocument;
207
0
  }
208
209
protected:
210
  WidgetPluginEvent()
211
    : mRetargetToFocusedDocument(false)
212
0
  {
213
0
  }
214
};
215
216
} // namespace mozilla
217
218
#endif // mozilla_MiscEvents_h__