mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-14 03:51:46 +00:00
Fix for bugs:
135002 - timing issues in the outliner content model. 137890 - twisties doesn't appear for empty="true" on treeitems. r=bryner, sr=hewitt,ben - added support for hidden attribute on a treeitem
This commit is contained in:
parent
41040451bd
commit
e17f6e1104
@ -773,15 +773,65 @@ nsTreeContentView::AttributeChanged(nsIDocument *aDocument,
|
|||||||
PRInt32 aModType,
|
PRInt32 aModType,
|
||||||
PRInt32 aHint)
|
PRInt32 aHint)
|
||||||
{
|
{
|
||||||
// First, get the element on which the attribute has changed
|
// Make sure this notification concerns us.
|
||||||
// and then try to find content item in our array of rows.
|
// First check the tag to see if it's one that we care about.
|
||||||
|
|
||||||
if (!aContent->IsContentOfType(nsIContent::eXUL))
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIAtom> tag;
|
nsCOMPtr<nsIAtom> tag;
|
||||||
aContent->GetTag(*getter_AddRefs(tag));
|
aContent->GetTag(*getter_AddRefs(tag));
|
||||||
|
|
||||||
|
if (aContent->IsContentOfType(nsIContent::eXUL)) {
|
||||||
|
if (tag != nsXULAtoms::treecol &&
|
||||||
|
tag != nsXULAtoms::treeitem &&
|
||||||
|
tag != nsXULAtoms::treeseparator &&
|
||||||
|
tag != nsXULAtoms::treerow &&
|
||||||
|
tag != nsXULAtoms::treecell)
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
// If we have a legal tag, go up to the tree and make sure that it's ours.
|
||||||
|
nsCOMPtr<nsIContent> parent = aContent;
|
||||||
|
nsCOMPtr<nsIAtom> parentTag;
|
||||||
|
do {
|
||||||
|
nsCOMPtr<nsIContent> temp = parent;
|
||||||
|
temp->GetParent(*getter_AddRefs(parent));
|
||||||
|
if (parent)
|
||||||
|
parent->GetTag(*getter_AddRefs(parentTag));
|
||||||
|
} while (parent && parentTag != nsXULAtoms::tree);
|
||||||
|
if (parent != mRoot) {
|
||||||
|
// This is not for us, we can bail out.
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle changes of the hidden attribute.
|
||||||
|
if (aAttribute == nsHTMLAtoms::hidden &&
|
||||||
|
(tag == nsXULAtoms::treeitem || tag == nsXULAtoms::treeseparator)) {
|
||||||
|
nsAutoString hiddenString;
|
||||||
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::hidden, hiddenString);
|
||||||
|
PRBool hidden = hiddenString.Equals(NS_LITERAL_STRING("true"));
|
||||||
|
|
||||||
|
PRInt32 index = FindContent(aContent);
|
||||||
|
if (hidden && index >= 0) {
|
||||||
|
// Hide this row along with its children.
|
||||||
|
PRInt32 count;
|
||||||
|
RemoveRow(index, &count);
|
||||||
|
mBoxObject->RowCountChanged(index, -count);
|
||||||
|
}
|
||||||
|
else if (!hidden && index < 0) {
|
||||||
|
// Show this row along with its children.
|
||||||
|
nsCOMPtr<nsIContent> container;
|
||||||
|
aContent->GetParent(*getter_AddRefs(container));
|
||||||
|
if (container) {
|
||||||
|
nsCOMPtr<nsIContent> parent;
|
||||||
|
container->GetParent(*getter_AddRefs(parent));
|
||||||
|
if (parent)
|
||||||
|
InsertRowFor(parent, container, aContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == nsXULAtoms::treecol) {
|
if (tag == nsXULAtoms::treecol) {
|
||||||
if (aAttribute == nsXULAtoms::properties) {
|
if (aAttribute == nsXULAtoms::properties) {
|
||||||
nsAutoString id;
|
nsAutoString id;
|
||||||
@ -791,18 +841,16 @@ nsTreeContentView::AttributeChanged(nsIDocument *aDocument,
|
|||||||
}
|
}
|
||||||
else if (tag == nsXULAtoms::treeitem) {
|
else if (tag == nsXULAtoms::treeitem) {
|
||||||
PRInt32 index = FindContent(aContent);
|
PRInt32 index = FindContent(aContent);
|
||||||
Row* row = (Row*)mRows[index];
|
if (index >= 0) {
|
||||||
if (aAttribute == nsXULAtoms::container) {
|
Row* row = (Row*)mRows[index];
|
||||||
if (index >= 0) {
|
if (aAttribute == nsXULAtoms::container) {
|
||||||
nsAutoString container;
|
nsAutoString container;
|
||||||
aContent->GetAttr(kNameSpaceID_None, nsXULAtoms::container, container);
|
aContent->GetAttr(kNameSpaceID_None, nsXULAtoms::container, container);
|
||||||
PRBool isContainer = container.Equals(NS_LITERAL_STRING("true"));
|
PRBool isContainer = container.Equals(NS_LITERAL_STRING("true"));
|
||||||
row->SetContainer(isContainer);
|
row->SetContainer(isContainer);
|
||||||
mBoxObject->InvalidateRow(index);
|
mBoxObject->InvalidateRow(index);
|
||||||
}
|
}
|
||||||
}
|
else if (aAttribute == nsXULAtoms::open) {
|
||||||
else if (aAttribute == nsXULAtoms::open) {
|
|
||||||
if (index >= 0) {
|
|
||||||
nsAutoString open;
|
nsAutoString open;
|
||||||
aContent->GetAttr(kNameSpaceID_None, nsXULAtoms::open, open);
|
aContent->GetAttr(kNameSpaceID_None, nsXULAtoms::open, open);
|
||||||
PRBool isOpen = open.Equals(NS_LITERAL_STRING("true"));
|
PRBool isOpen = open.Equals(NS_LITERAL_STRING("true"));
|
||||||
@ -812,12 +860,19 @@ nsTreeContentView::AttributeChanged(nsIDocument *aDocument,
|
|||||||
else if (isOpen && ! wasOpen)
|
else if (isOpen && ! wasOpen)
|
||||||
OpenContainer(index);
|
OpenContainer(index);
|
||||||
}
|
}
|
||||||
|
else if (aAttribute == nsXULAtoms::empty) {
|
||||||
|
nsAutoString empty;
|
||||||
|
aContent->GetAttr(kNameSpaceID_None, nsXULAtoms::empty, empty);
|
||||||
|
PRBool isEmpty = empty.Equals(NS_LITERAL_STRING("true"));
|
||||||
|
row->SetEmpty(isEmpty);
|
||||||
|
mBoxObject->InvalidateRow(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (tag == nsXULAtoms::treeseparator) {
|
else if (tag == nsXULAtoms::treeseparator) {
|
||||||
if (aAttribute == nsXULAtoms::properties) {
|
PRInt32 index = FindContent(aContent);
|
||||||
PRInt32 index = FindContent(aContent);
|
if (index >= 0) {
|
||||||
if (index >= 0) {
|
if (aAttribute == nsXULAtoms::properties) {
|
||||||
Row* row = (Row*)mRows[index];
|
Row* row = (Row*)mRows[index];
|
||||||
row->SetProperty(nsnull);
|
row->SetProperty(nsnull);
|
||||||
ParseProperties(aContent, &row->mProperty);
|
ParseProperties(aContent, &row->mProperty);
|
||||||
@ -921,53 +976,13 @@ nsTreeContentView::ContentInserted(nsIDocument *aDocument,
|
|||||||
|
|
||||||
if (childTag == nsXULAtoms::treeitem ||
|
if (childTag == nsXULAtoms::treeitem ||
|
||||||
childTag == nsXULAtoms::treeseparator) {
|
childTag == nsXULAtoms::treeseparator) {
|
||||||
PRInt32 parentIndex = -1;
|
|
||||||
PRBool insertRow = PR_FALSE;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> parent;
|
nsCOMPtr<nsIContent> parent;
|
||||||
aContainer->GetParent(*getter_AddRefs(parent));
|
aContainer->GetParent(*getter_AddRefs(parent));
|
||||||
nsCOMPtr<nsIAtom> parentTag;
|
if (parent)
|
||||||
parent->GetTag(*getter_AddRefs(parentTag));
|
InsertRowFor(parent, aContainer, aChild);
|
||||||
if (parentTag == nsXULAtoms::tree) {
|
|
||||||
// Allow insertion to the outermost container.
|
|
||||||
insertRow = PR_TRUE;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Test insertion to an inner container.
|
|
||||||
|
|
||||||
// First try to find this parent in our array of rows, if we find one
|
|
||||||
// we can be sure that all other parents are open too.
|
|
||||||
parentIndex = FindContent(parent);
|
|
||||||
if (parentIndex >= 0) {
|
|
||||||
// Got it, now test if it is open.
|
|
||||||
if (((Row*)mRows[parentIndex])->IsOpen())
|
|
||||||
insertRow = PR_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (insertRow) {
|
|
||||||
PRInt32 index = 0;
|
|
||||||
GetIndexInSubtree(aContainer, aChild, &index);
|
|
||||||
|
|
||||||
PRInt32 count;
|
|
||||||
InsertRow(parentIndex, index, aChild, &count);
|
|
||||||
mBoxObject->RowCountChanged(parentIndex + index + 1, count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (childTag == nsHTMLAtoms::optgroup) {
|
else if (childTag == nsHTMLAtoms::optgroup) {
|
||||||
PRInt32 parentIndex = -1;
|
InsertRowFor(aContainer, aContainer, aChild);
|
||||||
|
|
||||||
nsCOMPtr<nsIAtom> containerTag;
|
|
||||||
aContainer->GetTag(*getter_AddRefs(containerTag));
|
|
||||||
if (containerTag != nsHTMLAtoms::select)
|
|
||||||
parentIndex = FindContent(aContainer);
|
|
||||||
|
|
||||||
PRInt32 index = 0;
|
|
||||||
GetIndexInSubtree(aContainer, aChild, &index);
|
|
||||||
|
|
||||||
PRInt32 count;
|
|
||||||
InsertRow(parentIndex, index, aChild, &count);
|
|
||||||
mBoxObject->RowCountChanged(parentIndex + index + 1, count);
|
|
||||||
}
|
}
|
||||||
else if (childTag == nsHTMLAtoms::option) {
|
else if (childTag == nsHTMLAtoms::option) {
|
||||||
PRInt32 count;
|
PRInt32 count;
|
||||||
@ -1199,6 +1214,11 @@ nsTreeContentView::Serialize(nsIContent* aContent, PRInt32 aParentIndex, PRInt32
|
|||||||
void
|
void
|
||||||
nsTreeContentView::SerializeItem(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows)
|
nsTreeContentView::SerializeItem(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows)
|
||||||
{
|
{
|
||||||
|
nsAutoString hidden;
|
||||||
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::hidden, hidden);
|
||||||
|
if (hidden.Equals(NS_LITERAL_STRING("true")))
|
||||||
|
return;
|
||||||
|
|
||||||
Row* row = Row::Create(mAllocator, aContent, aParentIndex);
|
Row* row = Row::Create(mAllocator, aContent, aParentIndex);
|
||||||
aRows.AppendElement(row);
|
aRows.AppendElement(row);
|
||||||
|
|
||||||
@ -1238,6 +1258,11 @@ nsTreeContentView::SerializeItem(nsIContent* aContent, PRInt32 aParentIndex, PRI
|
|||||||
void
|
void
|
||||||
nsTreeContentView::SerializeSeparator(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows)
|
nsTreeContentView::SerializeSeparator(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows)
|
||||||
{
|
{
|
||||||
|
nsAutoString hidden;
|
||||||
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::hidden, hidden);
|
||||||
|
if (hidden.Equals(NS_LITERAL_STRING("true")))
|
||||||
|
return;
|
||||||
|
|
||||||
Row* row = Row::Create(mAllocator, aContent, aParentIndex);
|
Row* row = Row::Create(mAllocator, aContent, aParentIndex);
|
||||||
row->SetSeparator(PR_TRUE);
|
row->SetSeparator(PR_TRUE);
|
||||||
aRows.AppendElement(row);
|
aRows.AppendElement(row);
|
||||||
@ -1299,17 +1324,21 @@ nsTreeContentView::GetIndexInSubtree(nsIContent* aContainer, nsIContent* aConten
|
|||||||
nsCOMPtr<nsIAtom> tag;
|
nsCOMPtr<nsIAtom> tag;
|
||||||
content->GetTag(*getter_AddRefs(tag));
|
content->GetTag(*getter_AddRefs(tag));
|
||||||
if (tag == nsXULAtoms::treeitem) {
|
if (tag == nsXULAtoms::treeitem) {
|
||||||
(*aIndex)++;
|
nsAutoString hidden;
|
||||||
nsAutoString container;
|
content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::hidden, hidden);
|
||||||
content->GetAttr(kNameSpaceID_None, nsXULAtoms::container, container);
|
if (! hidden.Equals(NS_LITERAL_STRING("true"))) {
|
||||||
if (container.Equals(NS_LITERAL_STRING("true"))) {
|
(*aIndex)++;
|
||||||
nsAutoString open;
|
nsAutoString container;
|
||||||
content->GetAttr(kNameSpaceID_None, nsXULAtoms::open, open);
|
content->GetAttr(kNameSpaceID_None, nsXULAtoms::container, container);
|
||||||
if (open.Equals(NS_LITERAL_STRING("true"))) {
|
if (container.Equals(NS_LITERAL_STRING("true"))) {
|
||||||
nsCOMPtr<nsIContent> child;
|
nsAutoString open;
|
||||||
nsTreeUtils::GetImmediateChild(content, nsXULAtoms::treechildren, getter_AddRefs(child));
|
content->GetAttr(kNameSpaceID_None, nsXULAtoms::open, open);
|
||||||
if (child)
|
if (open.Equals(NS_LITERAL_STRING("true"))) {
|
||||||
GetIndexInSubtree(child, aContent, aIndex);
|
nsCOMPtr<nsIContent> child;
|
||||||
|
nsTreeUtils::GetImmediateChild(content, nsXULAtoms::treechildren, getter_AddRefs(child));
|
||||||
|
if (child)
|
||||||
|
GetIndexInSubtree(child, aContent, aIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1317,8 +1346,13 @@ nsTreeContentView::GetIndexInSubtree(nsIContent* aContainer, nsIContent* aConten
|
|||||||
(*aIndex)++;
|
(*aIndex)++;
|
||||||
GetIndexInSubtree(content, aContent, aIndex);
|
GetIndexInSubtree(content, aContent, aIndex);
|
||||||
}
|
}
|
||||||
else if (tag == nsXULAtoms::treeseparator ||
|
else if (tag == nsXULAtoms::treeseparator) {
|
||||||
tag == nsHTMLAtoms::option)
|
nsAutoString hidden;
|
||||||
|
content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::hidden, hidden);
|
||||||
|
if (! hidden.Equals(NS_LITERAL_STRING("true")))
|
||||||
|
(*aIndex)++;
|
||||||
|
}
|
||||||
|
else if (tag == nsHTMLAtoms::option)
|
||||||
(*aIndex)++;
|
(*aIndex)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1377,6 +1411,42 @@ nsTreeContentView::RemoveSubtree(PRInt32 aIndex, PRInt32* aCount)
|
|||||||
*aCount = count;
|
*aCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsTreeContentView::InsertRowFor(nsIContent* aParent, nsIContent* aContainer, nsIContent* aChild)
|
||||||
|
{
|
||||||
|
PRInt32 parentIndex = -1;
|
||||||
|
PRBool insertRow = PR_FALSE;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIAtom> parentTag;
|
||||||
|
aParent->GetTag(*getter_AddRefs(parentTag));
|
||||||
|
if ((aParent->IsContentOfType(nsIContent::eXUL) && parentTag == nsXULAtoms::tree) ||
|
||||||
|
(aParent->IsContentOfType(nsIContent::eHTML) && parentTag == nsHTMLAtoms::select)) {
|
||||||
|
// Allow insertion to the outermost container.
|
||||||
|
insertRow = PR_TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Test insertion to an inner container.
|
||||||
|
|
||||||
|
// First try to find this parent in our array of rows, if we find one
|
||||||
|
// we can be sure that all other parents are open too.
|
||||||
|
parentIndex = FindContent(aParent);
|
||||||
|
if (parentIndex >= 0) {
|
||||||
|
// Got it, now test if it is open.
|
||||||
|
if (((Row*)mRows[parentIndex])->IsOpen())
|
||||||
|
insertRow = PR_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (insertRow) {
|
||||||
|
PRInt32 index = 0;
|
||||||
|
GetIndexInSubtree(aContainer, aChild, &index);
|
||||||
|
|
||||||
|
PRInt32 count;
|
||||||
|
InsertRow(parentIndex, index, aChild, &count);
|
||||||
|
mBoxObject->RowCountChanged(parentIndex + index + 1, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsTreeContentView::InsertRow(PRInt32 aParentIndex, PRInt32 aIndex, nsIContent* aContent, PRInt32* aCount)
|
nsTreeContentView::InsertRow(PRInt32 aParentIndex, PRInt32 aIndex, nsIContent* aContent, PRInt32* aCount)
|
||||||
{
|
{
|
||||||
|
@ -167,6 +167,8 @@ class nsTreeContentView : public nsITreeView,
|
|||||||
|
|
||||||
void RemoveSubtree(PRInt32 aIndex, PRInt32* aCount);
|
void RemoveSubtree(PRInt32 aIndex, PRInt32* aCount);
|
||||||
|
|
||||||
|
void InsertRowFor(nsIContent* aParent, nsIContent* aContainer, nsIContent* aChild);
|
||||||
|
|
||||||
void InsertRow(PRInt32 aParentIndex, PRInt32 aIndex, nsIContent* aContent, PRInt32* aCount);
|
void InsertRow(PRInt32 aParentIndex, PRInt32 aIndex, nsIContent* aContent, PRInt32* aCount);
|
||||||
|
|
||||||
void RemoveRow(PRInt32 aIndex, PRInt32* aCount);
|
void RemoveRow(PRInt32 aIndex, PRInt32* aCount);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user