Commit 2af751ce authored by Maksim Lebedev's avatar Maksim Lebedev
Browse files

Bug 968148 - Implement PointerCapture for pointer events. r=smaug

--HG--
extra : rebase_source : 331cf187194c8827e4b75835e85b2d79fdc419c7
parent 026df438
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -632,6 +632,32 @@ public:
    GetElementsByClassName(const nsAString& aClassNames);
  bool MozMatchesSelector(const nsAString& aSelector,
                          ErrorResult& aError);
  void SetPointerCapture(int32_t aPointerId, ErrorResult& aError)
  {
    bool activeState = false;
    if (!nsIPresShell::GetPointerInfo(aPointerId, activeState)) {
      aError.Throw(NS_ERROR_DOM_INVALID_POINTER_ERR);
      return;
    }
    if (!activeState) {
      return;
    }
    nsIPresShell::SetPointerCapturingContent(aPointerId, this);
  }
  void ReleasePointerCapture(int32_t aPointerId, ErrorResult& aError)
  {
    bool activeState = false;
    if (!nsIPresShell::GetPointerInfo(aPointerId, activeState)) {
      aError.Throw(NS_ERROR_DOM_INVALID_POINTER_ERR);
      return;
    }

    // Ignoring ReleasePointerCapture call on incorrect element (on element
    // that didn't have capture before).
    if (nsIPresShell::GetPointerCapturingContent(aPointerId) == this) {
      nsIPresShell::ReleasePointerCapturingContent(aPointerId, this);
    }
  }
  void SetCapture(bool aRetargetToElement)
  {
    // If there is already an active capture, ignore this request. This would
+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ enum DOM4ErrorTypeCodeMap {
  TimeoutError               = nsIDOMDOMException::TIMEOUT_ERR,
  InvalidNodeTypeError       = nsIDOMDOMException::INVALID_NODE_TYPE_ERR,
  DataCloneError             = nsIDOMDOMException::DATA_CLONE_ERR,
  InvalidPointerId           = nsIDOMDOMException::INVALID_POINTER_ERR,
  EncodingError              = 0,

  /* XXX Should be JavaScript native errors */
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ DOM4_MSG_DEF(QuotaExceededError, "The quota has been exceeded.", NS_ERROR_DOM_QU
DOM4_MSG_DEF(TimeoutError, "The operation timed out.", NS_ERROR_DOM_TIMEOUT_ERR)
DOM4_MSG_DEF(InvalidNodeTypeError, "The supplied node is incorrect or has an incorrect ancestor for this operation.", NS_ERROR_DOM_INVALID_NODE_TYPE_ERR)
DOM4_MSG_DEF(DataCloneError, "The object could not be cloned.", NS_ERROR_DOM_DATA_CLONE_ERR)
DOM4_MSG_DEF(InvalidPointerId, "Invalid pointer id.", NS_ERROR_DOM_INVALID_POINTER_ERR)

/* XXX Should be JavaScript native TypeError */
DOM4_MSG_DEF(TypeError, "The method parameter is missing or invalid.", NS_ERROR_TYPE_ERR)
+23 −17
Original line number Diff line number Diff line
@@ -50,24 +50,19 @@ ConvertStringToPointerType(const nsAString& aPointerTypeArg)

// static
already_AddRefed<PointerEvent>
PointerEvent::Constructor(const GlobalObject& aGlobal,
PointerEvent::Constructor(EventTarget* aOwner,
                          const nsAString& aType,
                          const PointerEventInit& aParam,
                          ErrorResult& aRv)
                          const PointerEventInit& aParam)
{
  nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
  nsRefPtr<PointerEvent> e = new PointerEvent(t, nullptr, nullptr);
  bool trusted = e->Init(t);
  nsRefPtr<PointerEvent> e = new PointerEvent(aOwner, nullptr, nullptr);
  bool trusted = e->Init(aOwner);

  aRv = e->InitMouseEvent(aType, aParam.mBubbles, aParam.mCancelable,
  e->InitMouseEvent(aType, aParam.mBubbles, aParam.mCancelable,
                    aParam.mView, aParam.mDetail, aParam.mScreenX,
                    aParam.mScreenY, aParam.mClientX, aParam.mClientY,
                    aParam.mCtrlKey, aParam.mAltKey, aParam.mShiftKey,
                    aParam.mMetaKey, aParam.mButton,
                    aParam.mRelatedTarget);
  if (aRv.Failed()) {
    return nullptr;
  }

  WidgetPointerEvent* widgetEvent = e->mEvent->AsPointerEvent();
  widgetEvent->pointerId = aParam.mPointerId;
@@ -84,6 +79,17 @@ PointerEvent::Constructor(const GlobalObject& aGlobal,
  return e.forget();
}

// static
already_AddRefed<PointerEvent>
PointerEvent::Constructor(const GlobalObject& aGlobal,
                          const nsAString& aType,
                          const PointerEventInit& aParam,
                          ErrorResult& aRv)
{
  nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
  return Constructor(owner, aType, aParam);
}

void
PointerEvent::GetPointerType(nsAString& aPointerType)
{
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@ public:
              const PointerEventInit& aParam,
              ErrorResult& aRv);

  static already_AddRefed<PointerEvent>
  Constructor(EventTarget* aOwner,
              const nsAString& aType,
              const PointerEventInit& aParam);

  int32_t PointerId();
  int32_t Width();
  int32_t Height();
Loading