1999-06-30 22:17:43 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* 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/
|
1999-06-30 22:17:43 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* 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.
|
1999-06-30 22:17:43 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 03:40:37 +00:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-06-30 22:17:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsSplitterFrame.h"
|
|
|
|
#include "nsXULAtoms.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIXMLContent.h"
|
|
|
|
#include "nsDocument.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsScrollbarButtonFrame.h"
|
1999-09-05 20:46:59 +00:00
|
|
|
#include "nsIDOMMouseListener.h"
|
|
|
|
#include "nsIDOMMouseMotionListener.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIScrollableView.h"
|
1999-11-03 07:11:45 +00:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
1999-09-05 20:46:59 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsFrameNavigator.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-09-14 22:17:19 +00:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
const PRInt32 kMaxZ = 0x7fffffff; //XXX: Shouldn't there be a define somewhere for MaxInt for PRInt32
|
|
|
|
|
1999-06-30 22:17:43 +00:00
|
|
|
|
1999-09-05 20:46:59 +00:00
|
|
|
class nsSplitterInfo {
|
|
|
|
public:
|
|
|
|
nscoord min;
|
|
|
|
nscoord max;
|
|
|
|
nscoord current;
|
|
|
|
nscoord changed;
|
|
|
|
nsIFrame* child;
|
|
|
|
float flex;
|
|
|
|
PRInt32 index;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsSplitterFrameImpl : public nsIDOMMouseListener, public nsIDOMMouseMotionListener {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsSplitterFrameImpl(nsSplitterFrame* aSplitter)
|
|
|
|
{
|
|
|
|
mSplitter = aSplitter;
|
|
|
|
mRefCnt = 0;
|
|
|
|
mPressed = PR_FALSE;
|
|
|
|
}
|
1999-09-10 08:46:17 +00:00
|
|
|
virtual ~nsSplitterFrameImpl() {}
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
// mouse listener
|
|
|
|
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
|
|
|
|
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
|
|
|
|
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }
|
1999-09-22 03:11:47 +00:00
|
|
|
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent) { return MouseMove(aMouseEvent); }
|
1999-09-05 20:46:59 +00:00
|
|
|
virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
|
|
|
|
|
|
|
|
// mouse motion listener
|
|
|
|
virtual nsresult MouseMove(nsIDOMEvent* aMouseEvent);
|
|
|
|
virtual nsresult DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }
|
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
void MouseDrag(nsIPresContext* aPresContext, nsGUIEvent* aEvent);
|
|
|
|
void MouseUp(nsIPresContext* aPresContext, nsGUIEvent* aEvent);
|
1999-09-05 20:46:59 +00:00
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
void AdjustChildren(nsIPresContext* aPresContext);
|
|
|
|
void AdjustChildren(nsIPresContext* aPresContext, nsSplitterInfo* aChildInfos, PRInt32 aCount, PRBool aIsHorizontal);
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
void AddRemoveSpace(nscoord aDiff,
|
|
|
|
nsSplitterInfo* aChildInfos,
|
|
|
|
PRInt32 aCount,
|
|
|
|
PRInt32& aSpaceLeft);
|
|
|
|
|
1999-10-26 04:44:41 +00:00
|
|
|
void ResizeChildTo(nsIPresContext* aPresContext,
|
|
|
|
nscoord& aDiff,
|
1999-09-05 20:46:59 +00:00
|
|
|
nsSplitterInfo* aChildrenBeforeInfos,
|
|
|
|
nsSplitterInfo* aChildrenAfterInfos,
|
|
|
|
PRInt32 aChildrenBeforeCount,
|
|
|
|
PRInt32 aChildrenAfterCount,
|
|
|
|
PRBool aBounded);
|
|
|
|
|
|
|
|
void UpdateState();
|
|
|
|
|
|
|
|
void AddListener();
|
|
|
|
void RemoveListener();
|
|
|
|
|
1999-09-08 23:51:02 +00:00
|
|
|
enum ResizeType { Closest, Farthest, Grow };
|
1999-09-05 20:46:59 +00:00
|
|
|
enum State { Open, Collapsed, Dragging };
|
1999-09-14 22:17:19 +00:00
|
|
|
enum CollapseDirection { Before, After, None };
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
ResizeType GetResizeBefore();
|
|
|
|
ResizeType GetResizeAfter();
|
|
|
|
State GetState();
|
|
|
|
|
1999-10-26 04:44:41 +00:00
|
|
|
nsresult CaptureMouse(nsIPresContext* aPresContext, PRBool aGrabMouseEvents);
|
|
|
|
PRBool IsMouseCaptured(nsIPresContext* aPresContext);
|
1999-09-05 20:46:59 +00:00
|
|
|
void Reverse(nsSplitterInfo*& aIndexes, PRInt32 aCount);
|
1999-09-14 22:17:19 +00:00
|
|
|
CollapseDirection GetCollapseDirection();
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
nsSplitterFrame* mSplitter;
|
|
|
|
PRBool mDidDrag;
|
|
|
|
nscoord mDragStartPx;
|
|
|
|
nscoord mCurrentPos;
|
|
|
|
nsBoxFrame* mParentBox;
|
|
|
|
PRBool mPressed;
|
|
|
|
nsSplitterInfo* mChildInfosBefore;
|
|
|
|
nsSplitterInfo* mChildInfosAfter;
|
|
|
|
PRInt32 mChildInfosBeforeCount;
|
|
|
|
PRInt32 mChildInfosAfterCount;
|
|
|
|
State mState;
|
|
|
|
nsString mCollapsedChildStyle;
|
|
|
|
nsCOMPtr<nsIContent> mCollapsedChild;
|
|
|
|
nscoord mSplitterPos;
|
1999-09-08 23:51:02 +00:00
|
|
|
nscoord mSplitterViewPos;
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(nsSplitterFrameImpl, nsIDOMMouseListener, nsIDOMMouseMotionListener)
|
|
|
|
|
|
|
|
nsSplitterFrameImpl::ResizeType
|
|
|
|
nsSplitterFrameImpl::GetResizeBefore()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mSplitter->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
nsString value;
|
|
|
|
content->GetAttribute(kNameSpaceID_None, nsXULAtoms::resizebefore, value);
|
1999-09-08 23:51:02 +00:00
|
|
|
if (value.EqualsIgnoreCase("farthest"))
|
|
|
|
return Farthest;
|
1999-09-05 20:46:59 +00:00
|
|
|
else
|
|
|
|
return Closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplitterFrameImpl::ResizeType
|
|
|
|
nsSplitterFrameImpl::GetResizeAfter()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mSplitter->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
nsString value;
|
|
|
|
content->GetAttribute(kNameSpaceID_None, nsXULAtoms::resizeafter, value);
|
1999-09-08 23:51:02 +00:00
|
|
|
if (value.EqualsIgnoreCase("farthest"))
|
|
|
|
return Farthest;
|
1999-09-05 20:46:59 +00:00
|
|
|
else if (value.EqualsIgnoreCase("grow"))
|
|
|
|
return Grow;
|
|
|
|
else
|
|
|
|
return Closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplitterFrameImpl::State
|
|
|
|
nsSplitterFrameImpl::GetState()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mSplitter->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
nsString value;
|
|
|
|
content->GetAttribute(kNameSpaceID_None, nsXULAtoms::state, value);
|
|
|
|
if (value.EqualsIgnoreCase("dragging"))
|
|
|
|
return Dragging;
|
|
|
|
else if (value.EqualsIgnoreCase("collapsed"))
|
|
|
|
return Collapsed;
|
|
|
|
else
|
|
|
|
return Open;
|
|
|
|
|
|
|
|
}
|
1999-06-30 22:17:43 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// NS_NewSplitterFrame
|
|
|
|
//
|
|
|
|
// Creates a new Toolbar frame and returns it in |aNewFrame|
|
|
|
|
//
|
|
|
|
nsresult
|
1999-12-04 23:49:50 +00:00
|
|
|
NS_NewSplitterFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
|
1999-06-30 22:17:43 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-04 23:49:50 +00:00
|
|
|
nsSplitterFrame* it = new (aPresShell) nsSplitterFrame;
|
1999-06-30 22:17:43 +00:00
|
|
|
if (nsnull == it)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
} // NS_NewSplitterFrame
|
|
|
|
|
1999-09-05 20:46:59 +00:00
|
|
|
nsSplitterFrame::nsSplitterFrame()
|
|
|
|
{
|
|
|
|
mImpl = new nsSplitterFrameImpl(this);
|
|
|
|
mImpl->AddRef();
|
|
|
|
mImpl->mChildInfosAfter = nsnull;
|
|
|
|
mImpl->mChildInfosBefore = nsnull;
|
|
|
|
mImpl->mState = nsSplitterFrameImpl::Open;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplitterFrame::~nsSplitterFrame()
|
|
|
|
{
|
1999-09-10 23:38:58 +00:00
|
|
|
mImpl->RemoveListener();
|
1999-09-05 20:46:59 +00:00
|
|
|
mImpl->Release();
|
|
|
|
}
|
|
|
|
|
1999-12-22 01:57:29 +00:00
|
|
|
//
|
|
|
|
// QueryInterface
|
|
|
|
//
|
|
|
|
// Since we inherit from a base class with its own implementation of QI, we
|
|
|
|
// need to rely on that for the other interfaces supported, yet we still want
|
|
|
|
// to use the map macros. Currently, there is no macro to let you use the
|
|
|
|
// inherited version of QI, so we cheat. Hopefully this will change in the near
|
|
|
|
// future (pinkerton)
|
|
|
|
//
|
1999-12-21 19:28:15 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsSplitterFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
|
1999-12-22 01:57:29 +00:00
|
|
|
foundInterface = 0;
|
|
|
|
nsresult status;
|
|
|
|
if ( !foundInterface )
|
|
|
|
status = nsBoxFrame::QueryInterface(aIID, NS_REINTERPRET_CAST(void**,&foundInterface)); \
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_ADDREF(foundInterface);
|
|
|
|
status = NS_OK;
|
|
|
|
}
|
|
|
|
*aInstancePtr = foundInterface;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-12-21 19:28:15 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
nsresult NS_CreateAnonymousNode(nsIContent* aParent, nsIAtom* aTag, PRInt32 aNameSpaceId, nsCOMPtr<nsIContent>& aNewNode);
|
|
|
|
|
1999-06-30 22:17:43 +00:00
|
|
|
/**
|
|
|
|
* Anonymous interface
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSplitterFrame::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren)
|
|
|
|
{
|
|
|
|
// if not content the create some anonymous content
|
|
|
|
PRInt32 count = 0;
|
|
|
|
mContent->ChildCount(count);
|
|
|
|
|
1999-09-08 23:51:02 +00:00
|
|
|
// create a grippy if we have no children and teh collapse attribute is before or after.
|
1999-09-14 22:17:19 +00:00
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
nsSplitterFrameImpl::CollapseDirection d = mImpl->GetCollapseDirection();
|
|
|
|
if (d != nsSplitterFrameImpl::None)
|
1999-09-08 23:51:02 +00:00
|
|
|
{
|
|
|
|
// create a spring
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
NS_CreateAnonymousNode(mContent, nsXULAtoms::spring, nsXULAtoms::nameSpaceID, content);
|
|
|
|
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, "100%", PR_FALSE);
|
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
|
|
|
|
// a grippy
|
|
|
|
NS_CreateAnonymousNode(mContent, nsXULAtoms::grippy, nsXULAtoms::nameSpaceID, content);
|
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
|
|
|
|
// create a spring
|
|
|
|
NS_CreateAnonymousNode(mContent, nsXULAtoms::spring, nsXULAtoms::nameSpaceID, content);
|
|
|
|
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, "100%", PR_FALSE);
|
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
}
|
1999-06-30 22:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-14 22:17:19 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrame::GetCursor(nsIPresContext* aPresContext,
|
1999-09-14 22:17:19 +00:00
|
|
|
nsPoint& aPoint,
|
|
|
|
PRInt32& aCursor)
|
|
|
|
{
|
|
|
|
if (IsHorizontal())
|
|
|
|
aCursor = NS_STYLE_CURSOR_N_RESIZE;
|
|
|
|
else
|
|
|
|
aCursor = NS_STYLE_CURSOR_W_RESIZE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-30 22:17:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSplitterFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
1999-10-15 23:16:45 +00:00
|
|
|
PRInt32 aNameSpaceID,
|
1999-06-30 22:17:43 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aPresContext, aChild,
|
1999-10-15 23:16:45 +00:00
|
|
|
aNameSpaceID, aAttribute, aHint);
|
1999-06-30 22:17:43 +00:00
|
|
|
// if the alignment changed. Let the grippy know
|
|
|
|
if (aAttribute == nsHTMLAtoms::align) {
|
|
|
|
// tell the slider its attribute changed so it can
|
|
|
|
// update itself
|
|
|
|
nsIFrame* grippy = nsnull;
|
|
|
|
nsScrollbarButtonFrame::GetChildWithTag(nsXULAtoms::grippy, this, grippy);
|
|
|
|
if (grippy)
|
1999-10-15 23:16:45 +00:00
|
|
|
grippy->AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
|
1999-09-05 20:46:59 +00:00
|
|
|
} else if (aAttribute == nsXULAtoms::state) {
|
|
|
|
mImpl->UpdateState();
|
1999-06-30 22:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize us. If we are in a box get our alignment so we know what direction we are
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrame::Init(nsIPresContext* aPresContext,
|
1999-06-30 22:17:43 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
|
1999-10-26 04:44:41 +00:00
|
|
|
// XXX Hack because we need the pres context in some of the event handling functions...
|
1999-11-24 06:03:41 +00:00
|
|
|
mPresContext = aPresContext;
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
nsHTMLContainerFrame::CreateViewForFrame(aPresContext,this,aContext,PR_TRUE);
|
|
|
|
nsIView* view;
|
1999-11-24 06:03:41 +00:00
|
|
|
GetView(aPresContext, &view);
|
1999-09-05 20:46:59 +00:00
|
|
|
view->SetContentTransparency(PR_TRUE);
|
|
|
|
view->SetZIndex(kMaxZ);
|
1999-09-15 02:21:18 +00:00
|
|
|
/*
|
1999-09-14 22:17:19 +00:00
|
|
|
nsWidgetInitData widgetData;
|
|
|
|
widgetData.mWindowType = eWindowType_child;
|
|
|
|
widgetData.mBorderStyle = eBorderStyle_default;
|
|
|
|
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
|
|
|
|
view->CreateWidget(kCChildCID,
|
|
|
|
&widgetData,
|
|
|
|
nsnull);
|
1999-09-15 02:21:18 +00:00
|
|
|
*/
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
mImpl->AddListener();
|
|
|
|
|
1999-06-30 22:17:43 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-18 21:05:43 +00:00
|
|
|
PRBool
|
|
|
|
nsSplitterFrame::GetInitialAlignment()
|
|
|
|
{
|
|
|
|
// find the box we are in
|
|
|
|
nsIFrame* box = nsnull;
|
|
|
|
nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::box, this, box);
|
|
|
|
|
|
|
|
// if no box get the window because it is a box.
|
|
|
|
if (box == nsnull)
|
|
|
|
nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::window, this, box);
|
|
|
|
|
|
|
|
// see if the box is horizontal or vertical
|
|
|
|
if (box) {
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
box->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
nsString value;
|
|
|
|
content->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, value);
|
|
|
|
if (value.EqualsIgnoreCase("vertical"))
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-09-05 20:46:59 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrame::HandlePress(nsIPresContext* aPresContext,
|
1999-09-05 20:46:59 +00:00
|
|
|
nsGUIEvent * aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrame::HandleMultiplePress(nsIPresContext* aPresContext,
|
1999-09-05 20:46:59 +00:00
|
|
|
nsGUIEvent * aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrame::HandleDrag(nsIPresContext* aPresContext,
|
1999-09-05 20:46:59 +00:00
|
|
|
nsGUIEvent * aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrame::HandleRelease(nsIPresContext* aPresContext,
|
1999-09-05 20:46:59 +00:00
|
|
|
nsGUIEvent * aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-26 04:44:41 +00:00
|
|
|
NS_IMETHODIMP nsSplitterFrame::GetFrameForPoint(nsIPresContext* aPresContext,
|
|
|
|
const nsPoint& aPoint,
|
1999-09-05 20:46:59 +00:00
|
|
|
nsIFrame** aFrame)
|
|
|
|
{
|
|
|
|
// if the mouse is captured always return us as the frame.
|
1999-10-26 04:44:41 +00:00
|
|
|
if (mImpl->IsMouseCaptured(aPresContext))
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
*aFrame = this;
|
|
|
|
return NS_OK;
|
|
|
|
} else
|
1999-10-26 04:44:41 +00:00
|
|
|
return nsBoxFrame::GetFrameForPoint(aPresContext, aPoint, aFrame);
|
1999-09-05 20:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrame::HandleEvent(nsIPresContext* aPresContext,
|
1999-09-05 20:46:59 +00:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
mImpl->MouseDrag(aPresContext, aEvent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
1999-09-08 23:51:02 +00:00
|
|
|
mImpl->MouseUp(aPresContext, aEvent);
|
1999-09-05 20:46:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLContainerFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
1999-09-08 23:51:02 +00:00
|
|
|
void
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrameImpl::MouseUp(nsIPresContext* aPresContext, nsGUIEvent* aEvent)
|
1999-09-08 23:51:02 +00:00
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
if (IsMouseCaptured(aPresContext)) {
|
1999-09-08 23:51:02 +00:00
|
|
|
AdjustChildren(aPresContext);
|
|
|
|
AddListener();
|
1999-11-24 06:03:41 +00:00
|
|
|
CaptureMouse(aPresContext, PR_FALSE);
|
1999-09-08 23:51:02 +00:00
|
|
|
mSplitter->mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::state, "", PR_TRUE);
|
|
|
|
mPressed = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-05 20:46:59 +00:00
|
|
|
void
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrameImpl::MouseDrag(nsIPresContext* aPresContext, nsGUIEvent* aEvent)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
if (IsMouseCaptured(aPresContext)) {
|
1999-09-05 20:46:59 +00:00
|
|
|
PRBool isHorizontal = !mSplitter->IsHorizontal();
|
|
|
|
// convert coord to pixels
|
|
|
|
nscoord pos = isHorizontal ? aEvent->point.x : aEvent->point.y;
|
|
|
|
|
|
|
|
// mDragStartPx is in pixels and is in our client areas coordinate system.
|
|
|
|
// so we need to first convert it so twips and then get it into our coordinate system.
|
|
|
|
|
|
|
|
// convert start to twips
|
|
|
|
nscoord startpx = mDragStartPx;
|
|
|
|
|
|
|
|
float p2t;
|
1999-11-24 06:03:41 +00:00
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
1999-09-05 20:46:59 +00:00
|
|
|
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
|
|
|
nscoord start = startpx*onePixel;
|
|
|
|
|
|
|
|
// get it into our coordintate system by subtracting our parents offsets.
|
|
|
|
nsIFrame* parent = mSplitter;
|
|
|
|
while(parent != nsnull)
|
|
|
|
{
|
|
|
|
// if we hit a scrollable view make sure we take into account
|
|
|
|
// how much we are scrolled.
|
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
nsIView* view;
|
1999-11-24 06:03:41 +00:00
|
|
|
parent->GetView(aPresContext, &view);
|
1999-09-05 20:46:59 +00:00
|
|
|
if (view) {
|
1999-12-21 19:28:15 +00:00
|
|
|
nsresult result = view->QueryInterface(NS_GET_IID(nsIScrollableView), (void**)&scrollingView);
|
1999-09-05 20:46:59 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nscoord xoff = 0;
|
|
|
|
nscoord yoff = 0;
|
|
|
|
scrollingView->GetScrollPosition(xoff, yoff);
|
|
|
|
isHorizontal ? start += xoff : start += yoff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect r;
|
|
|
|
parent->GetRect(r);
|
|
|
|
isHorizontal ? start -= r.x : start -= r.y;
|
|
|
|
parent->GetParent(&parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// take our current position and substract the start location
|
|
|
|
pos -= start;
|
|
|
|
|
1999-09-08 23:51:02 +00:00
|
|
|
//printf("Diff=%d\n", pos);
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
ResizeType resizeAfter = GetResizeAfter();
|
|
|
|
|
|
|
|
PRBool bounded;
|
|
|
|
|
|
|
|
if (resizeAfter == nsSplitterFrameImpl::Grow)
|
|
|
|
bounded = PR_FALSE;
|
|
|
|
else
|
|
|
|
bounded = PR_TRUE;
|
|
|
|
|
1999-09-14 22:17:19 +00:00
|
|
|
int i;
|
1999-09-05 20:46:59 +00:00
|
|
|
for (i=0; i < mChildInfosBeforeCount; i++)
|
|
|
|
mChildInfosBefore[i].changed = mChildInfosBefore[i].current;
|
|
|
|
|
|
|
|
for (i=0; i < mChildInfosAfterCount; i++)
|
|
|
|
mChildInfosAfter[i].changed = mChildInfosAfter[i].current;
|
|
|
|
|
1999-10-20 00:46:21 +00:00
|
|
|
// nscoord oldPos = pos;
|
1999-09-14 22:17:19 +00:00
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
ResizeChildTo(aPresContext, pos, mChildInfosBefore, mChildInfosAfter, mChildInfosBeforeCount, mChildInfosAfterCount, bounded);
|
1999-09-05 20:46:59 +00:00
|
|
|
|
1999-09-22 03:11:47 +00:00
|
|
|
/*
|
1999-09-14 22:17:19 +00:00
|
|
|
if (oldPos > 0 && oldPos > pos)
|
|
|
|
{
|
|
|
|
printf("Collapse right\n");
|
|
|
|
if (GetCollapseDirection() == After) {
|
|
|
|
mSplitter->mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::state, "collapsed", PR_TRUE);
|
|
|
|
AdjustChildren(aPresContext);
|
|
|
|
AddListener();
|
|
|
|
CaptureMouse(PR_FALSE);
|
|
|
|
mPressed = PR_FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldPos < 0 && oldPos < pos)
|
|
|
|
{
|
|
|
|
printf("Collapse left\n");
|
|
|
|
if (GetCollapseDirection() == Before) {
|
|
|
|
mSplitter->mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::state, "collapsed", PR_TRUE);
|
|
|
|
AdjustChildren(aPresContext);
|
|
|
|
AddListener();
|
|
|
|
CaptureMouse(PR_FALSE);
|
|
|
|
mPressed = PR_FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-09-22 03:11:47 +00:00
|
|
|
*/
|
1999-09-05 20:46:59 +00:00
|
|
|
|
1999-09-08 23:51:02 +00:00
|
|
|
// printf("----- resize ----- ");
|
|
|
|
/*
|
1999-09-05 20:46:59 +00:00
|
|
|
for (i=0; i < mChildInfosBeforeCount; i++)
|
|
|
|
printf("before, index=%d, current=%d, changed=%d\n", mChildInfosBefore[i].index, mChildInfosBefore[i].current, mChildInfosBefore[i].changed);
|
|
|
|
for (i=0; i < mChildInfosAfterCount; i++)
|
|
|
|
printf("after, index=%d, current=%d, changed=%d\n", mChildInfosAfter[i].index, mChildInfosAfter[i].current, mChildInfosAfter[i].changed);
|
1999-09-08 23:51:02 +00:00
|
|
|
*/
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
1999-11-24 06:03:41 +00:00
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIReflowCommand> reflowCmd;
|
|
|
|
nsresult rv = NS_NewHTMLReflowCommand(getter_AddRefs(reflowCmd), mSplitter->mParent,
|
|
|
|
nsIReflowCommand::StyleChanged);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
|
|
|
|
mDidDrag = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameImpl::AddListener()
|
|
|
|
{
|
|
|
|
nsIFrame* thumbFrame = nsnull;
|
|
|
|
mSplitter->FirstChild(nsnull,&thumbFrame);
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mSplitter->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(content));
|
|
|
|
|
1999-12-21 19:28:15 +00:00
|
|
|
reciever->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMMouseListener*,this), NS_GET_IID(nsIDOMMouseListener));
|
|
|
|
reciever->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMMouseMotionListener*,this), NS_GET_IID(nsIDOMMouseMotionListener));
|
1999-09-05 20:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameImpl::RemoveListener()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mSplitter->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(content));
|
|
|
|
|
1999-12-21 19:28:15 +00:00
|
|
|
reciever->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMMouseListener*,this),NS_GET_IID(nsIDOMMouseListener));
|
|
|
|
reciever->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMMouseMotionListener*,this),NS_GET_IID(nsIDOMMouseMotionListener));
|
1999-09-05 20:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-10-26 04:44:41 +00:00
|
|
|
nsSplitterFrameImpl :: CaptureMouse(nsIPresContext* aPresContext, PRBool aGrabMouseEvents)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
// get its view
|
|
|
|
nsIView* view = nsnull;
|
1999-10-26 04:44:41 +00:00
|
|
|
mSplitter->GetView(aPresContext, &view);
|
1999-09-05 20:46:59 +00:00
|
|
|
nsCOMPtr<nsIViewManager> viewMan;
|
|
|
|
PRBool result;
|
1999-09-22 03:11:47 +00:00
|
|
|
//nsCOMPtr<nsIWidget> widget;
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
if (view) {
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewMan));
|
1999-09-22 03:11:47 +00:00
|
|
|
//view->GetWidget(*getter_AddRefs(widget));
|
1999-09-05 20:46:59 +00:00
|
|
|
if (viewMan) {
|
|
|
|
if (aGrabMouseEvents) {
|
|
|
|
viewMan->GrabMouseEvents(view,result);
|
1999-09-22 03:11:47 +00:00
|
|
|
// if (widget)
|
|
|
|
// widget->CaptureMouse(PR_TRUE);
|
1999-09-05 20:46:59 +00:00
|
|
|
} else {
|
|
|
|
viewMan->GrabMouseEvents(nsnull,result);
|
1999-09-22 03:11:47 +00:00
|
|
|
// if (widget)
|
|
|
|
// widget->CaptureMouse(PR_FALSE);
|
1999-09-05 20:46:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1999-10-26 04:44:41 +00:00
|
|
|
nsSplitterFrameImpl :: IsMouseCaptured(nsIPresContext* aPresContext)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
// get its view
|
|
|
|
nsIView* view = nsnull;
|
1999-10-26 04:44:41 +00:00
|
|
|
mSplitter->GetView(aPresContext, &view);
|
1999-09-05 20:46:59 +00:00
|
|
|
nsCOMPtr<nsIViewManager> viewMan;
|
|
|
|
|
|
|
|
if (view) {
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewMan));
|
|
|
|
|
|
|
|
if (viewMan) {
|
|
|
|
nsIView* grabbingView;
|
|
|
|
viewMan->GetMouseEventGrabber(grabbingView);
|
|
|
|
if (grabbingView == view)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSplitterFrameImpl::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
1999-09-08 23:51:02 +00:00
|
|
|
// printf("Released\n");
|
1999-09-05 20:46:59 +00:00
|
|
|
mPressed = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSplitterFrameImpl::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
mCurrentPos = 0;
|
|
|
|
mPressed = PR_TRUE;
|
|
|
|
|
|
|
|
mDidDrag = PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* parent = nsnull;
|
|
|
|
mSplitter->GetParent(&parent);
|
|
|
|
mParentBox = (nsBoxFrame*)parent;
|
|
|
|
|
|
|
|
// get our index
|
|
|
|
nscoord childIndex = nsFrameNavigator::IndexOf(mParentBox, mSplitter);
|
|
|
|
PRInt32 childCount = nsFrameNavigator::CountFrames(mParentBox);
|
|
|
|
|
|
|
|
// if its 0 or the last index then stop right here.
|
|
|
|
if (childIndex == 0 || childIndex == childCount-1) {
|
|
|
|
mPressed = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool isHorizontal = mParentBox->IsHorizontal();
|
|
|
|
|
|
|
|
ResizeType resizeBefore = GetResizeBefore();
|
|
|
|
ResizeType resizeAfter = GetResizeAfter();
|
|
|
|
|
|
|
|
delete mChildInfosBefore;
|
|
|
|
delete mChildInfosAfter;
|
|
|
|
|
|
|
|
mChildInfosBefore = new nsSplitterInfo[childCount];
|
|
|
|
mChildInfosAfter = new nsSplitterInfo[childCount];
|
|
|
|
|
|
|
|
// create info 2 lists. One of the children before us and one after.
|
|
|
|
PRInt32 count = 0;
|
|
|
|
mChildInfosBeforeCount = 0;
|
|
|
|
mChildInfosAfterCount = 0;
|
|
|
|
|
|
|
|
nsIFrame* childFrame = nsnull;
|
|
|
|
mParentBox->FirstChild(nsnull, &childFrame);
|
|
|
|
|
|
|
|
while (nsnull != childFrame)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
childFrame->GetContent(getter_AddRefs(content));
|
|
|
|
nsIAtom* atom;
|
|
|
|
content->GetTag(atom);
|
|
|
|
|
|
|
|
// skip over any splitters
|
|
|
|
if (atom != nsXULAtoms::splitter) {
|
|
|
|
nsBoxInfo info;
|
|
|
|
mParentBox->GetChildBoxInfo(count, info);
|
|
|
|
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
nsresult rv = childFrame->GetStyleData(eStyleStruct_Spacing,
|
|
|
|
(const nsStyleStruct*&) spacing);
|
|
|
|
|
|
|
|
NS_ASSERTION(rv == NS_OK,"failed to get spacing info");
|
|
|
|
|
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
spacing->GetMargin(margin);
|
|
|
|
nsRect r(0,0,0,0);
|
|
|
|
childFrame->GetRect(r);
|
|
|
|
r.Inflate(margin);
|
|
|
|
|
|
|
|
if (count < childIndex) {
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].child = childFrame;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].min = isHorizontal ? info.minSize.width : info.minSize.height;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].max = isHorizontal ? info.maxSize.width : info.maxSize.height;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].current = isHorizontal ? r.width : r.height;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].flex = info.flex;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].index = count;
|
|
|
|
mChildInfosBeforeCount++;
|
|
|
|
} else if (count > childIndex) {
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].child = childFrame;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].min = isHorizontal ? info.minSize.width : info.minSize.height;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].max = isHorizontal ? info.maxSize.width : info.maxSize.height;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].current = isHorizontal ? r.width : r.height;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].flex = info.flex;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].index = count;
|
|
|
|
mChildInfosAfterCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = childFrame->GetNextSibling(&childFrame);
|
|
|
|
NS_ASSERTION(rv == NS_OK,"failed to get next child");
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the resizebefore is closest we must reverse the list because the first child in the list
|
1999-09-08 23:51:02 +00:00
|
|
|
// is the Farthest we want the first child to be the closest.
|
1999-09-05 20:46:59 +00:00
|
|
|
if (resizeBefore == Closest)
|
|
|
|
Reverse(mChildInfosBefore, mChildInfosBeforeCount);
|
|
|
|
|
1999-09-08 23:51:02 +00:00
|
|
|
// if the resizeafter is the Farthest we must reverse the list because the first child in the list
|
|
|
|
// is the closest we want the first child to be the Farthest.
|
|
|
|
if (resizeAfter == Farthest)
|
1999-09-05 20:46:59 +00:00
|
|
|
Reverse(mChildInfosAfter, mChildInfosAfterCount);
|
|
|
|
|
|
|
|
// grow only applys to the children after. If grow is set then no space should be taken out of any children after
|
|
|
|
// us. To do this we just set the size of that list to be 0.
|
|
|
|
if (resizeAfter == Grow)
|
|
|
|
mChildInfosAfterCount = 0;
|
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aMouseEvent));
|
1999-09-05 20:46:59 +00:00
|
|
|
|
1999-09-08 23:51:02 +00:00
|
|
|
nsRect vr(0,0,0,0);
|
|
|
|
nsIView *v;
|
1999-10-26 04:44:41 +00:00
|
|
|
mSplitter->GetView(mSplitter->mPresContext, &v);
|
1999-09-08 23:51:02 +00:00
|
|
|
v->GetBounds(vr);
|
|
|
|
|
1999-09-05 20:46:59 +00:00
|
|
|
PRInt32 c = 0;
|
|
|
|
if (isHorizontal) {
|
1999-11-03 07:11:45 +00:00
|
|
|
mouseEvent->GetClientX(&c);
|
1999-09-05 20:46:59 +00:00
|
|
|
mSplitterPos = mSplitter->mRect.x;
|
1999-09-08 23:51:02 +00:00
|
|
|
mSplitterViewPos = vr.x;
|
1999-09-05 20:46:59 +00:00
|
|
|
} else {
|
1999-11-03 07:11:45 +00:00
|
|
|
mouseEvent->GetClientY(&c);
|
1999-09-05 20:46:59 +00:00
|
|
|
mSplitterPos = mSplitter->mRect.y;
|
1999-09-08 23:51:02 +00:00
|
|
|
mSplitterViewPos = vr.y;
|
1999-09-05 20:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mDragStartPx = c;
|
|
|
|
|
1999-09-08 23:51:02 +00:00
|
|
|
//printf("Pressed mDragStartPx=%d\n",mDragStartPx);
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSplitterFrameImpl::MouseMove(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
1999-09-08 23:51:02 +00:00
|
|
|
//printf("Mouse move\n");
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
if (!mPressed)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-10-26 04:44:41 +00:00
|
|
|
if (IsMouseCaptured(mSplitter->mPresContext))
|
1999-09-05 20:46:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
1999-09-14 22:17:19 +00:00
|
|
|
// if (mState == Collapsed)
|
|
|
|
// return NS_OK;
|
1999-09-08 23:51:02 +00:00
|
|
|
|
|
|
|
|
1999-09-05 20:46:59 +00:00
|
|
|
mSplitter->mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::state, "dragging", PR_TRUE);
|
|
|
|
|
|
|
|
RemoveListener();
|
1999-10-26 04:44:41 +00:00
|
|
|
CaptureMouse(mSplitter->mPresContext, PR_TRUE);
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameImpl::Reverse(nsSplitterInfo*& aChildInfos, PRInt32 aCount)
|
|
|
|
{
|
|
|
|
nsSplitterInfo* infos = new nsSplitterInfo[aCount];
|
|
|
|
|
|
|
|
for (int i=0; i < aCount; i++)
|
|
|
|
infos[i] = aChildInfos[aCount - 1 - i];
|
|
|
|
|
|
|
|
delete aChildInfos;
|
|
|
|
aChildInfos = infos;
|
|
|
|
}
|
|
|
|
|
1999-09-14 22:17:19 +00:00
|
|
|
nsSplitterFrameImpl::CollapseDirection
|
|
|
|
nsSplitterFrameImpl::GetCollapseDirection()
|
|
|
|
{
|
|
|
|
nsString value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mSplitter->mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::collapse, value))
|
|
|
|
{
|
|
|
|
if (value.EqualsIgnoreCase("before"))
|
|
|
|
return Before;
|
|
|
|
else if (value.EqualsIgnoreCase("after"))
|
|
|
|
return After;
|
|
|
|
else
|
|
|
|
return None;
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-05 20:46:59 +00:00
|
|
|
void
|
|
|
|
nsSplitterFrameImpl::UpdateState()
|
|
|
|
{
|
1999-09-14 22:17:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// states
|
|
|
|
//
|
|
|
|
// Open -> Dragging
|
|
|
|
// Open -> Collapsed
|
|
|
|
// Collapsed -> Open
|
|
|
|
// Collapsed -> Dragging
|
|
|
|
// Dragging -> Open
|
|
|
|
// Dragging -> Collapsed (auto collapse)
|
|
|
|
|
1999-09-05 20:46:59 +00:00
|
|
|
State newState = GetState();
|
|
|
|
|
1999-09-14 22:17:19 +00:00
|
|
|
// if the state are the same we are done
|
1999-09-05 20:46:59 +00:00
|
|
|
if (newState == mState)
|
|
|
|
return;
|
|
|
|
|
1999-09-14 22:17:19 +00:00
|
|
|
nsString style;
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
if (mState == Collapsed) {
|
1999-09-14 22:17:19 +00:00
|
|
|
// Collapsed -> Open
|
|
|
|
// Collapsed -> Dragging
|
|
|
|
|
|
|
|
// set the old style back
|
1999-09-05 20:46:59 +00:00
|
|
|
style = mCollapsedChildStyle;
|
1999-09-14 22:17:19 +00:00
|
|
|
} else if ((mState == Open || mState == Dragging) && newState == Collapsed) {
|
1999-09-05 20:46:59 +00:00
|
|
|
// when clicked see if we are in a splitter.
|
|
|
|
nsIFrame* splitter = mSplitter;
|
|
|
|
|
|
|
|
// get the splitters content node
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
splitter->GetContent(getter_AddRefs(content));
|
|
|
|
|
1999-09-14 22:17:19 +00:00
|
|
|
|
|
|
|
CollapseDirection d = GetCollapseDirection();
|
|
|
|
|
|
|
|
if (d != None) {
|
|
|
|
// find the child just in the box just before the splitter. If we are not currently collapsed then
|
|
|
|
// then get the childs style attribute and store it. Then set the child style attribute to be display none.
|
|
|
|
// if we are already collapsed then set the child's style back to our stored value.
|
|
|
|
nsIFrame* child = nsFrameNavigator::GetChildBeforeAfter(splitter,(d == Before));
|
|
|
|
if (child == nsnull)
|
|
|
|
return;
|
|
|
|
|
|
|
|
child->GetContent(getter_AddRefs(mCollapsedChild));
|
|
|
|
|
|
|
|
style = "visibility: collapse";
|
|
|
|
mCollapsedChildStyle = "";
|
|
|
|
mCollapsedChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::style, mCollapsedChildStyle);
|
1999-09-08 23:51:02 +00:00
|
|
|
} else {
|
1999-09-14 22:17:19 +00:00
|
|
|
mState = newState;
|
1999-09-08 23:51:02 +00:00
|
|
|
return;
|
1999-09-05 20:46:59 +00:00
|
|
|
}
|
1999-09-14 22:17:19 +00:00
|
|
|
} else {
|
|
|
|
mState = newState;
|
1999-09-05 20:46:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCollapsedChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::style, style, PR_TRUE);
|
|
|
|
|
|
|
|
mState = newState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrameImpl::AdjustChildren(nsIPresContext* aPresContext)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
|
|
|
PRBool isHorizontal = mParentBox->IsHorizontal();
|
|
|
|
AdjustChildren(aPresContext, mChildInfosBefore, mChildInfosBeforeCount, isHorizontal);
|
|
|
|
AdjustChildren(aPresContext, mChildInfosAfter, mChildInfosAfterCount, isHorizontal);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
1999-11-24 06:03:41 +00:00
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIReflowCommand> reflowCmd;
|
|
|
|
nsresult rv = NS_NewHTMLReflowCommand(getter_AddRefs(reflowCmd), mParentBox,
|
|
|
|
nsIReflowCommand::StyleChanged);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSplitterFrameImpl::AdjustChildren(nsIPresContext* aPresContext, nsSplitterInfo* aChildInfos, PRInt32 aCount, PRBool aIsHorizontal)
|
1999-09-05 20:46:59 +00:00
|
|
|
{
|
1999-09-08 23:51:02 +00:00
|
|
|
// printf("------- AdjustChildren------\n");
|
1999-09-05 20:46:59 +00:00
|
|
|
|
|
|
|
for (int i=0; i < aCount; i++)
|
|
|
|
{
|
|
|
|
nscoord pref = aChildInfos[i].changed;
|
|
|
|
nsIFrame* childFrame = aChildInfos[i].child;
|
|
|
|
PRInt32 index = aChildInfos[i].index;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
rv = childFrame->GetStyleData(eStyleStruct_Spacing,
|
|
|
|
(const nsStyleStruct*&) spacing);
|
|
|
|
|
|
|
|
NS_ASSERTION(rv == NS_OK,"failed to get spacing info");
|
|
|
|
|
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
spacing->GetMargin(margin);
|
|
|
|
nsMargin border(0,0,0,0);
|
|
|
|
spacing->GetBorderPadding(border);
|
|
|
|
margin += border;
|
|
|
|
|
|
|
|
nsIAtom* attribute;
|
|
|
|
|
|
|
|
if (aIsHorizontal) {
|
|
|
|
pref -= (margin.left + margin.right);
|
|
|
|
attribute = nsHTMLAtoms::width;
|
|
|
|
} else {
|
|
|
|
pref -= (margin.top + margin.bottom);
|
|
|
|
attribute = nsHTMLAtoms::height;
|
|
|
|
}
|
|
|
|
|
|
|
|
float p2t;
|
1999-11-24 06:03:41 +00:00
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
1999-09-05 20:46:59 +00:00
|
|
|
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
childFrame->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
// set its preferred size.
|
|
|
|
char ch[50];
|
|
|
|
sprintf(ch,"%d",pref/onePixel);
|
1999-09-08 23:51:02 +00:00
|
|
|
//printf("index=%d, pref=%s\n", i, ch);
|
1999-09-05 20:46:59 +00:00
|
|
|
content->SetAttribute(kNameSpaceID_None, attribute, ch, PR_FALSE);
|
|
|
|
mParentBox->SetChildNeedsRecalc(index, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameImpl::AddRemoveSpace(nscoord aDiff,
|
|
|
|
nsSplitterInfo* aChildInfos,
|
|
|
|
PRInt32 aCount,
|
|
|
|
PRInt32& aSpaceLeft)
|
|
|
|
{
|
|
|
|
aSpaceLeft = 0;
|
|
|
|
|
|
|
|
for (int i=0; i < aCount; i++) {
|
|
|
|
nscoord min = aChildInfos[i].min;
|
|
|
|
nscoord max = aChildInfos[i].max;
|
|
|
|
nscoord& c = aChildInfos[i].changed;
|
|
|
|
|
|
|
|
// figure our how much space to add or remove
|
|
|
|
if (c + aDiff < min) {
|
|
|
|
aDiff += (c - min);
|
|
|
|
c = min;
|
|
|
|
} else if (c + aDiff > max) {
|
|
|
|
aDiff -= (max - c);
|
|
|
|
c = max;
|
|
|
|
} else {
|
|
|
|
c += aDiff;
|
|
|
|
aDiff = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// there is not space left? We are done
|
|
|
|
if (aDiff == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSpaceLeft = aDiff;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PR_ABS(x) (x < 0 ? -x : x)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ok if we want to resize a child we will know the actual size in pixels we want it to be.
|
|
|
|
* This is not the preferred size. But they only way we can change a child is my manipulating its
|
|
|
|
* preferred size. So give the actual pixel size this return method will return figure out the preferred
|
|
|
|
* size and set it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1999-10-26 04:44:41 +00:00
|
|
|
nsSplitterFrameImpl::ResizeChildTo(nsIPresContext* aPresContext,
|
|
|
|
nscoord& aDiff,
|
1999-09-05 20:46:59 +00:00
|
|
|
nsSplitterInfo* aChildrenBeforeInfos,
|
|
|
|
nsSplitterInfo* aChildrenAfterInfos,
|
|
|
|
PRInt32 aChildrenBeforeCount,
|
|
|
|
PRInt32 aChildrenAfterCount,
|
|
|
|
PRBool aBounded)
|
|
|
|
{
|
|
|
|
nscoord spaceLeft;
|
|
|
|
AddRemoveSpace(aDiff, aChildrenBeforeInfos,aChildrenBeforeCount,spaceLeft);
|
|
|
|
|
|
|
|
// if there is any space left over remove it from the dif we were originally given
|
|
|
|
aDiff -= spaceLeft;
|
|
|
|
AddRemoveSpace(-aDiff, aChildrenAfterInfos,aChildrenAfterCount,spaceLeft);
|
|
|
|
|
|
|
|
if (spaceLeft != 0) {
|
|
|
|
if (aBounded) {
|
|
|
|
aDiff += spaceLeft;
|
|
|
|
AddRemoveSpace(spaceLeft, aChildrenBeforeInfos,aChildrenBeforeCount,spaceLeft);
|
|
|
|
} else {
|
|
|
|
spaceLeft = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsRect& r = mSplitter->mRect;
|
1999-09-08 23:51:02 +00:00
|
|
|
nsRect vr;
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
nsIView *v;
|
1999-10-26 04:44:41 +00:00
|
|
|
mSplitter->GetView(aPresContext, &v);
|
1999-09-08 23:51:02 +00:00
|
|
|
v->GetViewManager(*getter_AddRefs(vm));
|
|
|
|
v->GetBounds(vr);
|
1999-09-14 22:17:19 +00:00
|
|
|
nsRect invalid;
|
1999-09-05 20:46:59 +00:00
|
|
|
if (mParentBox->IsHorizontal()) {
|
1999-10-26 04:44:41 +00:00
|
|
|
mSplitter->MoveTo(aPresContext, mSplitterPos + aDiff, r.y);
|
1999-09-08 23:51:02 +00:00
|
|
|
vm->MoveViewTo(v, mSplitterViewPos + aDiff, vr.y);
|
1999-09-14 22:17:19 +00:00
|
|
|
invalid.UnionRect(r,mSplitter->mRect);
|
1999-09-05 20:46:59 +00:00
|
|
|
} else {
|
1999-10-26 04:44:41 +00:00
|
|
|
mSplitter->MoveTo(aPresContext, r.x, mSplitterPos + aDiff);
|
1999-09-08 23:51:02 +00:00
|
|
|
vm->MoveViewTo(v, vr.x, mSplitterViewPos + aDiff);
|
1999-09-14 22:17:19 +00:00
|
|
|
invalid.UnionRect(r,mSplitter->mRect);
|
1999-09-05 20:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// redraw immediately only what changed. This is animation so
|
|
|
|
// it must be immediate.
|
1999-10-26 04:44:41 +00:00
|
|
|
mParentBox->Invalidate(aPresContext, invalid, PR_TRUE);
|
1999-09-05 20:46:59 +00:00
|
|
|
}
|
|
|
|
|