2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsSplitterFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsScrollbarButtonFrame.h"
|
2011-06-28 10:59:14 -07:00
|
|
|
#include "nsIDOMEventListener.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
|
|
|
#include "nsIPresShell.h"
|
2009-04-25 01:33:32 -07:00
|
|
|
#include "nsFrameList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2011-12-27 12:18:48 -08:00
|
|
|
#include "nsContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsContentUtils.h"
|
2011-07-20 12:18:54 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsSplitterInfo {
|
|
|
|
public:
|
|
|
|
nscoord min;
|
|
|
|
nscoord max;
|
|
|
|
nscoord current;
|
|
|
|
nscoord changed;
|
|
|
|
nsCOMPtr<nsIContent> childElem;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t flex;
|
|
|
|
int32_t index;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-08-05 10:33:55 -07:00
|
|
|
class nsSplitterFrameInner MOZ_FINAL : public nsIDOMEventListener
|
2011-06-28 10:59:14 -07:00
|
|
|
{
|
2014-06-23 15:40:01 -07:00
|
|
|
protected:
|
|
|
|
virtual ~nsSplitterFrameInner();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-28 10:59:14 -07:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSplitterFrameInner(nsSplitterFrame* aSplitter)
|
|
|
|
{
|
|
|
|
mOuter = aSplitter;
|
2011-10-17 07:59:28 -07:00
|
|
|
mPressed = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
void Disconnect() { mOuter = nullptr; }
|
2007-05-21 00:33:32 -07:00
|
|
|
|
2011-06-28 10:59:14 -07:00
|
|
|
nsresult MouseDown(nsIDOMEvent* aMouseEvent);
|
|
|
|
nsresult MouseUp(nsIDOMEvent* aMouseEvent);
|
|
|
|
nsresult MouseMove(nsIDOMEvent* aMouseEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
void MouseDrag(nsPresContext* aPresContext, WidgetGUIEvent* aEvent);
|
|
|
|
void MouseUp(nsPresContext* aPresContext, WidgetGUIEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void AdjustChildren(nsPresContext* aPresContext);
|
2012-08-22 08:56:38 -07:00
|
|
|
void AdjustChildren(nsPresContext* aPresContext, nsSplitterInfo* aChildInfos, int32_t aCount, bool aIsHorizontal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void AddRemoveSpace(nscoord aDiff,
|
|
|
|
nsSplitterInfo* aChildInfos,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aCount,
|
|
|
|
int32_t& aSpaceLeft);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void ResizeChildTo(nsPresContext* aPresContext,
|
|
|
|
nscoord& aDiff,
|
|
|
|
nsSplitterInfo* aChildrenBeforeInfos,
|
|
|
|
nsSplitterInfo* aChildrenAfterInfos,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aChildrenBeforeCount,
|
|
|
|
int32_t aChildrenAfterCount,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aBounded);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void UpdateState();
|
|
|
|
|
|
|
|
void AddListener(nsPresContext* aPresContext);
|
|
|
|
void RemoveListener();
|
|
|
|
|
2007-11-14 19:38:16 -08:00
|
|
|
enum ResizeType { Closest, Farthest, Flex, Grow };
|
2007-03-22 10:30:00 -07:00
|
|
|
enum State { Open, CollapsedBefore, CollapsedAfter, Dragging };
|
|
|
|
enum CollapseDirection { Before, After };
|
|
|
|
|
|
|
|
ResizeType GetResizeBefore();
|
|
|
|
ResizeType GetResizeAfter();
|
|
|
|
State GetState();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void Reverse(nsSplitterInfo*& aIndexes, int32_t aCount);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SupportsCollapseDirection(CollapseDirection aDirection);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void EnsureOrient();
|
2012-08-05 20:00:57 -07:00
|
|
|
void SetPreferredSize(nsBoxLayoutState& aState, nsIFrame* aChildBox, nscoord aOnePixel, bool aIsHorizontal, nscoord* aSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSplitterFrame* mOuter;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDidDrag;
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord mDragStart;
|
|
|
|
nscoord mCurrentPos;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* mParentBox;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mPressed;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSplitterInfo* mChildInfosBefore;
|
|
|
|
nsSplitterInfo* mChildInfosAfter;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mChildInfosBeforeCount;
|
|
|
|
int32_t mChildInfosAfterCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
State mState;
|
|
|
|
nscoord mSplitterPos;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDragging;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsSplitterFrameInner, nsIDOMEventListener)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSplitterFrameInner::ResizeType
|
|
|
|
nsSplitterFrameInner::GetResizeBefore()
|
|
|
|
{
|
2007-11-14 19:38:16 -08:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::farthest, &nsGkAtoms::flex, nullptr};
|
2007-11-14 19:38:16 -08:00
|
|
|
switch (mOuter->GetContent()->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::resizebefore,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0: return Farthest;
|
|
|
|
case 1: return Flex;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return Closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplitterFrameInner::~nsSplitterFrameInner()
|
|
|
|
{
|
|
|
|
delete[] mChildInfosBefore;
|
|
|
|
delete[] mChildInfosAfter;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplitterFrameInner::ResizeType
|
|
|
|
nsSplitterFrameInner::GetResizeAfter()
|
|
|
|
{
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::farthest, &nsGkAtoms::flex, &nsGkAtoms::grow, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (mOuter->GetContent()->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::resizeafter,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0: return Farthest;
|
2007-11-14 19:38:16 -08:00
|
|
|
case 1: return Flex;
|
|
|
|
case 2: return Grow;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return Closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplitterFrameInner::State
|
|
|
|
nsSplitterFrameInner::GetState()
|
|
|
|
{
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::dragging, &nsGkAtoms::collapsed, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsIContent::AttrValuesArray strings_substate[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::before, &nsGkAtoms::after, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (mOuter->GetContent()->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::state,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0: return Dragging;
|
|
|
|
case 1:
|
|
|
|
switch (mOuter->GetContent()->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::substate,
|
|
|
|
strings_substate,
|
|
|
|
eCaseMatters)) {
|
|
|
|
case 0: return CollapsedBefore;
|
|
|
|
case 1: return CollapsedAfter;
|
|
|
|
default:
|
|
|
|
if (SupportsCollapseDirection(After))
|
|
|
|
return CollapsedAfter;
|
|
|
|
return CollapsedBefore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Open;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// NS_NewSplitterFrame
|
|
|
|
//
|
|
|
|
// Creates a new Toolbar frame and returns it
|
|
|
|
//
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSplitterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsSplitterFrame(aPresShell, aContext);
|
2009-09-12 09:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSplitterFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSplitterFrame::nsSplitterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
: nsBoxFrame(aPresShell, aContext),
|
|
|
|
mInner(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-05-21 00:33:32 -07:00
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsSplitterFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mInner) {
|
|
|
|
mInner->RemoveListener();
|
2007-05-21 00:33:32 -07:00
|
|
|
mInner->Disconnect();
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner->Release();
|
2012-07-30 07:20:58 -07:00
|
|
|
mInner = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSplitterFrame::GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor)
|
|
|
|
{
|
|
|
|
return nsBoxFrame::GetCursor(aPoint, aCursor);
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (IsHorizontal())
|
|
|
|
aCursor = NS_STYLE_CURSOR_N_RESIZE;
|
|
|
|
else
|
|
|
|
aCursor = NS_STYLE_CURSOR_W_RESIZE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSplitterFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
|
|
|
// if the alignment changed. Let the grippy know
|
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
|
|
|
// tell the slider its attribute changed so it can
|
|
|
|
// update itself
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* grippy = nullptr;
|
2007-03-30 14:11:41 -07:00
|
|
|
nsScrollbarButtonFrame::GetChildWithTag(PresContext(), nsGkAtoms::grippy, this, grippy);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (grippy)
|
|
|
|
grippy->AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
|
|
|
} else if (aAttribute == nsGkAtoms::state) {
|
|
|
|
mInner->UpdateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize us. If we are in a box get our alignment so we know what direction we are
|
|
|
|
*/
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsSplitterFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
MOZ_ASSERT(!mInner);
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner = new nsSplitterFrameInner(this);
|
|
|
|
|
|
|
|
mInner->AddRef();
|
2012-07-30 07:20:58 -07:00
|
|
|
mInner->mChildInfosAfter = nullptr;
|
|
|
|
mInner->mChildInfosBefore = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner->mState = nsSplitterFrameInner::Open;
|
2011-10-17 07:59:28 -07:00
|
|
|
mInner->mDragging = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// determine orientation of parent, and if vertical, set orient to vertical
|
|
|
|
// on splitter content, then re-resolve style
|
2007-10-03 19:58:48 -07:00
|
|
|
// XXXbz this is pretty messed up, since this can change whether we should
|
|
|
|
// have a frame at all. This really needs a better solution.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aParent && aParent->IsBoxFrame()) {
|
|
|
|
if (!aParent->IsHorizontal()) {
|
|
|
|
if (!nsContentUtils::HasNonEmptyAttr(aContent, kNameSpaceID_None,
|
|
|
|
nsGkAtoms::orient)) {
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::orient,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("vertical"), false);
|
2013-02-15 21:38:33 -08:00
|
|
|
nsStyleContext* parentStyleContext = StyleContext()->GetParent();
|
2007-10-03 19:58:48 -07:00
|
|
|
nsRefPtr<nsStyleContext> newContext = PresContext()->StyleSet()->
|
2010-04-30 06:12:06 -07:00
|
|
|
ResolveStyleFor(aContent->AsElement(), parentStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
SetStyleContextWithoutNotification(newContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mInner->mState = nsSplitterFrameInner::Open;
|
2007-03-30 14:11:41 -07:00
|
|
|
mInner->AddListener(PresContext());
|
2012-07-30 07:20:58 -07:00
|
|
|
mInner->mParentBox = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSplitterFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
if (GetStateBits() & NS_FRAME_FIRST_REFLOW)
|
|
|
|
{
|
2014-05-24 15:20:41 -07:00
|
|
|
mInner->mParentBox = nsBox::GetParentBox(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner->UpdateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsBoxFrame::DoLayout(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSplitterFrame::GetInitialOrientation(bool& aIsHorizontal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIFrame* box = nsBox::GetParentBox(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (box) {
|
|
|
|
aIsHorizontal = !box->IsHorizontal();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nsBoxFrame::GetInitialOrientation(aIsHorizontal);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSplitterFrame::HandlePress(nsPresContext* aPresContext,
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSplitterFrame::HandleMultiplePress(nsPresContext* aPresContext,
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aControlHeld)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-02 20:39:02 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSplitterFrame::HandleDrag(nsPresContext* aPresContext,
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2011-08-02 20:39:02 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSplitterFrame::HandleRelease(nsPresContext* aPresContext,
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2011-08-02 20:39:02 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSplitterFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2013-02-14 03:08:08 -08:00
|
|
|
nsBoxFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if the mouse is captured always return us as the frame.
|
|
|
|
if (mInner->mDragging)
|
|
|
|
{
|
|
|
|
// XXX It's probably better not to check visibility here, right?
|
2013-02-14 03:08:08 -08:00
|
|
|
aLists.Outlines()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayEventReceiver(aBuilder, this));
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2013-10-01 20:46:03 -07:00
|
|
|
nsSplitterFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-27 02:48:25 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
nsRefPtr<nsSplitterFrameInner> kungFuDeathGrip(mInner);
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
mInner->MouseDrag(aPresContext, aEvent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_BUTTON_UP:
|
2013-10-22 01:55:20 -07:00
|
|
|
if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner->MouseUp(aPresContext, aEvent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
|
|
|
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-01 20:46:03 -07:00
|
|
|
nsSplitterFrameInner::MouseUp(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-21 00:33:32 -07:00
|
|
|
if (mDragging && mOuter) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AdjustChildren(aPresContext);
|
|
|
|
AddListener(aPresContext);
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0); // XXXndeakin is this needed?
|
2011-10-17 07:59:28 -07:00
|
|
|
mDragging = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
State newState = GetState();
|
|
|
|
// if the state is dragging then make it Open.
|
|
|
|
if (newState == Dragging)
|
2011-10-17 07:59:28 -07:00
|
|
|
mOuter->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::state, EmptyString(), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mPressed = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if we dragged then fire a command event.
|
|
|
|
if (mDidDrag) {
|
|
|
|
nsCOMPtr<nsIDOMXULElement> element = do_QueryInterface(mOuter->GetContent());
|
|
|
|
element->DoCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
//printf("MouseUp\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] mChildInfosBefore;
|
|
|
|
delete[] mChildInfosAfter;
|
2012-07-30 07:20:58 -07:00
|
|
|
mChildInfosBefore = nullptr;
|
|
|
|
mChildInfosAfter = nullptr;
|
2008-09-17 07:38:33 -07:00
|
|
|
mChildInfosBeforeCount = 0;
|
|
|
|
mChildInfosAfterCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-01 20:46:03 -07:00
|
|
|
nsSplitterFrameInner::MouseDrag(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-21 00:33:32 -07:00
|
|
|
if (mDragging && mOuter) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//printf("Dragging\n");
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = !mOuter->IsHorizontal();
|
2007-03-22 10:30:00 -07:00
|
|
|
// convert coord to pixels
|
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
|
|
|
|
mParentBox);
|
|
|
|
nscoord pos = isHorizontal ? pt.x : pt.y;
|
|
|
|
|
|
|
|
// mDragStart is in frame coordinates
|
|
|
|
nscoord start = mDragStart;
|
|
|
|
|
|
|
|
// take our current position and subtract the start location
|
|
|
|
pos -= start;
|
|
|
|
|
|
|
|
//printf("Diff=%d\n", pos);
|
|
|
|
|
|
|
|
ResizeType resizeAfter = GetResizeAfter();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool bounded;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (resizeAfter == nsSplitterFrameInner::Grow)
|
2011-10-17 07:59:28 -07:00
|
|
|
bounded = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2011-10-17 07:59:28 -07:00
|
|
|
bounded = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i=0; i < mChildInfosBeforeCount; i++)
|
|
|
|
mChildInfosBefore[i].changed = mChildInfosBefore[i].current;
|
|
|
|
|
|
|
|
for (i=0; i < mChildInfosAfterCount; i++)
|
|
|
|
mChildInfosAfter[i].changed = mChildInfosAfter[i].current;
|
|
|
|
|
|
|
|
nscoord oldPos = pos;
|
|
|
|
|
|
|
|
ResizeChildTo(aPresContext, pos, mChildInfosBefore, mChildInfosAfter, mChildInfosBeforeCount, mChildInfosAfterCount, bounded);
|
|
|
|
|
|
|
|
State currentState = GetState();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool supportsBefore = SupportsCollapseDirection(Before);
|
|
|
|
bool supportsAfter = SupportsCollapseDirection(After);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const bool isRTL = mOuter->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool pastEnd = oldPos > 0 && oldPos > pos;
|
|
|
|
bool pastBegin = oldPos < 0 && oldPos < pos;
|
2010-04-11 16:46:08 -07:00
|
|
|
if (isRTL) {
|
|
|
|
// Swap the boundary checks in RTL mode
|
2011-09-28 23:19:26 -07:00
|
|
|
bool tmp = pastEnd;
|
2010-04-11 16:46:08 -07:00
|
|
|
pastEnd = pastBegin;
|
|
|
|
pastBegin = tmp;
|
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
const bool isCollapsedBefore = pastBegin && supportsBefore;
|
|
|
|
const bool isCollapsedAfter = pastEnd && supportsAfter;
|
2010-04-11 16:46:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// if we are in a collapsed position
|
2010-04-11 16:46:08 -07:00
|
|
|
if (isCollapsedBefore || isCollapsedAfter)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// and we are not collapsed then collapse
|
|
|
|
if (currentState == Dragging) {
|
2010-04-11 16:46:08 -07:00
|
|
|
if (pastEnd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
//printf("Collapse right\n");
|
|
|
|
if (supportsAfter)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> outer = mOuter->mContent;
|
|
|
|
outer->SetAttr(kNameSpaceID_None, nsGkAtoms::substate,
|
|
|
|
NS_LITERAL_STRING("after"),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
outer->SetAttr(kNameSpaceID_None, nsGkAtoms::state,
|
|
|
|
NS_LITERAL_STRING("collapsed"),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-11 16:46:08 -07:00
|
|
|
} else if (pastBegin)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
//printf("Collapse left\n");
|
|
|
|
if (supportsBefore)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> outer = mOuter->mContent;
|
|
|
|
outer->SetAttr(kNameSpaceID_None, nsGkAtoms::substate,
|
|
|
|
NS_LITERAL_STRING("before"),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
outer->SetAttr(kNameSpaceID_None, nsGkAtoms::state,
|
|
|
|
NS_LITERAL_STRING("collapsed"),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if we are not in a collapsed position and we are not dragging make sure
|
|
|
|
// we are dragging.
|
|
|
|
if (currentState != Dragging)
|
2011-10-17 07:59:28 -07:00
|
|
|
mOuter->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::state, NS_LITERAL_STRING("dragging"), true);
|
2009-07-04 02:47:59 -07:00
|
|
|
AdjustChildren(aPresContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mDidDrag = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameInner::AddListener(nsPresContext* aPresContext)
|
|
|
|
{
|
2007-05-14 02:11:38 -07:00
|
|
|
mOuter->GetContent()->
|
2011-10-17 07:59:28 -07:00
|
|
|
AddEventListener(NS_LITERAL_STRING("mouseup"), this, false, false);
|
2007-05-14 02:11:38 -07:00
|
|
|
mOuter->GetContent()->
|
2011-10-17 07:59:28 -07:00
|
|
|
AddEventListener(NS_LITERAL_STRING("mousedown"), this, false, false);
|
2011-06-28 10:59:14 -07:00
|
|
|
mOuter->GetContent()->
|
2011-10-17 07:59:28 -07:00
|
|
|
AddEventListener(NS_LITERAL_STRING("mousemove"), this, false, false);
|
2011-06-28 10:59:14 -07:00
|
|
|
mOuter->GetContent()->
|
2011-10-17 07:59:28 -07:00
|
|
|
AddEventListener(NS_LITERAL_STRING("mouseout"), this, false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameInner::RemoveListener()
|
|
|
|
{
|
2007-05-21 00:33:32 -07:00
|
|
|
ENSURE_TRUE(mOuter);
|
2007-05-14 02:11:38 -07:00
|
|
|
mOuter->GetContent()->
|
2011-10-17 07:59:28 -07:00
|
|
|
RemoveEventListener(NS_LITERAL_STRING("mouseup"), this, false);
|
2011-06-28 10:59:14 -07:00
|
|
|
mOuter->GetContent()->
|
2011-10-17 07:59:28 -07:00
|
|
|
RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, false);
|
2007-05-14 02:11:38 -07:00
|
|
|
mOuter->GetContent()->
|
2011-10-17 07:59:28 -07:00
|
|
|
RemoveEventListener(NS_LITERAL_STRING("mousemove"), this, false);
|
2011-06-28 10:59:14 -07:00
|
|
|
mOuter->GetContent()->
|
2011-10-17 07:59:28 -07:00
|
|
|
RemoveEventListener(NS_LITERAL_STRING("mouseout"), this, false);
|
2011-06-28 10:59:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSplitterFrameInner::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
|
|
|
if (eventType.EqualsLiteral("mouseup"))
|
|
|
|
return MouseUp(aEvent);
|
|
|
|
if (eventType.EqualsLiteral("mousedown"))
|
|
|
|
return MouseDown(aEvent);
|
|
|
|
if (eventType.EqualsLiteral("mousemove") ||
|
|
|
|
eventType.EqualsLiteral("mouseout"))
|
|
|
|
return MouseMove(aEvent);
|
|
|
|
|
|
|
|
NS_ABORT();
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSplitterFrameInner::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2007-05-21 00:33:32 -07:00
|
|
|
NS_ENSURE_TRUE(mOuter, NS_OK);
|
2011-10-17 07:59:28 -07:00
|
|
|
mPressed = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSplitterFrameInner::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2007-05-21 00:33:32 -07:00
|
|
|
NS_ENSURE_TRUE(mOuter, NS_OK);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aMouseEvent));
|
2011-06-28 10:59:14 -07:00
|
|
|
if (!mouseEvent)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-20 10:38:13 -08:00
|
|
|
int16_t button = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
mouseEvent->GetButton(&button);
|
|
|
|
|
|
|
|
// only if left button
|
|
|
|
if (button != 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (mOuter->GetContent()->
|
|
|
|
AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
|
|
|
return NS_OK;
|
|
|
|
|
2014-05-24 15:20:41 -07:00
|
|
|
mParentBox = nsBox::GetParentBox(mOuter);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mParentBox)
|
|
|
|
return NS_OK;
|
2009-04-25 01:33:32 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// get our index
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* outerPresContext = mOuter->PresContext();
|
2011-08-24 13:54:30 -07:00
|
|
|
const nsFrameList& siblingList(mParentBox->PrincipalChildList());
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childIndex = siblingList.IndexOf(mOuter);
|
2009-04-25 01:33:32 -07:00
|
|
|
// if it's 0 (or not found) then stop right here.
|
|
|
|
// It might be not found if we're not in the parent's primary frame list.
|
|
|
|
if (childIndex <= 0)
|
2007-08-24 03:39:08 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childCount = siblingList.GetLength();
|
2007-08-24 03:39:08 -07:00
|
|
|
// if it's the last index then we need to allow for resizeafter="grow"
|
|
|
|
if (childIndex == childCount - 1 && GetResizeAfter() != Grow)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRefPtr<nsRenderingContext> rc =
|
2014-04-14 21:30:25 -07:00
|
|
|
outerPresContext->PresShell()->CreateReferenceRenderingContext();
|
2007-04-29 15:24:59 -07:00
|
|
|
nsBoxLayoutState state(outerPresContext, rc);
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentPos = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
mPressed = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mDidDrag = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
EnsureOrient();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = !mOuter->IsHorizontal();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
mChildInfosBeforeCount = 0;
|
|
|
|
mChildInfosAfterCount = 0;
|
|
|
|
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIFrame* childBox = nsBox::GetChildBox(mParentBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != childBox)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIContent* content = childBox->GetContent();
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* doc = content->OwnerDoc();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t dummy;
|
2011-10-18 04:19:44 -07:00
|
|
|
nsIAtom* atom = doc->BindingManager()->ResolveTag(content, &dummy);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// skip over any splitters
|
|
|
|
if (atom != nsGkAtoms::splitter) {
|
|
|
|
nsSize prefSize = childBox->GetPrefSize(state);
|
|
|
|
nsSize minSize = childBox->GetMinSize(state);
|
2008-01-04 21:49:44 -08:00
|
|
|
nsSize maxSize = nsBox::BoundsCheckMinMax(minSize, childBox->GetMaxSize(state));
|
|
|
|
prefSize = nsBox::BoundsCheck(minSize, prefSize, maxSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mOuter->AddMargin(childBox, minSize);
|
|
|
|
mOuter->AddMargin(childBox, prefSize);
|
|
|
|
mOuter->AddMargin(childBox, maxSize);
|
|
|
|
|
|
|
|
nscoord flex = childBox->GetFlex(state);
|
|
|
|
|
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
childBox->GetMargin(margin);
|
|
|
|
nsRect r(childBox->GetRect());
|
|
|
|
r.Inflate(margin);
|
|
|
|
|
|
|
|
// We need to check for hidden attribute too, since treecols with
|
|
|
|
// the hidden="true" attribute are not really hidden, just collapsed
|
|
|
|
if (!content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::fixed,
|
|
|
|
nsGkAtoms::_true, eCaseMatters) &&
|
|
|
|
!content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
2007-11-14 19:38:16 -08:00
|
|
|
if (count < childIndex && (resizeBefore != Flex || flex > 0)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].childElem = content;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].min = isHorizontal ? minSize.width : minSize.height;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].max = isHorizontal ? maxSize.width : maxSize.height;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].current = isHorizontal ? r.width : r.height;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].flex = flex;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].index = count;
|
|
|
|
mChildInfosBefore[mChildInfosBeforeCount].changed = mChildInfosBefore[mChildInfosBeforeCount].current;
|
|
|
|
mChildInfosBeforeCount++;
|
2007-11-14 19:38:16 -08:00
|
|
|
} else if (count > childIndex && (resizeAfter != Flex || flex > 0)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mChildInfosAfter[mChildInfosAfterCount].childElem = content;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].min = isHorizontal ? minSize.width : minSize.height;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].max = isHorizontal ? maxSize.width : maxSize.height;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].current = isHorizontal ? r.width : r.height;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].flex = flex;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].index = count;
|
|
|
|
mChildInfosAfter[mChildInfosAfterCount].changed = mChildInfosAfter[mChildInfosAfterCount].current;
|
|
|
|
mChildInfosAfterCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 15:20:41 -07:00
|
|
|
childBox = nsBox::GetNextBox(childBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mParentBox->IsNormalDirection()) {
|
|
|
|
// The before array is really the after array, and the order needs to be reversed.
|
|
|
|
// First reverse both arrays.
|
|
|
|
Reverse(mChildInfosBefore, mChildInfosBeforeCount);
|
|
|
|
Reverse(mChildInfosAfter, mChildInfosAfterCount);
|
|
|
|
|
|
|
|
// Now swap the two arrays.
|
|
|
|
nscoord newAfterCount = mChildInfosBeforeCount;
|
|
|
|
mChildInfosBeforeCount = mChildInfosAfterCount;
|
|
|
|
mChildInfosAfterCount = newAfterCount;
|
|
|
|
nsSplitterInfo* temp = mChildInfosAfter;
|
|
|
|
mChildInfosAfter = mChildInfosBefore;
|
|
|
|
mChildInfosBefore = temp;
|
|
|
|
}
|
|
|
|
|
2007-11-14 19:38:16 -08:00
|
|
|
// if resizebefore is not Farthest, reverse the list because the first child
|
|
|
|
// in the list is the farthest, and we want the first child to be the closest.
|
|
|
|
if (resizeBefore != Farthest)
|
2007-03-22 10:30:00 -07:00
|
|
|
Reverse(mChildInfosBefore, mChildInfosBeforeCount);
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
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;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t c;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPoint pt = nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(mouseEvent,
|
|
|
|
mParentBox);
|
|
|
|
if (isHorizontal) {
|
|
|
|
c = pt.x;
|
|
|
|
mSplitterPos = mOuter->mRect.x;
|
|
|
|
} else {
|
|
|
|
c = pt.y;
|
|
|
|
mSplitterPos = mOuter->mRect.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDragStart = c;
|
|
|
|
|
|
|
|
//printf("Pressed mDragStart=%d\n",mDragStart);
|
|
|
|
|
2009-09-13 06:13:16 -07:00
|
|
|
nsIPresShell::SetCapturingContent(mOuter->GetContent(), CAPTURE_IGNOREALLOWED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSplitterFrameInner::MouseMove(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2007-05-21 00:33:32 -07:00
|
|
|
NS_ENSURE_TRUE(mOuter, NS_OK);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mPressed)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (mDragging)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-06-28 10:59:14 -07:00
|
|
|
nsCOMPtr<nsIDOMEventListener> kungfuDeathGrip(this);
|
|
|
|
mOuter->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::state,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("dragging"), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
RemoveListener();
|
2011-10-17 07:59:28 -07:00
|
|
|
mDragging = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSplitterFrameInner::Reverse(nsSplitterInfo*& aChildInfos, int32_t aCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsSplitterInfo* infos = new nsSplitterInfo[aCount];
|
|
|
|
|
|
|
|
for (int i=0; i < aCount; i++)
|
|
|
|
infos[i] = aChildInfos[aCount - 1 - i];
|
|
|
|
|
|
|
|
delete[] aChildInfos;
|
|
|
|
aChildInfos = infos;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSplitterFrameInner::SupportsCollapseDirection
|
|
|
|
(
|
|
|
|
nsSplitterFrameInner::CollapseDirection aDirection
|
|
|
|
)
|
|
|
|
{
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::before, &nsGkAtoms::after, &nsGkAtoms::both, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (mOuter->mContent->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::collapse,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
return (aDirection == Before);
|
|
|
|
case 1:
|
|
|
|
return (aDirection == After);
|
|
|
|
case 2:
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameInner::UpdateState()
|
|
|
|
{
|
|
|
|
// State Transitions:
|
|
|
|
// Open -> Dragging
|
|
|
|
// Open -> CollapsedBefore
|
|
|
|
// Open -> CollapsedAfter
|
|
|
|
// CollapsedBefore -> Open
|
|
|
|
// CollapsedBefore -> Dragging
|
|
|
|
// CollapsedAfter -> Open
|
|
|
|
// CollapsedAfter -> Dragging
|
|
|
|
// Dragging -> Open
|
|
|
|
// Dragging -> CollapsedBefore (auto collapse)
|
|
|
|
// Dragging -> CollapsedAfter (auto collapse)
|
|
|
|
|
|
|
|
State newState = GetState();
|
|
|
|
|
|
|
|
if (newState == mState) {
|
|
|
|
// No change.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-25 01:33:32 -07:00
|
|
|
if ((SupportsCollapseDirection(Before) || SupportsCollapseDirection(After)) &&
|
|
|
|
mOuter->GetParent()->IsBoxFrame()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Find the splitter's immediate sibling.
|
2009-04-25 01:33:32 -07:00
|
|
|
nsIFrame* splitterSibling;
|
|
|
|
if (newState == CollapsedBefore || mState == CollapsedBefore) {
|
2009-10-02 09:27:37 -07:00
|
|
|
splitterSibling = mOuter->GetPrevSibling();
|
2009-04-25 01:33:32 -07:00
|
|
|
} else {
|
|
|
|
splitterSibling = mOuter->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
2009-05-20 19:50:17 -07:00
|
|
|
if (splitterSibling) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIContent> sibling = splitterSibling->GetContent();
|
|
|
|
if (sibling) {
|
|
|
|
if (mState == CollapsedBefore || mState == CollapsedAfter) {
|
|
|
|
// CollapsedBefore -> Open
|
|
|
|
// CollapsedBefore -> Dragging
|
|
|
|
// CollapsedAfter -> Open
|
|
|
|
// CollapsedAfter -> Dragging
|
2008-04-14 16:59:21 -07:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsUnsetAttrRunnable(sibling, nsGkAtoms::collapsed));
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if ((mState == Open || mState == Dragging)
|
|
|
|
&& (newState == CollapsedBefore ||
|
|
|
|
newState == CollapsedAfter)) {
|
|
|
|
// Open -> CollapsedBefore / CollapsedAfter
|
|
|
|
// Dragging -> CollapsedBefore / CollapsedAfter
|
2008-04-14 16:59:21 -07:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsSetAttrRunnable(sibling, nsGkAtoms::collapsed,
|
|
|
|
NS_LITERAL_STRING("true")));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mState = newState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameInner::EnsureOrient()
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = !(mParentBox->GetStateBits() & NS_STATE_IS_HORIZONTAL);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isHorizontal)
|
|
|
|
mOuter->mState |= NS_STATE_IS_HORIZONTAL;
|
|
|
|
else
|
|
|
|
mOuter->mState &= ~NS_STATE_IS_HORIZONTAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameInner::AdjustChildren(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
EnsureOrient();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = !mOuter->IsHorizontal();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
AdjustChildren(aPresContext, mChildInfosBefore, mChildInfosBeforeCount, isHorizontal);
|
|
|
|
AdjustChildren(aPresContext, mChildInfosAfter, mChildInfosAfterCount, isHorizontal);
|
|
|
|
}
|
|
|
|
|
2012-08-05 20:00:57 -07:00
|
|
|
static nsIFrame* GetChildBoxForContent(nsIFrame* aParentBox, nsIContent* aContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIFrame* childBox = nsBox::GetChildBox(aParentBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != childBox) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (childBox->GetContent() == aContent) {
|
|
|
|
return childBox;
|
|
|
|
}
|
2014-05-24 15:20:41 -07:00
|
|
|
childBox = nsBox::GetNextBox(childBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSplitterFrameInner::AdjustChildren(nsPresContext* aPresContext, nsSplitterInfo* aChildInfos, int32_t aCount, bool aIsHorizontal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
///printf("------- AdjustChildren------\n");
|
|
|
|
|
|
|
|
nsBoxLayoutState state(aPresContext);
|
|
|
|
|
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
|
|
|
|
// first set all the widths.
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(mOuter);
|
2007-03-22 10:30:00 -07:00
|
|
|
while(child)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
SetPreferredSize(state, child, onePixel, aIsHorizontal, nullptr);
|
2014-05-24 15:20:41 -07:00
|
|
|
child = nsBox::GetNextBox(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// now set our changed widths.
|
|
|
|
for (int i=0; i < aCount; i++)
|
|
|
|
{
|
|
|
|
nscoord pref = aChildInfos[i].changed;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* childBox = GetChildBoxForContent(mParentBox, aChildInfos[i].childElem);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (childBox) {
|
|
|
|
SetPreferredSize(state, childBox, onePixel, aIsHorizontal, &pref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsSplitterFrameInner::SetPreferredSize(nsBoxLayoutState& aState, nsIFrame* aChildBox, nscoord aOnePixel, bool aIsHorizontal, nscoord* aSize)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsRect rect(aChildBox->GetRect());
|
|
|
|
nscoord pref = 0;
|
|
|
|
|
|
|
|
if (!aSize)
|
|
|
|
{
|
|
|
|
if (aIsHorizontal)
|
|
|
|
pref = rect.width;
|
|
|
|
else
|
|
|
|
pref = rect.height;
|
|
|
|
} else {
|
|
|
|
pref = *aSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
aChildBox->GetMargin(margin);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> attribute;
|
|
|
|
|
|
|
|
if (aIsHorizontal) {
|
|
|
|
pref -= (margin.left + margin.right);
|
|
|
|
attribute = nsGkAtoms::width;
|
|
|
|
} else {
|
|
|
|
pref -= (margin.top + margin.bottom);
|
|
|
|
attribute = nsGkAtoms::height;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* content = aChildBox->GetContent();
|
|
|
|
|
|
|
|
// set its preferred size.
|
|
|
|
nsAutoString prefValue;
|
|
|
|
prefValue.AppendInt(pref/aOnePixel);
|
|
|
|
if (content->AttrValueIs(kNameSpaceID_None, attribute,
|
|
|
|
prefValue, eCaseMatters))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsWeakFrame weakBox(aChildBox);
|
2011-10-17 07:59:28 -07:00
|
|
|
content->SetAttr(kNameSpaceID_None, attribute, prefValue, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
ENSURE_TRUE(weakBox.IsAlive());
|
2007-05-06 12:16:51 -07:00
|
|
|
aState.PresShell()->FrameNeedsReflow(aChildBox, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSplitterFrameInner::AddRemoveSpace(nscoord aDiff,
|
|
|
|
nsSplitterInfo* aChildInfos,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aCount,
|
|
|
|
int32_t& aSpaceLeft)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
nsSplitterFrameInner::ResizeChildTo(nsPresContext* aPresContext,
|
|
|
|
nscoord& aDiff,
|
|
|
|
nsSplitterInfo* aChildrenBeforeInfos,
|
|
|
|
nsSplitterInfo* aChildrenAfterInfos,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aChildrenBeforeCount,
|
|
|
|
int32_t aChildrenAfterCount,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aBounded)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|