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 "nsReadableUtils.h"
|
|
|
|
#include "nsTreeUtils.h"
|
2013-05-01 15:50:08 -07:00
|
|
|
#include "ChildIterator.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
namespace dom = mozilla::dom;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2013-03-19 08:46:20 -07:00
|
|
|
nsTreeUtils::TokenizeProperties(const nsAString& aProperties, AtomArray & aPropertiesArray)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsAString::const_iterator end;
|
|
|
|
aProperties.EndReading(end);
|
|
|
|
|
|
|
|
nsAString::const_iterator iter;
|
|
|
|
aProperties.BeginReading(iter);
|
|
|
|
|
|
|
|
do {
|
|
|
|
// Skip whitespace
|
|
|
|
while (iter != end && nsCRT::IsAsciiSpace(*iter))
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
// If only whitespace, we're done
|
|
|
|
if (iter == end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Note the first non-whitespace character
|
|
|
|
nsAString::const_iterator first = iter;
|
|
|
|
|
|
|
|
// Advance to the next whitespace character
|
|
|
|
while (iter != end && ! nsCRT::IsAsciiSpace(*iter))
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
// XXX this would be nonsensical
|
|
|
|
NS_ASSERTION(iter != first, "eh? something's wrong here");
|
|
|
|
if (iter == first)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> atom = do_GetAtom(Substring(first, iter));
|
2013-03-19 08:46:20 -07:00
|
|
|
aPropertiesArray.AppendElement(atom);
|
2007-03-22 10:30:00 -07:00
|
|
|
} while (iter != end);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-19 08:55:07 -08:00
|
|
|
nsIContent*
|
|
|
|
nsTreeUtils::GetImmediateChild(nsIContent* aContainer, nsIAtom* aTag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-05-01 15:50:08 -07:00
|
|
|
dom::FlattenedChildIterator iter(aContainer);
|
|
|
|
for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (child->Tag() == aTag) {
|
2009-02-19 08:55:07 -08:00
|
|
|
return child;
|
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
|
|
|
}
|
|
|
|
|
2009-02-19 08:55:07 -08:00
|
|
|
nsIContent*
|
|
|
|
nsTreeUtils::GetDescendantChild(nsIContent* aContainer, nsIAtom* aTag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-05-01 15:50:08 -07:00
|
|
|
dom::FlattenedChildIterator iter(aContainer);
|
|
|
|
for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (child->Tag() == aTag) {
|
2009-02-19 08:55:07 -08:00
|
|
|
return child;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-02-19 08:55:07 -08:00
|
|
|
child = GetDescendantChild(child, aTag);
|
|
|
|
if (child) {
|
|
|
|
return child;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTreeUtils::UpdateSortIndicators(nsIContent* aColumn, const nsAString& aDirection)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
aColumn->SetAttr(kNameSpaceID_None, nsGkAtoms::sortDirection, aDirection, true);
|
|
|
|
aColumn->SetAttr(kNameSpaceID_None, nsGkAtoms::sortActive, NS_LITERAL_STRING("true"), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Unset sort attribute(s) on the other columns
|
|
|
|
nsCOMPtr<nsIContent> parentContent = aColumn->GetParent();
|
|
|
|
if (parentContent &&
|
|
|
|
parentContent->NodeInfo()->Equals(nsGkAtoms::treecols,
|
|
|
|
kNameSpaceID_XUL)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i, numChildren = parentContent->GetChildCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < numChildren; ++i) {
|
|
|
|
nsCOMPtr<nsIContent> childContent = parentContent->GetChildAt(i);
|
|
|
|
|
|
|
|
if (childContent &&
|
|
|
|
childContent != aColumn &&
|
|
|
|
childContent->NodeInfo()->Equals(nsGkAtoms::treecol,
|
|
|
|
kNameSpaceID_XUL)) {
|
|
|
|
childContent->UnsetAttr(kNameSpaceID_None,
|
2011-10-17 07:59:28 -07:00
|
|
|
nsGkAtoms::sortDirection, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
childContent->UnsetAttr(kNameSpaceID_None,
|
2011-10-17 07:59:28 -07:00
|
|
|
nsGkAtoms::sortActive, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsTreeUtils::GetColumnIndex(nsIContent* aColumn, int32_t* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIContent* parentContent = aColumn->GetParent();
|
|
|
|
if (parentContent &&
|
|
|
|
parentContent->NodeInfo()->Equals(nsGkAtoms::treecols,
|
|
|
|
kNameSpaceID_XUL)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i, numChildren = parentContent->GetChildCount();
|
|
|
|
int32_t colIndex = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < numChildren; ++i) {
|
|
|
|
nsIContent *childContent = parentContent->GetChildAt(i);
|
|
|
|
if (childContent &&
|
|
|
|
childContent->NodeInfo()->Equals(nsGkAtoms::treecol,
|
|
|
|
kNameSpaceID_XUL)) {
|
|
|
|
if (childContent == aColumn) {
|
|
|
|
*aResult = colIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
++colIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|