From 74ac88465a5e47f0b4867fca658bdcf4f90eeaa0 Mon Sep 17 00:00:00 2001 From: "mats.palmgren%bredband.net" Date: Tue, 28 Jun 2005 21:40:15 +0000 Subject: [PATCH] Make drag-n-drop of frame-less content work again. b=289667 r+sr=roc a=benjamin git-svn-id: svn://10.0.0.236/trunk@175262 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/src/nsEventStateManager.cpp | 9 ++++--- .../content/events/src/nsEventStateManager.h | 6 +++++ .../src/xpwidgets/nsBaseDragService.cpp | 24 +++++++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 8543f09e6a8..f4e2482fe63 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -1214,7 +1214,7 @@ nsEventStateManager::FireContextClick() // event and it will get reset on the very next event to the correct frame). mCurrentTarget = nsnull; if ( mGestureDownContent ) { - mPresContext->GetPresShell()->GetPrimaryFrameFor(mGestureDownContent, + mPresContext->GetPresShell()->GetPrimaryFrameFor(mGestureDownFrameOwner, &mCurrentTarget); if ( mCurrentTarget ) { @@ -1293,8 +1293,9 @@ nsEventStateManager::FireContextClick() } // now check if the event has been handled. If so, stop tracking a drag - if ( status == nsEventStatus_eConsumeNoDefault ) + if ( status == nsEventStatus_eConsumeNoDefault ) { StopTrackingDragGesture(); + } KillClickHoldTimer(); @@ -1330,6 +1331,7 @@ nsEventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext, inDownFrame->GetContentForEvent(aPresContext, inDownEvent, getter_AddRefs(mGestureDownContent)); + mGestureDownFrameOwner = inDownFrame->GetContent(); mGestureDownShift = inDownEvent->isShift; mGestureDownControl = inDownEvent->isControl; mGestureDownAlt = inDownEvent->isAlt; @@ -1352,6 +1354,7 @@ void nsEventStateManager::StopTrackingDragGesture() { mGestureDownContent = nsnull; + mGestureDownFrameOwner = nsnull; } @@ -1448,7 +1451,7 @@ nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext, { NS_WARN_IF_FALSE(aPresContext, "This shouldn't happen."); if ( IsTrackingDragGesture() ) { - aPresContext->GetPresShell()->GetPrimaryFrameFor(mGestureDownContent, + aPresContext->GetPresShell()->GetPrimaryFrameFor(mGestureDownFrameOwner, &mCurrentTarget); if (!mCurrentTarget) { StopTrackingDragGesture(); diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 9756fe47540..01630be8dba 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Mats Palmgren * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -290,7 +291,12 @@ protected: // member variables for the d&d gesture state machine nsPoint mGestureDownPoint; // screen coordinates + // The content to use as target if we start a d&d (what we drag). nsCOMPtr mGestureDownContent; + // The content of the frame where the mouse-down event occurred. It's the same + // as the target in most cases but not always - for example when dragging + // an of an image map this is the image. (bug 289667) + nsCOMPtr mGestureDownFrameOwner; // State of keys when the original gesture-down happened PRPackedBool mGestureDownShift; PRPackedBool mGestureDownControl; diff --git a/mozilla/widget/src/xpwidgets/nsBaseDragService.cpp b/mozilla/widget/src/xpwidgets/nsBaseDragService.cpp index 485f1c0f2e9..d86e200aae7 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseDragService.cpp +++ b/mozilla/widget/src/xpwidgets/nsBaseDragService.cpp @@ -50,6 +50,7 @@ #include "nsIDocument.h" #include "nsIContent.h" #include "nsIPresShell.h" +#include "nsIViewManager.h" #include "nsIDOMNode.h" #include "nsPresContext.h" @@ -208,13 +209,22 @@ nsBaseDragService::InvokeDragSession(nsIDOMNode *aDOMNode, // When the mouse goes down, the selection code starts a mouse // capture. However, this gets in the way of determining drag // feedback for things like trees because the event coordinates - // are in the wrong coord system. Turn off capture by getting the - // frame associated with the DOM Node. - nsIFrame* dragFrame = nsnull; - nsCOMPtr context; - GetFrameFromNode(aDOMNode, &dragFrame, getter_AddRefs(context)); - if (dragFrame && context) - dragFrame->CaptureMouse(context, PR_FALSE); + // are in the wrong coord system. Turn off mouse capture in + // the associated view manager. + nsCOMPtr contentNode = do_QueryInterface(aDOMNode); + if (contentNode) { + nsIDocument* doc = contentNode->GetCurrentDoc(); + if (doc) { + nsIPresShell* presShell = doc->GetShellAt(0); + if (presShell) { + nsIViewManager* vm = presShell->GetViewManager(); + if (vm) { + PRBool notUsed; + vm->GrabMouseEvents(nsnull, notUsed); + } + } + } + } return NS_OK; }