void nsTreeContentView::SerializeItem(Element* aContent, int32_t aParentIndex, int32_t* aIndex, nsTArray<UniquePtr<Row>>& aRows) { if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden, nsGkAtoms::_true, eCaseMatters)) return; aRows.AppendElement(MakeUnique<Row>(aContent, aParentIndex)); Row* row = aRows.LastElement().get(); if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::container, nsGkAtoms::_true, eCaseMatters)) { row->SetContainer(true); if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::open, nsGkAtoms::_true, eCaseMatters)) { row->SetOpen(true); nsIContent* child = nsTreeUtils::GetImmediateChild(aContent, nsGkAtoms::treechildren); if (child && child->IsXULElement()) { // Now, recursively serialize our child. int32_t count = aRows.Length(); int32_t index = 0; Serialize(child, aParentIndex + *aIndex + 1, &index, aRows); row->mSubtreeSize += aRows.Length() - count; } else row->SetEmpty(true); } else if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::empty, nsGkAtoms::_true, eCaseMatters)) { row->SetEmpty(true); } } }
void nsTreeContentView::AttributeChanged(nsIDocument* aDocument, dom::Element* aElement, int32_t aNameSpaceID, nsAtom* aAttribute, int32_t aModType, const nsAttrValue* aOldValue) { // Lots of codepaths under here that do all sorts of stuff, so be safe. nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this); // Make sure this notification concerns us. // First check the tag to see if it's one that we care about. if (mBoxObject && (aElement == mRoot || aElement == mBody)) { mBoxObject->ClearStyleAndImageCaches(); mBoxObject->Invalidate(); } // We don't consider non-XUL nodes. nsIContent* parent = nullptr; if (!aElement->IsXULElement() || ((parent = aElement->GetParent()) && !parent->IsXULElement())) { return; } if (!aElement->IsAnyOfXULElements(nsGkAtoms::treecol, nsGkAtoms::treeitem, nsGkAtoms::treeseparator, nsGkAtoms::treerow, nsGkAtoms::treecell)) { return; } // If we have a legal tag, go up to the tree/select and make sure // that it's ours. for (nsIContent* element = aElement; element != mBody; element = element->GetParent()) { if (!element) return; // this is not for us if (element->IsXULElement(nsGkAtoms::tree)) return; // this is not for us } // Handle changes of the hidden attribute. if (aAttribute == nsGkAtoms::hidden && aElement->IsAnyOfXULElements(nsGkAtoms::treeitem, nsGkAtoms::treeseparator)) { bool hidden = aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden, nsGkAtoms::_true, eCaseMatters); int32_t index = FindContent(aElement); if (hidden && index >= 0) { // Hide this row along with its children. int32_t count = RemoveRow(index); if (mBoxObject) mBoxObject->RowCountChanged(index, -count); } else if (!hidden && index < 0) { // Show this row along with its children. nsCOMPtr<nsIContent> parent = aElement->GetParent(); if (parent) { InsertRowFor(parent, aElement); } } return; } if (aElement->IsXULElement(nsGkAtoms::treecol)) { if (aAttribute == nsGkAtoms::properties) { if (mBoxObject) { nsCOMPtr<nsITreeColumns> cols; mBoxObject->GetColumns(getter_AddRefs(cols)); if (cols) { nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aElement); nsCOMPtr<nsITreeColumn> col; cols->GetColumnFor(element, getter_AddRefs(col)); mBoxObject->InvalidateColumn(col); } } } } else if (aElement->IsXULElement(nsGkAtoms::treeitem)) { int32_t index = FindContent(aElement); if (index >= 0) { Row* row = mRows[index].get(); if (aAttribute == nsGkAtoms::container) { bool isContainer = aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::container, nsGkAtoms::_true, eCaseMatters); row->SetContainer(isContainer); if (mBoxObject) mBoxObject->InvalidateRow(index); } else if (aAttribute == nsGkAtoms::open) { bool isOpen = aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::open, nsGkAtoms::_true, eCaseMatters); bool wasOpen = row->IsOpen(); if (! isOpen && wasOpen) CloseContainer(index); else if (isOpen && ! wasOpen) OpenContainer(index); } else if (aAttribute == nsGkAtoms::empty) { bool isEmpty = aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::empty, nsGkAtoms::_true, eCaseMatters); row->SetEmpty(isEmpty); if (mBoxObject) mBoxObject->InvalidateRow(index); } } } else if (aElement->IsXULElement(nsGkAtoms::treeseparator)) { int32_t index = FindContent(aElement); if (index >= 0) { if (aAttribute == nsGkAtoms::properties && mBoxObject) { mBoxObject->InvalidateRow(index); } } } else if (aElement->IsXULElement(nsGkAtoms::treerow)) { if (aAttribute == nsGkAtoms::properties) { nsCOMPtr<nsIContent> parent = aElement->GetParent(); if (parent) { int32_t index = FindContent(parent); if (index >= 0 && mBoxObject) { mBoxObject->InvalidateRow(index); } } } } else if (aElement->IsXULElement(nsGkAtoms::treecell)) { if (aAttribute == nsGkAtoms::properties || aAttribute == nsGkAtoms::mode || aAttribute == nsGkAtoms::src || aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::label) { nsIContent* parent = aElement->GetParent(); if (parent) { nsCOMPtr<nsIContent> grandParent = parent->GetParent(); if (grandParent && grandParent->IsXULElement()) { int32_t index = FindContent(grandParent); if (index >= 0 && mBoxObject) { // XXX Should we make an effort to invalidate only cell ? mBoxObject->InvalidateRow(index); } } } } } }
void nsTreeContentView::ContentRemoved(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aChild, nsIContent* aPreviousSibling) { NS_ASSERTION(aChild, "null ptr"); // Make sure this notification concerns us. // First check the tag to see if it's one that we care about. // We don't consider non-XUL nodes. if (!aChild->IsXULElement() || !aContainer->IsXULElement()) return; if (!aChild->IsAnyOfXULElements(nsGkAtoms::treeitem, nsGkAtoms::treeseparator, nsGkAtoms::treechildren, nsGkAtoms::treerow, nsGkAtoms::treecell)) { return; } // If we have a legal tag, go up to the tree/select and make sure // that it's ours. for (nsIContent* element = aContainer; element != mBody; element = element->GetParent()) { if (!element) return; // this is not for us if (element->IsXULElement(nsGkAtoms::tree)) return; // this is not for us } // Lots of codepaths under here that do all sorts of stuff, so be safe. nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this); if (aChild->IsXULElement(nsGkAtoms::treechildren)) { int32_t index = FindContent(aContainer); if (index >= 0) { Row* row = mRows[index].get(); row->SetEmpty(true); int32_t count = RemoveSubtree(index); // Invalidate also the row to update twisty. if (mBoxObject) { mBoxObject->InvalidateRow(index); mBoxObject->RowCountChanged(index + 1, -count); } } } else if (aChild->IsAnyOfXULElements(nsGkAtoms::treeitem, nsGkAtoms::treeseparator)) { int32_t index = FindContent(aChild); if (index >= 0) { int32_t count = RemoveRow(index); if (mBoxObject) mBoxObject->RowCountChanged(index, -count); } } else if (aChild->IsXULElement(nsGkAtoms::treerow)) { int32_t index = FindContent(aContainer); if (index >= 0 && mBoxObject) mBoxObject->InvalidateRow(index); } else if (aChild->IsXULElement(nsGkAtoms::treecell)) { nsCOMPtr<nsIContent> parent = aContainer->GetParent(); if (parent) { int32_t index = FindContent(parent); if (index >= 0 && mBoxObject) mBoxObject->InvalidateRow(index); } } }
void nsTreeContentView::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aChild, int32_t /* unused */) { NS_ASSERTION(aChild, "null ptr"); // Make sure this notification concerns us. // First check the tag to see if it's one that we care about. nsIAtom *childTag = aChild->Tag(); // Don't allow non-XUL nodes. if (!aChild->IsXUL() || !aContainer->IsXUL()) return; if (childTag != nsGkAtoms::treeitem && childTag != nsGkAtoms::treeseparator && childTag != nsGkAtoms::treechildren && childTag != nsGkAtoms::treerow && childTag != nsGkAtoms::treecell) { return; } // If we have a legal tag, go up to the tree/select and make sure // that it's ours. for (nsIContent* element = aContainer; element != mBody; element = element->GetParent()) { if (!element) return; // this is not for us nsIAtom *parentTag = element->Tag(); if (element->IsXUL() && parentTag == nsGkAtoms::tree) return; // this is not for us } // Lots of codepaths under here that do all sorts of stuff, so be safe. nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this); if (childTag == nsGkAtoms::treechildren) { int32_t index = FindContent(aContainer); if (index >= 0) { Row* row = mRows[index]; row->SetEmpty(false); if (mBoxObject) mBoxObject->InvalidateRow(index); if (row->IsContainer() && row->IsOpen()) { int32_t count = EnsureSubtree(index); if (mBoxObject) mBoxObject->RowCountChanged(index + 1, count); } } } else if (childTag == nsGkAtoms::treeitem || childTag == nsGkAtoms::treeseparator) { InsertRowFor(aContainer, aChild); } else if (childTag == nsGkAtoms::treerow) { int32_t index = FindContent(aContainer); if (index >= 0 && mBoxObject) mBoxObject->InvalidateRow(index); } else if (childTag == nsGkAtoms::treecell) { nsCOMPtr<nsIContent> parent = aContainer->GetParent(); if (parent) { int32_t index = FindContent(parent); if (index >= 0 && mBoxObject) mBoxObject->InvalidateRow(index); } } }