fix for 42635 and related cleanup, r=ben,hyatt

This commit is contained in:
dr%netscape.com 2000-08-09 22:38:46 +00:00
parent 184bb65ca4
commit de9b64bca7
10 changed files with 8 additions and 966 deletions

View File

@ -133,8 +133,6 @@ NS_NewPolylineFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
#ifdef INCLUDE_XUL
#include "nsXULAtoms.h"
#include "nsToolboxFrame.h"
#include "nsToolbarFrame.h"
#include "nsTreeIndentationFrame.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"

View File

@ -133,8 +133,6 @@ NS_NewPolylineFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
#ifdef INCLUDE_XUL
#include "nsXULAtoms.h"
#include "nsToolboxFrame.h"
#include "nsToolbarFrame.h"
#include "nsTreeIndentationFrame.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"

View File

@ -74,9 +74,6 @@ CPPSRCS = \
nsBoxFrame.cpp \
nsProgressMeterFrame.cpp \
nsTitledButtonFrame.cpp \
nsToolbarFrame.cpp \
nsToolbarDragListener.cpp \
nsToolboxFrame.cpp \
nsTreeIndentationFrame.cpp \
nsTreeItemDragCapturer.cpp \
nsSpinnerFrame.cpp \

View File

@ -63,14 +63,11 @@ CPPSRCS= \
nsTextBoxFrame.cpp \
nsFrameNavigator.cpp \
nsRepeatService.cpp \
nsToolbarDragListener.cpp \
nsToolbarItemFrame.cpp \
nsGrippyFrame.cpp \
nsTabFrame.cpp \
nsStackFrame.cpp \
nsDeckFrame.cpp \
nsToolboxFrame.cpp \
nsToolbarFrame.cpp \
nsTreeIndentationFrame.cpp \
nsTreeItemDragCapturer.cpp \
nsXULTreeFrame.cpp \
@ -112,8 +109,6 @@ CPP_OBJS= \
.\$(OBJDIR)\nsImageBoxFrame.obj \
.\$(OBJDIR)\nsRootBoxFrame.obj \
.\$(OBJDIR)\nsStackLayout.obj \
.\$(OBJDIR)\nsToolboxFrame.obj \
.\$(OBJDIR)\nsToolbarFrame.obj \
.\$(OBJDIR)\nsPopupSetFrame.obj \
.\$(OBJDIR)\nsMenuBarFrame.obj \
.\$(OBJDIR)\nsMenuFrame.obj \
@ -136,7 +131,6 @@ CPP_OBJS= \
.\$(OBJDIR)\nsTextBoxFrame.obj \
.\$(OBJDIR)\nsFrameNavigator.obj \
.\$(OBJDIR)\nsRepeatService.obj \
.\$(OBJDIR)\nsToolbarDragListener.obj \
.\$(OBJDIR)\nsToolbarItemFrame.obj \
.\$(OBJDIR)\nsGrippyFrame.obj \
.\$(OBJDIR)\nsTabFrame.obj \

View File

