Commit 51b0e867 authored by Neil Deakin's avatar Neil Deakin
Browse files

Bug 503943, add mouse capturing api to elements, remove capturing from views, r=roc,sr=smaug

parent 83b480a7
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -2773,6 +2773,18 @@ nsDocument::DestroyClassNameArray(void* aData)
  delete info;
}

NS_IMETHODIMP
nsDocument::ReleaseCapture()
{
  // only release the capture if the caller can access it. This prevents a
  // page from stopping a scrollbar grab for example.
  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(nsIPresShell::GetCapturingContent());
  if (node && nsContentUtils::CanCallerAccess(node)) {
    nsIPresShell::SetCapturingContent(nsnull, 0);
  }
  return NS_OK;
}

nsresult
nsDocument::SetBaseURI(nsIURI* aURI)
{
+23 −0
Original line number Diff line number Diff line
@@ -1084,6 +1084,29 @@ nsNSElementTearoff::GetClassList(nsIDOMDOMTokenList** aResult)
  return NS_OK;
}

NS_IMETHODIMP
nsNSElementTearoff::SetCapture(PRBool aRetargetToElement)
{
  // If there is already an active capture, ignore this request. This would
  // occur if a splitter, frame resizer, etc had already captured and we don't
  // want to override those.
  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(nsIPresShell::GetCapturingContent());
  if (node)
    return NS_OK;

  nsIPresShell::SetCapturingContent(mContent, aRetargetToElement ? CAPTURE_RETARGETTOELEMENT : 0);
  return NS_OK;
}

NS_IMETHODIMP
nsNSElementTearoff::ReleaseCapture()
{
  if (nsIPresShell::GetCapturingContent() == mContent) {
    nsIPresShell::SetCapturingContent(nsnull, 0);
  }
  return NS_OK;
}

//----------------------------------------------------------------------


+4 −22
Original line number Diff line number Diff line
@@ -2741,19 +2741,9 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
    {
      if (static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton &&
          !mNormalLMouseEventInProcess) {
        //Our state is out of whack.  We got a mouseup while still processing
        //the mousedown.  Kill View-level mouse capture or it'll stay stuck
        if (aView) {
          nsIViewManager* viewMan = aView->GetViewManager();
          if (viewMan) {
            nsIView* grabbingView;
            viewMan->GetMouseEventGrabber(grabbingView);
            if (grabbingView == aView) {
              PRBool result;
              viewMan->GrabMouseEvents(nsnull, result);
            }
          }
        }
        // We got a mouseup event while a mousedown event was being processed.
        // Make sure that the capturing content is cleared.
        nsIPresShell::SetCapturingContent(nsnull, 0);
        break;
      }

@@ -2858,17 +2848,9 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
        ret =
          CheckForAndDispatchClick(presContext, (nsMouseEvent*)aEvent, aStatus);
      }

      nsIPresShell *shell = presContext->GetPresShell();
      if (shell) {
        nsIViewManager* viewMan = shell->GetViewManager();
        if (viewMan) {
          nsIView* grabbingView = nsnull;
          viewMan->GetMouseEventGrabber(grabbingView);
          if (grabbingView == aView) {
            PRBool result;
            viewMan->GrabMouseEvents(nsnull, result);
          }
        }
        nsCOMPtr<nsFrameSelection> frameSelection = shell->FrameSelection();
        frameSelection->SetMouseDownState(PR_FALSE);
      }
+14 −3
Original line number Diff line number Diff line
@@ -411,15 +411,22 @@ protected:
  static PRInt32 sUserInputEventDepth;
};


/**
 * This class is used while processing real user input. During this time, popups
 * are allowed. For mousedown events, mouse capturing is also permitted.
 */
class nsAutoHandlingUserInputStatePusher
{
public:
  nsAutoHandlingUserInputStatePusher(PRBool aIsHandlingUserInput)
    : mIsHandlingUserInput(aIsHandlingUserInput)
  nsAutoHandlingUserInputStatePusher(PRBool aIsHandlingUserInput, PRBool aIsMouseDown)
    : mIsHandlingUserInput(aIsHandlingUserInput), mIsMouseDown(aIsMouseDown)
  {
    if (aIsHandlingUserInput) {
      nsEventStateManager::StartHandlingUserInput();
      if (aIsMouseDown) {
        nsIPresShell::SetCapturingContent(nsnull, 0);
        nsIPresShell::AllowMouseCapture(PR_TRUE);
      }
    }
  }

@@ -427,11 +434,15 @@ public:
  {
    if (mIsHandlingUserInput) {
      nsEventStateManager::StopHandlingUserInput();
      if (mIsMouseDown) {
        nsIPresShell::AllowMouseCapture(PR_FALSE);
      }
    }
  }

protected:
  PRBool mIsHandlingUserInput;
  PRBool mIsMouseDown;

private:
  // Hide so that this class can only be stack-allocated
+1 −1
Original line number Diff line number Diff line
@@ -1139,7 +1139,7 @@ nsHTMLFormElement::SubmitSubmission(nsIFormSubmission* aFormSubmission)
  {
    nsAutoPopupStatePusher popupStatePusher(mSubmitPopupState);

    nsAutoHandlingUserInputStatePusher userInpStatePusher(mSubmitInitiatedFromUserInput);
    nsAutoHandlingUserInputStatePusher userInpStatePusher(mSubmitInitiatedFromUserInput, PR_FALSE);

    rv = aFormSubmission->SubmitTo(actionURI, target, this, linkHandler,
                                   getter_AddRefs(docShell),
Loading