Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/nsBaseDragService.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 nsBaseDragService_h__
7
#define nsBaseDragService_h__
8
9
#include "nsIDragService.h"
10
#include "nsIDragSession.h"
11
#include "nsITransferable.h"
12
#include "nsCOMPtr.h"
13
#include "nsRect.h"
14
#include "nsPoint.h"
15
#include "nsString.h"
16
#include "mozilla/RefPtr.h"
17
#include "mozilla/dom/ContentParent.h"
18
#include "mozilla/dom/HTMLCanvasElement.h"
19
#include "nsTArray.h"
20
#include "nsRegion.h"
21
#include "Units.h"
22
23
// translucency level for drag images
24
#define DRAG_TRANSLUCENCY 0.65
25
26
class nsIContent;
27
class nsIDocument;
28
class nsINode;
29
class nsPresContext;
30
class nsIImageLoadingContent;
31
32
namespace mozilla {
33
namespace gfx {
34
class SourceSurface;
35
} // namespace gfx
36
37
namespace dom {
38
class DataTransfer;
39
class Selection;
40
} // namespace dom
41
} // namespace mozilla
42
43
/**
44
 * XP DragService wrapper base class
45
 */
46
47
class nsBaseDragService : public nsIDragService,
48
                          public nsIDragSession
49
{
50
51
public:
52
  typedef mozilla::gfx::SourceSurface SourceSurface;
53
54
  nsBaseDragService();
55
56
  //nsISupports
57
  NS_DECL_ISUPPORTS
58
59
  //nsIDragSession and nsIDragService
60
  NS_DECL_NSIDRAGSERVICE
61
  NS_DECL_NSIDRAGSESSION
62
63
  void SetDragEndPoint(nsIntPoint aEndDragPoint)
64
0
  {
65
0
    mEndDragPoint = mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
66
0
  }
67
  void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint)
68
0
  {
69
0
    mEndDragPoint = aEndDragPoint;
70
0
  }
71
72
0
  uint16_t GetInputSource() { return mInputSource; }
73
74
  int32_t TakeChildProcessDragAction();
75
76
protected:
77
  virtual ~nsBaseDragService();
78
79
  /**
80
   * Called from nsBaseDragService to initiate a platform drag from a source
81
   * in this process.  This is expected to ensure that StartDragSession() and
82
   * EndDragSession() get called if the platform drag is successfully invoked.
83
   */
84
  virtual nsresult InvokeDragSessionImpl(nsIArray* aTransferableArray,
85
                                         const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
86
                                         uint32_t aActionType) = 0;
87
88
  /**
89
   * Draw the drag image, if any, to a surface and return it. The drag image
90
   * is constructed from mImage if specified, or aDOMNode if mImage is null.
91
   *
92
   * aRegion may be used to draw only a subset of the element. This region
93
   * should be supplied using x and y coordinates measured in css pixels
94
   * that are relative to the upper-left corner of the window.
95
   *
96
   * aScreenPosition should be the screen coordinates of the mouse click
97
   * for the drag. These are in CSS pixels.
98
   *
99
   * On return, aScreenDragRect will contain the screen coordinates of the
100
   * area being dragged. This is used by the platform-specific part of the
101
   * drag service to determine the drag feedback. This rect will be in the
102
   * device pixels of the presContext.
103
   *
104
   * If there is no drag image, the returned surface will be null, but
105
   * aScreenDragRect will still be set to the drag area.
106
   *
107
   * aPresContext will be set to the nsPresContext used determined from
108
   * whichever of mImage or aDOMNode is used.
109
   */
110
  nsresult DrawDrag(nsINode* aDOMNode,
111
                    const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
112
                    mozilla::CSSIntPoint aScreenPosition,
113
                    mozilla::LayoutDeviceIntRect* aScreenDragRect,
114
                    RefPtr<SourceSurface>* aSurface,
115
                    nsPresContext **aPresContext);
116
117
  /**
118
   * Draw a drag image for an image node specified by aImageLoader or aCanvas.
119
   * This is called by DrawDrag.
120
   */
121
  nsresult DrawDragForImage(nsPresContext *aPresContext,
122
                            nsIImageLoadingContent* aImageLoader,
123
                            mozilla::dom::HTMLCanvasElement* aCanvas,
124
                            mozilla::LayoutDeviceIntRect* aScreenDragRect,
125
                            RefPtr<SourceSurface>* aSurface);
126
127
  /**
128
   * Convert aScreenPosition from CSS pixels into unscaled device pixels.
129
   */
130
  mozilla::LayoutDeviceIntPoint
131
  ConvertToUnscaledDevPixels(nsPresContext* aPresContext,
132
                             mozilla::CSSIntPoint aScreenPosition);
133
134
  /**
135
   * If the drag image is a popup, open the popup when the drag begins.
136
   */
137
  void OpenDragPopup();
138
139
  /**
140
   * Free resources contained in DataTransferItems that aren't needed by JS.
141
   */
142
  void DiscardInternalTransferData();
143
144
  // Returns true if a drag event was dispatched to a child process after
145
  // the previous TakeDragEventDispatchedToChildProcess() call.
146
  bool TakeDragEventDispatchedToChildProcess()
147
0
  {
148
0
    bool retval = mDragEventDispatchedToChildProcess;
149
0
    mDragEventDispatchedToChildProcess = false;
150
0
    return retval;
151
0
  }
152
153
  bool mCanDrop;
154
  bool mOnlyChromeDrop;
155
  bool mDoingDrag;
156
  // true if mImage should be used to set a drag image
157
  bool mHasImage;
158
  // true if the user cancelled the drag operation
159
  bool mUserCancelled;
160
161
  bool mDragEventDispatchedToChildProcess;
162
163
  uint32_t mDragAction;
164
  uint32_t mDragActionFromChildProcess;
165
166
  nsSize mTargetSize;
167
  nsCOMPtr<nsINode> mSourceNode;
168
  nsCString mTriggeringPrincipalURISpec;
169
  nsCOMPtr<nsIDocument> mSourceDocument;          // the document at the drag source. will be null
170
                                                  //  if it came from outside the app.
171
  nsContentPolicyType mContentPolicyType;         // the contentpolicy type passed to the channel
172
                                                  // when initiating the drag session
173
  RefPtr<mozilla::dom::DataTransfer> mDataTransfer;
174
175
  // used to determine the image to appear on the cursor while dragging
176
  nsCOMPtr<nsINode> mImage;
177
  // offset of cursor within the image
178
  mozilla::CSSIntPoint mImageOffset;
179
180
  // set if a selection is being dragged
181
  RefPtr<mozilla::dom::Selection> mSelection;
182
183
  // set if the image in mImage is a popup. If this case, the popup will be opened
184
  // and moved instead of using a drag image.
185
  nsCOMPtr<nsIContent> mDragPopup;
186
187
  // the screen position where drag gesture occurred, used for positioning the
188
  // drag image.
189
  mozilla::CSSIntPoint mScreenPosition;
190
191
  // the screen position where the drag ended
192
  mozilla::LayoutDeviceIntPoint mEndDragPoint;
193
194
  uint32_t mSuppressLevel;
195
196
  // The input source of the drag event. Possible values are from MouseEvent.
197
  uint16_t mInputSource;
198
199
  nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
200
201
  // Sub-region for tree-selections.
202
  mozilla::Maybe<mozilla::CSSIntRegion> mRegion;
203
};
204
205
#endif // nsBaseDragService_h__