@ -19,7 +19,7 @@
*
* Original Author: David W. Hyatt (hyatt@netscape.com)
*
* Contributor(s):
* Contributor(s): Dan Rosen <dr@netscape.com>
*/
#include "nsMenuListener.h"
@ -79,13 +79,13 @@ nsMenuBarFrame::Release(void)
//
NS_INTERFACE_MAP_BEGIN(nsMenuBarFrame)
NS_INTERFACE_MAP_ENTRY(nsIMenuParent)
NS_INTERFACE_MAP_END_INHERITING(nsToolbarFrame)
NS_INTERFACE_MAP_END_INHERITING(nsBoxFrame)
//
// nsMenuBarFrame cntr
//
nsMenuBarFrame::nsMenuBarFrame(nsIPresShell* aShell):nsToolbarFrame(aShell),
nsMenuBarFrame::nsMenuBarFrame(nsIPresShell* aShell):nsBoxFrame(aShell),
mMenuBarListener(nsnull), mKeyboardNavigator(nsnull),
mIsActive(PR_FALSE), mTarget(nsnull)
{
@ -110,7 +110,7 @@ nsMenuBarFrame::Init(nsIPresContext* aPresContext,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsToolbarFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
// XXX hack
mPresContext = aPresContext;
@ -680,5 +680,5 @@ nsMenuBarFrame::Destroy(nsIPresContext* aPresContext)
NS_IF_RELEASE(mMenuBarListener);
return nsToolbarFrame::Destroy(aPresContext);
return nsBoxFrame::Destroy(aPresContext);
}

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* Dean Tessman <dean_tessman@hotmail.com>
* Dan Rosen <dr@netscape.com>
*/
//
@ -33,7 +34,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
#include "nsToolbarFrame.h"
#include "nsBoxFrame.h"
#include "nsMenuBarListener.h"
#include "nsMenuListener.h"
#include "nsIMenuParent.h"
@ -44,7 +45,7 @@ class nsIMenuFrame;
nsresult NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsIFrame** aResult) ;
class nsMenuBarFrame : public nsToolbarFrame, public nsIMenuParent
class nsMenuBarFrame : public nsBoxFrame, public nsIMenuParent
{
public:
nsMenuBarFrame(nsIPresShell* aShell);

View File

@ -1,390 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
//
// Mike Pinkerton
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsToolbarFrame.h"
#include "nsCSSRendering.h"
#include "nsToolbarDragListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMDragListener.h"
#include "nsIContent.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
#include "nsIViewManager.h"
#include "nsXULAtoms.h"
#include "nsINameSpaceManager.h"
#define TEMP_HACK_FOR_BUG_11291 1
#if TEMP_HACK_FOR_BUG_11291
// for temp fix of bug 11291. This should really be in JavaScript, I think.
#include "nsIDOMNodeList.h"
#include "nsIDOMElement.h"
class nsTEMPDragGestureEater : public nsIDOMDragListener
{
public:
// default ctor and dtor
nsTEMPDragGestureEater ( ) ;
virtual ~nsTEMPDragGestureEater() { };
// interfaces for addref and release and queryinterface
NS_DECL_ISUPPORTS
// nsIDOMMouseListener
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
virtual nsresult DragEnter(nsIDOMEvent* aMouseEvent);
virtual nsresult DragOver(nsIDOMEvent* aMouseEvent);
virtual nsresult DragExit(nsIDOMEvent* aMouseEvent);
virtual nsresult DragDrop(nsIDOMEvent* aMouseEvent);
virtual nsresult DragGesture(nsIDOMEvent* aMouseEvent);
}; // class nsTEMPDragGestureEater
NS_IMPL_ADDREF(nsTEMPDragGestureEater)
NS_IMPL_RELEASE(nsTEMPDragGestureEater)
NS_IMPL_QUERY_INTERFACE2(nsTEMPDragGestureEater, nsIDOMEventListener, nsIDOMDragListener)
nsTEMPDragGestureEater :: nsTEMPDragGestureEater ( )
{
NS_INIT_REFCNT();
}
nsresult
nsTEMPDragGestureEater :: HandleEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult
nsTEMPDragGestureEater::DragGesture(nsIDOMEvent* aMouseEvent)
{
// we want the text widget to see this event, but not anyone above us that
// might be registered as a listener for drags. Therefore, don't
// allow this event to bubble.
aMouseEvent->PreventBubble();
return NS_ERROR_BASE; // means I AM consuming event
}
nsresult
nsTEMPDragGestureEater::DragEnter(nsIDOMEvent* aMouseEvent)
{
return NS_OK; // means I am NOT consuming event
}
nsresult
nsTEMPDragGestureEater::DragOver(nsIDOMEvent* aMouseEvent)
{
return NS_OK; // means I am NOT consuming event
}
nsresult
nsTEMPDragGestureEater::DragExit(nsIDOMEvent* aMouseEvent)
{
return NS_OK; // means I am NOT consuming event
}
nsresult
nsTEMPDragGestureEater::DragDrop(nsIDOMEvent* aMouseEvent)
{
return NS_OK; // means I am NOT consuming event
}
#endif /* TEMP_HACK_FOR_BUG_11291 */
#ifdef XP_MAC
#pragma mark -
#endif
//
// NS_NewToolbarFrame
//
// Creates a new Toolbar frame and returns it in |aNewFrame|
//
nsresult
NS_NewToolbarFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsToolbarFrame* it = new (aPresShell) nsToolbarFrame (aPresShell);
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
// it->SetFlags(aFlags);
* aNewFrame = it;
return NS_OK;
} // NS_NewToolbarFrame
//
// nsToolbarFrame ctor
//
// Most of the work need to be delayed until Init(). Lame!
//
nsToolbarFrame :: nsToolbarFrame (nsIPresShell* aShell):nsBoxFrame(aShell),
mXDropLoc ( -1 )
{
}
//
// nsToolbarFrame dtor
//
// Cleanup. Remove our registered event listener from the content model.
//
nsToolbarFrame :: ~nsToolbarFrame ( )
{
nsCOMPtr<nsIContent> content;
GetContent(getter_AddRefs(content));
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
// NOTE: the last Remove will delete the drag listener
if ( receiver ) {
receiver->RemoveEventListener(NS_ConvertASCIItoUCS2("dragover"), mDragListener, PR_TRUE);
receiver->RemoveEventListener(NS_ConvertASCIItoUCS2("dragexit"), mDragListener, PR_TRUE);
}
}
//
// Init
//
// Setup event capturers for drag and drop. Our frame's lifetime is bounded by the
// lifetime of the content model, so we're guaranteed that the content node won't go away on us. As
// a result, our drag capturer can't go away before the frame is deleted. Since the content
// node holds owning references to our drag capturer, which we tear down in the dtor, there is no
// need to hold an owning ref to it ourselves.
//
NS_IMETHODIMP
nsToolbarFrame::Init ( nsIPresContext* aPresContext, nsIContent* aContent,
nsIFrame* aParent, nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
nsCOMPtr<nsIContent> content;
GetContent(getter_AddRefs(content));
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));
// register our drag over and exit capturers. These annotate the content object
// with enough info to determine where the drop would happen so that JS down the
// line can do the right thing.
mDragListener = new nsToolbarDragListener(this, aPresContext);
receiver->AddEventListener(NS_ConvertASCIItoUCS2("dragover"), mDragListener, PR_TRUE);
receiver->AddEventListener(NS_ConvertASCIItoUCS2("dragexit"), mDragListener, PR_TRUE);
#if 0 //TEMP_HACK_FOR_BUG_11291
// Ok, this is a hack until Ender lands. We need to have a mouse listener on text widgets
// in order to make sure that mouseDowns within the text widget don't bubble up to the toolbar
// listener. This would cause problems where selecting text and moving the mouse outside the text
// widget and into the toolbar would start a drag (bug #11291)
nsCOMPtr<nsIDOMElement> element ( do_QueryInterface(content) );
if ( element ) {
nsCOMPtr<nsIDOMNodeList> inputList;
element->GetElementsByTagName("INPUT", getter_AddRefs(inputList));
if ( inputList ) {
PRUint32 length = 0;
inputList->GetLength(&length);
for ( PRUint32 i = 0; i < length; ++i ) {
nsCOMPtr<nsIDOMNode> node;
inputList->Item(i, getter_AddRefs(node));
receiver = do_QueryInterface(node);
if ( receiver )
receiver->AddEventListenerByIID(new nsTEMPDragGestureEater, NS_GET_IID(nsIDOMDragListener));
// yes, i know this will leak. That's ok, i don't care because this code will go away
}
}
}
#endif
return rv;
}
//
// Paint
//
// Used to draw the drop feedback based on attributes set by the drag event capturer
//
NS_IMETHODIMP
nsToolbarFrame :: Paint ( nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
nsresult res = nsBoxFrame::Paint ( aPresContext, aRenderingContext, aDirtyRect, aWhichLayer );
if (mXDropLoc != -1) {
// go looking for the psuedo-style that describes the drop feedback marker. If we don't
// have it yet, go looking for it.
if (!mMarkerStyle) {
nsCOMPtr<nsIAtom> atom ( getter_AddRefs(NS_NewAtom(":-moz-drop-marker")) );
aPresContext->ProbePseudoStyleContextFor(mContent, atom, mStyleContext,
PR_FALSE, getter_AddRefs(mMarkerStyle));
}
nscolor color;
if (mMarkerStyle) {
const nsStyleColor* styleColor =
NS_STATIC_CAST(const nsStyleColor*, mMarkerStyle->GetStyleData(eStyleStruct_Color));
color = styleColor->mColor;
} else {
color = NS_RGB(0,0,0);
}
// draw different drop feedback depending on if we have subitems or not
int numChildren = 0;
mContent->ChildCount(numChildren);
if ( numChildren ) {
aRenderingContext.SetColor(color);
nsRect dividingLine ( mXDropLoc, 0, 40, mRect.height );
aRenderingContext.FillRect(dividingLine);
}
else
aRenderingContext.DrawRect ( mRect );
}
return res;
} // Paint
//
// HandleEvent
//
// Process events that come to this frame. If they end up here, they are
// almost certainly drag and drop events.
//
NS_IMETHODIMP
nsToolbarFrame :: HandleEvent ( nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
if ( !aEvent )
return nsEventStatus_eIgnore;
//XXX this needs to change when I am really handling the D&D events
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
} // HandleEvent
#if NOT_YET_NEEDED
/**
* Call this when styles change
*/
void
nsToolbarFrame::ReResolveStyles(nsIPresContext* aPresContext,
PRInt32 aParentChange,
nsStyleChangeList* aChangeList,
PRInt32* aLocalChange)
{
// style that draw an Marker around the button
// see if the Marker has changed.
/*nsCOMPtr<nsIStyleContext> oldMarker = mMarkerStyle;
nsCOMPtr<nsIAtom> atom ( getter_AddRefs(NS_NewAtom(":-moz-marker")) );
aPresContext->ProbePseudoStyleContextFor(mContent, atom, mStyleContext,
PR_FALSE,
getter_AddRefs(mMarkerStyle));
if ((mMarkerStyle && oldMarker) && (mMarkerStyle != oldMarker)) {
nsFrame::CaptureStyleChangeFor(this, oldMarker, mMarkerStyle,
aParentChange, aChangeList, aLocalChange);
}*/
}
#endif
////////////////////////////////////////////////////////////////////////
// This is temporary until the bubling of event for CSS actions work
////////////////////////////////////////////////////////////////////////
static void ForceDrawFrame(nsIPresContext* aPresContext, nsIFrame * aFrame);
static void ForceDrawFrame(nsIPresContext* aPresContext, nsIFrame * aFrame)
{
if (aFrame == nsnull) {
return;
}
nsRect rect;
nsIView * view;
nsPoint pnt;
aFrame->GetOffsetFromView(aPresContext, pnt, &view);
aFrame->GetRect(rect);
rect.x = pnt.x;
rect.y = pnt.y;
if (view) {
nsCOMPtr<nsIViewManager> viewMgr;
view->GetViewManager(*getter_AddRefs(viewMgr));
if (viewMgr)
viewMgr->UpdateView(view, rect, NS_VMREFRESH_AUTO_DOUBLE_BUFFER | NS_VMREFRESH_IMMEDIATE);
}
}
//
// AttributeChanged
//
// Track several attributes set by the d&d drop feedback tracking mechanism. The first
// is the "tb-triggerrepaint" attribute so JS can trigger a repaint when it
// needs up update the drop feedback. The second is the x (or y, if bar is vertical)
// coordinate of where the drop feedback bar should be drawn.
//
NS_IMETHODIMP
nsToolbarFrame :: AttributeChanged ( nsIPresContext* aPresContext, nsIContent* aChild,
PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aHint)
{
nsresult rv = NS_OK;
if ( aAttribute == nsXULAtoms::ddTriggerRepaint )
ForceDrawFrame ( aPresContext, this );
else if ( aAttribute == nsXULAtoms::ddDropLocationCoord ) {
nsAutoString attribute;
aChild->GetAttribute ( kNameSpaceID_None, aAttribute, attribute );
char* iHateNSString = attribute.ToNewCString();
mXDropLoc = atoi( iHateNSString );
nsMemory::Free ( iHateNSString );
}
else
rv = nsBoxFrame::AttributeChanged ( aPresContext, aChild, aNameSpaceID, aAttribute, aHint );
return rv;
} // AttributeChanged

