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
|
|
|
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIBoxObject.h"
|
|
|
|
#include "nsTreeColumns.h"
|
|
|
|
#include "nsTreeUtils.h"
|
|
|
|
#include "nsStyleContext.h"
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
#include "nsContentUtils.h"
|
2007-08-23 05:27:50 -07:00
|
|
|
#include "nsTreeBodyFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Column class that caches all the info about our column.
|
|
|
|
nsTreeColumn::nsTreeColumn(nsTreeColumns* aColumns, nsIContent* aContent)
|
|
|
|
: mContent(aContent),
|
|
|
|
mColumns(aColumns),
|
2012-07-30 07:20:58 -07:00
|
|
|
mPrevious(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent &&
|
|
|
|
aContent->NodeInfo()->Equals(nsGkAtoms::treecol,
|
|
|
|
kNameSpaceID_XUL),
|
|
|
|
"nsTreeColumn's content must be a <xul:treecol>");
|
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTreeColumn::~nsTreeColumn()
|
|
|
|
{
|
|
|
|
if (mNext) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mNext->SetPrevious(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-28 07:07:26 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsTreeColumn)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mContent)
|
2011-08-28 07:07:26 -07:00
|
|
|
if (tmp->mNext) {
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mNext->SetPrevious(nullptr);
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNext)
|
2011-08-28 07:07:26 -07:00
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsTreeColumn)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNext)
|
2011-08-28 07:07:26 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2009-08-21 05:50:15 -07:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTreeColumn)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTreeColumn)
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(TreeColumn, nsTreeColumn)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsTreeColumn
|
2009-08-21 05:50:15 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTreeColumn)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITreeColumn)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2009-02-17 06:08:08 -08:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TreeColumn)
|
2008-10-27 21:47:19 -07:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsTreeColumn))) {
|
|
|
|
AddRef();
|
|
|
|
*aInstancePtr = this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsTreeColumn::GetFrame()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(mContent, nullptr);
|
2009-08-21 05:50:15 -07:00
|
|
|
|
2009-12-24 13:20:06 -08:00
|
|
|
return mContent->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-09-04 02:08:15 -07:00
|
|
|
nsTreeColumn::IsLastVisible(nsTreeBodyFrame* aBodyFrame)
|
|
|
|
{
|
2009-12-24 13:20:06 -08:00
|
|
|
NS_ASSERTION(GetFrame(), "should have checked for this already");
|
2007-09-04 02:08:15 -07:00
|
|
|
|
|
|
|
// cyclers are fixed width, don't adjust them
|
|
|
|
if (IsCycler())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-09-04 02:08:15 -07:00
|
|
|
|
|
|
|
// we're certainly not the last visible if we're not visible
|
2009-12-24 13:20:06 -08:00
|
|
|
if (GetFrame()->GetRect().width == 0)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-09-04 02:08:15 -07:00
|
|
|
|
|
|
|
// try to find a visible successor
|
|
|
|
for (nsTreeColumn *next = GetNext(); next; next = next->GetNext()) {
|
2009-12-24 13:20:06 -08:00
|
|
|
nsIFrame* frame = next->GetFrame();
|
2007-09-04 02:08:15 -07:00
|
|
|
if (frame && frame->GetRect().width > 0)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-09-04 02:08:15 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-09-04 02:08:15 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2007-08-23 05:27:50 -07:00
|
|
|
nsTreeColumn::GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight, nsRect* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-24 13:20:06 -08:00
|
|
|
nsIFrame* frame = GetFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frame) {
|
|
|
|
*aResult = nsRect();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
bool isRTL = aBodyFrame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
|
2007-03-22 10:30:00 -07:00
|
|
|
*aResult = frame->GetRect();
|
|
|
|
aResult->y = aY;
|
|
|
|
aResult->height = aHeight;
|
2009-01-13 10:00:06 -08:00
|
|
|
if (isRTL)
|
|
|
|
aResult->x += aBodyFrame->mAdjustWidth;
|
|
|
|
else if (IsLastVisible(aBodyFrame))
|
2007-08-23 05:27:50 -07:00
|
|
|
aResult->width += aBodyFrame->mAdjustWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2007-08-23 05:27:50 -07:00
|
|
|
nsTreeColumn::GetXInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-24 13:20:06 -08:00
|
|
|
nsIFrame* frame = GetFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frame) {
|
|
|
|
*aResult = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
*aResult = frame->GetRect().x;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2007-08-23 05:27:50 -07:00
|
|
|
nsTreeColumn::GetWidthInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-24 13:20:06 -08:00
|
|
|
nsIFrame* frame = GetFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frame) {
|
|
|
|
*aResult = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
*aResult = frame->GetRect().width;
|
2007-09-04 02:08:15 -07:00
|
|
|
if (IsLastVisible(aBodyFrame))
|
2007-08-23 05:27:50 -07:00
|
|
|
*aResult += aBodyFrame->mAdjustWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumn::GetElement(nsIDOMElement** aElement)
|
|
|
|
{
|
2009-08-21 05:50:15 -07:00
|
|
|
if (mContent) {
|
|
|
|
return CallQueryInterface(mContent, aElement);
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
*aElement = nullptr;
|
2009-08-21 05:50:15 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumn::GetColumns(nsITreeColumns** aColumns)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aColumns = mColumns);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeColumn::GetX(int32_t* aX)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
*aX = nsPresContext::AppUnitsToIntCSSPixels(frame->GetRect().x);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeColumn::GetWidth(int32_t* aWidth)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
*aWidth = nsPresContext::AppUnitsToIntCSSPixels(frame->GetRect().width);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumn::GetId(nsAString& aId)
|
|
|
|
{
|
|
|
|
aId = GetId();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumn::GetIdConst(const PRUnichar** aIdConst)
|
|
|
|
{
|
|
|
|
*aIdConst = mId.get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumn::GetAtom(nsIAtom** aAtom)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aAtom = GetAtom());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeColumn::GetIndex(int32_t* aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aIndex = GetIndex();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTreeColumn::GetPrimary(bool* aPrimary)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aPrimary = IsPrimary();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTreeColumn::GetCycler(bool* aCycler)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aCycler = IsCycler();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTreeColumn::GetEditable(bool* aEditable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aEditable = IsEditable();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTreeColumn::GetSelectable(bool* aSelectable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aSelectable = IsSelectable();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeColumn::GetType(int16_t* aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aType = GetType();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumn::GetNext(nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*_retval = GetNext());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumn::GetPrevious(nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*_retval = GetPrevious());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumn::Invalidate()
|
|
|
|
{
|
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Fetch the Id.
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, mId);
|
|
|
|
|
|
|
|
// If we have an Id, cache the Id as an atom.
|
|
|
|
if (!mId.IsEmpty()) {
|
|
|
|
mAtom = do_GetAtom(mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache our index.
|
|
|
|
nsTreeUtils::GetColumnIndex(mContent, &mIndex);
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleVisibility* vis = frame->StyleVisibility();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Cache our text alignment policy.
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleText* textStyle = frame->StyleText();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mTextAlignment = textStyle->mTextAlign;
|
2009-02-05 19:48:30 -08:00
|
|
|
// DEFAULT or END alignment sometimes means RIGHT
|
|
|
|
if ((mTextAlignment == NS_STYLE_TEXT_ALIGN_DEFAULT &&
|
|
|
|
vis->mDirection == NS_STYLE_DIRECTION_RTL) ||
|
|
|
|
(mTextAlignment == NS_STYLE_TEXT_ALIGN_END &&
|
|
|
|
vis->mDirection == NS_STYLE_DIRECTION_LTR)) {
|
|
|
|
mTextAlignment = NS_STYLE_TEXT_ALIGN_RIGHT;
|
2009-02-05 19:52:47 -08:00
|
|
|
} else if (mTextAlignment == NS_STYLE_TEXT_ALIGN_DEFAULT ||
|
|
|
|
mTextAlignment == NS_STYLE_TEXT_ALIGN_END) {
|
|
|
|
mTextAlignment = NS_STYLE_TEXT_ALIGN_LEFT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out if we're the primary column (that has to have indentation
|
|
|
|
// and twisties drawn.
|
|
|
|
mIsPrimary = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::primary,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
|
|
|
|
|
|
// Figure out if we're a cycling column (one that doesn't cause a selection
|
|
|
|
// to happen).
|
|
|
|
mIsCycler = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::cycler,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
|
|
|
|
|
|
mIsEditable = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::editable,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
|
|
|
|
|
|
mIsSelectable = !mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::selectable,
|
|
|
|
nsGkAtoms::_false, eCaseMatters);
|
|
|
|
|
|
|
|
mOverflow = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::overflow,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
|
|
|
|
|
|
// Figure out our column type. Default type is text.
|
|
|
|
mType = nsITreeColumn::TYPE_TEXT;
|
|
|
|
static nsIContent::AttrValuesArray typestrings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::checkbox, &nsGkAtoms::progressmeter, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
typestrings, eCaseMatters)) {
|
|
|
|
case 0: mType = nsITreeColumn::TYPE_CHECKBOX; break;
|
|
|
|
case 1: mType = nsITreeColumn::TYPE_PROGRESSMETER; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch the crop style.
|
|
|
|
mCropStyle = 0;
|
|
|
|
static nsIContent::AttrValuesArray cropstrings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::center, &nsGkAtoms::left, &nsGkAtoms::start, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::crop,
|
|
|
|
cropstrings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
mCropStyle = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
mCropStyle = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-18 04:37:19 -08:00
|
|
|
nsTreeColumns::nsTreeColumns(nsTreeBodyFrame* aTree)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mTree(aTree),
|
2012-07-30 07:20:58 -07:00
|
|
|
mFirstColumn(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTreeColumns::~nsTreeColumns()
|
|
|
|
{
|
2009-08-07 14:17:02 -07:00
|
|
|
nsTreeColumns::InvalidateColumns();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(TreeColumns, nsTreeColumns)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsTreeColumns
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsTreeColumns)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITreeColumns)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2009-02-17 06:08:08 -08:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TreeColumns)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTreeColumns)
|
|
|
|
NS_IMPL_RELEASE(nsTreeColumns)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::GetTree(nsITreeBoxObject** _retval)
|
|
|
|
{
|
2012-11-18 04:37:19 -08:00
|
|
|
NS_IF_ADDREF(*_retval = mTree ? mTree->GetTreeBoxObject() : nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeColumns::GetCount(int32_t* _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
EnsureColumns();
|
|
|
|
*_retval = 0;
|
|
|
|
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
|
|
|
|
++(*_retval);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeColumns::GetLength(int32_t* _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return GetCount(_retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::GetFirstColumn(nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*_retval = GetFirstColumn());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::GetLastColumn(nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
EnsureColumns();
|
2012-07-30 07:20:58 -07:00
|
|
|
*_retval = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTreeColumn* currCol = mFirstColumn;
|
|
|
|
while (currCol) {
|
|
|
|
nsTreeColumn* next = currCol->GetNext();
|
|
|
|
if (!next) {
|
|
|
|
NS_ADDREF(*_retval = currCol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
currCol = next;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::GetPrimaryColumn(nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*_retval = GetPrimaryColumn());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::GetSortedColumn(nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
EnsureColumns();
|
2012-07-30 07:20:58 -07:00
|
|
|
*_retval = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
|
2009-08-21 05:50:15 -07:00
|
|
|
if (currCol->mContent &&
|
|
|
|
nsContentUtils::HasNonEmptyAttr(currCol->mContent, kNameSpaceID_None,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::sortDirection)) {
|
|
|
|
NS_ADDREF(*_retval = currCol);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::GetKeyColumn(nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
EnsureColumns();
|
2012-07-30 07:20:58 -07:00
|
|
|
*_retval = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsTreeColumn* first;
|
|
|
|
nsTreeColumn* primary;
|
|
|
|
nsTreeColumn* sorted;
|
2012-07-30 07:20:58 -07:00
|
|
|
first = primary = sorted = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
|
|
|
|
// Skip hidden columns.
|
2009-08-21 05:50:15 -07:00
|
|
|
if (!currCol->mContent ||
|
|
|
|
currCol->mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Skip non-text column
|
|
|
|
if (currCol->GetType() != nsITreeColumn::TYPE_TEXT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
first = currCol;
|
|
|
|
|
|
|
|
if (nsContentUtils::HasNonEmptyAttr(currCol->mContent, kNameSpaceID_None,
|
|
|
|
nsGkAtoms::sortDirection)) {
|
|
|
|
// Use sorted column as the key.
|
|
|
|
sorted = currCol;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currCol->IsPrimary())
|
|
|
|
if (!primary)
|
|
|
|
primary = currCol;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sorted)
|
|
|
|
*_retval = sorted;
|
|
|
|
else if (primary)
|
|
|
|
*_retval = primary;
|
|
|
|
else
|
|
|
|
*_retval = first;
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::GetColumnFor(nsIDOMElement* aElement, nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
EnsureColumns();
|
2012-07-30 07:20:58 -07:00
|
|
|
*_retval = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIContent> element = do_QueryInterface(aElement);
|
|
|
|
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
|
|
|
|
if (currCol->mContent == element) {
|
|
|
|
NS_ADDREF(*_retval = currCol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-31 14:40:35 -07:00
|
|
|
nsITreeColumn*
|
|
|
|
nsTreeColumns::GetNamedColumn(const nsAString& aId)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
EnsureColumns();
|
|
|
|
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
|
|
|
|
if (currCol->GetId().Equals(aId)) {
|
2008-10-31 14:40:35 -07:00
|
|
|
return currCol;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-31 14:40:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::GetNamedColumn(const nsAString& aId, nsITreeColumn** _retval)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*_retval = GetNamedColumn(aId));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 07:31:14 -07:00
|
|
|
nsITreeColumn*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeColumns::GetColumnAt(int32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
EnsureColumns();
|
|
|
|
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
|
|
|
|
if (currCol->GetIndex() == aIndex) {
|
2008-10-22 07:31:14 -07:00
|
|
|
return currCol;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeColumns::GetColumnAt(int32_t aIndex, nsITreeColumn** _retval)
|
2008-10-22 07:31:14 -07:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*_retval = GetColumnAt(aIndex));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::InvalidateColumns()
|
|
|
|
{
|
2009-08-07 14:17:02 -07:00
|
|
|
for (nsTreeColumn* currCol = mFirstColumn; currCol;
|
|
|
|
currCol = currCol->GetNext()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
currCol->SetColumns(nullptr);
|
2009-08-07 14:17:02 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IF_RELEASE(mFirstColumn);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTreeColumns::RestoreNaturalOrder()
|
|
|
|
{
|
|
|
|
if (!mTree)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-11-18 04:37:19 -08:00
|
|
|
nsIContent* content = mTree->GetBaseElement();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-19 08:55:07 -08:00
|
|
|
// Strong ref, since we'll be setting attributes
|
|
|
|
nsCOMPtr<nsIContent> colsContent =
|
|
|
|
nsTreeUtils::GetImmediateChild(content, nsGkAtoms::treecols);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!colsContent)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t numChildren = colsContent->GetChildCount();
|
|
|
|
for (uint32_t i = 0; i < numChildren; ++i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent *child = colsContent->GetChildAt(i);
|
|
|
|
nsAutoString ordinal;
|
|
|
|
ordinal.AppendInt(i);
|
2011-10-17 07:59:28 -07:00
|
|
|
child->SetAttr(kNameSpaceID_None, nsGkAtoms::ordinal, ordinal, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-07 14:17:02 -07:00
|
|
|
nsTreeColumns::InvalidateColumns();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mTree->Invalidate();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTreeColumn*
|
|
|
|
nsTreeColumns::GetPrimaryColumn()
|
|
|
|
{
|
|
|
|
EnsureColumns();
|
|
|
|
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
|
|
|
|
if (currCol->IsPrimary()) {
|
|
|
|
return currCol;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTreeColumns::EnsureColumns()
|
|
|
|
{
|
|
|
|
if (mTree && !mFirstColumn) {
|
2012-11-18 04:37:19 -08:00
|
|
|
nsIContent* treeContent = mTree->GetBaseElement();
|
2009-02-19 08:55:07 -08:00
|
|
|
nsIContent* colsContent =
|
|
|
|
nsTreeUtils::GetDescendantChild(treeContent, nsGkAtoms::treecols);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!colsContent)
|
|
|
|
return;
|
|
|
|
|
2009-02-19 08:55:07 -08:00
|
|
|
nsIContent* colContent =
|
|
|
|
nsTreeUtils::GetDescendantChild(colsContent, nsGkAtoms::treecol);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!colContent)
|
|
|
|
return;
|
|
|
|
|
2009-12-24 13:20:06 -08:00
|
|
|
nsIFrame* colFrame = colContent->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!colFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
colFrame = colFrame->GetParent();
|
|
|
|
if (!colFrame)
|
|
|
|
return;
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
colFrame = colFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!colFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Now that we have the first visible column,
|
|
|
|
// we can enumerate the columns in visible order
|
2012-07-30 07:20:58 -07:00
|
|
|
nsTreeColumn* currCol = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (colFrame) {
|
|
|
|
nsIContent* colContent = colFrame->GetContent();
|
|
|
|
|
|
|
|
if (colContent->NodeInfo()->Equals(nsGkAtoms::treecol,
|
|
|
|
kNameSpaceID_XUL)) {
|
|
|
|
// Create a new column structure.
|
|
|
|
nsTreeColumn* col = new nsTreeColumn(this, colContent);
|
|
|
|
if (!col)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (currCol) {
|
|
|
|
currCol->SetNext(col);
|
|
|
|
col->SetPrevious(currCol);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(mFirstColumn = col);
|
|
|
|
}
|
|
|
|
currCol = col;
|
|
|
|
}
|
|
|
|
|
|
|
|
colFrame = colFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|