author Nicholas Nethercote <nnethercote@mozilla.com>
Wed, 25 Oct 2017 10:22:38 +1100
changeset 387909 3d0093f961eec929caa370444cd0f7fcbfbc82bc
parent 324364 6a359b09d915a72c5624a28157dd757445af47fc
child 403046 fc5cbc7e0d7ff28ed81f802a4973e2e8634cfe61
permissions -rw-r--r--
Bug 1410794 - Change some |string| occurrences in nsIPrefBranch.idl to |ACString|. r=erahm. This makes the code nicer. In particular, it removes many getter_Copies() calls. The patch also converts a lot of nsCStrings to nsAutoCString, which will avoid heap allocation in the common case. The patch also renames PREF_CopyCharPref() as PREF_GetCStringPref(), because it's actually getting a string, not a char, and that matches the existing GetCString() and GetDefaultCString() methods. Correspondingly, it also renames PREF_SetCharPref() as PREF_SetCStringPref(). The |aPrefName| arguments in nsIPrefBranch.idl remain as |string| because they almost always involve passing in C string literals, and passing "foo" is much nicer than passing NS_LITERAL_CSTRING("foo"). It's worth noting that early versions of this patch used |AUTF8String| instead of |ACString|. But it turns out that libpref stores prefs internally as Latin1. And |ACString| is compatible with Latin1 but |AUTF8String| isn't, because non-ASCII Latin1 strings are not valid UTF-8!

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsBaseDragService_h__
#define nsBaseDragService_h__

#include "nsIDragService.h"
#include "nsIDragSession.h"
#include "nsITransferable.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDataTransfer.h"
#include "nsCOMPtr.h"
#include "nsRect.h"
#include "nsPoint.h"
#include "mozilla/RefPtr.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "nsTArray.h"
#include "Units.h"

// translucency level for drag images

class nsIContent;
class nsIDOMNode;
class nsPresContext;
class nsIImageLoadingContent;

namespace mozilla {
namespace gfx {
class SourceSurface;
} // namespace gfx
} // namespace mozilla

 * XP DragService wrapper base class

class nsBaseDragService : public nsIDragService,
                          public nsIDragSession

  typedef mozilla::gfx::SourceSurface SourceSurface;



  //nsIDragSession and nsIDragService

  void SetDragEndPoint(nsIntPoint aEndDragPoint)
    mEndDragPoint = mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
  void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint)
    mEndDragPoint = aEndDragPoint;

  uint16_t GetInputSource() { return mInputSource; }

  int32_t TakeChildProcessDragAction();

  virtual ~nsBaseDragService();

   * Called from nsBaseDragService to initiate a platform drag from a source
   * in this process.  This is expected to ensure that StartDragSession() and
   * EndDragSession() get called if the platform drag is successfully invoked.
  virtual nsresult InvokeDragSessionImpl(nsIArray* aTransferableArray,
                                         nsIScriptableRegion* aDragRgn,
                                         uint32_t aActionType) = 0;

   * Draw the drag image, if any, to a surface and return it. The drag image
   * is constructed from mImage if specified, or aDOMNode if mImage is null.
   * aRegion may be used to draw only a subset of the element. This region
   * should be supplied using x and y coordinates measured in css pixels
   * that are relative to the upper-left corner of the window.
   * aScreenPosition should be the screen coordinates of the mouse click
   * for the drag. These are in CSS pixels.
   * On return, aScreenDragRect will contain the screen coordinates of the
   * area being dragged. This is used by the platform-specific part of the
   * drag service to determine the drag feedback. This rect will be in the
   * device pixels of the presContext.
   * If there is no drag image, the returned surface will be null, but
   * aScreenDragRect will still be set to the drag area.
   * aPresContext will be set to the nsPresContext used determined from
   * whichever of mImage or aDOMNode is used.
  nsresult DrawDrag(nsIDOMNode* aDOMNode,
                    nsIScriptableRegion* aRegion,
                    mozilla::CSSIntPoint aScreenPosition,
                    mozilla::LayoutDeviceIntRect* aScreenDragRect,
                    RefPtr<SourceSurface>* aSurface,
                    nsPresContext **aPresContext);

   * Draw a drag image for an image node specified by aImageLoader or aCanvas.
   * This is called by DrawDrag.
  nsresult DrawDragForImage(nsPresContext *aPresContext,
                            nsIImageLoadingContent* aImageLoader,
                            mozilla::dom::HTMLCanvasElement* aCanvas,
                            mozilla::LayoutDeviceIntRect* aScreenDragRect,
                            RefPtr<SourceSurface>* aSurface);

   * Convert aScreenPosition from CSS pixels into unscaled device pixels.
  ConvertToUnscaledDevPixels(nsPresContext* aPresContext,
                             mozilla::CSSIntPoint aScreenPosition);

   * If the drag image is a popup, open the popup when the drag begins.
  void OpenDragPopup();

   * Free resources contained in DataTransferItems that aren't needed by JS.
  void DiscardInternalTransferData();

  // Returns true if a drag event was dispatched to a child process after
  // the previous TakeDragEventDispatchedToChildProcess() call.
  bool TakeDragEventDispatchedToChildProcess()
    bool retval = mDragEventDispatchedToChildProcess;
    mDragEventDispatchedToChildProcess = false;
    return retval;

  bool mCanDrop;
  bool mOnlyChromeDrop;
  bool mDoingDrag;
  // true if mImage should be used to set a drag image
  bool mHasImage;
  // true if the user cancelled the drag operation
  bool mUserCancelled;

  bool mDragEventDispatchedToChildProcess;

  uint32_t mDragAction;
  uint32_t mDragActionFromChildProcess;

  nsSize mTargetSize;
  nsCOMPtr<nsIDOMNode> mSourceNode;
  nsCOMPtr<nsIDOMDocument> mSourceDocument;       // the document at the drag source. will be null
                                                  //  if it came from outside the app.
  nsContentPolicyType mContentPolicyType;         // the contentpolicy type passed to the channel
                                                  // when initiating the drag session
  nsCOMPtr<nsIDOMDataTransfer> mDataTransfer;

  // used to determine the image to appear on the cursor while dragging
  nsCOMPtr<nsIDOMNode> mImage;
  // offset of cursor within the image
  mozilla::CSSIntPoint mImageOffset;

  // set if a selection is being dragged
  nsCOMPtr<nsISelection> mSelection;

  // set if the image in mImage is a popup. If this case, the popup will be opened
  // and moved instead of using a drag image.
  nsCOMPtr<nsIContent> mDragPopup;

  // the screen position where drag gesture occurred, used for positioning the
  // drag image.
  mozilla::CSSIntPoint mScreenPosition;

  // the screen position where the drag ended
  mozilla::LayoutDeviceIntPoint mEndDragPoint;

  uint32_t mSuppressLevel;

  // The input source of the drag event. Possible values are from nsIDOMMouseEvent.
  uint16_t mInputSource;

  nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;

#endif // nsBaseDragService_h__