View File

@ -1,126 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
//
// Mike Pinkerton
// Netscape Communications
//
// nsToolbarFrame is a layout object that contains items (specified as
// children in the DOM). The layout for toolbars is a little complicated, but
// it basically just lays out its children in as a box. Toolbars themselves
// don't know anything about grippies (as in 4.x) but are associated with them
// through toolboxes. This allows a developer to create a standalone toolbar
// (for inclusion in a webpage), which obviously doesn't need to have a grippy.
//
// As mentioned above, the Toolbar expects its toolbars to be its children in
// the DOM. The exact structure of the children is documented on:
// http://www.mozilla.org/xpfe/DMWSpecNew.html
//
// This implementation of toolbars now uses evaughan's box code for layout
// of its children and to determine its size.
//
#ifndef nsToolbarFrame_h__
#define nsToolbarFrame_h__
#define TOOLBARITEM_MIME "moz/toolbaritem"
#define TOOLBAR_MIME "moz/toolbar"
#include "nsCOMPtr.h"
#include "nsBoxFrame.h"
#include "nsIStyleContext.h"
class nsIContent;
class nsIPresContext;
class nsIFrame;
class nsToolbarDragListener;
class nsToolbarFrame : public nsBoxFrame
{
public:
friend nsresult NS_NewToolbarFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
NS_IMETHOD Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* asPrevInFlow);
// nsIHTMLReflow overrides
NS_IMETHOD Paint(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint) ;
NS_IMETHOD HandleEvent ( nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
#if WTF_IS_THIS
//¥¥¥ not sure at all where this comes from. I asked rods, no reply yet.
virtual void ReResolveStyles(nsIPresContext* aPresContext,
PRInt32 aParentChange,
nsStyleChangeList* aChangeList,
PRInt32* aLocalChange);
#endif
#if 0
void SetDropfeedbackLocation(nscoord aX) { mXDropLoc = aX; }
#endif
NS_IMETHOD GetFrameName(nsString& aResult) const
{
aResult.AssignWithConversion("Toolbar");
return NS_OK;
}
protected:
nsToolbarFrame(nsIPresShell* aShell);
virtual ~nsToolbarFrame();
// pass-by-value not allowed for a coordinator because it corresponds 1-to-1
// with an element in the UI.
nsToolbarFrame ( const nsToolbarFrame& aFrame ) ; // DO NOT IMPLEMENT
nsToolbarFrame& operator= ( const nsToolbarFrame& aFrame ) ; // DO NOT IMPLEMENT
// our event handler registered with the content model. See the discussion
// in Init() for why this is a weak ref.
nsToolbarDragListener* mDragListener;
// only used during drag and drop for drop feedback. These are not
// guaranteed to be meaningful when no drop is underway.
PRInt32 mXDropLoc;
nsCOMPtr<nsIStyleContext> mMarkerStyle;
}; // class nsToolbarFrame
#endif

