Move nsBaseDragService::GetFrameFromNode() to Mac widget code (only consumer); clean it up a bit. b=299084 r+sr=roc
git-svn-id: svn://10.0.0.236/trunk@179184 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mats Palmgren <mats.palmgren@bredband.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -85,6 +86,23 @@
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsStylClipboardUtils.h"
|
||||
|
||||
//
|
||||
// Get the primary frame for a content node in the current document.
|
||||
//
|
||||
static nsIFrame*
|
||||
GetPrimaryFrameFor(nsIContent* aContent)
|
||||
{
|
||||
nsIFrame* result = nsnull;
|
||||
nsIDocument* doc = aContent->GetCurrentDoc();
|
||||
if (doc) {
|
||||
nsIPresShell* presShell = doc->GetShellAt(0);
|
||||
if (presShell) {
|
||||
result = presShell->GetPrimaryFrameFor(aContent);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// we need our own stuff for MacOS because of nsIDragSessionMac.
|
||||
NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService)
|
||||
@@ -130,13 +148,14 @@ nsDragService::ComputeGlobalRectFromFrame ( nsIDOMNode* aDOMNode, Rect & outScre
|
||||
{
|
||||
NS_ASSERTION ( aDOMNode, "Oopps, no DOM node" );
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aDOMNode);
|
||||
|
||||
// this isn't so much of an issue as long as we're just dragging around outlines,
|
||||
// but it is when we are showing the text being drawn. Comment it out for now
|
||||
// but leave it around when we turn this all back on (pinkerton).
|
||||
#if USE_TRANSLUCENT_DRAGGING && defined(MOZ_XUL)
|
||||
// until bug 41237 is fixed, only do translucent dragging if the drag is in
|
||||
// the chrome or it's a link.
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aDOMNode);
|
||||
if (!content || !content->IsContentOfType(nsIContent::eXUL)) {
|
||||
// the link node is the parent of the node we have (which is probably text or image).
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
@@ -154,11 +173,12 @@ nsDragService::ComputeGlobalRectFromFrame ( nsIDOMNode* aDOMNode, Rect & outScre
|
||||
|
||||
outScreenRect.left = outScreenRect.right = outScreenRect.top = outScreenRect.bottom = 0;
|
||||
|
||||
if (!content)
|
||||
return PR_FALSE;
|
||||
|
||||
// Get the frame for this content node (note: frames are not refcounted)
|
||||
nsIFrame *aFrame = nsnull;
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
GetFrameFromNode ( aDOMNode, &aFrame, getter_AddRefs(presContext) );
|
||||
if ( !aFrame || !presContext )
|
||||
nsIFrame *frame = ::GetPrimaryFrameFor(content);
|
||||
if (!frame)
|
||||
return PR_FALSE;
|
||||
|
||||
//
|
||||
@@ -166,12 +186,12 @@ nsDragService::ComputeGlobalRectFromFrame ( nsIDOMNode* aDOMNode, Rect & outScre
|
||||
// coordinates.
|
||||
//
|
||||
|
||||
nsRect rect = aFrame->GetRect();
|
||||
nsRect rect = frame->GetRect();
|
||||
|
||||
// Find offset from our view
|
||||
nsIView *containingView = nsnull;
|
||||
nsPoint viewOffset(0,0);
|
||||
aFrame->GetOffsetFromView(viewOffset, &containingView);
|
||||
frame->GetOffsetFromView(viewOffset, &containingView);
|
||||
NS_ASSERTION(containingView, "No containing view!");
|
||||
if ( !containingView )
|
||||
return PR_FALSE;
|
||||
@@ -180,8 +200,7 @@ nsDragService::ComputeGlobalRectFromFrame ( nsIDOMNode* aDOMNode, Rect & outScre
|
||||
nsPoint widgetOffset;
|
||||
nsIWidget* aWidget = containingView->GetNearestWidget ( &widgetOffset );
|
||||
|
||||
float t2p = 1.0;
|
||||
t2p = presContext->TwipsToPixels();
|
||||
float t2p = frame->GetPresContext()->TwipsToPixels();
|
||||
|
||||
// Shift our offset rect by offset into our view, and
|
||||
// the view's offset to the closest widget. Then convert that to global coordinates.
|
||||
@@ -1064,7 +1083,7 @@ nsDragService::ExtractDataFromOS ( DragReference inDragRef, ItemReference inItem
|
||||
err = ::GetFlavorData ( inDragRef, inItemRef, inFlavor, buff, &buffSize, 0 );
|
||||
if ( err ) {
|
||||
#ifdef NS_DEBUG
|
||||
printf("nsDragService: Error getting data out of drag manager, #%ld\n", err);
|
||||
printf("nsDragService: Error getting data out of drag manager, #%d\n", err);
|
||||
#endif
|
||||
retval = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mats Palmgren <mats.palmgren@bredband.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -69,11 +70,6 @@ nsBaseDragService::nsBaseDragService()
|
||||
: mCanDrop(PR_FALSE), mDoingDrag(PR_FALSE),
|
||||
mDragAction(DRAGDROP_ACTION_NONE), mTargetSize(0,0)
|
||||
{
|
||||
nsresult result = NS_NewISupportsArray(getter_AddRefs(mTransArray));
|
||||
if (NS_FAILED(result)) {
|
||||
//what do we do? we can't throw!
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -276,33 +272,3 @@ nsBaseDragService::EndDragSession()
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// GetFrameFromNode
|
||||
//
|
||||
// Get the frame for this content node (note: frames are not refcounted).
|
||||
//
|
||||
void
|
||||
nsBaseDragService::GetFrameFromNode(nsIDOMNode* inNode, nsIFrame** outFrame,
|
||||
nsPresContext** outContext)
|
||||
{
|
||||
*outFrame = nsnull;
|
||||
*outContext = nsnull;
|
||||
if (!inNode || !outContext)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIContent> contentNode = do_QueryInterface(inNode);
|
||||
if (contentNode) {
|
||||
nsIDocument* doc = contentNode->GetDocument();
|
||||
if (doc) {
|
||||
nsIPresShell *presShell = doc->GetShellAt(0);
|
||||
if (presShell) {
|
||||
NS_IF_ADDREF(*outContext = presShell->GetPresContext());
|
||||
*outFrame = presShell->GetPrimaryFrameFor(contentNode);
|
||||
NS_ASSERTION(*outFrame, "Can't get frame for this dom node");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // GetFrameFromNode
|
||||
|
||||
@@ -71,14 +71,10 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
virtual void GetFrameFromNode(nsIDOMNode* inNode, nsIFrame** outFrame,
|
||||
nsPresContext** outContext);
|
||||
|
||||
PRPackedBool mCanDrop;
|
||||
PRPackedBool mDoingDrag;
|
||||
PRUint32 mDragAction;
|
||||
nsSize mTargetSize;
|
||||
nsCOMPtr<nsISupportsArray> mTransArray;
|
||||
nsCOMPtr<nsIDOMNode> mSourceNode;
|
||||
nsCOMPtr<nsIDOMDocument> mSourceDocument; // the document at the drag source. will be null
|
||||
// if it came from outside the app.
|
||||
|
||||
Reference in New Issue
Block a user