2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-02-05 05:45:55 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2002-03-29 05:46:01 +03:00
|
|
|
#include "nsTreeColFrame.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2001-02-05 05:45:55 +03:00
|
|
|
#include "nsIContent.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2001-03-06 05:27:50 +03:00
|
|
|
#include "nsIBoxObject.h"
|
2014-10-15 00:15:21 +04:00
|
|
|
#include "mozilla/dom/TreeBoxObject.h"
|
2001-03-06 05:27:50 +03:00
|
|
|
#include "nsIDOMElement.h"
|
2006-12-29 16:20:23 +03:00
|
|
|
#include "nsITreeColumns.h"
|
2004-05-14 17:58:00 +04:00
|
|
|
#include "nsIDOMXULTreeElement.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2008-10-28 07:47:19 +03:00
|
|
|
#include "nsTreeBodyFrame.h"
|
2001-02-05 05:45:55 +03:00
|
|
|
|
|
|
|
//
|
2002-03-29 05:46:01 +03:00
|
|
|
// NS_NewTreeColFrame
|
2001-02-05 05:45:55 +03:00
|
|
|
//
|
|
|
|
// Creates a new col frame
|
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
nsIFrame*
|
2009-01-19 21:31:33 +03:00
|
|
|
NS_NewTreeColFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2001-02-05 05:45:55 +03:00
|
|
|
{
|
2015-01-06 12:27:56 +03:00
|
|
|
return new (aPresShell) nsTreeColFrame(aContext);
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTreeColFrame)
|
2001-02-05 05:45:55 +03:00
|
|
|
|
|
|
|
// Destructor
|
2002-03-29 05:46:01 +03:00
|
|
|
nsTreeColFrame::~nsTreeColFrame()
|
2001-02-05 05:45:55 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsTreeColFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2001-09-26 02:17:47 +04:00
|
|
|
{
|
2013-03-20 05:47:48 +04:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2006-12-29 16:20:23 +03:00
|
|
|
InvalidateColumns();
|
2001-09-26 02:17:47 +04:00
|
|
|
}
|
|
|
|
|
2009-12-24 08:21:15 +03:00
|
|
|
void
|
|
|
|
nsTreeColFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2004-05-04 15:13:32 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
InvalidateColumns(false);
|
2009-12-24 08:21:15 +03:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
2004-05-04 15:13:32 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
class nsDisplayXULTreeColSplitterTarget : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayXULTreeColSplitterTarget(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame) :
|
|
|
|
nsDisplayItem(aBuilder, aFrame) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayXULTreeColSplitterTarget);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayXULTreeColSplitterTarget() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayXULTreeColSplitterTarget);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
2014-02-24 18:41:56 +04:00
|
|
|
HitTestState* aState,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsTArray<nsIFrame*> *aOutFrames) override;
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("XULTreeColSplitterTarget", TYPE_XUL_TREE_COL_SPLITTER_TARGET)
|
2006-01-26 05:29:17 +03:00
|
|
|
};
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
void
|
|
|
|
nsDisplayXULTreeColSplitterTarget::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
2001-02-05 05:45:55 +03:00
|
|
|
{
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect rect = aRect - ToReferenceFrame();
|
2010-04-08 04:31:26 +04:00
|
|
|
// If we are in either in the first 4 pixels or the last 4 pixels, we're going to
|
2001-02-05 05:45:55 +03:00
|
|
|
// do something really strange. Check for an adjacent splitter.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool left = false;
|
|
|
|
bool right = false;
|
2010-04-08 04:31:26 +04:00
|
|
|
if (mFrame->GetSize().width - nsPresContext::CSSPixelsToAppUnits(4) <= rect.XMost()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
right = true;
|
2010-04-08 04:31:26 +04:00
|
|
|
} else if (nsPresContext::CSSPixelsToAppUnits(4) > rect.x) {
|
2011-10-17 18:59:28 +04:00
|
|
|
left = true;
|
2010-04-08 04:31:26 +04:00
|
|
|
}
|
2001-02-05 05:45:55 +03:00
|
|
|
|
2009-07-15 11:22:42 +04:00
|
|
|
// Swap left and right for RTL trees in order to find the correct splitter
|
2013-02-17 01:51:02 +04:00
|
|
|
if (mFrame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool tmp = left;
|
2009-07-15 11:22:42 +04:00
|
|
|
left = right;
|
|
|
|
right = tmp;
|
|
|
|
}
|
|
|
|
|
2001-02-05 05:45:55 +03:00
|
|
|
if (left || right) {
|
|
|
|
// We are a header. Look for the correct splitter.
|
|
|
|
nsIFrame* child;
|
|
|
|
if (left)
|
2009-10-02 20:27:37 +04:00
|
|
|
child = mFrame->GetPrevSibling();
|
2003-08-04 16:39:51 +04:00
|
|
|
else
|
2006-01-26 05:29:17 +03:00
|
|
|
child = mFrame->GetNextSibling();
|
2001-02-05 05:45:55 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (child && child->GetContent()->NodeInfo()->Equals(nsGkAtoms::splitter,
|
2005-09-24 22:43:15 +04:00
|
|
|
kNameSpaceID_XUL)) {
|
2010-04-08 04:31:26 +04:00
|
|
|
aOutFrames->AppendElement(child);
|
2001-02-05 05:45:55 +03:00
|
|
|
}
|
|
|
|
}
|
2010-04-08 04:31:26 +04:00
|
|
|
|
2001-02-05 05:45:55 +03:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsTreeColFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2013-02-14 15:08:08 +04:00
|
|
|
if (!aBuilder->IsForEventDelivery()) {
|
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2013-02-14 15:08:08 +04:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
nsDisplayListCollection set;
|
2013-02-14 15:08:08 +04:00
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, set);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
WrapListsInRedirector(aBuilder, set, aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayXULTreeColSplitterTarget(aBuilder, this));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsTreeColFrame::AttributeChanged(int32_t aNameSpaceID,
|
2003-07-12 01:16:12 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2001-03-06 05:27:50 +03:00
|
|
|
{
|
2005-09-07 20:49:21 +04:00
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
2001-03-06 05:27:50 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::ordinal || aAttribute == nsGkAtoms::primary) {
|
2006-12-29 16:20:23 +03:00
|
|
|
InvalidateColumns();
|
2004-10-01 02:41:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
void
|
2004-10-01 02:41:23 +04:00
|
|
|
nsTreeColFrame::SetBounds(nsBoxLayoutState& aBoxLayoutState,
|
|
|
|
const nsRect& aRect,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRemoveOverflowArea) {
|
2004-10-01 02:41:23 +04:00
|
|
|
nscoord oldWidth = mRect.width;
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
nsBoxFrame::SetBounds(aBoxLayoutState, aRect, aRemoveOverflowArea);
|
2004-10-01 02:41:23 +04:00
|
|
|
if (mRect.width != oldWidth) {
|
2006-12-29 16:20:23 +03:00
|
|
|
nsITreeBoxObject* treeBoxObject = GetTreeBoxObject();
|
|
|
|
if (treeBoxObject) {
|
|
|
|
treeBoxObject->Invalidate();
|
2004-05-14 17:58:00 +04:00
|
|
|
}
|
2004-04-17 09:53:38 +04:00
|
|
|
}
|
2001-03-06 05:27:50 +03:00
|
|
|
}
|
2001-09-26 02:17:47 +04:00
|
|
|
|
2006-12-29 16:20:23 +03:00
|
|
|
nsITreeBoxObject*
|
|
|
|
nsTreeColFrame::GetTreeBoxObject()
|
2001-09-26 02:17:47 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
nsITreeBoxObject* result = nullptr;
|
2006-12-29 16:20:23 +03:00
|
|
|
|
|
|
|
nsIContent* parent = mContent->GetParent();
|
|
|
|
if (parent) {
|
|
|
|
nsIContent* grandParent = parent->GetParent();
|
|
|
|
nsCOMPtr<nsIDOMXULElement> treeElement = do_QueryInterface(grandParent);
|
|
|
|
if (treeElement) {
|
|
|
|
nsCOMPtr<nsIBoxObject> boxObject;
|
|
|
|
treeElement->GetBoxObject(getter_AddRefs(boxObject));
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeBoxObject> treeBoxObject = do_QueryInterface(boxObject);
|
|
|
|
result = treeBoxObject.get();
|
2001-12-18 16:42:28 +03:00
|
|
|
}
|
2001-09-26 02:17:47 +04:00
|
|
|
}
|
2006-12-29 16:20:23 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsTreeColFrame::InvalidateColumns(bool aCanWalkFrameTree)
|
2006-12-29 16:20:23 +03:00
|
|
|
{
|
|
|
|
nsITreeBoxObject* treeBoxObject = GetTreeBoxObject();
|
|
|
|
if (treeBoxObject) {
|
|
|
|
nsCOMPtr<nsITreeColumns> columns;
|
2007-11-20 05:01:19 +03:00
|
|
|
|
|
|
|
if (aCanWalkFrameTree) {
|
|
|
|
treeBoxObject->GetColumns(getter_AddRefs(columns));
|
|
|
|
} else {
|
2014-10-15 00:15:21 +04:00
|
|
|
nsTreeBodyFrame* body = static_cast<mozilla::dom::TreeBoxObject*>
|
|
|
|
(treeBoxObject)->GetCachedTreeBodyFrame();
|
2007-11-20 05:01:19 +03:00
|
|
|
if (body) {
|
2012-11-18 16:40:17 +04:00
|
|
|
columns = body->Columns();
|
2007-11-20 05:01:19 +03:00
|
|
|
}
|
|
|
|
}
|
2006-12-29 16:20:23 +03:00
|
|
|
|
|
|
|
if (columns)
|
|
|
|
columns->InvalidateColumns();
|
|
|
|
}
|
2001-09-26 02:17:47 +04:00
|
|
|
}
|