зеркало из https://github.com/mozilla/gecko-dev.git
Bug 616746 - remove HTML option/optgroup stuff from nsTreeContentView. r=tn
This commit is contained in:
Родитель
c8ccf73987
Коммит
83667bdaff
|
@ -41,8 +41,6 @@
|
|||
#include "nsTreeUtils.h"
|
||||
#include "nsTreeContentView.h"
|
||||
#include "nsChildIterator.h"
|
||||
#include "nsIDOMHTMLOptionElement.h"
|
||||
#include "nsIDOMHTMLOptGroupElement.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "nsIEventStateManager.h"
|
||||
#include "nsINodeInfo.h"
|
||||
|
@ -140,8 +138,7 @@ nsTreeContentView::nsTreeContentView(void) :
|
|||
mBoxObject(nsnull),
|
||||
mSelection(nsnull),
|
||||
mRoot(nsnull),
|
||||
mDocument(nsnull),
|
||||
mUpdateSelection(PR_FALSE)
|
||||
mDocument(nsnull)
|
||||
{
|
||||
static const size_t kBucketSizes[] = {
|
||||
sizeof(Row)
|
||||
|
@ -222,24 +219,6 @@ nsTreeContentView::SetSelection(nsITreeSelection* aSelection)
|
|||
NS_ERROR_DOM_SECURITY_ERR);
|
||||
|
||||
mSelection = aSelection;
|
||||
if (!mSelection || !mUpdateSelection)
|
||||
return NS_OK;
|
||||
|
||||
mUpdateSelection = PR_FALSE;
|
||||
|
||||
mSelection->SetSelectEventsSuppressed(PR_TRUE);
|
||||
for (PRUint32 i = 0; i < mRows.Length(); ++i) {
|
||||
Row* row = mRows[i];
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> optEl = do_QueryInterface(row->mContent);
|
||||
if (optEl) {
|
||||
PRBool isSelected;
|
||||
optEl->GetSelected(&isSelected);
|
||||
if (isSelected)
|
||||
mSelection->ToggleSelect(i);
|
||||
}
|
||||
}
|
||||
mSelection->SetSelectEventsSuppressed(PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -536,25 +515,13 @@ nsTreeContentView::GetCellText(PRInt32 aRow, nsITreeColumn* aCol, nsAString& _re
|
|||
Row* row = mRows[aRow];
|
||||
|
||||
// Check for a "label" attribute - this is valid on an <treeitem>
|
||||
// or an <option>, with a single implied column.
|
||||
// with a single implied column.
|
||||
if (row->mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, _retval)
|
||||
&& !_retval.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
nsIAtom *rowTag = row->mContent->Tag();
|
||||
if (rowTag == nsGkAtoms::option &&
|
||||
row->mContent->IsHTML()) {
|
||||
// Use the text node child as the label
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> elem = do_QueryInterface(row->mContent);
|
||||
elem->GetText(_retval);
|
||||
}
|
||||
else if (rowTag == nsGkAtoms::optgroup &&
|
||||
row->mContent->IsHTML()) {
|
||||
nsCOMPtr<nsIDOMHTMLOptGroupElement> elem = do_QueryInterface(row->mContent);
|
||||
elem->GetLabel(_retval);
|
||||
}
|
||||
else if (rowTag == nsGkAtoms::treeitem &&
|
||||
row->mContent->IsXUL()) {
|
||||
if (rowTag == nsGkAtoms::treeitem && row->mContent->IsXUL()) {
|
||||
nsIContent* realRow =
|
||||
nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow);
|
||||
if (realRow) {
|
||||
|
@ -613,20 +580,10 @@ nsTreeContentView::ToggleOpenState(PRInt32 aIndex)
|
|||
// lazily.
|
||||
Row* row = mRows[aIndex];
|
||||
|
||||
if (row->mContent->Tag() == nsGkAtoms::optgroup &&
|
||||
row->mContent->IsHTML()) {
|
||||
// we don't use an attribute for optgroup's open state
|
||||
if (row->IsOpen())
|
||||
CloseContainer(aIndex);
|
||||
else
|
||||
OpenContainer(aIndex);
|
||||
}
|
||||
else {
|
||||
if (row->IsOpen())
|
||||
row->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::open, NS_LITERAL_STRING("false"), PR_TRUE);
|
||||
else
|
||||
row->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::open, NS_LITERAL_STRING("true"), PR_TRUE);
|
||||
}
|
||||
if (row->IsOpen())
|
||||
row->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::open, NS_LITERAL_STRING("false"), PR_TRUE);
|
||||
else
|
||||
row->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::open, NS_LITERAL_STRING("true"), PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -819,24 +776,6 @@ nsTreeContentView::GetIndexOfItem(nsIDOMElement* aItem, PRInt32* _retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeContentView::ContentStateChanged(nsIDocument* aDocument,
|
||||
nsIContent* aContent,
|
||||
nsEventStates aStateMask)
|
||||
{
|
||||
if (!mSelection ||
|
||||
!aContent->IsHTML() ||
|
||||
!aStateMask.HasState(NS_EVENT_STATE_CHECKED))
|
||||
return;
|
||||
|
||||
if (aContent->Tag() == nsGkAtoms::option) {
|
||||
// update the selected state for this node
|
||||
PRInt32 index = FindContent(aContent);
|
||||
if (index >= 0)
|
||||
mSelection->ToggleSelect(index);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeContentView::AttributeChanged(nsIDocument* aDocument,
|
||||
dom::Element* aElement,
|
||||
|
@ -856,18 +795,17 @@ nsTreeContentView::AttributeChanged(nsIDocument* aDocument,
|
|||
mBoxObject->Invalidate();
|
||||
}
|
||||
|
||||
if (aElement->IsXUL()) {
|
||||
if (tag != nsGkAtoms::treecol &&
|
||||
tag != nsGkAtoms::treeitem &&
|
||||
tag != nsGkAtoms::treeseparator &&
|
||||
tag != nsGkAtoms::treerow &&
|
||||
tag != nsGkAtoms::treecell)
|
||||
return;
|
||||
// We don't consider XUL nodes under non-XUL nodes.
|
||||
if (!aElement->GetParent()->IsXUL())
|
||||
return;
|
||||
// We don't consider non-XUL nodes.
|
||||
nsIContent* parent = nsnull;
|
||||
if (!aElement->IsXUL() ||
|
||||
((parent = aElement->GetParent()) && !parent->IsXUL())) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (tag != nsGkAtoms::treecol &&
|
||||
tag != nsGkAtoms::treeitem &&
|
||||
tag != nsGkAtoms::treeseparator &&
|
||||
tag != nsGkAtoms::treerow &&
|
||||
tag != nsGkAtoms::treecell) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -878,8 +816,7 @@ nsTreeContentView::AttributeChanged(nsIDocument* aDocument,
|
|||
if (!element)
|
||||
return; // this is not for us
|
||||
nsIAtom *parentTag = element->Tag();
|
||||
if ((element->IsXUL() && parentTag == nsGkAtoms::tree) ||
|
||||
(element->IsHTML() && parentTag == nsGkAtoms::select))
|
||||
if (element->IsXUL() && parentTag == nsGkAtoms::tree)
|
||||
return; // this is not for us
|
||||
}
|
||||
|
||||
|
@ -1019,23 +956,14 @@ nsTreeContentView::ContentInserted(nsIDocument *aDocument,
|
|||
// First check the tag to see if it's one that we care about.
|
||||
nsIAtom *childTag = aChild->Tag();
|
||||
|
||||
if (aChild->IsHTML()) {
|
||||
if (childTag != nsGkAtoms::option &&
|
||||
childTag != nsGkAtoms::optgroup)
|
||||
return;
|
||||
}
|
||||
else if (aChild->IsXUL()) {
|
||||
if (childTag != nsGkAtoms::treeitem &&
|
||||
childTag != nsGkAtoms::treeseparator &&
|
||||
childTag != nsGkAtoms::treechildren &&
|
||||
childTag != nsGkAtoms::treerow &&
|
||||
childTag != nsGkAtoms::treecell)
|
||||
return;
|
||||
// Don't allow XUL nodes to be inserted under non-XUL nodes.
|
||||
if (!aContainer->IsXUL())
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -1046,8 +974,7 @@ nsTreeContentView::ContentInserted(nsIDocument *aDocument,
|
|||
if (!element)
|
||||
return; // this is not for us
|
||||
nsIAtom *parentTag = element->Tag();
|
||||
if ((element->IsXUL() && parentTag == nsGkAtoms::tree) ||
|
||||
(element->IsHTML() && parentTag == nsGkAtoms::select))
|
||||
if (element->IsXUL() && parentTag == nsGkAtoms::tree)
|
||||
return; // this is not for us
|
||||
}
|
||||
|
||||
|
@ -1085,20 +1012,6 @@ nsTreeContentView::ContentInserted(nsIDocument *aDocument,
|
|||
mBoxObject->InvalidateRow(index);
|
||||
}
|
||||
}
|
||||
else if (childTag == nsGkAtoms::optgroup) {
|
||||
InsertRowFor(aContainer, aChild);
|
||||
}
|
||||
else if (childTag == nsGkAtoms::option) {
|
||||
PRInt32 parentIndex = FindContent(aContainer);
|
||||
|
||||
if (parentIndex >= 0) {
|
||||
PRInt32 index = 0;
|
||||
GetIndexInSubtree(aContainer, aChild, &index);
|
||||
PRInt32 count = InsertRow(parentIndex, index, aChild);
|
||||
if (mBoxObject)
|
||||
mBoxObject->RowCountChanged(parentIndex + index + 1, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1114,23 +1027,14 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument,
|
|||
// First check the tag to see if it's one that we care about.
|
||||
nsIAtom *tag = aChild->Tag();
|
||||
|
||||
if (aChild->IsHTML()) {
|
||||
if (tag != nsGkAtoms::option &&
|
||||
tag != nsGkAtoms::optgroup)
|
||||
return;
|
||||
}
|
||||
else if (aChild->IsXUL()) {
|
||||
if (tag != nsGkAtoms::treeitem &&
|
||||
tag != nsGkAtoms::treeseparator &&
|
||||
tag != nsGkAtoms::treechildren &&
|
||||
tag != nsGkAtoms::treerow &&
|
||||
tag != nsGkAtoms::treecell)
|
||||
return;
|
||||
// We don't consider XUL nodes under non-XUL nodes.
|
||||
if (!aContainer->IsXUL())
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// We don't consider non-XUL nodes.
|
||||
if (!aChild->IsXUL() || !aContainer->IsXUL())
|
||||
return;
|
||||
if (tag != nsGkAtoms::treeitem &&
|
||||
tag != nsGkAtoms::treeseparator &&
|
||||
tag != nsGkAtoms::treechildren &&
|
||||
tag != nsGkAtoms::treerow &&
|
||||
tag != nsGkAtoms::treecell) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1141,8 +1045,7 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument,
|
|||
if (!element)
|
||||
return; // this is not for us
|
||||
nsIAtom *parentTag = element->Tag();
|
||||
if ((element->IsXUL() && parentTag == nsGkAtoms::tree) ||
|
||||
(element->IsHTML() && parentTag == nsGkAtoms::select))
|
||||
if (element->IsXUL() && parentTag == nsGkAtoms::tree)
|
||||
return; // this is not for us
|
||||
}
|
||||
|
||||
|
@ -1163,9 +1066,7 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument,
|
|||
}
|
||||
}
|
||||
else if (tag == nsGkAtoms::treeitem ||
|
||||
tag == nsGkAtoms::treeseparator ||
|
||||
tag == nsGkAtoms::option ||
|
||||
tag == nsGkAtoms::optgroup
|
||||
tag == nsGkAtoms::treeseparator
|
||||
) {
|
||||
PRInt32 index = FindContent(aChild);
|
||||
if (index >= 0) {
|
||||
|
@ -1203,8 +1104,9 @@ void
|
|||
nsTreeContentView::Serialize(nsIContent* aContent, PRInt32 aParentIndex,
|
||||
PRInt32* aIndex, nsTArray<Row*>& aRows)
|
||||
{
|
||||
// Don't allow XUL nodes under non-XUL nodes.
|
||||
PRBool containerIsXUL = aContent->IsXUL();
|
||||
// Don't allow non-XUL nodes.
|
||||
if (!aContent->IsXUL())
|
||||
return;
|
||||
|
||||
ChildIterator iter, last;
|
||||
for (ChildIterator::Init(aContent, &iter, &last); iter != last; ++iter) {
|
||||
|
@ -1212,18 +1114,12 @@ nsTreeContentView::Serialize(nsIContent* aContent, PRInt32 aParentIndex,
|
|||
nsIAtom *tag = content->Tag();
|
||||
PRInt32 count = aRows.Length();
|
||||
|
||||
if (content->IsXUL() && containerIsXUL) {
|
||||
if (content->IsXUL()) {
|
||||
if (tag == nsGkAtoms::treeitem)
|
||||
SerializeItem(content, aParentIndex, aIndex, aRows);
|
||||
else if (tag == nsGkAtoms::treeseparator)
|
||||
SerializeSeparator(content, aParentIndex, aIndex, aRows);
|
||||
}
|
||||
else if (content->IsHTML()) {
|
||||
if (tag == nsGkAtoms::option)
|
||||
SerializeOption(content, aParentIndex, aIndex, aRows);
|
||||
else if (tag == nsGkAtoms::optgroup)
|
||||
SerializeOptGroup(content, aParentIndex, aIndex, aRows);
|
||||
}
|
||||
*aIndex += aRows.Length() - count;
|
||||
}
|
||||
}
|
||||
|
@ -1277,51 +1173,15 @@ nsTreeContentView::SerializeSeparator(nsIContent* aContent,
|
|||
aRows.AppendElement(row);
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeContentView::SerializeOption(nsIContent* aContent, PRInt32 aParentIndex,
|
||||
PRInt32* aIndex, nsTArray<Row*>& aRows)
|
||||
{
|
||||
Row* row = Row::Create(mAllocator, aContent, aParentIndex);
|
||||
aRows.AppendElement(row);
|
||||
|
||||
// This will happen before the TreeSelection is hooked up. So, cache the selected
|
||||
// state in the row properties and update the selection when it is attached.
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> optEl = do_QueryInterface(aContent);
|
||||
PRBool isSelected;
|
||||
optEl->GetSelected(&isSelected);
|
||||
if (isSelected)
|
||||
mUpdateSelection = PR_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeContentView::SerializeOptGroup(nsIContent* aContent, PRInt32 aParentIndex,
|
||||
PRInt32* aIndex, nsTArray<Row*>& aRows)
|
||||
{
|
||||
Row* row = Row::Create(mAllocator, aContent, aParentIndex);
|
||||
aRows.AppendElement(row);
|
||||
row->SetContainer(PR_TRUE);
|
||||
row->SetOpen(PR_TRUE);
|
||||
|
||||
nsIContent* child =
|
||||
nsTreeUtils::GetImmediateChild(aContent, nsGkAtoms::option);
|
||||
if (child) {
|
||||
// Now, recursively serialize our child.
|
||||
PRInt32 count = aRows.Length();
|
||||
PRInt32 index = 0;
|
||||
Serialize(aContent, aParentIndex + *aIndex + 1, &index, aRows);
|
||||
row->mSubtreeSize += aRows.Length() - count;
|
||||
}
|
||||
else
|
||||
row->SetEmpty(PR_TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
nsTreeContentView::GetIndexInSubtree(nsIContent* aContainer,
|
||||
nsIContent* aContent, PRInt32* aIndex)
|
||||
{
|
||||
PRBool containerIsXUL = aContainer->IsXUL();
|
||||
PRUint32 childCount = aContainer->GetChildCount();
|
||||
|
||||
if (!aContainer->IsXUL())
|
||||
return;
|
||||
|
||||
for (PRUint32 i = 0; i < childCount; i++) {
|
||||
nsIContent *content = aContainer->GetChildAt(i);
|
||||
|
||||
|
@ -1330,7 +1190,7 @@ nsTreeContentView::GetIndexInSubtree(nsIContent* aContainer,
|
|||
|
||||
nsIAtom *tag = content->Tag();
|
||||
|
||||
if (content->IsXUL() && containerIsXUL) {
|
||||
if (content->IsXUL()) {
|
||||
if (tag == nsGkAtoms::treeitem) {
|
||||
if (! content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
|
||||
nsGkAtoms::_true, eCaseMatters)) {
|
||||
|
@ -1352,14 +1212,6 @@ nsTreeContentView::GetIndexInSubtree(nsIContent* aContainer,
|
|||
(*aIndex)++;
|
||||
}
|
||||
}
|
||||
else if (content->IsHTML()) {
|
||||
if (tag == nsGkAtoms::optgroup) {
|
||||
(*aIndex)++;
|
||||
GetIndexInSubtree(content, aContent, aIndex);
|
||||
}
|
||||
else if (tag == nsGkAtoms::option)
|
||||
(*aIndex)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1369,14 +1221,9 @@ nsTreeContentView::EnsureSubtree(PRInt32 aIndex)
|
|||
Row* row = mRows[aIndex];
|
||||
|
||||
nsIContent* child;
|
||||
if (row->mContent->Tag() == nsGkAtoms::optgroup)
|
||||
child = row->mContent;
|
||||
else {
|
||||
child =
|
||||
nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treechildren);
|
||||
if (! child) {
|
||||
return 0;
|
||||
}
|
||||
child = nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treechildren);
|
||||
if (! child) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsAutoTArray<Row*, 8> rows;
|
||||
|
@ -1424,9 +1271,7 @@ nsTreeContentView::InsertRowFor(nsIContent* aParent, nsIContent* aChild)
|
|||
nsCOMPtr<nsIContent> grandParent = aParent->GetParent();
|
||||
nsIAtom* grandParentTag = grandParent->Tag();
|
||||
|
||||
if ((grandParent->IsXUL() && grandParentTag == nsGkAtoms::tree) ||
|
||||
(grandParent->IsHTML() && grandParentTag == nsGkAtoms::select)
|
||||
) {
|
||||
if (grandParent->IsXUL() && grandParentTag == nsGkAtoms::tree) {
|
||||
// Allow insertion to the outermost container.
|
||||
insertRow = PR_TRUE;
|
||||
}
|
||||
|
@ -1464,12 +1309,6 @@ nsTreeContentView::InsertRow(PRInt32 aParentIndex, PRInt32 aIndex, nsIContent* a
|
|||
else if (tag == nsGkAtoms::treeseparator)
|
||||
SerializeSeparator(aContent, aParentIndex, &aIndex, rows);
|
||||
}
|
||||
else if (aContent->IsHTML()) {
|
||||
if (tag == nsGkAtoms::option)
|
||||
SerializeOption(aContent, aParentIndex, &aIndex, rows);
|
||||
else if (tag == nsGkAtoms::optgroup)
|
||||
SerializeOptGroup(aContent, aParentIndex, &aIndex, rows);
|
||||
}
|
||||
|
||||
mRows.InsertElementsAt(aParentIndex + aIndex + 1, rows);
|
||||
PRInt32 count = rows.Length();
|
||||
|
|
|
@ -72,7 +72,6 @@ class nsTreeContentView : public nsINativeTreeView,
|
|||
NS_DECL_NSITREECONTENTVIEW
|
||||
|
||||
// nsIDocumentObserver
|
||||
NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED
|
||||
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
||||
|
@ -92,12 +91,6 @@ class nsTreeContentView : public nsINativeTreeView,
|
|||
void SerializeSeparator(nsIContent* aContent, PRInt32 aParentIndex,
|
||||
PRInt32* aIndex, nsTArray<Row*>& aRows);
|
||||
|
||||
void SerializeOption(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex,
|
||||
nsTArray<Row*>& aRows);
|
||||
|
||||
void SerializeOptGroup(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex,
|
||||
nsTArray<Row*>& aRows);
|
||||
|
||||
void GetIndexInSubtree(nsIContent* aContainer, nsIContent* aContent, PRInt32* aResult);
|
||||
|
||||
// Helper methods which we use to manage our plain array of rows.
|
||||
|
@ -134,8 +127,6 @@ class nsTreeContentView : public nsINativeTreeView,
|
|||
nsIDocument* mDocument; // WEAK
|
||||
nsFixedSizeAllocator mAllocator;
|
||||
nsTArray<Row*> mRows;
|
||||
|
||||
PRPackedBool mUpdateSelection;
|
||||
};
|
||||
|
||||
#endif // nsTreeContentView_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче