1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_InputEventOptions_h
8 #define mozilla_InputEventOptions_h
9 
10 #include "mozilla/Attributes.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/TextEvents.h"
13 #include "mozilla/dom/DataTransfer.h"
14 #include "mozilla/dom/StaticRange.h"
15 #include "nsString.h"
16 #include "nsTArray.h"
17 
18 namespace mozilla {
19 
20 /**
21  * InputEventOptions is used by nsContentUtils::DispatchInputEvent() to specify
22  * some attributes of InputEvent.  It would be nice if this was in
23  * nsContentUtils.h, however, it needs to include StaticRange.h for declaring
24  * this.  That would cause unnecessary dependency and makes incremental build
25  * slower when you touch StaticRange.h even though most nsContentUtils.h users
26  * don't use it.  Therefore, this struct is declared in separated header file
27  * here.
28  */
29 struct MOZ_STACK_CLASS InputEventOptions final {
30   InputEventOptions() = default;
31   explicit InputEventOptions(const InputEventOptions& aOther) = delete;
32   InputEventOptions(InputEventOptions&& aOther) = default;
InputEventOptionsfinal33   explicit InputEventOptions(const nsAString& aData)
34       : mData(aData), mDataTransfer(nullptr) {}
InputEventOptionsfinal35   explicit InputEventOptions(dom::DataTransfer* aDataTransfer)
36       : mDataTransfer(aDataTransfer) {
37     MOZ_ASSERT(mDataTransfer);
38     MOZ_ASSERT(mDataTransfer->IsReadOnly());
39   }
InputEventOptionsfinal40   InputEventOptions(const nsAString& aData,
41                     OwningNonNullStaticRangeArray&& aTargetRanges)
42       : mData(aData),
43         mDataTransfer(nullptr),
44         mTargetRanges(std::move(aTargetRanges)) {}
InputEventOptionsfinal45   InputEventOptions(dom::DataTransfer* aDataTransfer,
46                     OwningNonNullStaticRangeArray&& aTargetRanges)
47       : mDataTransfer(aDataTransfer), mTargetRanges(std::move(aTargetRanges)) {
48     MOZ_ASSERT(mDataTransfer);
49     MOZ_ASSERT(mDataTransfer->IsReadOnly());
50   }
51 
52   nsString mData;
53   dom::DataTransfer* mDataTransfer;
54   OwningNonNullStaticRangeArray mTargetRanges;
55 };
56 
57 }  // namespace mozilla
58 
59 #endif  // #ifndef mozilla_InputEventOptions_h