View File

@ -1,286 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
//
// Mike Pinkerton
// Netscape Communications
//
// Significant portions of the collapse/expanding code donated by Chris Lattner
// (sabre@skylab.org). Thanks Chris!
//
// See documentation in associated header file
//
#include "nsToolboxFrame.h"
#include "nsToolbarFrame.h" // needed for MIME definitions
#include "nsIStyleContext.h"
#include "nsCSSRendering.h"
#include "nsIReflowCommand.h"
#include "nsHTMLIIDs.h"
#include "nsIPresContext.h"
#include "nsIWidget.h"
#include "nsINameSpaceManager.h"
#include "nsBoxLayoutState.h"
#include "nsIServiceManager.h"
#include "nsWidgetsCID.h"
#include "nsIDragService.h"
#include "nsIDragSession.h"
#include "nsITransferable.h"
#include "nsIFormatConverter.h"
#include "nsCOMPtr.h"
#include "nsIDOMUIEvent.h"
#include "nsIDOMDragListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h"
#include "nsISupportsPrimitives.h"
#include "nsISupportsArray.h"
#include "nsHTMLAtoms.h"
// Drag & Drop, Clipboard Support
static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID);
static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID);
NS_IMPL_ADDREF(nsToolboxFrame::DragListenerDelegate);
NS_IMPL_RELEASE(nsToolboxFrame::DragListenerDelegate);
NS_IMPL_QUERY_INTERFACE2(nsToolboxFrame::DragListenerDelegate, nsIDOMDragListener, nsIDOMEventListener)
//
// NS_NewToolboxFrame
//
// Creates a new toolbox frame and returns it in |aNewFrame|
//
nsresult
NS_NewToolboxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsToolboxFrame* it = new (aPresShell) nsToolboxFrame (aPresShell);
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
//it->SetFlags(aFlags);
*aNewFrame = it;
return NS_OK;
} // NS_NewToolboxFrame
//
// nsToolboxFrame cntr
//
// Init, if necessary
//
nsToolboxFrame :: nsToolboxFrame (nsIPresShell* aShell):nsBoxFrame(aShell)
, mDragListenerDelegate(nsnull)
{
}
//
// nsToolboxFrame dstr
//
// Cleanup, as necessary
//
nsToolboxFrame :: ~nsToolboxFrame ( )
{
if (mDragListenerDelegate) {
mDragListenerDelegate->NotifyFrameDestroyed();
NS_RELEASE(mDragListenerDelegate);
}
}
NS_IMETHODIMP
nsToolboxFrame::Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
// Register the delegate as a drag listener.
mDragListenerDelegate = new DragListenerDelegate(this);
if (! mDragListenerDelegate)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mDragListenerDelegate);
nsCOMPtr<nsIContent> content;
rv = GetContent(getter_AddRefs(content));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(content));
reciever->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMDragListener*, mDragListenerDelegate), NS_GET_IID(nsIDOMDragListener));
return rv;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::HandleEvent(nsIDOMEvent* aEvent)
{
//printf("nsToolbarDragListener::HandleEvent\n");
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::DragEnter(nsIDOMEvent* aDragEvent)
{
nsIDragService* dragService;
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
NS_GET_IID(nsIDragService),
(nsISupports **)&dragService);
if ( NS_SUCCEEDED(rv) ) {
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
if ( dragSession ) {
PRBool flavorSupported = PR_FALSE;
dragSession->IsDataFlavorSupported(TOOLBAR_MIME, &flavorSupported);
if ( flavorSupported ) {
dragSession->SetCanDrop(PR_TRUE);
rv = NS_ERROR_BASE; // consume event
}
}
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
} else {
rv = NS_OK;
}
return rv;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::DragOver(nsIDOMEvent* aDragEvent)
{
// now tell the drag session whether we can drop here
nsIDragService* dragService;
nsresult rv = nsServiceManager::GetService(kCDragServiceCID, NS_GET_IID(nsIDragService),
(nsISupports **)&dragService);
if ( NS_SUCCEEDED(rv) ) {
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
if ( dragSession ) {
PRBool flavorSupported = PR_FALSE;
dragSession->IsDataFlavorSupported(TOOLBAR_MIME, &flavorSupported);
if ( flavorSupported ) {
// Right here you need to figure out where the mouse is
// and whether you can drop here
dragSession->SetCanDrop(PR_TRUE);
rv = NS_ERROR_BASE; // consume event
}
}
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
}
// NS_OK means event is NOT consumed
return rv;
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::DragExit(nsIDOMEvent* aDragEvent)
{
return NS_ERROR_BASE; // consumes event
}
////////////////////////////////////////////////////////////////////////
nsresult
nsToolboxFrame::DragDrop(nsIDOMEvent* aMouseEvent)
{
// Create drag service for getting state of drag
nsIDragService* dragService;
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
NS_GET_IID(nsIDragService),
(nsISupports **)&dragService);
if (NS_OK == rv) {
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
if (dragSession) {
// Create transferable for getting the drag data
nsCOMPtr<nsITransferable> trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
NS_GET_IID(nsITransferable),
(void**) getter_AddRefs(trans));
if ( NS_SUCCEEDED(rv) && trans ) {
// Add the toolbar Flavor to the transferable, because that is the only type of data we are
// looking for at the moment.
trans->AddDataFlavor(TOOLBAR_MIME);
// Fill the transferable with data for each drag item in succession
PRUint32 numItems = 0;
if (NS_SUCCEEDED(dragSession->GetNumDropItems(&numItems))) {
//printf("Num Drop Items %d\n", numItems);
PRUint32 i;
for (i=0;i<numItems;++i) {
if (NS_SUCCEEDED(dragSession->GetData(trans, i))) {
// Get the string data out of the transferable as a nsISupportsString.
nsCOMPtr<nsISupports> data;
PRUint32 len;
char* whichFlavor = nsnull;
trans->GetAnyTransferData(&whichFlavor, getter_AddRefs(data), &len);
nsCOMPtr<nsISupportsString> dataAsString ( do_QueryInterface(data) );
// If the string was not empty then make it so.
if ( dataAsString ) {
char* stuffToPaste;
dataAsString->ToString ( &stuffToPaste );
printf("Dropped: %s\n", stuffToPaste);
dragSession->SetCanDrop(PR_TRUE);
}
nsMemory::Free ( whichFlavor );
}
} // foreach drag item
}
} // if valid transferable
} // if valid drag session
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
} // if valid drag service
return NS_ERROR_BASE; // consume the event;
}

View File

@ -1,144 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
//
// Mike Pinkerton
// Netscape Communications
//
// nsToolboxFrame is a layout object that contains one or more toolbar frames
// (specified as children in the DOM). These toolbars are laid out one on top
// of the other, and can be of varying heights but are all of the same width
// (the full width of the toolbox). Each toolbar is associated with a "grippy"
// which can be used to either collapse a particular toolbar or as a handle to
// pick up and move a toolbar to a new position within the toolbox. When toolbars
// are collapsed, it's grippy is moved to the bottom of the box and laid on
// its side. Clicking again on the grippy will reinstate the toolbar to its previous
// position in the toolbox.
//
// As mentioned above, the toolbox expects its toolbars to be its children in
// the DOM. The exact structure of the children is documented on:
// http://www.mozilla.org/xpfe/DMWSpecNew.html
//
#ifndef nsToolBoxFrame_h___
#define nsToolBoxFrame_h___
#include "nsIDOMDragListener.h"
#include "nsHTMLContainerFrame.h"
#include "nsIStyleContext.h"
#include "nsIContent.h"
#include "nsXULAtoms.h"
#include "nsCOMPtr.h"
#include "nsBoxFrame.h"
class nsToolboxFrame : public nsBoxFrame
{
public:
friend nsresult NS_NewToolboxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
NS_IMETHOD Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
/*BEGIN implementations of dragevent handler interface*/
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
virtual nsresult DragEnter(nsIDOMEvent* aDragEvent);
virtual nsresult DragOver(nsIDOMEvent* aDragEvent);
virtual nsresult DragExit(nsIDOMEvent* aDragEvent);
virtual nsresult DragDrop(nsIDOMEvent* aDragEvent);
virtual nsresult DragGesture(nsIDOMEvent* aDragEvent) { return NS_OK; }
/*END implementations of dragevent handler interface*/
NS_IMETHOD GetFrameName(nsString& aResult) const
{
aResult.AssignWithConversion("Toolbox");
return NS_OK;
}
protected:
nsToolboxFrame(nsIPresShell* aShell);
virtual ~nsToolboxFrame();
class DragListenerDelegate : public nsIDOMDragListener
{
protected:
nsToolboxFrame* mFrame;
public:
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMEventListener interface
virtual nsresult HandleEvent(nsIDOMEvent* aEvent)
{
return mFrame ? mFrame->HandleEvent(aEvent) : NS_OK;
}
virtual nsresult DragGesture(nsIDOMEvent* aEvent)
{
return mFrame ? mFrame->DragGesture(aEvent) : NS_OK;
}
// nsIDOMDragListener interface
virtual nsresult DragEnter(nsIDOMEvent* aMouseEvent)
{
return mFrame ? mFrame->DragEnter(aMouseEvent) : NS_OK;
}
virtual nsresult DragOver(nsIDOMEvent* aMouseEvent)
{
return mFrame ? mFrame->DragOver(aMouseEvent) : NS_OK;
}
virtual nsresult DragExit(nsIDOMEvent* aMouseEvent)
{
return mFrame ? mFrame->DragExit(aMouseEvent) : NS_OK;
}
virtual nsresult DragDrop(nsIDOMEvent* aMouseEvent)
{
return mFrame ? mFrame->DragDrop(aMouseEvent) : NS_OK;
}
// Implementation methods
DragListenerDelegate(nsToolboxFrame* aFrame) : mFrame(aFrame)
{
NS_INIT_REFCNT();
}
virtual ~DragListenerDelegate() {}
void NotifyFrameDestroyed() { mFrame = nsnull; }
};
DragListenerDelegate* mDragListenerDelegate;
// pass-by-value not allowed for a toolbox because it corresponds 1-to-1
// with an element in the UI.
nsToolboxFrame ( const nsToolboxFrame& aFrame ) ; // DO NOT IMPLEMENT
nsToolboxFrame& operator= ( const nsToolboxFrame& aFrame ) ; // DO NOT IMPLEMENT
}; // class nsToolboxFrame
#endif