From ce53bd6ec22955af85133fd7d42f0515230459bb Mon Sep 17 00:00:00 2001 From: "varga%nixcorp.com" Date: Sat, 17 Apr 2004 05:53:38 +0000 Subject: [PATCH] Fix for bug 221619. Tree widget refactoring and enhancement. r=neil sr=bryner git-svn-id: svn://10.0.0.236/trunk@155017 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/atk/nsXULTreeAccessibleWrap.cpp | 23 +- .../accessible/src/base/nsRootAccessible.cpp | 30 +- .../src/xul/nsXULTreeAccessible.cpp | 111 +- .../accessible/src/xul/nsXULTreeAccessible.h | 7 +- mozilla/browser/base/content/pageInfo.js | 71 +- .../bookmarks/content/addBookmark.js | 10 +- .../bookmarks/content/addBookmark2.js | 6 +- .../components/bookmarks/content/bookmarks.js | 6 +- .../bookmarks/content/bookmarksManager.js | 2 +- .../bookmarks/content/bookmarksTree.xml | 46 +- .../bookmarks/content/selectBookmark.js | 2 +- .../cookieviewer/content/CookieViewer.js | 12 +- .../cookieviewer/content/treeUtils.js | 8 +- .../components/history/content/history.js | 15 +- .../prefwindow/content/permissions.js | 12 +- .../components/prefwindow/content/plugins.js | 18 +- .../resources/content/pref/prefBird.xul | 2 +- .../content/selectAddressesDialog.js | 110 +- .../calendar/resources/content/unifinder.js | 35 +- .../resources/content/unifinderToDo.js | 35 +- .../content/shared/public/nsCSSAnonBoxList.h | 13 +- mozilla/content/shared/public/nsXULAtomList.h | 8 +- .../xul/document/src/nsXULDocument.cpp | 1 + .../public/nsIXULTemplateBuilder.idl | 25 +- .../xul/templates/src/nsXULTreeBuilder.cpp | 211 +- mozilla/dom/public/idl/xul/Makefile.in | 1 + .../idl/xul/nsIDOMXULMultSelectCntrlEl.idl | 3 +- .../public/idl/xul/nsIDOMXULTreeElement.idl | 63 + mozilla/dom/public/nsIDOMClassInfo.h | 5 + mozilla/dom/src/base/nsDOMClassInfo.cpp | 55 + mozilla/dom/src/base/nsDOMClassInfo.h | 32 + .../ui/dialogs/content/EdAECSSAttributes.js | 6 +- .../ui/dialogs/content/EdAEHTMLAttributes.js | 6 +- .../ui/dialogs/content/EdAEJSEAttributes.js | 4 +- .../ui/dialogs/content/EdAdvancedEdit.js | 6 +- .../ui/dialogs/content/EdSelectProps.js | 44 +- .../ui/dialogs/content/EditorSaveAsCharset.js | 8 +- .../cview/resources/content/cview-handlers.js | 12 +- .../cview/resources/content/cview-trees.js | 4 +- .../cview/resources/content/tree-utils.js | 91 +- .../resources/content/EdCssProps-utils.js | 6 +- .../extensions/help/resources/content/help.js | 5 +- .../inspector/base/src/inDOMView.cpp | 57 +- .../content/jsutil/xul/inBaseTreeView.js | 23 +- .../viewers/computedStyle/computedStyle.js | 6 +- .../resources/content/viewers/dom/dom.js | 6 +- .../content/viewers/domNode/domNode.js | 2 +- .../content/viewers/jsObject/jsObjectView.js | 28 +- .../content/viewers/styleRules/styleRules.js | 24 +- .../viewers/stylesheets/stylesheets.js | 8 +- .../viewers/xblBindings/xblBindings.js | 20 +- mozilla/extensions/irc/xul/content/static.js | 4 +- .../p3p/resources/content/pageInfoOverlay.js | 2 +- mozilla/extensions/sql/base/src/Makefile.in | 2 + .../extensions/sql/base/src/mozSqlResult.cpp | 296 ++- .../extensions/sql/base/src/mozSqlResult.h | 25 +- mozilla/extensions/sql/build/src/Makefile.in | 2 +- .../extensions/sql/build/src/mozSqlModule.cpp | 2 +- mozilla/extensions/sql/pgsql/src/Makefile.in | 2 + .../sql/pgsql/src/mozSqlConnectionPgsql.cpp | 1 + .../sql/pgsql/src/mozSqlResultPgsql.cpp | 4 +- .../resources/buster/buster-view.js | 6 +- .../resources/buster/result-view.js | 2 +- .../venkman/resources/content/tree-utils.js | 121 +- .../resources/content/venkman-views.js | 71 +- .../resources/content/CookieViewer.js | 22 +- .../resources/content/nsWalletTreeUtils.js | 12 +- .../resources/content/SignonViewer.js | 42 +- .../layout/forms/resources/content/select.xml | 38 +- .../html/forms/resources/content/select.xml | 38 +- mozilla/layout/style/nsCSSAnonBoxList.h | 13 +- .../xul/base/src/nsXULTooltipListener.cpp | 31 +- .../xul/base/src/nsXULTooltipListener.h | 3 +- .../xul/base/src/tree/public/Makefile.in | 5 +- .../base/src/tree/public/nsITreeBoxObject.idl | 57 +- .../base/src/tree/public/nsITreeColumns.idl | 119 + .../src/tree/public/nsITreeContentView.idl | 5 - .../base/src/tree/public/nsITreeSelection.idl | 7 +- .../xul/base/src/tree/public/nsITreeView.idl | 105 +- .../layout/xul/base/src/tree/src/Makefile.in | 30 +- .../xul/base/src/tree/src/nsTreeBodyFrame.cpp | 1969 +++++++---------- .../xul/base/src/tree/src/nsTreeBodyFrame.h | 468 ++-- .../xul/base/src/tree/src/nsTreeBoxObject.cpp | 106 +- .../xul/base/src/tree/src/nsTreeColFrame.cpp | 56 +- .../xul/base/src/tree/src/nsTreeColFrame.h | 7 +- .../xul/base/src/tree/src/nsTreeColumns.cpp | 549 +++++ .../xul/base/src/tree/src/nsTreeColumns.h | 142 ++ .../base/src/tree/src/nsTreeContentView.cpp | 391 ++-- .../xul/base/src/tree/src/nsTreeContentView.h | 25 +- .../base/src/tree/src/nsTreeImageListener.cpp | 170 ++ .../base/src/tree/src/nsTreeImageListener.h | 113 + .../xul/base/src/tree/src/nsTreeSelection.cpp | 23 +- .../xul/base/src/tree/src/nsTreeSelection.h | 3 +- .../base/src/tree/src/nsTreeStyleCache.cpp | 137 ++ .../xul/base/src/tree/src/nsTreeStyleCache.h | 141 ++ .../xul/base/src/tree/src/nsTreeUtils.cpp | 96 + .../xul/base/src/tree/src/nsTreeUtils.h | 11 + mozilla/mail/base/content/commandglue.js | 4 +- .../base/content/mail3PaneWindowCommands.js | 8 +- .../mail/base/content/msgMail3PaneWindow.js | 49 +- mozilla/mail/base/content/widgetglue.js | 6 +- .../components/addrbook/content/abCommon.js | 11 +- .../addrbook/content/abContactsPanel.js | 5 +- .../components/compose/content/abCommon.js | 8 +- .../compose/content/autocomplete.xml | 31 +- .../addrbook/resources/content/abCommon.js | 11 +- .../addrbook/resources/content/abDragDrop.js | 17 +- .../resources/content/abResultsPane.js | 12 +- mozilla/mailnews/addrbook/src/nsAbView.cpp | 39 +- .../prefs/resources/content/AccountManager.js | 6 +- .../base/resources/content/commandglue.js | 4 +- .../content/mail3PaneWindowCommands.js | 8 +- .../resources/content/mailContextMenus.js | 5 +- .../base/resources/content/messengerdnd.js | 25 +- .../resources/content/msgMail3PaneWindow.js | 47 +- .../base/resources/content/msgSynchronize.js | 5 +- .../base/resources/content/subscribe.js | 14 +- .../base/resources/content/threadPane.js | 29 +- .../base/resources/content/widgetglue.js | 6 +- .../resources/content/FilterListDialog.js | 15 +- mozilla/mailnews/base/src/nsMsgDBView.cpp | 79 +- .../mailnews/base/src/nsMsgSearchDBView.cpp | 9 +- mozilla/mailnews/base/src/nsMsgSearchDBView.h | 2 +- .../news/src/nsNntpIncomingServer.cpp | 42 +- .../pki/resources/content/crlManager.js | 2 +- .../security/manager/pki/src/nsASN1Tree.cpp | 104 +- .../security/manager/ssl/src/nsCertTree.cpp | 108 +- .../communicator/sidebar/sidebarListView.css | 3 +- mozilla/themes/classic/global/mac/jar.mn | 2 + mozilla/themes/classic/global/mac/tree.css | 14 + .../global/mac/tree/checkbox-checked.gif | Bin 0 -> 103 bytes .../classic/global/mac/tree/checkbox.gif | Bin 0 -> 65 bytes mozilla/themes/classic/global/win/jar.mn | 2 + mozilla/themes/classic/global/win/tree.css | 14 + .../global/win/tree/checkbox-checked.gif | Bin 0 -> 103 bytes .../classic/global/win/tree/checkbox.gif | Bin 0 -> 65 bytes mozilla/themes/modern/global/tree.css | 12 + .../modern/global/tree/checkbox-checked.gif | Bin 0 -> 180 bytes .../themes/modern/global/tree/checkbox.gif | Bin 0 -> 160 bytes mozilla/themes/modern/jar.mn | 2 + .../src/nsAutoCompleteController.cpp | 44 +- .../toolkit/components/help/content/help.js | 2 +- .../resources/content/passwordManager.js | 30 +- .../components/viewconfig/content/config.js | 36 +- mozilla/toolkit/content/nsDragAndDrop.js | 4 +- .../toolkit/content/widgets/autocomplete.xml | 6 +- mozilla/toolkit/content/widgets/tree.xml | 288 ++- mozilla/toolkit/locale/jar.mn | 1 + mozilla/toolkit/locale/widgets/tree.dtd | 1 + .../obsolete/content/nsTreeController.js | 6 +- .../toolkit/obsolete/content/nsTreeSorting.js | 11 +- .../browser/resources/content/pageInfo.js | 72 +- .../resources/content/popupManager.js | 8 +- .../resources/content/autocomplete.xml | 31 +- .../bookmarks/resources/addBookmark.js | 6 +- .../bookmarks/resources/bm-panel.js | 2 +- .../bookmarks/resources/bookmarks.js | 6 +- .../bookmarks/resources/bookmarksManager.js | 2 +- .../bookmarks/resources/bookmarksTree.xml | 78 +- .../locale/en-US/bookmarks.properties | 4 - .../xpfe/components/directory/directory.js | 5 +- .../resources/downloadmanager.js | 16 +- .../components/filepicker/src/nsFileView.cpp | 49 +- .../components/history/resources/history.js | 43 +- .../history/resources/historyTreeOverlay.xul | 2 +- .../permissions/content/cookieViewer.js | 22 +- .../permissions/content/permissionsManager.js | 8 +- .../permissions/content/treeUtils.js | 12 +- .../resources/content/nsPrefWindow.js | 2 +- .../resources/content/pref-advanced.xul | 12 +- mozilla/xpfe/global/jar.mn | 1 + .../resources/content/bindings/listbox.xml | 14 +- .../resources/content/bindings/tree.xml | 288 ++- .../xpfe/global/resources/content/config.js | 36 +- .../global/resources/content/nsDragAndDrop.js | 4 +- .../resources/content/nsTreeController.js | 8 +- .../global/resources/content/nsTreeSorting.js | 11 +- .../global/resources/locale/en-US/tree.dtd | 1 + 178 files changed, 5022 insertions(+), 3728 deletions(-) create mode 100644 mozilla/dom/public/idl/xul/nsIDOMXULTreeElement.idl create mode 100644 mozilla/layout/xul/base/src/tree/public/nsITreeColumns.idl create mode 100644 mozilla/layout/xul/base/src/tree/src/nsTreeColumns.cpp create mode 100644 mozilla/layout/xul/base/src/tree/src/nsTreeColumns.h create mode 100644 mozilla/layout/xul/base/src/tree/src/nsTreeImageListener.cpp create mode 100644 mozilla/layout/xul/base/src/tree/src/nsTreeImageListener.h create mode 100644 mozilla/layout/xul/base/src/tree/src/nsTreeStyleCache.cpp create mode 100644 mozilla/layout/xul/base/src/tree/src/nsTreeStyleCache.h create mode 100644 mozilla/themes/classic/global/mac/tree/checkbox-checked.gif create mode 100644 mozilla/themes/classic/global/mac/tree/checkbox.gif create mode 100644 mozilla/themes/classic/global/win/tree/checkbox-checked.gif create mode 100644 mozilla/themes/classic/global/win/tree/checkbox.gif create mode 100644 mozilla/themes/modern/global/tree/checkbox-checked.gif create mode 100644 mozilla/themes/modern/global/tree/checkbox.gif create mode 100644 mozilla/toolkit/locale/widgets/tree.dtd create mode 100644 mozilla/xpfe/global/resources/locale/en-US/tree.dtd diff --git a/mozilla/accessible/src/atk/nsXULTreeAccessibleWrap.cpp b/mozilla/accessible/src/atk/nsXULTreeAccessibleWrap.cpp index 6086ed2b803..e89d88684f8 100644 --- a/mozilla/accessible/src/atk/nsXULTreeAccessibleWrap.cpp +++ b/mozilla/accessible/src/atk/nsXULTreeAccessibleWrap.cpp @@ -39,6 +39,7 @@ #include "nsIDOMElement.h" #include "nsITreeSelection.h" +#include "nsITreeColumns.h" #include "nsXULTreeAccessibleWrap.h" // -------------------------------------------------------- @@ -170,8 +171,12 @@ NS_IMETHODIMP nsXULTreeAccessibleWrap::GetSelectedRows(PRUint32 *aNumRows, PRInt PRInt32 *outArray = (PRInt32 *)nsMemory::Alloc((*aNumRows) * sizeof(PRInt32)); NS_ENSURE_TRUE(outArray, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr view; + rv = mTree->GetView(getter_AddRefs(view)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr selection; - rv = mTree->GetSelection(getter_AddRefs(selection)); + rv = view->GetSelection(getter_AddRefs(selection)); NS_ENSURE_SUCCESS(rv, rv); PRInt32 rowCount; @@ -212,15 +217,15 @@ NS_IMETHODIMP nsXULTreeAccessibleWrap::CellRefAt(PRInt32 aRow, PRInt32 aColumn, nsCOMPtr columnElement(do_QueryInterface(columnNode, &rv)); NS_ENSURE_SUCCESS(rv, rv); - nsAutoString id; - rv = columnElement->GetAttribute(NS_LITERAL_STRING("id"), id); + nsCOMPtr treeColumns; + rv = mTree->GetColumns(getter_AddRefs(treeColumns)); NS_ENSURE_SUCCESS(rv, rv); - PRInt32 realColumn; - rv = mTree->GetColumnIndex(id.get(), &realColumn); + nsCOMPtr treeColumn; + rv = treeColumns->GetColumnFor(columnElement, getter_AddRefs(treeColumn)); NS_ENSURE_SUCCESS(rv, rv); - *_retval = new nsXULTreeitemAccessible(this, mDOMNode, mWeakShell, aRow, realColumn); + *_retval = new nsXULTreeitemAccessible(this, mDOMNode, mWeakShell, aRow, treeColumn); NS_ENSURE_TRUE(*_retval, NS_ERROR_OUT_OF_MEMORY); NS_IF_ADDREF(*_retval); @@ -323,8 +328,12 @@ NS_IMETHODIMP nsXULTreeAccessibleWrap::IsRowSelected(PRInt32 aRow, PRBool *_retv nsresult rv = NS_OK; + nsCOMPtr view; + rv = mTree->GetView(getter_AddRefs(view)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr selection; - rv = mTree->GetSelection(getter_AddRefs(selection)); + rv = view->GetSelection(getter_AddRefs(selection)); NS_ENSURE_SUCCESS(rv, rv); return selection->IsSelected(aRow, _retval); diff --git a/mozilla/accessible/src/base/nsRootAccessible.cpp b/mozilla/accessible/src/base/nsRootAccessible.cpp index 6b4fe0fde61..1bf4dabc916 100644 --- a/mozilla/accessible/src/base/nsRootAccessible.cpp +++ b/mozilla/accessible/src/base/nsRootAccessible.cpp @@ -337,19 +337,23 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) nsCOMPtr treeItemAccessible; nsXULTreeAccessible::GetTreeBoxObject(targetNode, getter_AddRefs(treeBox)); if (treeBox) { - nsCOMPtr selection; - treeBox->GetSelection(getter_AddRefs(selection)); - if (selection) { - selection->GetCurrentIndex(&treeIndex); - if (treeIndex >= 0) { - // XXX todo Kyle - fix bug 201922 so that tree is respohsible for keeping track - // of it's own accessibles. Then we'll ask the tree so we can reuse - // the accessibles already created. - nsCOMPtr weakEventShell(do_GetWeakReference(eventShell)); - treeItemAccessible = new nsXULTreeitemAccessible(accessible, targetNode, - weakEventShell, treeIndex); - if (!treeItemAccessible) - return NS_ERROR_OUT_OF_MEMORY; + nsCOMPtr view; + treeBox->GetView(getter_AddRefs(view)); + if (view) { + nsCOMPtr selection; + view->GetSelection(getter_AddRefs(selection)); + if (selection) { + selection->GetCurrentIndex(&treeIndex); + if (treeIndex >= 0) { + // XXX todo Kyle - fix bug 201922 so that tree is responsible for keeping track + // of it's own accessibles. Then we'll ask the tree so we can reuse + // the accessibles already created. + nsCOMPtr weakEventShell(do_GetWeakReference(eventShell)); + treeItemAccessible = new nsXULTreeitemAccessible(accessible, targetNode, + weakEventShell, treeIndex); + if (!treeItemAccessible) + return NS_ERROR_OUT_OF_MEMORY; + } } } } diff --git a/mozilla/accessible/src/xul/nsXULTreeAccessible.cpp b/mozilla/accessible/src/xul/nsXULTreeAccessible.cpp index f4f8efda565..dafb6da4ceb 100644 --- a/mozilla/accessible/src/xul/nsXULTreeAccessible.cpp +++ b/mozilla/accessible/src/xul/nsXULTreeAccessible.cpp @@ -40,6 +40,7 @@ #include "nsIBoxObject.h" #include "nsIDOMXULElement.h" #include "nsITreeSelection.h" +#include "nsITreeColumns.h" #include "nsXULTreeAccessible.h" #include "nsArray.h" @@ -119,7 +120,7 @@ NS_IMETHODIMP nsXULTreeAccessible::GetValue(nsAString& _retval) NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (! selection) return NS_ERROR_FAILURE; @@ -127,11 +128,14 @@ NS_IMETHODIMP nsXULTreeAccessible::GetValue(nsAString& _retval) nsCOMPtr selectItem; selection->GetCurrentIndex(¤tIndex); if (currentIndex >= 0) { - nsAutoString colID; - PRInt32 keyColumn; - mTree->GetKeyColumnIndex(&keyColumn); - mTree->GetColumnID(keyColumn, colID); - return mTreeView->GetCellText(currentIndex, colID.get(), _retval); + nsCOMPtr keyCol; + + nsCOMPtr cols; + mTree->GetColumns(getter_AddRefs(cols)); + if (cols) + cols->GetKeyColumn(getter_AddRefs(keyCol)); + + return mTreeView->GetCellText(currentIndex, keyCol, _retval); } return NS_OK; @@ -205,7 +209,7 @@ NS_IMETHODIMP nsXULTreeAccessible::GetSelectedChildren(nsIArray **_retval) NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (!selection) return NS_ERROR_FAILURE; nsCOMPtr selectedAccessibles; @@ -244,7 +248,7 @@ NS_IMETHODIMP nsXULTreeAccessible::GetSelectionCount(PRInt32 *aSelectionCount) NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (selection) selection->GetCount(aSelectionCount); @@ -256,7 +260,7 @@ NS_IMETHODIMP nsXULTreeAccessible::ChangeSelection(PRInt32 aIndex, PRUint8 aMeth NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (selection) { selection->IsSelected(aIndex, aSelState); if ((!(*aSelState) && eSelection_Add == aMethod) || @@ -289,7 +293,7 @@ NS_IMETHODIMP nsXULTreeAccessible::ClearSelection() NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (selection) selection->ClearSelection(); @@ -303,7 +307,7 @@ NS_IMETHODIMP nsXULTreeAccessible::RefSelection(PRInt32 aIndex, nsIAccessible ** NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (!selection) return NS_ERROR_FAILURE; @@ -343,7 +347,7 @@ NS_IMETHODIMP nsXULTreeAccessible::SelectAllSelection(PRBool *_retval) if (selType.IsEmpty() || !selType.Equals(NS_LITERAL_STRING("single"))) { *_retval = PR_TRUE; nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (selection) selection->SelectAll(); } @@ -354,8 +358,8 @@ NS_IMETHODIMP nsXULTreeAccessible::SelectAllSelection(PRBool *_retval) // ---------- nsXULTreeitemAccessible ---------- -nsXULTreeitemAccessible::nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMNode *aDOMNode, nsIWeakReference *aShell, PRInt32 aRow, PRInt32 aColumn): -nsLeafAccessible(aDOMNode, aShell) +nsXULTreeitemAccessible::nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMNode *aDOMNode, nsIWeakReference *aShell, PRInt32 aRow, nsITreeColumn* aColumn) + : nsLeafAccessible(aDOMNode, aShell) { Init(); // Add ourselves to cache using GetUniqueID() override mParent = aParent; // xxx todo: do we need this? We already have mParent on nsAccessible @@ -367,15 +371,13 @@ nsLeafAccessible(aDOMNode, aShell) // Since the real tree item does not correspond to any DOMNode, use the row index to distinguish each item mRow = aRow; - mColumnIndex = aColumn; - if (mTree) { - if (mColumnIndex < 0) { - PRInt32 keyColumn; - mTree->GetKeyColumnIndex(&keyColumn); - mTree->GetColumnID(keyColumn, mColumn); - } else { - mTree->GetColumnID(aColumn, mColumn); - } + mColumn = aColumn; + + if (!mColumn && mTree) { + nsCOMPtr cols; + mTree->GetColumns(getter_AddRefs(cols)); + if (cols) + cols->GetKeyColumn(getter_AddRefs(mColumn)); } } @@ -385,7 +387,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetName(nsAString& _retval) { NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); - return mTreeView->GetCellText(mRow, mColumn.get(), _retval); + return mTreeView->GetCellText(mRow, mColumn, _retval); } NS_IMETHODIMP nsXULTreeitemAccessible::GetValue(nsAString& _retval) @@ -435,7 +437,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetState(PRUint32 *_retval) // get selected state nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (selection) { PRBool isSelected, currentIndex; selection->IsSelected(mRow, &isSelected); @@ -504,7 +506,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetParent(nsIAccessible **aParent) return NS_OK; } -// Return the next row of tree if mColumnIndex < 0 (if any), +// Return the next row of tree if mColumn (if any), // otherwise return the next cell. NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibling) { @@ -515,7 +517,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibli PRInt32 rowCount; mTreeView->GetRowCount(&rowCount); - if (mColumnIndex < 0) { + if (!mColumn) { if (mRow < rowCount - 1) { *aNextSibling = new nsXULTreeitemAccessible(mParent, mDOMNode, mWeakShell, mRow + 1); if (! *aNextSibling) @@ -528,18 +530,17 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibli nsresult rv = NS_OK; #ifdef MOZ_ACCESSIBILITY_ATK - nsCOMPtr table(do_QueryInterface(mParent, &rv)); + PRInt32 row = mRow; + nsCOMPtr column; + rv = mColumn->GetNext(getter_AddRefs(column)); NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 columnCount, row = mRow, column = mColumnIndex; - rv = table->GetColumns(&columnCount); - NS_ENSURE_SUCCESS(rv, rv); - - if (mColumnIndex < columnCount - 1) { - column++; - } else if (mRow < rowCount - 1) { - column = 0; + + if (!column && mRow < rowCount - 1) { row++; + nsCOMPtr cols; + mTree->GetColumns(getter_AddRefs(cols)); + if (cols) + cols->GetFirstColumn(getter_AddRefs(column)); } *aNextSibling = new nsXULTreeitemAccessible(mParent, mDOMNode, mWeakShell, row, column); @@ -551,15 +552,15 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibli return rv; } -// Return the previou row of tree if mColumnIndex < 0 (if any), -// otherwise return the previou cell. +// Return the previous row of tree if mColumn (if any), +// otherwise return the previous cell. NS_IMETHODIMP nsXULTreeitemAccessible::GetPreviousSibling(nsIAccessible **aPreviousSibling) { *aPreviousSibling = nsnull; NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); - if (mRow > 0 && mColumnIndex < 0) { + if (!mColumn && mRow > 0) { *aPreviousSibling = new nsXULTreeitemAccessible(mParent, mDOMNode, mWeakShell, mRow - 1); if (! *aPreviousSibling) return NS_ERROR_OUT_OF_MEMORY; @@ -570,18 +571,17 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetPreviousSibling(nsIAccessible **aPrevi nsresult rv = NS_OK; #ifdef MOZ_ACCESSIBILITY_ATK - nsCOMPtr table(do_QueryInterface(mParent, &rv)); + PRInt32 row = mRow; + nsCOMPtr column; + rv = mColumn->GetPrevious(getter_AddRefs(column)); NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 columnCount, row = mRow, column = mColumnIndex; - rv = table->GetColumns(&columnCount); - NS_ENSURE_SUCCESS(rv, rv); - - if (mColumnIndex > 0) { - column--; - } else if (mRow > 0) { - column = columnCount - 1; + + if (!column && mRow > 0) { row--; + nsCOMPtr cols; + mTree->GetColumns(getter_AddRefs(cols)); + if (cols) + cols->GetLastColumn(getter_AddRefs(column)); } *aPreviousSibling = new nsXULTreeitemAccessible(mParent, mDOMNode, mWeakShell, row, column); @@ -609,12 +609,11 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); - const PRUnichar empty[] = {'\0'}; - // This Bounds are based on Tree's coord - mTree->GetCoordsForCellItem(mRow, mColumn.get(), empty, x, y, width, height); + mTree->GetCoordsForCellItem(mRow, mColumn, NS_LITERAL_CSTRING(""), x, y, width, height); // Get treechildren's BoxObject to adjust the Bounds' upper left corner + // XXXvarga consider using mTree->GetTreeBody() nsCOMPtr boxObject(do_QueryInterface(mTree)); if (boxObject) { nsCOMPtr boxElement; @@ -660,7 +659,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::RemoveSelection() NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (selection) { PRBool isSelected; selection->IsSelected(mRow, &isSelected); @@ -676,7 +675,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::TakeSelection() NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (selection) { PRBool isSelected; selection->IsSelected(mRow, &isSelected); @@ -692,7 +691,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::TakeFocus() NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); nsCOMPtr selection; - mTree->GetSelection(getter_AddRefs(selection)); + mTreeView->GetSelection(getter_AddRefs(selection)); if (selection) selection->SetCurrentIndex(mRow); diff --git a/mozilla/accessible/src/xul/nsXULTreeAccessible.h b/mozilla/accessible/src/xul/nsXULTreeAccessible.h index 4a422060f80..138e2093a23 100644 --- a/mozilla/accessible/src/xul/nsXULTreeAccessible.h +++ b/mozilla/accessible/src/xul/nsXULTreeAccessible.h @@ -42,6 +42,7 @@ #include "nsBaseWidgetAccessible.h" #include "nsITreeBoxObject.h" #include "nsITreeView.h" +#include "nsITreeColumns.h" #include "nsXULSelectAccessible.h" /* @@ -82,7 +83,7 @@ class nsXULTreeitemAccessible : public nsLeafAccessible public: NS_DECL_ISUPPORTS_INHERITED - nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMNode *aDOMNode, nsIWeakReference *aShell, PRInt32 aRow, PRInt32 aColumn = -1); + nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMNode *aDOMNode, nsIWeakReference *aShell, PRInt32 aRow, nsITreeColumn* aColumn = nsnull); virtual ~nsXULTreeitemAccessible() {} /* ----- nsIAccessible ----- */ @@ -109,8 +110,8 @@ public: private: nsCOMPtr mTree; nsCOMPtr mTreeView; - PRInt32 mRow, mColumnIndex; - nsString mColumn; + PRInt32 mRow; + nsCOMPtr mColumn; }; class nsXULTreeColumnsAccessible : public nsAccessibleWrap diff --git a/mozilla/browser/base/content/pageInfo.js b/mozilla/browser/base/content/pageInfo.js index b750fb4343f..d1e3c61c640 100644 --- a/mozilla/browser/base/content/pageInfo.js +++ b/mozilla/browser/base/content/pageInfo.js @@ -67,30 +67,21 @@ pageInfoTreeView.prototype = { getCellText: function(row, column) { - var colidx = 0; - // loop through the list of column names to find the index to the column - // we should be worrying about. very much a hack, but what can you do? - while(colidx < this.colcount && column != this.columnids[colidx]) - colidx++; - // row can be null, but js arrays are 0-indexed. // colidx cannot be null, but can be larger than the number // of columns in the array (when column is a string not in // this.columnids.) In this case it's the fault of // whoever typoed while calling this function. - return this.data[row][colidx] || ""; + return this.data[row][column.index] || ""; + }, + + setCellValue: function(row, column, value) + { }, setCellText: function(row, column, value) { - var colidx = 0; - // loop through the list of column names to find the index - // to the column the should be worrying about. very much a hack, but - // what can you do? - // XXX: I think there's a better way to do this now... - while(colidx < this.colcount && column != this.columnids[colidx]) - colidx++; - this.data[row][colidx] = value; + this.data[row][column.index] = value; }, addRow: function(row) @@ -137,15 +128,14 @@ pageInfoTreeView.prototype = { } }, - getRowProperties: function(row, column, prop) { }, - getCellProperties: function(row, prop) { }, - getColumnProperties: function(column, elem, prop) { }, + getRowProperties: function(row, prop) { }, + getCellProperties: function(row, column, prop) { }, + getColumnProperties: function(column, prop) { }, isContainer: function(index) { return false; }, isContainerOpen: function(index) { return false; }, isSeparator: function(index) { return false; }, isSorted: function() { }, - canDropOn: function(index) { return false; }, - canDropBeforeAfter: function(index, before) { return false; }, + canDrop: function(index, orientation) { return false; }, drop: function(row, orientation) { return false; }, getParentIndex: function(index) { return 0; }, hasNextSibling: function(index, after) { return false; }, @@ -154,7 +144,7 @@ pageInfoTreeView.prototype = { getProgressMode: function(row, column) { }, getCellValue: function(row, column) { }, toggleOpenState: function(index) { }, - cycleHeader: function(col, elem) { }, + cycleHeader: function(col) { }, selectionChanged: function() { }, cycleCell: function(row, column) { }, isEditable: function(row, column) { return false; }, @@ -598,7 +588,8 @@ function onFormSelect() formPreview.treeBoxObject.view = fieldView; var clickedRow = formView.selection.currentIndex; - var form = formView.getCellText(clickedRow, "form-node"); + // form-node + var form = formView.data[clickedRow][3]; var ft = null; if (form.name) @@ -643,8 +634,10 @@ function onFormSelect() { var labeltext = getValueText(label); for (var j = 0; j < length; j++) - if (formfields[j] == whatfor) - fieldView.setCellText(j, "field-label", labeltext); + if (formfields[j] == whatfor) { + var col = formPreview.columns["field-label"]; + fieldView.setCellText(j, col, labeltext); + } } } @@ -684,11 +677,8 @@ function onBeginLinkDrag(event,urlField,descField) if (!("treeBoxObject" in tree)) tree = tree.parentNode; - var row = {}; - var col = {}; - var elt = {}; - tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, elt); - if (row.value == -1) + var row = tree.treeBoxObject.getRowAt(event.clientX, event.clientY); + if (row == -1) return; // Getting drag-system needed services @@ -702,8 +692,10 @@ function onBeginLinkDrag(event,urlField,descField) // Adding URL flavor trans.addDataFlavor("text/x-moz-url"); - var url = tree.treeBoxObject.view.getCellText(row.value, urlField); - var desc = tree.treeBoxObject.view.getCellText(row.value, descField); + var col = tree.columns[urlField]; + var url = tree.view.getCellText(row, col); + col = tree.columns[descField]; + var desc = tree.view.getCellText(row, col); var stringURL = Components.classes[STRING_CONTRACTID].createInstance(Components.interfaces.nsISupportsString); stringURL.data = url + "\n"+desc; trans.setTransferData("text/x-moz-url", stringURL, stringURL.data.length * 2 ); @@ -728,8 +720,9 @@ function getSelectedImage(tree) if (!imageView.rowCount) return null; // Only works if only one item is selected - var clickedRow = tree.treeBoxObject.selection.currentIndex; - return imageView.getCellText(clickedRow, "image-node"); + var clickedRow = tree.currentIndex; + // image-node + return imageView.data[clickedRow][3]; } function saveMedia() @@ -747,9 +740,9 @@ function onImageSelect() var tree = document.getElementById("imagetree"); var saveAsButton = document.getElementById("imagesaveasbutton"); - if (tree.treeBoxObject.selection.count == 1) + if (tree.view.selection.count == 1) { - makePreview(tree.treeBoxObject.selection.currentIndex); + makePreview(tree.currentIndex); saveAsButton.setAttribute("disabled", "false"); } else @@ -758,9 +751,11 @@ function onImageSelect() function makePreview(row) { - var item = getSelectedImage(document.getElementById("imagetree")); - var url = imageView.getCellText(row, "image-address"); - var isBG = imageView.getCellText(row, "image-bg"); + var imageTree = document.getElementById("imagetree"); + var item = getSelectedImage(imageTree); + var col = imageTree.columns["image-address"]; + var url = imageView.getCellText(row, col); + var isBG = imageView.data[row][4]; document.getElementById("imageurltext").value = url; document.getElementById("imagetitletext").value = item.title || gStrings.notSet; diff --git a/mozilla/browser/components/bookmarks/content/addBookmark.js b/mozilla/browser/components/bookmarks/content/addBookmark.js index 1d16019e710..fc4662b3ba8 100644 --- a/mozilla/browser/components/bookmarks/content/addBookmark.js +++ b/mozilla/browser/components/bookmarks/content/addBookmark.js @@ -138,7 +138,7 @@ function Startup() folderItem = RDF.GetResource(window.arguments[2]); if (folderItem) { ind = bookmarkView.treeBuilder.getIndexOfResource(folderItem); - bookmarkView.treeBoxObject.selection.select(ind); + bookmarkView.treeBoxObject.view.selection.select(ind); } break; case "newBookmark": @@ -168,7 +168,7 @@ function Startup() folderItem = bookmarkView.rdf.GetResource(gCreateInFolder); if (folderItem) { ind = bookmarkView.treeBuilder.getIndexOfResource(folderItem); - bookmarkView.treeBoxObject.selection.select(ind); + bookmarkView.treeBoxObject.view.selection.select(ind); } } } @@ -179,7 +179,7 @@ function Startup() if (document.getElementById("bookmarknamegrid").hasAttribute("hidden")) { bookmarkView.tree.focus(); if (bookmarkView.currentIndex == -1) - bookmarkView.treeBoxObject.selection.select(0); + bookmarkView.treeBoxObject.view.selection.select(0); } else { gFld_Name.select(); @@ -303,9 +303,9 @@ function useDefaultFolder () var ind = bookmarkView.treeBuilder.getIndexOfResource(folder); if (ind != -1) { bookmarkView.tree.focus(); - bookmarkView.treeBoxObject.selection.select(ind); + bookmarkView.treeBoxObject.view.selection.select(ind); } else { - bookmarkView.treeBoxObject.selection.clearSelection(); + bookmarkView.treeBoxObject.view.selection.clearSelection(); } gCreateInFolder = folder.Value; } diff --git a/mozilla/browser/components/bookmarks/content/addBookmark2.js b/mozilla/browser/components/bookmarks/content/addBookmark2.js index 0f6312e8219..b2dfcb4987e 100644 --- a/mozilla/browser/components/bookmarks/content/addBookmark2.js +++ b/mozilla/browser/components/bookmarks/content/addBookmark2.js @@ -233,12 +233,12 @@ function selectTreeFolder() function selectFolder(aFolder) { - gBookmarksTree.treeBoxObject.selection.selectEventsSuppressed = true; - gBookmarksTree.treeBoxObject.selection.clearSelection(); + gBookmarksTree.treeBoxObject.view.selection.selectEventsSuppressed = true; + gBookmarksTree.treeBoxObject.view.selection.clearSelection(); gBookmarksTree.selectResource(aFolder); var index = gBookmarksTree.currentIndex; gBookmarksTree.treeBoxObject.ensureRowIsVisible(index); - gBookmarksTree.treeBoxObject.selection.selectEventsSuppressed = false; + gBookmarksTree.treeBoxObject.view.selection.selectEventsSuppressed = false; # triggers a select event that will provoke a call to selectTreeFolder() } diff --git a/mozilla/browser/components/bookmarks/content/bookmarks.js b/mozilla/browser/components/bookmarks/content/bookmarks.js index 34278ee40d1..c4e2c7f056d 100644 --- a/mozilla/browser/components/bookmarks/content/bookmarks.js +++ b/mozilla/browser/components/bookmarks/content/bookmarks.js @@ -987,9 +987,9 @@ CommandArrayEnumerator.prototype = { var BookmarksUtils = { - DROP_BEFORE: Components.interfaces.nsITreeView.inDropBefore, - DROP_ON : Components.interfaces.nsITreeView.inDropOn, - DROP_AFTER : Components.interfaces.nsITreeView.inDropAfter, + DROP_BEFORE: Components.interfaces.nsITreeView.DROP_BEFORE, + DROP_ON : Components.interfaces.nsITreeView.DROP_ON, + DROP_AFTER : Components.interfaces.nsITreeView.DROP_AFTER, _bundle : null, _brandShortName: null, diff --git a/mozilla/browser/components/bookmarks/content/bookmarksManager.js b/mozilla/browser/components/bookmarks/content/bookmarksManager.js index c8f8b04b654..f4e14e89b55 100644 --- a/mozilla/browser/components/bookmarks/content/bookmarksManager.js +++ b/mozilla/browser/components/bookmarks/content/bookmarksManager.js @@ -57,7 +57,7 @@ function Startup() bookmarksView.treeBoxObject.view.toggleOpenState(0); } - bookmarksView.treeBoxObject.selection.select(0); + bookmarksView.treeBoxObject.view.selection.select(0); windowNode.setAttribute("title", titleString); diff --git a/mozilla/browser/components/bookmarks/content/bookmarksTree.xml b/mozilla/browser/components/bookmarks/content/bookmarksTree.xml index 737448741eb..dcf0e429f09 100644 --- a/mozilla/browser/components/bookmarks/content/bookmarksTree.xml +++ b/mozilla/browser/components/bookmarks/content/bookmarksTree.xml @@ -264,7 +264,7 @@ @@ -307,8 +307,8 @@ @@ -352,13 +352,13 @@ selection.item = []; selection.parent = []; selection.isExpanded = []; - var rangeCount = this.treeBoxObject.selection.getRangeCount(); + var rangeCount = this.treeBoxObject.view.selection.getRangeCount(); // workaround for bug 171547: if rowCount==0, rangeCount==1 if (this.treeBuilder.rowCount > 0) for (var k = 0; k < rangeCount; ++k) { var rangeMin = {}; var rangeMax = {}; - this.treeBoxObject.selection.getRangeAt(k, rangeMin, rangeMax); + this.treeBoxObject.view.selection.getRangeAt(k, rangeMin, rangeMax); for (var i = rangeMin.value; i <= rangeMax.value; ++i) { var selectedItem = this.getRowResource(i); var selectedParent = this.getParentResource(i); @@ -493,11 +493,11 @@ @@ -536,7 +536,7 @@ return; if (this.clickCount == 2 && modifKey) { - this.treeBoxObject.selection.select(row); + this.treeBoxObject.view.selection.select(row); this._selection = this.getTreeSelection(); } var selection = this._selection; @@ -614,12 +614,12 @@ { var selection = this.mOuter._selection; var target = this.mOuter._target; - this.mOuter.treeBoxObject.selection.selectEventsSuppressed = true; + this.mOuter.treeBoxObject.view.selection.selectEventsSuppressed = true; this.mOuter._itemToBeToggled = []; switch (aCommand) { case "cmd_selectAll": - this.mOuter.treeBoxObject.selection.selectAll(); + this.mOuter.treeBoxObject.view.selection.selectAll(); break; case "cmd_bm_expandfolder": this.mOuter.treeBoxObject.view.toggleOpenState(this.mOuter.currentIndex); @@ -629,7 +629,7 @@ BookmarksController.doCommand(aCommand, selection, target); this.mOuter.restoreSelection(aCommand); } - this.mOuter.treeBoxObject.selection.selectEventsSuppressed = false; + this.mOuter.treeBoxObject.view.selection.selectEventsSuppressed = false; } }) ]]> @@ -652,15 +652,7 @@ " + title + ""; aXferData.data = new TransferData(); @@ -129,7 +130,7 @@ function checkURLSecurity(aURL) function OpenURL(aWhere, event) { - var count = gHistoryTree.treeBoxObject.view.selection.count; + var count = gHistoryTree.view.selection.count; if (count != 1) return; @@ -176,7 +177,8 @@ function SortBy(sortKey) var col = document.getElementById("Name"); col.setAttribute("sort", sortKey); col.setAttribute("sortDirection", sortDirection); - gHistoryTree.treeBoxObject.view.cycleHeader(sortKey, col); + var column = gHistoryTree.columns.getColumnFor(col); + gHistoryTree.view.cycleHeader(column); } function IsFindResource(uri) @@ -232,7 +234,7 @@ function Sort(groupingType) function historyAddBookmarks() { - var count = gHistoryTree.treeBoxObject.view.selection.count; + var count = gHistoryTree.view.selection.count; if (count != 1) return; @@ -241,7 +243,8 @@ function historyAddBookmarks() var url = builder.getResourceAtIndex(currentIndex).ValueUTF8; //XXXBlake don't use getCellText - var title = gHistoryTree.treeBoxObject.view.getCellText(currentIndex, "Name"); + var col = gHistoryTree.columns["Name"]; + var title = gHistoryTree.view.getCellText(currentIndex, col); BookmarksUtils.addBookmark(url, title, undefined); } @@ -256,7 +259,7 @@ function historyCopyLink() function buildContextMenu() { - var count = gHistoryTree.treeBoxObject.view.selection.count; + var count = gHistoryTree.view.selection.count; var openItem = document.getElementById("miOpen"); var openItemInNewWindow = document.getElementById("miOpenInNewWindow"); var openItemInNewTab = document.getElementById("miOpenInNewTab"); diff --git a/mozilla/browser/components/prefwindow/content/permissions.js b/mozilla/browser/components/prefwindow/content/permissions.js index 5361fe2a679..d60e0a88968 100644 --- a/mozilla/browser/components/prefwindow/content/permissions.js +++ b/mozilla/browser/components/prefwindow/content/permissions.js @@ -62,9 +62,9 @@ var permissionsTreeView = { getCellValue : function(row,column) {}, getCellText : function(row,column){ var rv=""; - if (column=="siteCol") { + if (column.id=="siteCol") { rv = permissions[row].rawHost; - } else if (column=="statusCol") { + } else if (column.id=="statusCol") { rv = permissions[row].capability; } return rv; @@ -72,10 +72,10 @@ var permissionsTreeView = { isSeparator : function(index) {return false;}, isSorted: function() { return false; }, isContainer : function(index) {return false;}, - cycleHeader : function(aColId, aElt) {}, - getRowProperties : function(row,column,prop){}, - getColumnProperties : function(column,columnElement,prop){}, - getCellProperties : function(row,prop){} + cycleHeader : function(column) {}, + getRowProperties : function(row,prop) {}, + getColumnProperties : function(column,prop) {}, + getCellProperties : function(row,column,prop) {} }; function Permission(number, host, rawHost, type, capability, perm) { diff --git a/mozilla/browser/components/prefwindow/content/plugins.js b/mozilla/browser/components/prefwindow/content/plugins.js index eff34c99797..50a4615f09a 100644 --- a/mozilla/browser/components/prefwindow/content/plugins.js +++ b/mozilla/browser/components/prefwindow/content/plugins.js @@ -257,7 +257,7 @@ PluginTypes.prototype = { getCellProperties: function (aRow, aCol, aProperties) { - if (aCol == "pluginEnabled") { + if (aCol.id == "pluginEnabled") { if (this._pluginTypes[aRow].pluginEnabled) aProperties.AppendElement(this._enabledAtom); } @@ -265,7 +265,7 @@ PluginTypes.prototype = { getImageSrc: function (aRow, aCol) { - if (aCol == "fileExtension") + if (aCol.id == "fileExtension") return "moz-icon://goat." + this._pluginTypes[aRow].MIMEInfo.primaryExtension + "?size=16"; return null; @@ -275,12 +275,12 @@ PluginTypes.prototype = { { var mimeInfo = this._pluginTypes[aRow].MIMEInfo; - if (aCol == "fileType") { + if (aCol.id == "fileType") { var desc = mimeInfo.Description; // XXXben localize return desc || mimeInfo.primaryExtension.toUpperCase() + " file"; } - else if (aCol == "fileExtension") + else if (aCol.id == "fileExtension") return mimeInfo.primaryExtension.toUpperCase(); return ""; @@ -288,7 +288,7 @@ PluginTypes.prototype = { cycleCell: function (aRow, aCol) { - if (aCol == "pluginEnabled") { + if (aCol.id == "pluginEnabled") { this._pluginTypes[aRow].pluginEnabled = !this._pluginTypes[aRow].pluginEnabled; gPluginTypesList.treeBoxObject.invalidateCell(aRow, aCol); } @@ -302,8 +302,7 @@ PluginTypes.prototype = { isContainerEmpty: function (aRow) { return true; }, isSeparator: function (aRow) { return false; }, isSorted: function () { return false; }, - canDropOn: function (aRow) { return false; }, - canDropBeforeAfter: function (aRow, aBefore) { return false; }, + canDrop: function (aRow, aOrientation) { return false; }, drop: function (aRow, aOrientation) { }, getParentIndex: function (aRow) { }, hasNextSibling: function (aRow, aNextIndex) { }, @@ -312,15 +311,16 @@ PluginTypes.prototype = { getCellValue: function (aRow, aCol) { }, setTree: function (aTree) { }, toggleOpenState: function (aRow) { }, - cycleHeader: function (aCol, aColElt) { }, + cycleHeader: function (aCol) { }, selectionChanged: function () { }, isEditable: function (aRow, aCol) { }, + setCellValue: function (aRow, aCol, aValue) { }, setCellText: function (aRow, aCol, aValue) { }, performAction: function (aAction) { }, performActionOnRow: function (aAction, aRow) { }, performActionOnCell: function (aAction, aRow, aCol) { }, getRowProperties: function (aRow, aProperties) { }, - getColumnProperties: function (aCol, aColElt, aProperties) { } + getColumnProperties: function (aCol, aProperties) { } }; diff --git a/mozilla/calendar/resources/content/pref/prefBird.xul b/mozilla/calendar/resources/content/pref/prefBird.xul index 54419a76e79..33c8eeeaf86 100644 --- a/mozilla/calendar/resources/content/pref/prefBird.xul +++ b/mozilla/calendar/resources/content/pref/prefBird.xul @@ -454,7 +454,7 @@ var PrefDialogService = var index = this.prefTree.view.getIndexOfItem(selectItem); if (index != -1) - this.prefTree.treeBoxObject.selection.select(index); + this.prefTree.view.selection.select(index); } }; diff --git a/mozilla/calendar/resources/content/selectAddressesDialog.js b/mozilla/calendar/resources/content/selectAddressesDialog.js index dc9828b7a1f..f847f2faea4 100644 --- a/mozilla/calendar/resources/content/selectAddressesDialog.js +++ b/mozilla/calendar/resources/content/selectAddressesDialog.js @@ -317,28 +317,28 @@ ContactsTree.prototype = set selection(aSelection) { this.mSelection = aSelection; }, setTree: function(aTree) { this.mTree = aTree; }, - getCellText: function(aRow, aColId) + getCellText: function(aRow, aCol) { var card = this.cardSet.cardList[ aRow ]; if( card ) { - if( aColId == "PrimaryEmail" && !card.isMailList() ) + if( aCol.id == "PrimaryEmail" && !card.isMailList() ) { - if( card.getCardValue( aColId ).length == 0 ) + if( card.getCardValue( aCol.id ).length == 0 ) { return DTD_noEmailMessage; } else { - return card.getCardValue( aColId ); + return card.getCardValue( aCol.id ); } } else { - return card.getCardValue( aColId ); + return card.getCardValue( aCol.id ); } } @@ -365,7 +365,7 @@ ContactsTree.prototype = } }, - getCellProperties: function(aRow, aColId, aProperties) + getCellProperties: function(aRow, aCol, aProperties) { var card = this.cardSet.cardList[ aRow ]; @@ -382,13 +382,13 @@ ContactsTree.prototype = } }, - getColumnProperties: function(aColId, aColElt, aProperties) {}, + getColumnProperties: function(aCol, aProperties) {}, getParentIndex: function(aRowIndex) { return -1; }, //hasNextSibling: function(aRowIndex, aAfterIndex) { }, getLevel: function(aIndex) { return 0; }, - getImageSrc: function(aRow, aColId) {}, - //getProgressMode: function(aRow, aColId) {}, - //getCellValue: function(aRow, aColId) {}, + getImageSrc: function(aRow, aCol) {}, + //getProgressMode: function(aRow, aCol) {}, + //getCellValue: function(aRow, aCol) {}, isContainer: function(aIndex) { return false; }, //isContainerOpen: function(aIndex) {}, //isContainerEmpty: function(aIndex) {}, @@ -401,13 +401,14 @@ ContactsTree.prototype = }, - cycleHeader: function(aColId, aElt) {}, - //cycleCell: function(aRow, aColId) {}, - //isEditable: function(aRow, aColId) {}, - setCellText: function(aRow, aColId, aValue) {}, + cycleHeader: function(aCol) {}, + //cycleCell: function(aRow, aCol) {}, + //isEditable: function(aRow, aCol) {}, + setCellValue: function(aRow, aCol, aValue) {}, + setCellText: function(aRow, aCol, aValue) {}, //performAction: function(aAction) {}, //performActionOnRow: function(aAction, aRow) {}, - //performActionOnCell: function(aAction, aRow, aColId) {}, + //performActionOnCell: function(aAction, aRow, aCol) {}, // extra utility stuff @@ -468,18 +469,16 @@ ContactsTree.prototype = } else if (target.localName == "treechildren") { - var row = new Object(); + var row = this.recipientTreeElement.treeBoxObject.getRowAt( event.clientX, event.clientY ); - this.recipientTreeElement.treeBoxObject.getCellAt( event.clientX, event.clientY, row, {}, {} ); - - if( row.value != -1 && row.value < this.recipientTreeElement.view.rowCount ) + if( row != -1 && row < this.recipientTreeElement.view.rowCount ) { - var card = this.cardSet.cardList[ row.value ]; + var card = this.cardSet.cardList[ row ]; if( card.getPrimaryEmail() != "" ) { card._checked = !card._checked; - this.recipientTreeElement.treeBoxObject.invalidateRow( row.value ); + this.recipientTreeElement.treeBoxObject.invalidateRow( row ); } } } @@ -493,17 +492,16 @@ ContactsTree.prototype = if( target.localName == "treechildren" ) { // Get the email address of the card just clicked - var row = new Object(); - this.resultsTree.treeBoxObject.getCellAt( event.clientX, event.clientY, row, {}, {} ); + var row = this.resultsTree.treeBoxObject.getRowAt( event.clientX, event.clientY ); - if( row.value != -1 ) + if( row != -1 ) { - var card = this.cardSet.cardList[ row.value ]; + var card = this.cardSet.cardList[ row ]; // If the card has no email address, remove it from the selection if( card && ( !card.isMailList() ) && ( card.getCardValue( "PrimaryEmail" ) == "" ) ) { - this.selection.clearRange( row.value, row.value ); + this.selection.clearRange( row, row ); return; } @@ -650,7 +648,7 @@ function addSelectedAddressesIntoBucket( displayPrefix, addressPrefix ) addSelectedCardsToBucket( displayPrefix, addressPrefix ); // Clear selection and update mailto commands - gContactsTree.resultsTree.treeBoxObject.selection.clearSelection(); + gContactsTree.resultsTree.view.selection.clearSelection(); updateCommands( gMailToCommandsArray, true ); } // End function addSelectedAddressesIntoBucket @@ -919,16 +917,16 @@ function getSelectedRecipients( tree ) { var selectedItems = new Array(); - if( tree && tree.treeBoxObject && tree.treeBoxObject.selection ) + if( tree && tree.view && tree.view.selection ) { - var rangeCount = tree.treeBoxObject.selection.getRangeCount(); + var rangeCount = tree.view.selection.getRangeCount(); for( var i = 0; i < rangeCount; i++ ) { var startIndex = new Object(); var endIndex = new Object(); - tree.treeBoxObject.selection.getRangeAt( i, startIndex, endIndex ); + tree.view.selection.getRangeAt( i, startIndex, endIndex ); for( var j = startIndex.value; j <= endIndex.value; j++ ) { @@ -1292,28 +1290,28 @@ EventContactsTree.prototype = set selection(aSelection) { this.mSelection = aSelection; }, setTree: function(aTree) { this.mTree = aTree; }, - getCellText: function(aRow, aColId) + getCellText: function(aRow, aCol) { var card = this.cardSet.cardList[ aRow ]; if( card ) { - if( aColId == "PrimaryEmail" && !card.isMailList() ) + if( aCol.id == "PrimaryEmail" && !card.isMailList() ) { - if( card.getCardValue( aColId ).length == 0 ) + if( card.getCardValue( aCol.id ).length == 0 ) { return DTD_noEmailMessage; } else { - return card.getCardValue( aColId ); + return card.getCardValue( aCol.id ); } } else { - return card.getCardValue( aColId ); + return card.getCardValue( aCol.id ); } } @@ -1340,7 +1338,7 @@ EventContactsTree.prototype = } }, - getCellProperties: function(aRow, aColId, aProperties) + getCellProperties: function(aRow, aCol, aProperties) { var card = this.cardSet.cardList[ aRow ]; @@ -1357,13 +1355,13 @@ EventContactsTree.prototype = } }, - getColumnProperties: function(aColId, aColElt, aProperties) {}, + getColumnProperties: function(aCol, aProperties) {}, getParentIndex: function(aRowIndex) { return -1; }, //hasNextSibling: function(aRowIndex, aAfterIndex) { }, getLevel: function(aIndex) { return 0; }, - getImageSrc: function(aRow, aColId) {}, - //getProgressMode: function(aRow, aColId) {}, - //getCellValue: function(aRow, aColId) {}, + getImageSrc: function(aRow, aCol) {}, + //getProgressMode: function(aRow, aCol) {}, + //getCellValue: function(aRow, aCol) {}, isContainer: function(aIndex) { return false; }, //isContainerOpen: function(aIndex) {}, //isContainerEmpty: function(aIndex) {}, @@ -1376,13 +1374,14 @@ EventContactsTree.prototype = }, - cycleHeader: function(aColId, aElt) {}, - //cycleCell: function(aRow, aColId) {}, - //isEditable: function(aRow, aColId) {}, - setCellText: function(aRow, aColId, aValue) {}, + cycleHeader: function(aCol) {}, + //cycleCell: function(aRow, aCol) {}, + //isEditable: function(aRow, aCol) {}, + setCellValue: function(aRow, aCol, aValue) {}, + setCellText: function(aRow, aCol, aValue) {}, //performAction: function(aAction) {}, //performActionOnRow: function(aAction, aRow) {}, - //performActionOnCell: function(aAction, aRow, aColId) {}, + //performActionOnCell: function(aAction, aRow, aCol) {}, // extra utility stuff @@ -1443,18 +1442,16 @@ EventContactsTree.prototype = } else if (target.localName == "treechildren") { - var row = new Object(); + var row = this.recipientTreeElement.treeBoxObject.getRowAt( event.clientX, event.clientY ); - this.recipientTreeElement.treeBoxObject.getCellAt( event.clientX, event.clientY, row, {}, {} ); - - if( row.value != -1 && row.value < this.recipientTreeElement.view.rowCount ) + if( row != -1 && row < this.recipientTreeElement.view.rowCount ) { - var card = this.cardSet.cardList[ row.value ]; + var card = this.cardSet.cardList[ row ]; if( card.getPrimaryEmail() != "" ) { card._checked = !card._checked; - this.recipientTreeElement.treeBoxObject.invalidateRow( row.value ); + this.recipientTreeElement.treeBoxObject.invalidateRow( row ); } } } @@ -1468,17 +1465,16 @@ EventContactsTree.prototype = if( target.localName == "treechildren" ) { // Get the email address of the card just clicked - var row = new Object(); - this.resultsTree.treeBoxObject.getCellAt( event.clientX, event.clientY, row, {}, {} ); + var row = this.resultsTree.treeBoxObject.getRowAt( event.clientX, event.clientY ); - if( row.value != -1 ) + if( row != -1 ) { - var card = this.cardSet.cardList[ row.value ]; + var card = this.cardSet.cardList[ row ]; // If the card has no email address, remove it from the selection if( card && ( !card.isMailList() ) && ( card.getCardValue( "PrimaryEmail" ) == "" ) ) { - this.selection.clearRange( row.value, row.value ); + this.selection.clearRange( row, row ); return; } @@ -1644,7 +1640,7 @@ function addSelectedAddressesIntoInviteBucket( displayPrefix, addressPrefix ) addSelectedInviteCardsToBucket( displayPrefix, addressPrefix ); // Clear selection and update mailto commands - gContactsTree.resultsTree.treeBoxObject.selection.clearSelection(); + gContactsTree.resultsTree.view.selection.clearSelection(); updateCommands( gInviteCommandsArray, true ); } // End function addSelectedAddressesIntoInviteBucket diff --git a/mozilla/calendar/resources/content/unifinder.js b/mozilla/calendar/resources/content/unifinder.js index 5b7b96c0ced..94ae3741f1b 100644 --- a/mozilla/calendar/resources/content/unifinder.js +++ b/mozilla/calendar/resources/content/unifinder.js @@ -61,7 +61,7 @@ function resetAllowSelection() doingSelection = false; var SearchTree = document.getElementById( UnifinderTreeName ); - SearchTree.treeBoxObject.selection.selectEventsSuppressed = false; + SearchTree.view.selection.selectEventsSuppressed = false; SearchTree.addEventListener( "select", unifinderOnSelect, true ); } @@ -88,7 +88,7 @@ function selectSelectedEventsInTree( EventsToSelect ) */ SearchTree.onselect = null; SearchTree.removeEventListener( "select", unifinderOnSelect, true ); - SearchTree.treeBoxObject.selection.selectEventsSuppressed = true; + SearchTree.view.selection.selectEventsSuppressed = true; if( EventsToSelect.length == 1 ) { @@ -96,15 +96,15 @@ function selectSelectedEventsInTree( EventsToSelect ) if( RowToScrollTo != "null" ) { - SearchTree.treeBoxObject.selection.clearSelection( ); + SearchTree.view.selection.clearSelection( ); SearchTree.treeBoxObject.ensureRowIsVisible( RowToScrollTo ); - SearchTree.treeBoxObject.selection.timedSelect( RowToScrollTo, 1 ); + SearchTree.view.selection.timedSelect( RowToScrollTo, 1 ); } else { - SearchTree.treeBoxObject.selection.clearSelection( ); + SearchTree.view.selection.clearSelection( ); } } else if( EventsToSelect.length > 1 ) @@ -113,7 +113,7 @@ function selectSelectedEventsInTree( EventsToSelect ) ** Other than that, there's no other way to get in here. */ if( gSelectAll === true ) { - SearchTree.treeBoxObject.selection.selectAll( ); + SearchTree.view.selection.selectAll( ); gSelectAll = false; } @@ -121,7 +121,7 @@ function selectSelectedEventsInTree( EventsToSelect ) else { dump( "\n--->>>>unifinder.js selection callback :: Clear selection" ); - SearchTree.treeBoxObject.selection.clearSelection( ); + SearchTree.view.selection.clearSelection( ); } /* This needs to be in a setTimeout */ @@ -262,13 +262,12 @@ function unifinderDoubleClickEvent( event ) function getCalendarEventFromEvent( event ) { var tree = document.getElementById( UnifinderTreeName ); - var row = new Object(); - tree.treeBoxObject.getCellAt( event.clientX, event.clientY, row, {}, {} ); + var row = tree.treeBoxObject.getRowAt( event.clientX, event.clientY ); - if( row.value != -1 && row.value < tree.view.rowCount ) + if( row != -1 && row < tree.view.rowCount ) { - return ( tree.eventView.getCalendarEventAtRow( row.value ) ); + return ( tree.eventView.getCalendarEventAtRow( row ) ); } else { return ( null ); } @@ -481,15 +480,15 @@ var treeView = isEditable : function(){return true;}, isSeparator : function(){return false;}, getImageSrc : function(){return false;}, - cycleHeader : function( ColId, element ) + cycleHeader : function(col) { //dump( "\nin cycle header" ); var sortActive; var treeCols; - this.selectedColumn = ColId; - sortActive = element.getAttribute("sortActive"); - this.sortDirection = element.getAttribute("sortDirection"); + this.selectedColumn = col.id; + sortActive = col.element.getAttribute("sortActive"); + this.sortDirection = col.element.getAttribute("sortDirection"); if (sortActive != "true") { @@ -514,8 +513,8 @@ var treeView = this.sortDirection = "descending"; } } - element.setAttribute("sortActive", sortActive); - element.setAttribute("sortDirection", this.sortDirection); + col.element.setAttribute("sortActive", sortActive); + col.element.setAttribute("sortDirection", this.sortDirection); //dump( "\nabout to sort events "+gEventArray.length ); gEventArray.sort( sortEvents ); //dump( "\nSORTED!"); @@ -525,7 +524,7 @@ var treeView = getCellText : function(row,column) { calendarEvent = gEventArray[row]; - switch( column ) + switch( column.id ) { case "unifinder-search-results-tree-col-title": return( calendarEvent.title ); diff --git a/mozilla/calendar/resources/content/unifinderToDo.js b/mozilla/calendar/resources/content/unifinderToDo.js index 190d7431b75..af8d577c9d1 100644 --- a/mozilla/calendar/resources/content/unifinderToDo.js +++ b/mozilla/calendar/resources/content/unifinderToDo.js @@ -143,13 +143,12 @@ function toDoUnifinderRefresh() function getToDoFromEvent( event ) { var tree = document.getElementById( ToDoUnifinderTreeName ); - var row = new Object(); - tree.treeBoxObject.getCellAt( event.clientX, event.clientY, row, {}, {} ); - - if( row.value != -1 && row.value < tree.view.rowCount ) + var row = tree.treeBoxObject.getRowAt( event.clientX, event.clientY ); + + if( row != -1 && row < tree.view.rowCount ) { - return( tree.taskView.getCalendarTaskAtRow( row.value ) ); + return( tree.taskView.getCalendarTaskAtRow( row ) ); } return false; } @@ -202,7 +201,7 @@ function unifinderMouseDownToDo( event ) { if(event.button == 2) treechildren.setAttribute("context", "context-menu"); - tree.treeBoxObject.selection.clearSelection(); + tree.view.selection.clearSelection(); // TODO HACK notifiers should be rewritten to integrate events and todos document.getElementById( "delete_todo_command" ).setAttribute( "disabled", "true" ); @@ -294,7 +293,7 @@ var toDoTreeView = calendarToDo = gTaskArray[row]; var aserv=Components.classes["@mozilla.org/atom-service;1"].createInstance(Components.interfaces.nsIAtomService); - if( column == "unifinder-todo-tree-col-priority" ) + if( column.id == "unifinder-todo-tree-col-priority" ) { if(calendarToDo.priority > 0 && calendarToDo.priority < 5) props.AppendElement(aserv.getAtom("highpriority")); @@ -322,12 +321,12 @@ var toDoTreeView = // to use moz-tree-image pseudoelement : // it is mandatory to return "" and not false :-( getImageSrc : function(){return("");}, - cycleCell : function(row,colId) + cycleCell : function(row,col) { calendarToDo = gTaskArray[row]; if( !calendarToDo ) return; - if( colId == "unifinder-todo-tree-col-completed") + if( col.id == "unifinder-todo-tree-col-completed") { var completed = calendarToDo.completed.getTime(); @@ -337,14 +336,14 @@ var toDoTreeView = checkboxClick( calendarToDo, true ) ; } }, - cycleHeader : function( ColId, element ) + cycleHeader : function(col ) { var sortActive; var treeCols; - this.selectedColumn = ColId; - sortActive = element.getAttribute("sortActive"); - this.sortDirection = element.getAttribute("sortDirection"); + this.selectedColumn = col.id; + sortActive = col.element.getAttribute("sortActive"); + this.sortDirection = col.element.getAttribute("sortDirection"); if (sortActive != "true") { @@ -369,8 +368,8 @@ var toDoTreeView = this.sortDirection = "descending"; } } - element.setAttribute("sortActive", sortActive); - element.setAttribute("sortDirection", this.sortDirection); + col.element.setAttribute("sortActive", sortActive); + col.element.setAttribute("sortDirection", this.sortDirection); gTaskArray.sort( sortTasks ); document.getElementById( ToDoUnifinderTreeName ).view = this; }, @@ -381,7 +380,7 @@ var toDoTreeView = if( !calendarToDo ) return false; - switch( column ) + switch( column.id ) { case "unifinder-todo-tree-col-completed": return( "" ); @@ -526,7 +525,7 @@ function contextChangeProgress( event, Progress ) { var tree = document.getElementById( ToDoUnifinderTreeName ); - if (tree.treeBoxObject.selection.count > 0) + if (tree.view.selection.count > 0) { var toDoItem = tree.taskView.getCalendarTaskAtRow( tree.currentIndex ); if(toDoItem) @@ -542,7 +541,7 @@ function contextChangePriority( event, Priority ) { var tree = document.getElementById( ToDoUnifinderTreeName ); - if (tree.treeBoxObject.selection.count > 0) + if (tree.view.selection.count > 0) { var toDoItem = tree.taskView.getCalendarTaskAtRow( tree.currentIndex ); if(toDoItem) diff --git a/mozilla/content/shared/public/nsCSSAnonBoxList.h b/mozilla/content/shared/public/nsCSSAnonBoxList.h index 59a0e9ebec1..78ddcc8d0f9 100644 --- a/mozilla/content/shared/public/nsCSSAnonBoxList.h +++ b/mozilla/content/shared/public/nsCSSAnonBoxList.h @@ -89,17 +89,18 @@ CSS_ANON_BOX(viewportScroll, ":-moz-viewport-scroll") CSS_ANON_BOX(selectScrolledContent, ":-moz-select-scrolled-content") #ifdef MOZ_XUL -CSS_ANON_BOX(moztreerow, ":-moz-tree-row") -CSS_ANON_BOX(moztreecell, ":-moz-tree-cell") CSS_ANON_BOX(moztreecolumn, ":-moz-tree-column") -CSS_ANON_BOX(moztreecelltext, ":-moz-tree-cell-text") -CSS_ANON_BOX(moztreetwisty, ":-moz-tree-twisty") +CSS_ANON_BOX(moztreerow, ":-moz-tree-row") +CSS_ANON_BOX(moztreeseparator, ":-moz-tree-separator") +CSS_ANON_BOX(moztreecell, ":-moz-tree-cell") CSS_ANON_BOX(moztreeindentation, ":-moz-tree-indentation") CSS_ANON_BOX(moztreeline, ":-moz-tree-line") +CSS_ANON_BOX(moztreetwisty, ":-moz-tree-twisty") CSS_ANON_BOX(moztreeimage, ":-moz-tree-image") -CSS_ANON_BOX(moztreeseparator, ":-moz-tree-separator") -CSS_ANON_BOX(moztreedropfeedback, ":-moz-tree-drop-feedback") +CSS_ANON_BOX(moztreecelltext, ":-moz-tree-cell-text") +CSS_ANON_BOX(moztreecheckbox, ":-moz-tree-checkbox") CSS_ANON_BOX(moztreeprogressmeter, ":-moz-tree-progressmeter") +CSS_ANON_BOX(moztreedropfeedback, ":-moz-tree-drop-feedback") #endif #ifdef MOZ_MATHML diff --git a/mozilla/content/shared/public/nsXULAtomList.h b/mozilla/content/shared/public/nsXULAtomList.h index 8a8ab0ccd32..b039040b88f 100644 --- a/mozilla/content/shared/public/nsXULAtomList.h +++ b/mozilla/content/shared/public/nsXULAtomList.h @@ -77,9 +77,6 @@ XUL_ATOM(description, "description") // The tree atoms XUL_ATOM(allowevents, "allowevents") // Lets events be handled on the cell contents or in menus. -XUL_ATOM(scrollbarlist, "scrollbarlist") // An atom for internal use by the tree view -XUL_ATOM(indent, "indent") // indicates that a cell should be indented -XUL_ATOM(outer, "outer") // indicates that a treechildren is the outermost rowgroup XUL_ATOM(sizemode, "sizemode") // when set, measure strings to determine preferred width XUL_ATOM(open, "open") // Whether or not a menu, tree, etc. is open @@ -95,8 +92,9 @@ XUL_ATOM(treerow, "treerow") XUL_ATOM(treeseparator, "treeseparator") XUL_ATOM(treecell, "treecell") -XUL_ATOM(cycler, "cycler") XUL_ATOM(primary, "primary") +XUL_ATOM(cycler, "cycler") +XUL_ATOM(editable, "editable") XUL_ATOM(current, "current") XUL_ATOM(seltype, "seltype") XUL_ATOM(sorted, "sorted") @@ -104,9 +102,9 @@ XUL_ATOM(dragSession, "dragSession") XUL_ATOM(dropOn, "dropOn") XUL_ATOM(dropBefore, "dropBefore") XUL_ATOM(dropAfter, "dropAfter") +XUL_ATOM(checked, "checked") XUL_ATOM(progressNormal, "progressNormal") XUL_ATOM(progressUndetermined, "progressUndetermined") -XUL_ATOM(progressNone, "progressNone") XUL_ATOM(odd, "odd") XUL_ATOM(even, "even") diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 0b69ec1d5de..544a1b58189 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -3449,6 +3449,7 @@ nsXULDocument::CreateTemplateBuilder(nsIContent* aElement) builder->Init(aElement); // Create a if one isn't there already. + // XXXvarga what about attributes? nsCOMPtr bodyContent; nsXULContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, nsXULAtoms::treechildren, diff --git a/mozilla/content/xul/templates/public/nsIXULTemplateBuilder.idl b/mozilla/content/xul/templates/public/nsIXULTemplateBuilder.idl index 7efb836b8ca..b2ff02ca339 100644 --- a/mozilla/content/xul/templates/public/nsIXULTemplateBuilder.idl +++ b/mozilla/content/xul/templates/public/nsIXULTemplateBuilder.idl @@ -112,21 +112,21 @@ interface nsIXULTemplateBuilder : nsISupports [scriptable, uuid(f6ed69be-1dd1-11b2-adfc-9db02ac57d88)] interface nsIXULTreeBuilderObserver : nsISupports { + const long DROP_BEFORE = -1; + const long DROP_ON = 0; + const long DROP_AFTER = 1; /** * Methods used by the drag feedback code to determine if a drag is allowable at * the current location. To get the behavior where drops are only allowed on - * items, such as the mailNews folder pane, always return false from |canDropBeforeAfter()|. + * items, such as the mailNews folder pane, always return false whe + * the orientation is not DROP_ON. */ - boolean canDropOn(in long index); - boolean canDropBeforeAfter(in long index, in boolean before); + boolean canDrop(in long index, in long orientation); /** * Called when the user drops something on this view. The |orientation| param * specifies before/on/after the given |row|. */ - const long inDropBefore = 1; - const long inDropOn = 2; - const long inDropAfter = 3; void onDrop(in long row, in long orientation); /** @@ -150,19 +150,6 @@ interface nsIXULTreeBuilderObserver : nsISupports */ void onSelectionChanged(); - /** - * APIs for inline editing. isEditable is called to ask the view if the - * cell contents are editable. A value of true will result in the - * tree popping up a text field when the user tries to inline edit - * the cell. - */ - boolean isEditable(in long row, in wstring colID); - - /** - * onSetCellText is called when the contents of the cell have been edited by the user. - */ - void onSetCellText(in long row, in wstring colID, in wstring value); - /** * A command API that can be used to invoke commands on the selection. * The tree will automatically invoke this method when certain keys diff --git a/mozilla/content/xul/templates/src/nsXULTreeBuilder.cpp b/mozilla/content/xul/templates/src/nsXULTreeBuilder.cpp index b990f55a856..3cf228bb4df 100644 --- a/mozilla/content/xul/templates/src/nsXULTreeBuilder.cpp +++ b/mozilla/content/xul/templates/src/nsXULTreeBuilder.cpp @@ -47,6 +47,7 @@ #include "nsIBoxObject.h" #include "nsITreeBoxObject.h" #include "nsITreeSelection.h" +#include "nsITreeColumns.h" #include "nsITreeView.h" #include "nsTreeUtils.h" #include "nsIServiceManager.h" @@ -153,7 +154,7 @@ protected: * the appropriate in the rule's . */ nsresult - GetTemplateActionCellFor(PRInt32 aRow, const PRUnichar* aColID, nsIContent** aResult); + GetTemplateActionCellFor(PRInt32 aRow, nsITreeColumn* aCol, nsIContent** aResult); /** * Return the resource corresponding to a row in the tree. The @@ -453,34 +454,7 @@ nsXULTreeBuilder::Sort(nsIDOMElement* aElement) if (mBoxObject) mBoxObject->Invalidate(); - header->SetAttr(kNameSpaceID_None, nsXULAtoms::sortDirection, dir, PR_TRUE); - header->SetAttr(kNameSpaceID_None, nsXULAtoms::sortActive, NS_LITERAL_STRING("true"), PR_TRUE); - - // Unset sort attribute(s) on the other columns - nsIContent* parentContent = header->GetParent(); - if (parentContent) { - nsINodeInfo *ni = parentContent->GetNodeInfo(); - - if (ni && ni->Equals(nsXULAtoms::treecols, kNameSpaceID_XUL)) { - PRUint32 numChildren = parentContent->GetChildCount(); - for (PRUint32 i = 0; i < numChildren; ++i) { - nsIContent *childContent = parentContent->GetChildAt(i); - - if (childContent) { - ni = childContent->GetNodeInfo(); - - if (ni && - ni->Equals(nsXULAtoms::treecol, kNameSpaceID_XUL) && - childContent != header) { - childContent->UnsetAttr(kNameSpaceID_None, - nsXULAtoms::sortDirection, PR_TRUE); - childContent->UnsetAttr(kNameSpaceID_None, - nsXULAtoms::sortActive, PR_TRUE); - } - } - } - } - } + nsTreeUtils::UpdateSortIndicators(header, dir); return NS_OK; } @@ -536,14 +510,14 @@ nsXULTreeBuilder::GetRowProperties(PRInt32 aIndex, nsISupportsArray* aProperties } NS_IMETHODIMP -nsXULTreeBuilder::GetCellProperties(PRInt32 aRow, const PRUnichar* aColID, nsISupportsArray* aProperties) +nsXULTreeBuilder::GetCellProperties(PRInt32 aRow, nsITreeColumn* aCol, nsISupportsArray* aProperties) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row"); if (aRow < 0 || aRow >= mRows.Count()) return NS_ERROR_INVALID_ARG; nsCOMPtr cell; - GetTemplateActionCellFor(aRow, aColID, getter_AddRefs(cell)); + GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell)); if (cell) { nsAutoString raw; cell->GetAttr(kNameSpaceID_None, nsXULAtoms::properties, raw); @@ -560,9 +534,8 @@ nsXULTreeBuilder::GetCellProperties(PRInt32 aRow, const PRUnichar* aColID, nsISu } NS_IMETHODIMP -nsXULTreeBuilder::GetColumnProperties(const PRUnichar* aColID, - nsIDOMElement* aColElt, - nsISupportsArray* aProperties) +nsXULTreeBuilder::GetColumnProperties(nsITreeColumn* aCol, + nsISupportsArray* aProperties) { // XXX sortactive fu return NS_OK; @@ -707,7 +680,7 @@ nsXULTreeBuilder::GetLevel(PRInt32 aRowIndex, PRInt32* aResult) } NS_IMETHODIMP -nsXULTreeBuilder::GetImageSrc(PRInt32 aRow, const PRUnichar* aColID, nsAString& aResult) +nsXULTreeBuilder::GetImageSrc(PRInt32 aRow, nsITreeColumn* aCol, nsAString& aResult) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index"); if (aRow < 0 || aRow >= mRows.Count()) @@ -715,7 +688,7 @@ nsXULTreeBuilder::GetImageSrc(PRInt32 aRow, const PRUnichar* aColID, nsAString& // Find the that corresponds to the column we want. nsCOMPtr cell; - GetTemplateActionCellFor(aRow, aColID, getter_AddRefs(cell)); + GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell)); if (cell) { nsAutoString raw; cell->GetAttr(kNameSpaceID_None, nsHTMLAtoms::src, raw); @@ -730,17 +703,17 @@ nsXULTreeBuilder::GetImageSrc(PRInt32 aRow, const PRUnichar* aColID, nsAString& NS_IMETHODIMP -nsXULTreeBuilder::GetProgressMode(PRInt32 aRow, const PRUnichar* aColID, PRInt32* aResult) +nsXULTreeBuilder::GetProgressMode(PRInt32 aRow, nsITreeColumn* aCol, PRInt32* aResult) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index"); if (aRow < 0 || aRow >= mRows.Count()) return NS_ERROR_INVALID_ARG; - *aResult = nsITreeView::progressNone; + *aResult = nsITreeView::PROGRESS_NONE; // Find the that corresponds to the column we want. nsCOMPtr cell; - GetTemplateActionCellFor(aRow, aColID, getter_AddRefs(cell)); + GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell)); if (cell) { nsAutoString raw; cell->GetAttr(kNameSpaceID_None, nsXULAtoms::mode, raw); @@ -749,16 +722,16 @@ nsXULTreeBuilder::GetProgressMode(PRInt32 aRow, const PRUnichar* aColID, PRInt32 SubstituteText(*(mRows[aRow]->mMatch), raw, mode); if (mode.Equals(NS_LITERAL_STRING("normal"))) - *aResult = nsITreeView::progressNormal; + *aResult = nsITreeView::PROGRESS_NORMAL; else if (mode.Equals(NS_LITERAL_STRING("undetermined"))) - *aResult = nsITreeView::progressUndetermined; + *aResult = nsITreeView::PROGRESS_UNDETERMINED; } return NS_OK; } NS_IMETHODIMP -nsXULTreeBuilder::GetCellValue(PRInt32 aRow, const PRUnichar* aColID, nsAString& aResult) +nsXULTreeBuilder::GetCellValue(PRInt32 aRow, nsITreeColumn* aCol, nsAString& aResult) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index"); if (aRow < 0 || aRow >= mRows.Count()) @@ -766,7 +739,7 @@ nsXULTreeBuilder::GetCellValue(PRInt32 aRow, const PRUnichar* aColID, nsAString& // Find the that corresponds to the column we want. nsCOMPtr cell; - GetTemplateActionCellFor(aRow, aColID, getter_AddRefs(cell)); + GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell)); if (cell) { nsAutoString raw; cell->GetAttr(kNameSpaceID_None, nsXULAtoms::value, raw); @@ -780,7 +753,7 @@ nsXULTreeBuilder::GetCellValue(PRInt32 aRow, const PRUnichar* aColID, nsAString& } NS_IMETHODIMP -nsXULTreeBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, nsAString& aResult) +nsXULTreeBuilder::GetCellText(PRInt32 aRow, nsITreeColumn* aCol, nsAString& aResult) { NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index"); if (aRow < 0 || aRow >= mRows.Count()) @@ -788,7 +761,7 @@ nsXULTreeBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, nsAString& // Find the that corresponds to the column we want. nsCOMPtr cell; - GetTemplateActionCellFor(aRow, aColID, getter_AddRefs(cell)); + GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell)); if (cell) { nsAutoString raw; cell->GetAttr(kNameSpaceID_None, nsXULAtoms::label, raw); @@ -917,26 +890,26 @@ nsXULTreeBuilder::ToggleOpenState(PRInt32 aIndex) } NS_IMETHODIMP -nsXULTreeBuilder::CycleHeader(const PRUnichar* aColID, nsIDOMElement* aElement) +nsXULTreeBuilder::CycleHeader(nsITreeColumn* aCol) { - nsresult rv; - + nsCOMPtr element; + aCol->GetElement(getter_AddRefs(element)); + if (mObservers) { + nsAutoString id; + aCol->GetId(id); + PRUint32 count; mObservers->Count(&count); for (PRUint32 i = 0; i < count; ++i) { nsCOMPtr observer; mObservers->QueryElementAt(i, NS_GET_IID(nsIXULTreeBuilderObserver), getter_AddRefs(observer)); if (observer) - observer->OnCycleHeader(aColID, aElement); + observer->OnCycleHeader(id.get(), element); } } - rv = Sort(aElement); - if (NS_FAILED(rv)) - return rv; - - return NS_OK; + return Sort(element); } NS_IMETHODIMP @@ -957,16 +930,19 @@ nsXULTreeBuilder::SelectionChanged() } NS_IMETHODIMP -nsXULTreeBuilder::CycleCell(PRInt32 row, const PRUnichar* colID) +nsXULTreeBuilder::CycleCell(PRInt32 row, nsITreeColumn* col) { if (mObservers) { + nsAutoString id; + col->GetId(id); + PRUint32 count; mObservers->Count(&count); for (PRUint32 i = 0; i < count; ++i) { nsCOMPtr observer; mObservers->QueryElementAt(i, NS_GET_IID(nsIXULTreeBuilderObserver), getter_AddRefs(observer)); if (observer) - observer->OnCycleCell(row, colID); + observer->OnCycleCell(row, id.get()); } } @@ -974,46 +950,40 @@ nsXULTreeBuilder::CycleCell(PRInt32 row, const PRUnichar* colID) } NS_IMETHODIMP -nsXULTreeBuilder::IsEditable(PRInt32 row, const PRUnichar* colID, PRBool* _retval) +nsXULTreeBuilder::IsEditable(PRInt32 aRow, nsITreeColumn* aCol, PRBool* _retval) { - *_retval = PR_FALSE; - if (mObservers) { - PRUint32 count; - mObservers->Count(&count); - for (PRUint32 i = 0; i < count; ++i) { - nsCOMPtr observer; - mObservers->QueryElementAt(i, NS_GET_IID(nsIXULTreeBuilderObserver), getter_AddRefs(observer)); - if (observer) { - observer->IsEditable(row, colID, _retval); - if (*_retval) - // No need to keep asking, show a textfield as at least one client will handle it. - break; - } - } + NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad index"); + if (aRow < 0 || aRow >= mRows.Count()) + return NS_ERROR_INVALID_ARG; + + *_retval = PR_TRUE; + + // Find the that corresponds to the column we want. + nsCOMPtr cell; + GetTemplateActionCellFor(aRow, aCol, getter_AddRefs(cell)); + if (cell) { + nsAutoString raw; + cell->GetAttr(kNameSpaceID_None, nsXULAtoms::editable, raw); + + nsAutoString editable; + SubstituteText(*(mRows[aRow]->mMatch), raw, editable); + + if (editable.Equals(NS_LITERAL_STRING("false"))) + *_retval = PR_FALSE; } return NS_OK; } NS_IMETHODIMP -nsXULTreeBuilder::SetCellText(PRInt32 row, const PRUnichar* colID, const PRUnichar* value) +nsXULTreeBuilder::SetCellValue(PRInt32 row, nsITreeColumn* col, const nsAString& value) { - if (mObservers) { - PRUint32 count; - mObservers->Count(&count); - for (PRUint32 i = 0; i < count; ++i) { - nsCOMPtr observer; - mObservers->QueryElementAt(i, NS_GET_IID(nsIXULTreeBuilderObserver), getter_AddRefs(observer)); - if (observer) { - // If the current observer supports a name change operation, go ahead and invoke it. - PRBool isEditable = PR_FALSE; - observer->IsEditable(row, colID, &isEditable); - if (isEditable) - observer->OnSetCellText(row, colID, value); - } - } - } + return NS_OK; +} +NS_IMETHODIMP +nsXULTreeBuilder::SetCellText(PRInt32 row, nsITreeColumn* col, const nsAString& value) +{ return NS_OK; } @@ -1052,16 +1022,19 @@ nsXULTreeBuilder::PerformActionOnRow(const PRUnichar* action, PRInt32 row) } NS_IMETHODIMP -nsXULTreeBuilder::PerformActionOnCell(const PRUnichar* action, PRInt32 row, const PRUnichar* colID) +nsXULTreeBuilder::PerformActionOnCell(const PRUnichar* action, PRInt32 row, nsITreeColumn* col) { if (mObservers) { + nsAutoString id; + col->GetId(id); + PRUint32 count; mObservers->Count(&count); for (PRUint32 i = 0; i < count; ++i) { nsCOMPtr observer; mObservers->QueryElementAt(i, NS_GET_IID(nsIXULTreeBuilderObserver), getter_AddRefs(observer)); if (observer) - observer->OnPerformActionOnCell(action, row, colID); + observer->OnPerformActionOnCell(action, row, id.get()); } } @@ -1113,10 +1086,18 @@ nsXULTreeBuilder::ReplaceMatch(nsIRDFResource* aMember, PRInt32 row = iter.GetRowIndex(); PRInt32 delta = mRows.GetSubtreeSizeFor(iter); if (mRows.RemoveRowAt(iter) == 0 && iter.GetRowIndex() >= 0) { - // In this case iter now points to its parent - // Invalidate the row's cached fill state - iter->mContainerFill = nsTreeRows::eContainerFill_Unknown; - mBoxObject->InvalidatePrimaryCell(iter.GetRowIndex()); + // In this case iter now points to its parent + // Invalidate the row's cached fill state + iter->mContainerFill = nsTreeRows::eContainerFill_Unknown; + + nsCOMPtr cols; + mBoxObject->GetColumns(getter_AddRefs(cols)); + if (cols) { + nsCOMPtr primaryCol; + cols->GetPrimaryColumn(getter_AddRefs(primaryCol)); + if (primaryCol) + mBoxObject->InvalidateCell(iter.GetRowIndex(), primaryCol); + } } // Notify the box object @@ -1485,7 +1466,7 @@ nsXULTreeBuilder::GetTemplateActionRowFor(PRInt32 aRow, nsIContent** aResult) nsresult nsXULTreeBuilder::GetTemplateActionCellFor(PRInt32 aRow, - const PRUnichar* aColID, + nsITreeColumn* aCol, nsIContent** aResult) { *aResult = nsnull; @@ -1493,9 +1474,10 @@ nsXULTreeBuilder::GetTemplateActionCellFor(PRInt32 aRow, nsCOMPtr row; GetTemplateActionRowFor(aRow, getter_AddRefs(row)); if (row) { - PRInt32 colIndex = -1; - if (mBoxObject) - mBoxObject->GetColumnIndex(aColID, &colIndex); + const PRUnichar* colID; + PRInt32 colIndex; + aCol->GetIdConst(&colID); + aCol->GetIndex(&colIndex); PRUint32 count = row->GetChildCount(); PRUint32 j = 0; @@ -1507,7 +1489,7 @@ nsXULTreeBuilder::GetTemplateActionCellFor(PRInt32 aRow, if (ni && ni->Equals(nsXULAtoms::treecell, kNameSpaceID_XUL)) { nsAutoString ref; child->GetAttr(kNameSpaceID_None, nsXULAtoms::ref, ref); - if (!ref.IsEmpty() && ref.Equals(aColID)) { + if (!ref.IsEmpty() && ref.Equals(colID)) { *aResult = child; break; } @@ -2034,9 +2016,9 @@ nsXULTreeBuilder::SortSubtree(nsTreeRows::Subtree* aSubtree) } -/* boolean canDropOn (in long index); */ +/* boolean canDrop (in long index, in long orientation); */ NS_IMETHODIMP -nsXULTreeBuilder::CanDropOn(PRInt32 index, PRBool *_retval) +nsXULTreeBuilder::CanDrop(PRInt32 index, PRInt32 orientation, PRBool *_retval) { *_retval = PR_FALSE; if (mObservers) { @@ -2046,29 +2028,7 @@ nsXULTreeBuilder::CanDropOn(PRInt32 index, PRBool *_retval) nsCOMPtr observer; mObservers->QueryElementAt(i, NS_GET_IID(nsIXULTreeBuilderObserver), getter_AddRefs(observer)); if (observer) { - observer->CanDropOn(index, _retval); - if (*_retval) - break; - } - } - } - - return NS_OK; -} - -/* boolean canDropBeforeAfter (in long index, in boolean before); */ -NS_IMETHODIMP -nsXULTreeBuilder::CanDropBeforeAfter(PRInt32 index, PRBool before, PRBool *_retval) -{ - *_retval = PR_FALSE; - if (mObservers) { - PRUint32 count; - mObservers->Count(&count); - for (PRUint32 i = 0; i < count; ++i) { - nsCOMPtr observer; - mObservers->QueryElementAt(i, NS_GET_IID(nsIXULTreeBuilderObserver), getter_AddRefs(observer)); - if (observer) { - observer->CanDropBeforeAfter(index, before, _retval); + observer->CanDrop(index, orientation, _retval); if (*_retval) break; } @@ -2089,10 +2049,7 @@ nsXULTreeBuilder::Drop(PRInt32 row, PRInt32 orient) mObservers->QueryElementAt(i, NS_GET_IID(nsIXULTreeBuilderObserver), getter_AddRefs(observer)); if (observer) { PRBool canDrop = PR_FALSE; - if (orient == nsITreeView::inDropOn) - observer->CanDropOn(row, &canDrop); - else - observer->CanDropBeforeAfter(row, orient == nsITreeView::inDropBefore, &canDrop); + observer->CanDrop(row, orient, &canDrop); if (canDrop) observer->OnDrop(row, orient); } diff --git a/mozilla/dom/public/idl/xul/Makefile.in b/mozilla/dom/public/idl/xul/Makefile.in index 914f2125825..2b4ee577837 100644 --- a/mozilla/dom/public/idl/xul/Makefile.in +++ b/mozilla/dom/public/idl/xul/Makefile.in @@ -47,6 +47,7 @@ XPIDLSRCS = \ nsIDOMXULSelectCntrlItemEl.idl \ nsIDOMXULMultSelectCntrlEl.idl \ nsIDOMXULTextboxElement.idl \ + nsIDOMXULTreeElement.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/dom/public/idl/xul/nsIDOMXULMultSelectCntrlEl.idl b/mozilla/dom/public/idl/xul/nsIDOMXULMultSelectCntrlEl.idl index 0094afb5105..863171a819c 100644 --- a/mozilla/dom/public/idl/xul/nsIDOMXULMultSelectCntrlEl.idl +++ b/mozilla/dom/public/idl/xul/nsIDOMXULMultSelectCntrlEl.idl @@ -46,7 +46,8 @@ interface nsIDOMXULMultiSelectControlElement : nsIDOMXULSelectControlElement attribute DOMString selType; attribute nsIDOMXULSelectControlItemElement currentItem; - + attribute long currentIndex; + readonly attribute nsIDOMNodeList selectedItems; void addItemToSelection(in nsIDOMXULSelectControlItemElement item); diff --git a/mozilla/dom/public/idl/xul/nsIDOMXULTreeElement.idl b/mozilla/dom/public/idl/xul/nsIDOMXULTreeElement.idl new file mode 100644 index 00000000000..395b67c65c7 --- /dev/null +++ b/mozilla/dom/public/idl/xul/nsIDOMXULTreeElement.idl @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Jan Varga + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIDOMXULElement.idl" +#include "nsIDOMElement.idl" + +interface nsITreeColumns; +interface nsITreeView; +interface nsIDOMXULTextBoxElement; + +/** + * @status UNDER_DEVELOPMENT + */ + +[scriptable, uuid(1f8111b2-d44d-4d11-845a-a70ae06b7d04)] +interface nsIDOMXULTreeElement : nsIDOMXULElement +{ + + readonly attribute nsITreeColumns columns; + + attribute nsITreeView view; + + readonly attribute nsIDOMElement body; + + attribute boolean editable; + + // For editable trees only. + readonly attribute nsIDOMXULTextBoxElement inputField; + +}; diff --git a/mozilla/dom/public/nsIDOMClassInfo.h b/mozilla/dom/public/nsIDOMClassInfo.h index 2cd3b03cce3..a4d0d0bfeaf 100644 --- a/mozilla/dom/public/nsIDOMClassInfo.h +++ b/mozilla/dom/public/nsIDOMClassInfo.h @@ -230,6 +230,11 @@ enum nsDOMClassInfoID { // NameList object used by the DOM eDOMClassInfo_NameList_id, +#ifdef MOZ_XUL + eDOMClassInfo_TreeColumn_id, + eDOMClassInfo_TreeColumns_id, +#endif + #ifdef MOZ_SVG // The SVG document eDOMClassInfo_SVGDocument_id, diff --git a/mozilla/dom/src/base/nsDOMClassInfo.cpp b/mozilla/dom/src/base/nsDOMClassInfo.cpp index 9000a795e49..090804b84d5 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.cpp +++ b/mozilla/dom/src/base/nsDOMClassInfo.cpp @@ -289,6 +289,7 @@ #include "nsITreeContentView.h" #include "nsITreeView.h" #include "nsIXULTemplateBuilder.h" +#include "nsITreeColumns.h" #endif #include "nsIDOMXPathEvaluator.h" @@ -764,6 +765,14 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(NameList, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) +#ifdef MOZ_XUL + NS_DEFINE_CLASSINFO_DATA(TreeColumn, nsDOMGenericSH, + DEFAULT_SCRIPTABLE_FLAGS) + + NS_DEFINE_CLASSINFO_DATA(TreeColumns, nsTreeColumnsSH, + ARRAY_SCRIPTABLE_FLAGS) +#endif + #ifdef MOZ_SVG // SVG document NS_DEFINE_CLASSINFO_DATA(SVGDocument, nsDocumentSH, @@ -2086,6 +2095,16 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMNameList) DOM_CLASSINFO_MAP_END +#ifdef MOZ_XUL + DOM_CLASSINFO_MAP_BEGIN(TreeColumn, nsITreeColumn) + DOM_CLASSINFO_MAP_ENTRY(nsITreeColumn) + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN(TreeColumns, nsITreeColumns) + DOM_CLASSINFO_MAP_ENTRY(nsITreeColumns) + DOM_CLASSINFO_MAP_END +#endif + #ifdef MOZ_SVG #define DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES \ DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGElement) \ @@ -6650,6 +6669,42 @@ nsCSSRuleListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex, } +#ifdef MOZ_XUL +// TreeColumns helper + +nsresult +nsTreeColumnsSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex, + nsISupports **aResult) +{ + nsCOMPtr columns(do_QueryInterface(aNative)); + NS_ENSURE_TRUE(columns, NS_ERROR_UNEXPECTED); + + nsITreeColumn* column = nsnull; // Weak, transfer the ownership over to aResult + nsresult rv = columns->GetColumnAt(aIndex, &column); + + *aResult = column; + + return rv; +} + +nsresult +nsTreeColumnsSH::GetNamedItem(nsISupports *aNative, + const nsAString& aName, + nsISupports **aResult) +{ + nsCOMPtr columns(do_QueryInterface(aNative)); + NS_ENSURE_TRUE(columns, NS_ERROR_UNEXPECTED); + + nsITreeColumn* column = nsnull; // Weak, transfer the ownership over to aResult + nsresult rv = columns->GetNamedColumn(aName, &column); + + *aResult = column; + + return rv; +} +#endif + + // nsIDOMEventListener::HandleEvent() 'this' converter helper NS_INTERFACE_MAP_BEGIN(nsEventListenerThisTranslator) diff --git a/mozilla/dom/src/base/nsDOMClassInfo.h b/mozilla/dom/src/base/nsDOMClassInfo.h index 15c3ad919b3..c3e6de3be5b 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.h +++ b/mozilla/dom/src/base/nsDOMClassInfo.h @@ -1193,6 +1193,38 @@ public: }; +#ifdef MOZ_XUL +// TreeColumns helper + +class nsTreeColumnsSH : public nsNamedArraySH +{ +protected: + nsTreeColumnsSH(nsDOMClassInfoData* aData) : nsNamedArraySH(aData) + { + } + + virtual ~nsTreeColumnsSH() + { + } + + // Override nsArraySH::GetItemAt() since our list isn't a + // nsIDOMNodeList + virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex, + nsISupports **aResult); + + // Override nsNamedArraySH::GetNamedItem() + virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName, + nsISupports **aResult); + +public: + static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) + { + return new nsTreeColumnsSH(aData); + } +}; +#endif + + // Event handler 'this' translator class, this is called by XPConnect // when a "function interface" (nsIDOMEventListener) is called, this // class extracts 'this' fomr the first argument to the called diff --git a/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js b/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js index 5569ae36133..6e691d3f5f1 100644 --- a/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js +++ b/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js @@ -75,7 +75,7 @@ function onChangeCSSAttribute() function ClearCSSInputWidgets() { - gDialog.AddCSSAttributeTree.treeBoxObject.selection.clearSelection(); + gDialog.AddCSSAttributeTree.view.selection.clearSelection(); gDialog.AddCSSAttributeNameInput.value =""; gDialog.AddCSSAttributeValueInput.value = ""; SetTextboxFocus(gDialog.AddCSSAttributeNameInput); @@ -87,7 +87,7 @@ function onSelectCSSTreeItem() return; var tree = gDialog.AddCSSAttributeTree; - if (tree && tree.treeBoxObject.selection.count) + if (tree && tree.view.selection.count) { gDialog.AddCSSAttributeNameInput.value = GetTreeItemAttributeStr(getSelectedItem(tree)); gDialog.AddCSSAttributeValueInput.value = GetTreeItemValueStr(getSelectedItem(tree)); @@ -148,7 +148,7 @@ function RemoveCSSAttribute() var treechildren = gDialog.AddCSSAttributeTree.lastChild; // We only allow 1 selected item - if (gDialog.AddCSSAttributeTree.treeBoxObject.selection.count) + if (gDialog.AddCSSAttributeTree.view.selection.count) { var item = getSelectedItem(gDialog.AddCSSAttributeTree); diff --git a/mozilla/editor/ui/dialogs/content/EdAEHTMLAttributes.js b/mozilla/editor/ui/dialogs/content/EdAEHTMLAttributes.js index 0cebafea8c3..5c8a50c7f10 100644 --- a/mozilla/editor/ui/dialogs/content/EdAEHTMLAttributes.js +++ b/mozilla/editor/ui/dialogs/content/EdAEHTMLAttributes.js @@ -151,7 +151,7 @@ function onChangeHTMLAttribute() function ClearHTMLInputWidgets() { - gDialog.AddHTMLAttributeTree.treeBoxObject.selection.clearSelection(); + gDialog.AddHTMLAttributeTree.view.selection.clearSelection(); gDialog.AddHTMLAttributeNameInput.value =""; gDialog.AddHTMLAttributeValueInput.value = ""; SetTextboxFocus(gDialog.AddHTMLAttributeNameInput); @@ -163,7 +163,7 @@ function onSelectHTMLTreeItem() return; var tree = gDialog.AddHTMLAttributeTree; - if (tree && tree.treeBoxObject.selection.count) + if (tree && tree.view.selection.count) { var inputName = TrimString(gDialog.AddHTMLAttributeNameInput.value).toLowerCase(); var selectedItem = getSelectedItem(tree); @@ -374,7 +374,7 @@ function RemoveHTMLAttribute() var treechildren = gDialog.AddHTMLAttributeTree.lastChild; // We only allow 1 selected item - if (gDialog.AddHTMLAttributeTree.treeBoxObject.selection.count) + if (gDialog.AddHTMLAttributeTree.view.selection.count) { var item = getSelectedItem(gDialog.AddHTMLAttributeTree); var attr = GetTreeItemAttributeStr(item); diff --git a/mozilla/editor/ui/dialogs/content/EdAEJSEAttributes.js b/mozilla/editor/ui/dialogs/content/EdAEJSEAttributes.js index ffa01a32794..4a31723c352 100644 --- a/mozilla/editor/ui/dialogs/content/EdAEJSEAttributes.js +++ b/mozilla/editor/ui/dialogs/content/EdAEJSEAttributes.js @@ -131,7 +131,7 @@ function onSelectJSEAttribute() function onSelectJSETreeItem() { var tree = gDialog.AddJSEAttributeTree; - if (tree && tree.treeBoxObject.selection.count) + if (tree && tree.view.selection.count) { // Select attribute name in list gDialog.AddJSEAttributeNameList.value = GetTreeItemAttributeStr(getSelectedItem(tree)); @@ -200,7 +200,7 @@ function RemoveJSEAttribute() var newIndex = gDialog.AddJSEAttributeTree.selectedIndex; // We only allow 1 selected item - if (gDialog.AddJSEAttributeTree.treeBoxObject.selection.count) + if (gDialog.AddJSEAttributeTree.view.selection.count) { var item = getSelectedItem(gDialog.AddJSEAttributeTree); diff --git a/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.js b/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.js index 3a5838a5aac..e250b3e659f 100644 --- a/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.js +++ b/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.js @@ -251,7 +251,7 @@ function GetAndSelectExistingAttributeValue( attName, treeChildrenId ) // Attribute doesn't exist in tree, so remove selection gDoOnSelectTree = false; try { - treeChildren.parentNode.treeBoxObject.selection.clearSelection(); + treeChildren.parentNode.view.selection.clearSelection(); } catch (e) {} gDoOnSelectTree = true; @@ -348,12 +348,12 @@ function doHelpButton() function selectTreeItem(treeChildren, item) { var index = treeChildren.parentNode.contentView.getIndexOfItem(item); - treeChildren.parentNode.treeBoxObject.selection.select(index); + treeChildren.parentNode.view.selection.select(index); } function getSelectedItem(tree) { - if (tree.treeBoxObject.selection.count == 1) + if (tree.view.selection.count == 1) return tree.contentView.getItemAtIndex(tree.currentIndex); else return null; diff --git a/mozilla/editor/ui/dialogs/content/EdSelectProps.js b/mozilla/editor/ui/dialogs/content/EdSelectProps.js index e86d619e518..cf8e688e5d0 100644 --- a/mozilla/editor/ui/dialogs/content/EdSelectProps.js +++ b/mozilla/editor/ui/dialogs/content/EdSelectProps.js @@ -109,9 +109,9 @@ optionObject.prototype.container = false; optionObject.prototype.getCellText = function getCellText(column) { - if (column == "SelectSelCol") + if (column.id == "SelectSelCol") return ""; - if (column == "SelectValCol" && this.element.hasAttribute("value")) + if (column.id == "SelectValCol" && this.element.hasAttribute("value")) return this.element.getAttribute("value"); return this.element.text; } @@ -132,12 +132,14 @@ optionObject.prototype.cycleCell = function cycleCell(index) else if (selectedOption) { selectedOption.removeAttribute("selected"); - treeBoxObject.invalidateColumn("SelectSelCol"); + var column = treeBoxObject.columns["SelectSelCol"]; + treeBoxObject.invalidateColumn(column); selectedOption = null; } this.element.setAttribute("selected", ""); selectedOption = this.element; - treeBoxObject.invalidateCell(index, "SelectSelCol"); + var column = treeBoxObject.columns["SelectSelCol"]; + treeBoxObject.invalidateCell(index, column); } if (currentItem == this) // Also update the deck @@ -281,7 +283,7 @@ optgroupObject.prototype.container = true; optgroupObject.prototype.getCellText = function getCellText(column) { - return column == "SelectTextCol" ? this.element.label : ""; + return column.id == "SelectTextCol" ? this.element.label : ""; } optgroupObject.prototype.cycleCell = function cycleCell(index) @@ -357,7 +359,8 @@ optgroupObject.prototype.appendOption = function appendOption(child, parent) { var index = gDialog.nextChild(parent); // XXX need to repaint the lines, tree won't do this - treeBoxObject.invalidatePrimaryCell(index - 1); + var primaryCol = treeBoxObject.getPrimaryColumn(); + treeBoxObject.invalidateCell(index - 1, primaryCol); // insert the wrapped object as the last child itemArray.splice(index, 0, new optionObject(child, 2)); treeBoxObject.rowCountChanged(index, 1); @@ -430,7 +433,7 @@ function Startup() container: true, getCellText: function getCellText(column) { - return column == "SelectTextCol" ? this.element.getAttribute("name") : ""; + return column.id == "SelectTextCol" ? this.element.getAttribute("name") : ""; }, cycleCell: function cycleCell(index) {}, onFocus: function onFocus() @@ -535,10 +538,10 @@ function Startup() // could have used a wrapper for this getCellProperties: function getCellProperties(index, column, prop) { - if (column == "SelectSelCol" && !itemArray[index].container) + if (column.id == "SelectSelCol" && !itemArray[index].container) prop.AppendElement(checkedAtoms[itemArray[index].element.hasAttribute("selected")]); }, - getColumnProperties: function getColumnProperties(column, elem, prop) { }, + getColumnProperties: function getColumnProperties(column, prop) { }, // get info from wrapper isContainer: function isContainer(index) { return itemArray[index].container; }, isContainerOpen: function isContainerOpen(index) { return true; }, @@ -546,8 +549,7 @@ function Startup() isSeparator: function isSeparator(index) { return false; }, isSorted: function isSorted() { return false; }, // d&d not implemented yet! - canDropOn: function canDropOn(index) { return false; }, - canDropBeforeAfter: function canDropBeforeAfter(index, before) { return index >= before; }, + canDrop: function canDrop(index, orientation) { return false; }, drop: function drop(index, orientation) { alert('drop:' + index + ',' + orientation); }, // same as the global helper getParentIndex: getParentIndex, @@ -572,7 +574,7 @@ function Startup() getCellText: function getCellText(index, column) { return itemArray[index].getCellText(column); }, setTree: function setTree(tree) { this.tree = tree; }, toggleOpenState: function toggleOpenState(index) { }, - cycleHeader: function cycleHeader(col, elem) { }, + cycleHeader: function cycleHeader(col) { }, selectionChanged: function selectionChanged() { // Save current values and update buttons and deck @@ -713,22 +715,26 @@ function onNameInput() gDialog.accept.disabled = disabled; gDialog.element.setAttribute("name", gDialog.selectName.value); // repaint the tree - treeBoxObject.invalidatePrimaryCell(treeSelection.currentIndex); + var primaryCol = treeBoxObject.getPrimaryColumn(); + treeBoxObject.invalidateCell(treeSelection.currentIndex, primaryCol); } function onLabelInput() { currentItem.element.setAttribute("label", gDialog.optgroupLabel.value); // repaint the tree - treeBoxObject.invalidatePrimaryCell(treeSelection.currentIndex); + var primaryCol = treeBoxObject.getPrimaryColumn(); + treeBoxObject.invalidateCell(treeSelection.currentIndex, primaryCol); } function onTextInput() { currentItem.element.text = gDialog.optionText.value; // repaint the tree - if (hasValue) - treeBoxObject.invalidatePrimaryCell(treeSelection.currentIndex); + if (hasValue) { + var primaryCol = treeBoxObject.getPrimaryColumn(); + treeBoxObject.invalidateCell(treeSelection.currentIndex, primaryCol); + } else { gDialog.optionValue.value = gDialog.optionText.value; @@ -742,7 +748,8 @@ function onValueInput() oldValue = gDialog.optionValue.value; currentItem.element.setAttribute("value", oldValue); // repaint the tree - treeBoxObject.invalidateCell(treeSelection.currentIndex, "SelectValCol"); + var column = treeBoxObject.columns["SelectValCol"]; + treeBoxObject.invalidateCell(treeSelection.currentIndex, column); } function onHasValueClick() @@ -760,7 +767,8 @@ function onHasValueClick() currentItem.element.removeAttribute("value"); } // repaint the tree - treeBoxObject.invalidateCell(treeSelection.currentIndex, "SelectValCol"); + var column = treeBoxObject.columns["SelectValCol"]; + treeBoxObject.invalidateCell(treeSelection.currentIndex, column); } function onSelectMultipleClick() diff --git a/mozilla/editor/ui/dialogs/content/EditorSaveAsCharset.js b/mozilla/editor/ui/dialogs/content/EditorSaveAsCharset.js index 3920deffa0c..3e827edd077 100644 --- a/mozilla/editor/ui/dialogs/content/EditorSaveAsCharset.js +++ b/mozilla/editor/ui/dialogs/content/EditorSaveAsCharset.js @@ -89,11 +89,11 @@ function InitDialog() gDialog.TitleInput.value = GetDocumentTitle(); var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); - var index = gDialog.charsetTree.builderView.getIndexOfResource(RDF.GetResource(gCharset)); + var tree = gDialog.charsetTree; + var index = tree.view.getIndexOfResource(RDF.GetResource(gCharset)); if (index >= 0) { - var treeBox = gDialog.charsetTree.treeBoxObject; - treeBox.selection.select(index); - treeBox.ensureRowIsVisible(index); + tree.view.selection.select(index); + tree.treeBoxObject.ensureRowIsVisible(index); } } diff --git a/mozilla/extensions/cview/resources/content/cview-handlers.js b/mozilla/extensions/cview/resources/content/cview-handlers.js index 2563add2394..98705522146 100644 --- a/mozilla/extensions/cview/resources/content/cview-handlers.js +++ b/mozilla/extensions/cview/resources/content/cview-handlers.js @@ -80,16 +80,16 @@ function onTreeResort (e, view) { /* resort by column */ var rowIndex = new Object(); - var colID = new Object(); + var col = new Object(); var childElt = new Object(); var obo = view.tree; - obo.getCellAt(e.clientX, e.clientY, rowIndex, colID, childElt); + obo.getCellAt(e.clientX, e.clientY, rowIndex, col, childElt); if (rowIndex.value == -1) return; var prop; - switch (colID.value.substr(4)) + switch (col.value.id.substr(4)) { case "name": prop = "sortName"; @@ -107,7 +107,7 @@ function onTreeResort (e, view) function onComponentSelect (e) { - var index = cview.componentView.tree.selection.currentIndex; + var index = cview.componentView.selection.currentIndex; var row = cview.componentView.childData.locateChildByVisualRow (index); if (!row) return; @@ -118,7 +118,7 @@ function onComponentSelect (e) function onInterfaceSelect (e) { - var index = cview.interfaceView.tree.selection.currentIndex; + var index = cview.interfaceView.selection.currentIndex; var row = cview.interfaceView.childData.locateChildByVisualRow (index); if (!row) return; @@ -129,7 +129,7 @@ function onInterfaceSelect (e) function onLXRIFCLookup (e, type) { - var index = cview.interfaceView.tree.selection.currentIndex; + var index = cview.interfaceView.selection.currentIndex; var row = cview.interfaceView.childData.locateChildByVisualRow (index); if (!row) return; diff --git a/mozilla/extensions/cview/resources/content/cview-trees.js b/mozilla/extensions/cview/resources/content/cview-trees.js index 9737f89a1b0..d069b5f301d 100644 --- a/mozilla/extensions/cview/resources/content/cview-trees.js +++ b/mozilla/extensions/cview/resources/content/cview-trees.js @@ -109,9 +109,9 @@ var componentShare = new Object(); cview.componentView = new TreeOView(componentShare); cview.componentView.getCellProperties = -function cmp_getrow (index, colID, properties) +function cmp_getrow (index, col, properties) { - if (colID != "cmp-name") + if (col.id != "cmp-name") return; var row = this.childData.locateChildByVisualRow(index); diff --git a/mozilla/extensions/cview/resources/content/tree-utils.js b/mozilla/extensions/cview/resources/content/tree-utils.js index 8b58b06dae0..1dee680ddb1 100644 --- a/mozilla/extensions/cview/resources/content/tree-utils.js +++ b/mozilla/extensions/cview/resources/content/tree-utils.js @@ -143,12 +143,14 @@ function bov_scrollto (line, align) BasicOView.prototype.rowCount = 0; +BasicOView.prototype.selection = null; + BasicOView.prototype.getCellProperties = -function bov_cellprops (row, colID, properties) +function bov_cellprops (row, col, properties) {} BasicOView.prototype.getColumnProperties = -function bov_colprops (colID, elem, properties) +function bov_colprops (col, properties) {} BasicOView.prototype.getRowProperties = @@ -185,14 +187,8 @@ function bov_issorted (index) return false; } -BasicOView.prototype.canDropOn = -function bov_dropon (index) -{ - return false; -} - -BasicOView.prototype.canDropBeforeAfter = -function bov_dropba (index, before) +BasicOView.prototype.canDrop = +function bov_drop (index, orientation) { return false; } @@ -222,32 +218,32 @@ function bov_getlvl (index) } BasicOView.prototype.getImageSrc = -function bov_getimgsrc (row, colID) +function bov_getimgsrc (row, col) { } BasicOView.prototype.getProgressMode = -function bov_getprgmode (row, colID) +function bov_getprgmode (row, col) { } BasicOView.prototype.getCellValue = -function bov_getcellval (row, colID) +function bov_getcellval (row, col) { } BasicOView.prototype.getCellText = -function bov_getcelltxt (row, colID) +function bov_getcelltxt (row, col) { if (!this.columnNames) return ""; - var col = this.columnNames[colID]; + var colName = this.columnNames[col.id]; - if (typeof col == "undefined") + if (typeof colName == "undefined") return ""; - return this.data[row][col]; + return this.data[row][colName]; } BasicOView.prototype.setTree = @@ -262,7 +258,7 @@ function bov_toggleopen (index) } BasicOView.prototype.cycleHeader = -function bov_cyclehdr (colID, elt) +function bov_cyclehdr (col) { } @@ -272,18 +268,23 @@ function bov_selchg () } BasicOView.prototype.cycleCell = -function bov_cyclecell (row, colID) +function bov_cyclecell (row, col) { } BasicOView.prototype.isEditable = -function bov_isedit (row, colID) +function bov_isedit (row, col) { return false; } +BasicOView.prototype.setCellValue = +function bov_setct (row, col, value) +{ +} + BasicOView.prototype.setCellText = -function bov_setct (row, colID, value) +function bov_setct (row, col, value) { } @@ -1026,18 +1027,18 @@ function tov_isctr (index) TreeOView.prototype.__defineGetter__("selectedIndex", tov_getsel); function tov_getsel() { - if (this.tree.selection.getRangeCount() < 1) + if (this.tree.view.selection.getRangeCount() < 1) return -1; var min = new Object(); - this.tree.selection.getRangeAt(0, min, {}); + this.tree.view.selection.getRangeAt(0, min, {}); return min.value; } TreeOView.prototype.__defineSetter__("selectedIndex", tov_setsel); function tov_setsel(i) { - this.tree.selection.timedSelect (i, 500); + this.tree.view.selection.timedSelect (i, 500); return i; } @@ -1124,37 +1125,37 @@ function tov_getlvl (index) } TreeOView.prototype.getImageSrc = -function tov_getimgsrc (index, colID) +function tov_getimgsrc (index, col) { } TreeOView.prototype.getProgressMode = -function tov_getprgmode (index, colID) +function tov_getprgmode (index, col) { } TreeOView.prototype.getCellValue = -function tov_getcellval (index, colID) +function tov_getcellval (index, col) { } TreeOView.prototype.getCellText = -function tov_getcelltxt (index, colID) +function tov_getcelltxt (index, col) { var row = this.childData.locateChildByVisualRow (index); //ASSERT(row, "bogus row " + index); if (row._colValues) - return row._colValues[colID]; + return row._colValues[col.id]; else return null; } TreeOView.prototype.getCellProperties = -function tov_cellprops (row, colID, properties) +function tov_cellprops (row, col, properties) {} TreeOView.prototype.getColumnProperties = -function tov_colprops (colID, elem, properties) +function tov_colprops (col, properties) {} TreeOView.prototype.getRowProperties = @@ -1173,21 +1174,12 @@ function tov_issorted (index) return false; } -TreeOView.prototype.canDropOn = -function tov_dropon (index) +TreeOView.prototype.canDrop = +function tov_dropon (index, orientation) { var row = this.childData.locateChildByVisualRow (index); //ASSERT(row, "bogus row " + index); - return (row && ("canDropOn" in row) && row.canDropOn()); -} - -TreeOView.prototype.canDropBeforeAfter = -function tov_dropba (index, before) -{ - var row = this.childData.locateChildByVisualRow (index); - //ASSERT(row, "bogus row " + index); - return (row && ("canDropBeforeAfter" in row) && - row.canDropBeforeAfter(before)); + return (row && ("canDrop" in row) && row.canDropOn(orientation)); } TreeOView.prototype.drop = @@ -1205,7 +1197,7 @@ function tov_seto (tree) } TreeOView.prototype.cycleHeader = -function tov_cyclehdr (colID, elt) +function tov_cyclehdr (col) { } @@ -1215,18 +1207,23 @@ function tov_selchg () } TreeOView.prototype.cycleCell = -function tov_cyclecell (row, colID) +function tov_cyclecell (row, col) { } TreeOView.prototype.isEditable = -function tov_isedit (row, colID) +function tov_isedit (row, col) { return false; } +TreeOView.prototype.setCellValue = +function tov_setct (row, col, value) +{ +} + TreeOView.prototype.setCellText = -function tov_setct (row, colID, value) +function tov_setct (row, col, value) { } diff --git a/mozilla/extensions/editor/cascades/resources/content/EdCssProps-utils.js b/mozilla/extensions/editor/cascades/resources/content/EdCssProps-utils.js index 148cba632b9..82c3554494f 100644 --- a/mozilla/extensions/editor/cascades/resources/content/EdCssProps-utils.js +++ b/mozilla/extensions/editor/cascades/resources/content/EdCssProps-utils.js @@ -40,7 +40,7 @@ // return integer function getSelectedItem(tree) { - if (tree.treeBoxObject.selection.count == 1) + if (tree.view.selection.count == 1) return tree.contentView.getItemAtIndex(tree.currentIndex); else return null; @@ -71,7 +71,7 @@ function selectTreeItem(aItem) /* then select the item */ var itemIndex = gDialog.sheetsTree.contentView.getIndexOfItem(aItem); - gDialog.sheetsTree.treeBoxObject.selection.select(itemIndex); + gDialog.sheetsTree.view.selection.select(itemIndex); /* and make sure it is visible in the clipping area of the tree */ gDialog.sheetsTree.treeBoxObject.ensureRowIsVisible(itemIndex); } @@ -162,5 +162,5 @@ function doDump(text, value) { function ClearTreeSelection(tree) { if (tree) - tree.treeBoxObject.selection.clearSelection(); + tree.view.selection.clearSelection(); } diff --git a/mozilla/extensions/help/resources/content/help.js b/mozilla/extensions/help/resources/content/help.js index c77479acbe0..19946851eb7 100644 --- a/mozilla/extensions/help/resources/content/help.js +++ b/mozilla/extensions/help/resources/content/help.js @@ -430,9 +430,10 @@ function showPanel(panelId) { function onselect_loadURI(tree, columnName) { try { - var row = tree.treeBoxObject.view.selection.currentIndex; + var row = tree.currentIndex; var properties = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); - tree.treeBoxObject.view.getCellProperties(row, columnName, properties); + var col = tree.columns[columnName]; + tree.view.getCellProperties(row, col, properties); if (!properties) return; var uri = getPropertyValue(properties, "link-"); if (uri) diff --git a/mozilla/extensions/inspector/base/src/inDOMView.cpp b/mozilla/extensions/inspector/base/src/inDOMView.cpp index b7159ccc164..3bc83e60582 100644 --- a/mozilla/extensions/inspector/base/src/inDOMView.cpp +++ b/mozilla/extensions/inspector/base/src/inDOMView.cpp @@ -56,6 +56,7 @@ #include "nsIBindingManager.h" #include "nsIDocument.h" #include "nsIServiceManager.h" +#include "nsITreeColumns.h" //////////////////////////////////////////////////////////////////////// // inDOMViewNode @@ -319,7 +320,7 @@ inDOMView::GetRowProperties(PRInt32 index, nsISupportsArray *properties) } NS_IMETHODIMP -inDOMView::GetCellProperties(PRInt32 row, const PRUnichar *colID, nsISupportsArray *properties) +inDOMView::GetCellProperties(PRInt32 row, nsITreeColumn* col, nsISupportsArray *properties) { inDOMViewNode* node = nsnull; RowToNode(row, &node); @@ -374,31 +375,31 @@ inDOMView::GetCellProperties(PRInt32 row, const PRUnichar *colID, nsISupportsArr } NS_IMETHODIMP -inDOMView::GetColumnProperties(const PRUnichar *colID, nsIDOMElement *colElt, nsISupportsArray *properties) +inDOMView::GetColumnProperties(nsITreeColumn* col, nsISupportsArray *properties) { return NS_OK; } NS_IMETHODIMP -inDOMView::GetImageSrc(PRInt32 row, const PRUnichar *colID, nsAString& _retval) +inDOMView::GetImageSrc(PRInt32 row, nsITreeColumn* col, nsAString& _retval) { return NS_OK; } NS_IMETHODIMP -inDOMView::GetProgressMode(PRInt32 row, const PRUnichar *colID, PRInt32* _retval) +inDOMView::GetProgressMode(PRInt32 row, nsITreeColumn* col, PRInt32* _retval) { return NS_OK; } NS_IMETHODIMP -inDOMView::GetCellValue(PRInt32 row, const PRUnichar *colID, nsAString& _retval) +inDOMView::GetCellValue(PRInt32 row, nsITreeColumn* col, nsAString& _retval) { return NS_OK; } NS_IMETHODIMP -inDOMView::GetCellText(PRInt32 row, const PRUnichar *colID, nsAString& _retval) +inDOMView::GetCellText(PRInt32 row, nsITreeColumn* col, nsAString& _retval) { inDOMViewNode* node = nsnull; RowToNode(row, &node); @@ -406,29 +407,30 @@ inDOMView::GetCellText(PRInt32 row, const PRUnichar *colID, nsAString& _retval) nsIDOMNode* domNode = node->node; - nsAutoString col(colID); - if (col.Equals(NS_LITERAL_STRING("colNodeName"))) + nsAutoString colID; + col->GetId(colID); + if (colID.Equals(NS_LITERAL_STRING("colNodeName"))) domNode->GetNodeName(_retval); - else if (col.Equals(NS_LITERAL_STRING("colLocalName"))) + else if (colID.Equals(NS_LITERAL_STRING("colLocalName"))) domNode->GetLocalName(_retval); - else if (col.Equals(NS_LITERAL_STRING("colPrefix"))) + else if (colID.Equals(NS_LITERAL_STRING("colPrefix"))) domNode->GetPrefix(_retval); - else if (col.Equals(NS_LITERAL_STRING("colNamespaceURI"))) + else if (colID.Equals(NS_LITERAL_STRING("colNamespaceURI"))) domNode->GetNamespaceURI(_retval); - else if (col.Equals(NS_LITERAL_STRING("colNodeType"))) { + else if (colID.Equals(NS_LITERAL_STRING("colNodeType"))) { PRUint16 nodeType; domNode->GetNodeType(&nodeType); nsAutoString temp; temp.AppendInt(PRInt32(nodeType)); _retval = temp; - } else if (col.Equals(NS_LITERAL_STRING("colNodeValue"))) + } else if (colID.Equals(NS_LITERAL_STRING("colNodeValue"))) domNode->GetNodeValue(_retval); else { - if (StringBeginsWith(col, NS_LITERAL_STRING("col@"))) { + if (StringBeginsWith(colID, NS_LITERAL_STRING("col@"))) { nsCOMPtr el = do_QueryInterface(node->node); if (el) { nsAutoString attr; - col.Right(attr, col.Length()-4); // have to use this because Substring is crashing on me! + colID.Right(attr, colID.Length()-4); // have to use this because Substring is crashing on me! el->GetAttribute(attr, _retval); } } @@ -563,25 +565,31 @@ inDOMView::SelectionChanged() } NS_IMETHODIMP -inDOMView::SetCellText(PRInt32 row, const PRUnichar *colID, const PRUnichar *value) +inDOMView::SetCellValue(PRInt32 row, nsITreeColumn* col, const nsAString& value) { return NS_OK; } NS_IMETHODIMP -inDOMView::CycleHeader(const PRUnichar *colID, nsIDOMElement *elt) +inDOMView::SetCellText(PRInt32 row, nsITreeColumn* col, const nsAString& value) { return NS_OK; } NS_IMETHODIMP -inDOMView::CycleCell(PRInt32 row, const PRUnichar *colID) +inDOMView::CycleHeader(nsITreeColumn* col) { return NS_OK; } NS_IMETHODIMP -inDOMView::IsEditable(PRInt32 row, const PRUnichar *colID, PRBool *_retval) +inDOMView::CycleCell(PRInt32 row, nsITreeColumn* col) +{ + return NS_OK; +} + +NS_IMETHODIMP +inDOMView::IsEditable(PRInt32 row, nsITreeColumn* col, PRBool *_retval) { return NS_OK; } @@ -599,14 +607,9 @@ inDOMView::IsSorted(PRBool *_retval) } NS_IMETHODIMP -inDOMView::CanDropOn(PRInt32 index, PRBool *_retval) -{ - return NS_OK; -} - -NS_IMETHODIMP -inDOMView::CanDropBeforeAfter(PRInt32 index, PRBool before, PRBool *_retval) +inDOMView::CanDrop(PRInt32 index, PRInt32 orientation, PRBool *_retval) { + *_retval = PR_FALSE; return NS_OK; } @@ -629,7 +632,7 @@ inDOMView::PerformActionOnRow(const PRUnichar *action, PRInt32 row) } NS_IMETHODIMP -inDOMView::PerformActionOnCell(const PRUnichar *action, PRInt32 row, const PRUnichar *colID) +inDOMView::PerformActionOnCell(const PRUnichar* action, PRInt32 row, nsITreeColumn* col) { return NS_OK; } diff --git a/mozilla/extensions/inspector/resources/content/jsutil/xul/inBaseTreeView.js b/mozilla/extensions/inspector/resources/content/jsutil/xul/inBaseTreeView.js index 2c9108e612c..682052ed70e 100644 --- a/mozilla/extensions/inspector/resources/content/jsutil/xul/inBaseTreeView.js +++ b/mozilla/extensions/inspector/resources/content/jsutil/xul/inBaseTreeView.js @@ -52,16 +52,16 @@ inBaseTreeView.prototype = get rowCount() { return this.mRowCount; }, setTree: function(aTree) { this.mTree = aTree; }, - getCellText: function(aRow, aColId) { return ""; }, + getCellText: function(aRow, aCol) { return ""; }, getRowProperties: function(aIndex, aProperties) {}, - getCellProperties: function(aIndex, aColId, aProperties) {}, - getColumnProperties: function(aColId, aColElt, aProperties) {}, + getCellProperties: function(aIndex, aCol, aProperties) {}, + getColumnProperties: function(aCol, aProperties) {}, getParentIndex: function(aRowIndex) { }, hasNextSibling: function(aRowIndex, aAfterIndex) { }, getLevel: function(aIndex) {}, - getImageSrc: function(aRow, aColId) {}, - getProgressMode: function(aRow, aColId) {}, - getCellValue: function(aRow, aColId) {}, + getImageSrc: function(aRow, aCol) {}, + getProgressMode: function(aRow, aCol) {}, + getCellValue: function(aRow, aCol) {}, isContainer: function(aIndex) {}, isContainerOpen: function(aIndex) {}, isContainerEmpty: function(aIndex) {}, @@ -69,13 +69,14 @@ inBaseTreeView.prototype = isSorted: function() {}, toggleOpenState: function(aIndex) {}, selectionChanged: function() {}, - cycleHeader: function(aColId, aElt) {}, - cycleCell: function(aRow, aColId) {}, - isEditable: function(aRow, aColId) {}, - setCellText: function(aRow, aColId, aValue) {}, + cycleHeader: function(aCol) {}, + cycleCell: function(aRow, aCol) {}, + isEditable: function(aRow, aCol) {}, + setCellValue: function(aRow, aCol, aValue) {}, + setCellText: function(aRow, aCol, aValue) {}, performAction: function(aAction) {}, performActionOnRow: function(aAction, aRow) {}, - performActionOnCell: function(aAction, aRow, aColId) {}, + performActionOnCell: function(aAction, aRow, aCol) {}, // extra utility stuff diff --git a/mozilla/extensions/inspector/resources/content/viewers/computedStyle/computedStyle.js b/mozilla/extensions/inspector/resources/content/viewers/computedStyle/computedStyle.js index 90c4573130b..2b989198be8 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/computedStyle/computedStyle.js +++ b/mozilla/extensions/inspector/resources/content/viewers/computedStyle/computedStyle.js @@ -144,11 +144,11 @@ function ComputedStyleView(aObject) ComputedStyleView.prototype = new inBaseTreeView(); ComputedStyleView.prototype.getCellText = -function(aRow, aColId) +function(aRow, aCol) { - if (aColId == "olcStyleName") { + if (aCol.id == "olcStyleName") { return this.mStyleList.item(aRow); - } else if (aColId == "olcStyleValue") { + } else if (aCol.id == "olcStyleValue") { var prop = this.mStyleList.item(aRow); return this.mStyleList.getPropertyValue(prop); } diff --git a/mozilla/extensions/inspector/resources/content/viewers/dom/dom.js b/mozilla/extensions/inspector/resources/content/viewers/dom/dom.js index 27a6fd7f866..0051c27f30d 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/dom/dom.js +++ b/mozilla/extensions/inspector/resources/content/viewers/dom/dom.js @@ -578,7 +578,7 @@ DOMViewer.prototype = var bx = this.mDOMTree.treeBoxObject; if (!aEl) { - bx.selection.select(null); + bx.view.selection.select(null); return false; } @@ -614,7 +614,7 @@ DOMViewer.prototype = } if (!aQuickie && lastIndex >= 0) { - bx.selection.select(lastIndex); + view.selection.select(lastIndex); bx.ensureRowIsVisible(lastIndex); } @@ -628,7 +628,7 @@ DOMViewer.prototype = rebuild: function() { var selNode = this.getNodeFromRowIndex(this.mDOMTree.currentIndex); - this.mDOMTree.treeBoxObject.selection.select(null); + this.mDOMView.selection.select(null); var opened = []; var i; diff --git a/mozilla/extensions/inspector/resources/content/viewers/domNode/domNode.js b/mozilla/extensions/inspector/resources/content/viewers/domNode/domNode.js index 85853ddbcec..98eda7e475d 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/domNode/domNode.js +++ b/mozilla/extensions/inspector/resources/content/viewers/domNode/domNode.js @@ -124,7 +124,7 @@ DOMNodeViewer.prototype = if (aObject != this.mDOMView.rootNode) { this.mDOMView.rootNode = aObject; - this.mAttrTree.treeBoxObject.selection.select(-1); + this.mAttrTree.view.selection.select(-1); } } else { deck.setAttribute("selectedIndex", 1); diff --git a/mozilla/extensions/inspector/resources/content/viewers/jsObject/jsObjectView.js b/mozilla/extensions/inspector/resources/content/viewers/jsObject/jsObjectView.js index ae4b3a31bdc..f1d2039f5d7 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/jsObject/jsObjectView.js +++ b/mozilla/extensions/inspector/resources/content/viewers/jsObject/jsObjectView.js @@ -86,11 +86,11 @@ JSObjectView.prototype = { }, - getCellProperties: function(aIndex, aProperties) + getCellProperties: function(aIndex, aCol, aProperties) { }, - getColumnProperties: function(aColId, aColElt, aProperties) + getColumnProperties: function(aCol, aProperties) { }, @@ -129,23 +129,23 @@ JSObjectView.prototype = { }, - getImageSrc: function(aRow, aColId) + getImageSrc: function(aRow, aCol) { }, - getProgressMode: function(aRow, aColId) + getProgressMode: function(aRow, aCol) { }, - getCellValue: function(aRow, aColId) + getCellValue: function(aRow, aCol) { }, - getCellText: function(aRow, aColId) + getCellText: function(aRow, aCol) { var object = null; - switch (aColId) { + switch (aCol.id) { case "olrCol1": return 1; break; @@ -164,7 +164,7 @@ JSObjectView.prototype = { }, - cycleHeader: function(aColId, aElt) + cycleHeader: function(aCol) { }, @@ -172,15 +172,19 @@ JSObjectView.prototype = { }, - cycleCell: function(aRow, aColId) + cycleCell: function(aRow, aCol) { }, - isEditable: function(aRow, aColId) + isEditable: function(aRow, aCol) { }, - setCellText: function(aRow, aColId, aValue) + setCellValue: function(aRow, aCol, aValue) + { + }, + + setCellText: function(aRow, aCol, aValue) { }, @@ -192,7 +196,7 @@ JSObjectView.prototype = { }, - performActionOnCell: function(aAction, aRow, aColId) + performActionOnCell: function(aAction, aRow, aCol) { }, diff --git a/mozilla/extensions/inspector/resources/content/viewers/styleRules/styleRules.js b/mozilla/extensions/inspector/resources/content/viewers/styleRules/styleRules.js index 1ffaa467756..52ad8727ca1 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/styleRules/styleRules.js +++ b/mozilla/extensions/inspector/resources/content/viewers/styleRules/styleRules.js @@ -375,22 +375,22 @@ function(aRow) } StyleRuleView.prototype.getCellText = -function(aRow, aColId) +function(aRow, aCol) { if (aRow > this.rowCount) return ""; // special case for the style attribute if (this.mStyleAttribute && aRow + 1 == this.rowCount) { - if (aColId == "olcRule") { + if (aCol.id == "olcRule") { return 'style=""'; } - if (aColId == "olcFileURL") { + if (aCol.id == "olcFileURL") { // we ought to be able to get to the URL... return ""; } - if (aColId == "olcLine") { + if (aCol.id == "olcLine") { return ""; } return ""; @@ -399,7 +399,7 @@ function(aRow, aColId) var rule = this.getRuleAt(aRow); if (!rule) return ""; - if (aColId == "olcRule") { + if (aCol.id == "olcRule") { switch (rule.type) { case CSSRule.STYLE_RULE: return rule.selectorText; @@ -411,11 +411,11 @@ function(aRow, aColId) } } - if (aColId == "olcFileURL") { + if (aCol.id == "olcFileURL") { return rule.parentStyleSheet ? rule.parentStyleSheet.href : ""; } - if (aColId == "olcLine") { + if (aCol.id == "olcLine") { return rule.type == CSSRule.STYLE_RULE ? this.mDOMUtils.getRuleLine(rule) : ""; } @@ -439,9 +439,9 @@ function() }); StylePropsView.prototype.getCellProperties = -function(aRow, aColId, aProperties) +function(aRow, aCol, aProperties) { - if (aColId == "olcPropPriority") { + if (aCol.id == "olcPropPriority") { var prop = this.mDec.item(aRow); if (this.mDec.getPropertyPriority(prop) == "important") { aProperties.AppendElement(this.createAtom("important")); @@ -450,13 +450,13 @@ function(aRow, aColId, aProperties) } StylePropsView.prototype.getCellText = -function(aRow, aColId) +function(aRow, aCol) { var prop = this.mDec.item(aRow); - if (aColId == "olcPropName") { + if (aCol.id == "olcPropName") { return prop; - } else if (aColId == "olcPropValue") { + } else if (aCol.id == "olcPropValue") { return this.mDec.getPropertyValue(prop) } diff --git a/mozilla/extensions/inspector/resources/content/viewers/stylesheets/stylesheets.js b/mozilla/extensions/inspector/resources/content/viewers/stylesheets/stylesheets.js index faa6c373552..71c46679aaa 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/stylesheets/stylesheets.js +++ b/mozilla/extensions/inspector/resources/content/viewers/stylesheets/stylesheets.js @@ -94,7 +94,7 @@ StylesheetsViewer.prototype = this.mView = new StyleSheetsView(aObject); this.mOlBox.view = this.mView; this.mObsMan.dispatchEvent("subjectChange", { subject: aObject }); - this.mOlBox.selection.select(0); + this.mView.selection.select(0); }, initialize: function(aPane) @@ -203,11 +203,11 @@ function(aRow, aDiff) } StyleSheetsView.prototype.getCellText = -function(aRow, aColId) +function(aRow, aCol) { - if (aColId == "olcHref") + if (aCol.id == "olcHref") return this.mSheets[aRow].href; - else if (aColId == "olcRules") + else if (aCol.id == "olcRules") return this.mSheets[aRow].cssRules.length; return ""; } diff --git a/mozilla/extensions/inspector/resources/content/viewers/xblBindings/xblBindings.js b/mozilla/extensions/inspector/resources/content/viewers/xblBindings/xblBindings.js index 97b5d38784e..36ff2fd2cd9 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/xblBindings/xblBindings.js +++ b/mozilla/extensions/inspector/resources/content/viewers/xblBindings/xblBindings.js @@ -418,10 +418,10 @@ function MethodTreeView(aBinding) MethodTreeView.prototype = new inBaseTreeView(); MethodTreeView.prototype.getCellText = -function(aRow, aColId) +function(aRow, aCol) { var method = this.mMethods[aRow]; - if (aColId == "olcMethodName") { + if (aCol.id == "olcMethodName") { var name = method.getAttribute("name"); var params = method.getElementsByTagName("parameter"); var pstr = ""; @@ -445,10 +445,10 @@ function PropTreeView(aBinding) PropTreeView.prototype = new inBaseTreeView(); PropTreeView.prototype.getCellText = -function(aRow, aColId) +function(aRow, aCol) { var prop = this.mProps[aRow]; - if (aColId == "olcPropName") { + if (aCol.id == "olcPropName") { return prop.getAttribute("name"); } @@ -467,12 +467,12 @@ function HandlerTreeView(aBinding) HandlerTreeView.prototype = new inBaseTreeView(); HandlerTreeView.prototype.getCellText = -function(aRow, aColId) +function(aRow, aCol) { var handler = this.mHandlers[aRow]; - if (aColId == "olcHandlerEvent") { + if (aCol.id == "olcHandlerEvent") { return handler.getAttribute("event"); - } else if (aColId == "olcHandlerPhase") { + } else if (aCol.id == "olcHandlerPhase") { return handler.getAttribute("phase"); } @@ -500,12 +500,12 @@ function ResourceTreeView(aBinding) ResourceTreeView.prototype = new inBaseTreeView(); ResourceTreeView.prototype.getCellText = -function(aRow, aColId) +function(aRow, aCol) { var resource = this.mResources[aRow]; - if (aColId == "olcResourceType") { + if (aCol.id == "olcResourceType") { return resource.localName; - } else if (aColId == "olcResourceSrc") { + } else if (aCol.id == "olcResourceSrc") { return resource.getAttribute("src"); } diff --git a/mozilla/extensions/irc/xul/content/static.js b/mozilla/extensions/irc/xul/content/static.js index c48954e455f..6fd17287ef5 100644 --- a/mozilla/extensions/irc/xul/content/static.js +++ b/mozilla/extensions/irc/xul/content/static.js @@ -1863,8 +1863,8 @@ function setCurrentObject (obj) { /* Remove currently selected items before this tree gets rerooted, * because it seems to remember the selections for eternity if not. */ - if (userList.treeBoxObject.selection) - userList.treeBoxObject.selection.select(-1); + if (userList.view.selection) + userList.view.selection.select(-1); if (obj.TYPE == "IRCChannel") { diff --git a/mozilla/extensions/p3p/resources/content/pageInfoOverlay.js b/mozilla/extensions/p3p/resources/content/pageInfoOverlay.js index 51ed4bc9b2d..c6de150119e 100755 --- a/mozilla/extensions/p3p/resources/content/pageInfoOverlay.js +++ b/mozilla/extensions/p3p/resources/content/pageInfoOverlay.js @@ -67,7 +67,7 @@ function initP3PTab() // now select the main link var tree = document.getElementById("linkList"); - tree.treeBoxObject.selection.select(0); + tree.view.selection.select(0); var linkTypes = [ diff --git a/mozilla/extensions/sql/base/src/Makefile.in b/mozilla/extensions/sql/base/src/Makefile.in index dc1c1247eb0..02be266178c 100644 --- a/mozilla/extensions/sql/base/src/Makefile.in +++ b/mozilla/extensions/sql/base/src/Makefile.in @@ -48,6 +48,8 @@ REQUIRES = xpcom \ locale \ necko \ rdf \ + dom \ + layout \ windowwatcher \ $(NULL) diff --git a/mozilla/extensions/sql/base/src/mozSqlResult.cpp b/mozilla/extensions/sql/base/src/mozSqlResult.cpp index 45d5e3ae322..eb728138b37 100644 --- a/mozilla/extensions/sql/base/src/mozSqlResult.cpp +++ b/mozilla/extensions/sql/base/src/mozSqlResult.cpp @@ -44,6 +44,7 @@ #include "nsDateTimeFormatCID.h" #include "mozSqlResult.h" #include "mozSqlConnection.h" +#include "nsITreeColumns.h" static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID); @@ -148,11 +149,12 @@ mozSqlResult::~mozSqlResult() } -NS_IMPL_THREADSAFE_ISUPPORTS4(mozSqlResult, +NS_IMPL_THREADSAFE_ISUPPORTS5(mozSqlResult, mozISqlResult, mozISqlDataSource, nsIRDFDataSource, - nsIRDFRemoteDataSource); + nsIRDFRemoteDataSource, + nsITreeView); NS_IMETHODIMP mozSqlResult::GetConnection(mozISqlConnection** aConnection) @@ -667,6 +669,284 @@ mozSqlResult::FlushTo(const char *aURI) return NS_ERROR_NOT_IMPLEMENTED; } + +/* +NS_IMETHODIMP +mozSqlResult::GetRowCount(PRInt32 *aRowCount) +{ + *aRowCount = mRows.Count(); + return NS_OK; +} +*/ + +NS_IMETHODIMP +mozSqlResult::GetSelection(nsITreeSelection * *aSelection) +{ + NS_IF_ADDREF(*aSelection = mSelection); + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::SetSelection(nsITreeSelection * aSelection) +{ + mSelection = aSelection; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetRowProperties(PRInt32 index, nsISupportsArray *properties) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetCellProperties(PRInt32 row, nsITreeColumn* col, nsISupportsArray *properties) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetColumnProperties(nsITreeColumn* aCol, nsISupportsArray *properties) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::IsContainer(PRInt32 index, PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::IsContainerOpen(PRInt32 index, PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::IsContainerEmpty(PRInt32 index, PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::IsSeparator(PRInt32 index, PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::IsSorted(PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::CanDrop(PRInt32 index, PRInt32 orientation, PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::Drop(PRInt32 row, PRInt32 orientation) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetParentIndex(PRInt32 rowIndex, PRInt32 *_retval) +{ + *_retval = -1; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::HasNextSibling(PRInt32 rowIndex, PRInt32 afterIndex, PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetLevel(PRInt32 index, PRInt32 *_retval) +{ + *_retval = 0; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetImageSrc(PRInt32 row, nsITreeColumn* col, nsAString & _retval) +{ + _retval.Truncate(); + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetProgressMode(PRInt32 row, nsITreeColumn* col, PRInt32 *_retval) +{ + *_retval = 0; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetCellValue(PRInt32 row, nsITreeColumn* col, nsAString & _retval) +{ + PRInt32 columnIndex; + col->GetIndex(&columnIndex); + + Cell* cell = ((Row*)mRows[row])->mCells[columnIndex]; + if (! cell->IsNull()) { + PRInt32 type = cell->GetType(); + if (type == mozISqlResult::TYPE_BOOL) { + if (cell->mBool) + _retval.Assign(NS_LITERAL_STRING("true")); + else + _retval.Assign(NS_LITERAL_STRING("false")); + } + } + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::GetCellText(PRInt32 row, nsITreeColumn* col, nsAString & _retval) +{ + PRInt32 columnIndex; + col->GetIndex(&columnIndex); + + Cell* cell = ((Row*)mRows[row])->mCells[columnIndex]; + if (! cell->IsNull()) { + PRInt32 type = cell->GetType(); + if (type == mozISqlResult::TYPE_STRING) + _retval.Assign(cell->mString); + else if (type == mozISqlResult::TYPE_INT) { + nsAutoString s; + s.AppendInt(cell->mInt); + _retval.Assign(s); + } + else if (type == mozISqlResult::TYPE_FLOAT || + type == mozISqlResult::TYPE_DECIMAL) { + nsAutoString s; + s.AppendFloat(cell->mFloat); + _retval.Assign(s); + } + else if (type == mozISqlResult::TYPE_DATE || + type == mozISqlResult::TYPE_TIME || + type == mozISqlResult::TYPE_DATETIME) { + nsAutoString value; + mozSqlResult::gFormat->FormatPRTime(nsnull, + type != mozISqlResult::TYPE_TIME ? kDateFormatShort : kDateFormatNone, + type != mozISqlResult::TYPE_DATE ? kTimeFormatSeconds : kTimeFormatNone, + PRTime(cell->mDate), + value); + _retval.Assign(value); + } + else if (type == mozISqlResult::TYPE_BOOL) { + if (cell->mBool) + _retval.Assign(NS_LITERAL_STRING("true")); + else + _retval.Assign(NS_LITERAL_STRING("false")); + } + } + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::SetTree(nsITreeBoxObject *tree) +{ + mBoxObject = tree; + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::ToggleOpenState(PRInt32 index) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::CycleHeader(nsITreeColumn* aCol) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::SelectionChanged() +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::CycleCell(PRInt32 row, nsITreeColumn* aCol) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::IsEditable(PRInt32 row, nsITreeColumn* col, PRBool *_retval) +{ + return CanUpdate(_retval); +} + +NS_IMETHODIMP +mozSqlResult::SetCellValue(PRInt32 row, nsITreeColumn* col, const nsAString& value) +{ + PRInt32 columnIndex; + col->GetIndex(&columnIndex); + + Row* srcRow = (Row*)mRows[row]; + Row* buffer = Row::Create(mAllocator, nsnull, mColumnInfo, srcRow); + + Cell* cell = buffer->mCells[columnIndex]; + + if (value.Equals(NS_LITERAL_STRING("true"))) { + cell->mBool = PR_TRUE; + } + else if (value.Equals(NS_LITERAL_STRING("false"))) { + cell->mBool = PR_FALSE; + } + + PRInt32 count; + nsresult rv = UpdateRow(row, buffer, &count); + if (NS_FAILED(rv)) + return rv; + + if (mBoxObject) + mBoxObject->InvalidateCell(row, col); + + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::SetCellText(PRInt32 row, nsITreeColumn* col, const nsAString& value) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::PerformAction(const PRUnichar *action) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::PerformActionOnRow(const PRUnichar *action, PRInt32 row) +{ + return NS_OK; +} + +NS_IMETHODIMP +mozSqlResult::PerformActionOnCell(const PRUnichar *action, PRInt32 row, nsITreeColumn* aCol) +{ + return NS_OK; +} + + void mozSqlResult::ClearColumnInfo() { @@ -1020,6 +1300,9 @@ mozSqlResult::InsertRow(Row* aSrcRow, PRInt32* _retval) for (i = 0; i < mObservers.Count(); i++) mObservers[i]->OnAssert(this, kSQL_ResultRoot, kNC_Child, resource); + if (mBoxObject) + mBoxObject->RowCountChanged(mRows.Count() - 1, 1); + *_retval = 1; return NS_OK; } @@ -1081,6 +1364,9 @@ mozSqlResult::UpdateRow(PRInt32 aRowIndex, Row* aSrcRow, PRInt32* _retval) for (PRInt32 i = 0; i < mObservers.Count(); i++) mObservers[i]->OnUnassert(this, kSQL_ResultRoot, kNC_Child, row->mSource); + if (mBoxObject) + mBoxObject->RowCountChanged(aRowIndex, -1); + Row::Destroy(mAllocator, mColumnInfo.Count(), row); *_retval = 0; @@ -1138,6 +1424,9 @@ mozSqlResult::UpdateRow(PRInt32 aRowIndex, Row* aSrcRow, PRInt32* _retval) } } + if (mBoxObject) + mBoxObject->InvalidateRow(aRowIndex); + *_retval = 1; return NS_OK; } @@ -1178,6 +1467,9 @@ mozSqlResult::DeleteRow(PRInt32 aRowIndex, PRInt32* _retval) for (PRInt32 i = 0; i < mObservers.Count(); i++) mObservers[i]->OnUnassert(this, kSQL_ResultRoot, kNC_Child, row->mSource); + if (mBoxObject) + mBoxObject->RowCountChanged(aRowIndex, -1); + Row::Destroy(mAllocator, mColumnInfo.Count(), row); *_retval = 1; diff --git a/mozilla/extensions/sql/base/src/mozSqlResult.h b/mozilla/extensions/sql/base/src/mozSqlResult.h index d30192ebd22..1a811064de3 100644 --- a/mozilla/extensions/sql/base/src/mozSqlResult.h +++ b/mozilla/extensions/sql/base/src/mozSqlResult.h @@ -47,6 +47,9 @@ #include "nsIRDFService.h" #include "nsIRDFDataSource.h" #include "nsIRDFRemoteDataSource.h" +#include "nsITreeView.h" +#include "nsITreeSelection.h" +#include "nsITreeBoxObject.h" #include "nsIDateTimeFormat.h" #include "nsIInputStream.h" #include "mozISqlConnection.h" @@ -285,7 +288,8 @@ class Row { class mozSqlResult : public mozISqlResult, public mozISqlDataSource, public nsIRDFDataSource, - public nsIRDFRemoteDataSource + public nsIRDFRemoteDataSource, + public nsITreeView { public: mozSqlResult(mozISqlConnection* aConnection, @@ -296,7 +300,20 @@ class mozSqlResult : public mozISqlResult, NS_DECL_ISUPPORTS - NS_DECL_MOZISQLRESULT + //NS_DECL_MOZISQLRESULT + NS_IMETHOD GetConnection(mozISqlConnection * *aConnection); + NS_IMETHOD GetQuery(nsAString & aQuery); + NS_IMETHOD GetTableName(nsAString & aTableName); + //NS_IMETHOD GetRowCount(PRInt32 *aRowCount); + NS_IMETHOD GetColumnCount(PRInt32 *aColumnCount); + NS_IMETHOD GetColumnName(PRInt32 aColumnIndex, nsAString & _retval); + NS_IMETHOD GetColumnIndex(const nsAString & aColumnName, PRInt32 *_retval); + NS_IMETHOD GetColumnType(PRInt32 aColumnIndex, PRInt32 *_retval); + NS_IMETHOD GetColumnTypeAsString(PRInt32 aColumnIndex, nsAString & _retval); + NS_IMETHOD GetColumnDisplaySize(PRInt32 aColumnIndex, PRInt32 *_retval); + NS_IMETHOD Enumerate(mozISqlResultEnumerator **_retval); + NS_IMETHOD Open(mozISqlInputStream **_retval); + NS_IMETHOD Reload(void); NS_DECL_MOZISQLDATASOURCE @@ -304,6 +321,8 @@ class mozSqlResult : public mozISqlResult, NS_DECL_NSIRDFREMOTEDATASOURCE + NS_DECL_NSITREEVIEW + friend class mozSqlResultEnumerator; friend class mozSqlResultStream; @@ -350,6 +369,8 @@ class mozSqlResult : public mozISqlResult, nsVoidArray mRows; nsObjectHashtable mSources; nsCOMArray mObservers; + nsCOMPtr mSelection; + nsCOMPtr mBoxObject; nsCOMPtr mPrimaryKeys; PRInt32 mCanInsert; PRInt32 mCanUpdate; diff --git a/mozilla/extensions/sql/build/src/Makefile.in b/mozilla/extensions/sql/build/src/Makefile.in index 0ef2ff43f66..aa654d0c00a 100644 --- a/mozilla/extensions/sql/build/src/Makefile.in +++ b/mozilla/extensions/sql/build/src/Makefile.in @@ -41,7 +41,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = sql -MODULE_NAME = sqlModule +MODULE_NAME = mozSqlModule LIBRARY_NAME = sql SHORT_LIBNAME = sql EXPORT_LIBRARY = 1 diff --git a/mozilla/extensions/sql/build/src/mozSqlModule.cpp b/mozilla/extensions/sql/build/src/mozSqlModule.cpp index cda94f34cdc..e3421da3dc1 100644 --- a/mozilla/extensions/sql/build/src/mozSqlModule.cpp +++ b/mozilla/extensions/sql/build/src/mozSqlModule.cpp @@ -65,4 +65,4 @@ static nsModuleComponentInfo components[] = #endif }; -NS_IMPL_NSGETMODULE("sql", components) +NS_IMPL_NSGETMODULE("mozSqlModule", components) diff --git a/mozilla/extensions/sql/pgsql/src/Makefile.in b/mozilla/extensions/sql/pgsql/src/Makefile.in index 10f68486b61..c6c535708a5 100644 --- a/mozilla/extensions/sql/pgsql/src/Makefile.in +++ b/mozilla/extensions/sql/pgsql/src/Makefile.in @@ -46,6 +46,8 @@ REQUIRES = xpcom \ string \ locale \ rdf \ + dom \ + layout \ $(NULL) CPPSRCS = \ diff --git a/mozilla/extensions/sql/pgsql/src/mozSqlConnectionPgsql.cpp b/mozilla/extensions/sql/pgsql/src/mozSqlConnectionPgsql.cpp index 5435f976dc8..aa0ec483f17 100644 --- a/mozilla/extensions/sql/pgsql/src/mozSqlConnectionPgsql.cpp +++ b/mozilla/extensions/sql/pgsql/src/mozSqlConnectionPgsql.cpp @@ -34,6 +34,7 @@ * ***** END LICENSE BLOCK ***** */ #include "prprf.h" +#include "nsReadableUtils.h" #include "mozSqlConnectionPgsql.h" #include "mozSqlResultPgsql.h" diff --git a/mozilla/extensions/sql/pgsql/src/mozSqlResultPgsql.cpp b/mozilla/extensions/sql/pgsql/src/mozSqlResultPgsql.cpp index e6215630f40..1e33967d7c7 100644 --- a/mozilla/extensions/sql/pgsql/src/mozSqlResultPgsql.cpp +++ b/mozilla/extensions/sql/pgsql/src/mozSqlResultPgsql.cpp @@ -106,7 +106,7 @@ mozSqlResultPgsql::BuildColumnInfo() { for (PRInt32 i = 0; i < PQnfields(mResult); i++) { char* n = PQfname(mResult, i); - PRUnichar* name = UTF8ToNewUnicode(n); + PRUnichar* name = UTF8ToNewUnicode(nsDependentCString(n)); PRInt32 type = GetColType(i); PRInt32 size = PQfsize(mResult, i); PRInt32 mod = PQfmod(mResult, i); @@ -140,7 +140,7 @@ mozSqlResultPgsql::BuildRows() cell->SetNull(PR_FALSE); PRInt32 type = cell->GetType(); if (type == mozISqlResult::TYPE_STRING) - cell->SetString(UTF8ToNewUnicode(value)); + cell->SetString(UTF8ToNewUnicode(nsDependentCString(value))); else if (type == mozISqlResult::TYPE_INT) PR_sscanf(value, "%d", &cell->mInt); else if (type == mozISqlResult::TYPE_FLOAT) diff --git a/mozilla/extensions/transformiix/resources/buster/buster-view.js b/mozilla/extensions/transformiix/resources/buster/buster-view.js index 137a8d10ded..c2158cff7bd 100644 --- a/mozilla/extensions/transformiix/resources/buster/buster-view.js +++ b/mozilla/extensions/transformiix/resources/buster/buster-view.js @@ -42,7 +42,7 @@ var view = onRun : function() { runQueue.mArray = new Array(); - var sels = this.boxObject.selection,a=new Object(),b=new Object(),k; + var sels = this.boxObject.view.selection,a=new Object(),b=new Object(),k; var rowResource, name, path; for (k=0;k this.rowCount) return; var rec = this.childData.locateChildByVisualRow(rowIndex); @@ -363,7 +362,7 @@ function bov_rkeypress (event) if (!this.selection) return; - rowIndex = this.tree.selection.currentIndex; + rowIndex = this.tree.view.selection.currentIndex; if (rowIndex == -1 || rowIndex > this.rowCount) return; rec = this.childData.locateChildByVisualRow(rowIndex); @@ -377,7 +376,7 @@ function bov_rkeypress (event) } else if ("onKeyPress" in this) { - rowIndex = this.tree.selection.currentIndex; + rowIndex = this.tree.view.selection.currentIndex; if (rowIndex != -1 && rowIndex < this.rowCount) { rec = this.childData.locateChildByVisualRow(rowIndex); @@ -1323,20 +1322,20 @@ function xtv_isctr (index) XULTreeView.prototype.__defineGetter__("selectedIndex", xtv_getsel); function xtv_getsel() { - if (!this.tree || this.tree.selection.getRangeCount() < 1) + if (!this.tree || this.tree.view.selection.getRangeCount() < 1) return -1; var min = new Object(); - this.tree.selection.getRangeAt(0, min, {}); + this.tree.view.selection.getRangeAt(0, min, {}); return min.value; } XULTreeView.prototype.__defineSetter__("selectedIndex", xtv_setsel); function xtv_setsel(i) { - this.tree.selection.clearSelection(); + this.tree.view.selection.clearSelection(); if (i != -1) - this.tree.selection.timedSelect (i, 500); + this.tree.view.selection.timedSelect (i, 500); return i; } @@ -1440,42 +1439,42 @@ function xtv_getlvl (index) } XULTreeView.prototype.getImageSrc = -function xtv_getimgsrc (index, colID) +function xtv_getimgsrc (index, col) { } XULTreeView.prototype.getProgressMode = -function xtv_getprgmode (index, colID) +function xtv_getprgmode (index, col) { } XULTreeView.prototype.getCellValue = -function xtv_getcellval (index, colID) +function xtv_getcellval (index, col) { } XULTreeView.prototype.getCellText = -function xtv_getcelltxt (index, colID) +function xtv_getcelltxt (index, col) { var row = this.childData.locateChildByVisualRow (index); //ASSERT(row, "bogus row " + index); - var ary = colID.match (/:(.*)/); + var ary = col.id.match (/:(.*)/); if (ary) - colID = ary[1]; + col = ary[1]; - if (row && row._colValues && colID in row._colValues) - return row._colValues[colID]; + if (row && row._colValues && col in row._colValues) + return row._colValues[col]; else return ""; } XULTreeView.prototype.getCellProperties = -function xtv_cellprops (row, colID, properties) +function xtv_cellprops (row, col, properties) {} XULTreeView.prototype.getColumnProperties = -function xtv_colprops (colID, elem, properties) +function xtv_colprops (col, properties) {} XULTreeView.prototype.getRowProperties = @@ -1488,21 +1487,12 @@ function xtv_issorted (index) return false; } -XULTreeView.prototype.canDropOn = -function xtv_dropon (index) +XULTreeView.prototype.canDrop = +function xtv_drop (index, orientation) { var row = this.childData.locateChildByVisualRow (index); //ASSERT(row, "bogus row " + index); - return (row && ("canDropOn" in row) && row.canDropOn()); -} - -XULTreeView.prototype.canDropBeforeAfter = -function xtv_dropba (index, before) -{ - var row = this.childData.locateChildByVisualRow (index); - //ASSERT(row, "bogus row " + index); - return (row && ("canDropBeforeAfter" in row) && - row.canDropBeforeAfter(before)); + return (row && ("canDrop" in row) && row.canDrop(orientation)); } XULTreeView.prototype.drop = @@ -1521,7 +1511,7 @@ function xtv_seto (tree) } XULTreeView.prototype.cycleHeader = -function xtv_cyclehdr (colID, elt) +function xtv_cyclehdr (col) { } @@ -1531,18 +1521,23 @@ function xtv_selchg () } XULTreeView.prototype.cycleCell = -function xtv_cyclecell (row, colID) +function xtv_cyclecell (row, col) { } XULTreeView.prototype.isEditable = -function xtv_isedit (row, colID) +function xtv_isedit (row, col) { return false; } +XULTreeView.prototype.setCellValue = +function xtv_setct (row, col, value) +{ +} + XULTreeView.prototype.setCellText = -function xtv_setct (row, colID, value) +function xtv_setct (row, col, value) { } @@ -1581,7 +1576,7 @@ function xtv_rdblclick (event) if (!("onRowCommand" in this) || event.target.localName != "treechildren") return; - var rowIndex = this.tree.selection.currentIndex; + var rowIndex = this.tree.view.selection.currentIndex; if (rowIndex == -1 || rowIndex > this.rowCount) return; var rec = this.childData.locateChildByVisualRow(rowIndex); @@ -1605,7 +1600,7 @@ function xtv_rkeypress (event) if (!this.selection) return; - rowIndex = this.tree.selection.currentIndex; + rowIndex = this.tree.view.selection.currentIndex; if (rowIndex == -1 || rowIndex > this.rowCount) return; rec = this.childData.locateChildByVisualRow(rowIndex); @@ -1619,7 +1614,7 @@ function xtv_rkeypress (event) } else if ("onKeyPress" in this) { - rowIndex = this.tree.selection.currentIndex; + rowIndex = this.tree.view.selection.currentIndex; if (rowIndex != -1 && rowIndex < this.rowCount) { rec = this.childData.locateChildByVisualRow(rowIndex); diff --git a/mozilla/extensions/venkman/resources/content/venkman-views.js b/mozilla/extensions/venkman/resources/content/venkman-views.js index 9656ca18c14..46b9beb9a69 100644 --- a/mozilla/extensions/venkman/resources/content/venkman-views.js +++ b/mozilla/extensions/venkman/resources/content/venkman-views.js @@ -142,10 +142,9 @@ function syncTreeView (treeContent, treeView, cb) throw "tantrum"; treeContent.treeBoxObject.view = treeView; - if (treeContent.treeBoxObject.selection) + if (treeView.selection) { - treeContent.treeBoxObject.selection.tree = - treeContent.treeBoxObject; + treeView.selection.tree = treeContent.treeBoxObject; } } catch (ex) @@ -194,7 +193,7 @@ function getTreeContext (view, cx, recordContextGetter) //dd ("getTreeContext {"); var i = 0; - var selection = view.tree.selection; + var selection = view.tree.view.selection; var row = selection.currentIndex; var rec; @@ -488,9 +487,9 @@ function bv_getcx(cx) } console.views.breaks.getCellProperties = -function bv_cellprops (index, colID, properties) +function bv_cellprops (index, col, properties) { - if (colID == "breaks:col-0") + if (col.id == "breaks:col-0") { var row = this.childData.locateChildByVisualRow(index); if (row.type == "future") @@ -763,9 +762,9 @@ function lv_rowcommand(rec) } console.views.locals.getCellProperties = -function lv_cellprops (index, colID, properties) +function lv_cellprops (index, col, properties) { - if (colID != "locals:col-0") + if (col.id != "locals:col-0") return null; var row = this.childData.locateChildByVisualRow(index); @@ -1246,13 +1245,13 @@ function scv_click (e) { /* resort by column */ var rowIndex = new Object(); - var colID = new Object(); + var col = new Object(); var childElt = new Object(); var treeBox = console.views.scripts.tree; - treeBox.getCellAt(e.clientX, e.clientY, rowIndex, colID, childElt); + treeBox.getCellAt(e.clientX, e.clientY, rowIndex, col, childElt); var prop; - switch (colID.value) + switch (col.value.id) { case "scripts:col-0": prop = "functionName"; @@ -1277,15 +1276,11 @@ console.views.scripts.onDragStart = Prophylactic(console.views.scripts, scv_dstart); function scv_dstart (e, transferData, dragAction) { - var row = new Object(); - var colID = new Object(); - var childElt = new Object(); - - this.tree.getCellAt(e.clientX, e.clientY, row, colID, childElt); - if (!colID.value) + var row = this.tree.getRowAt(e.clientX, e.clientY); + if (row == -1) return false; - row = this.childData.locateChildByVisualRow (row.value); + row = this.childData.locateChildByVisualRow (row); var rv = false; if (row && ("onDragStart" in row)) rv = row.onDragStart (e, transferData, dragAction); @@ -1304,9 +1299,9 @@ function scv_setmode (flag) } console.views.scripts.getCellProperties = -function scv_cellprops (index, colID, properties) +function scv_cellprops (index, col, properties) { - if (colID != "scripts:col-0") + if (col.id != "scripts:col-0") return null; var row = this.childData.locateChildByVisualRow(index); @@ -2098,7 +2093,7 @@ function skv_hookFrame (e) if (console.views.stack.tree) { stackView.scrollTo (e.frameIndex, 0); - stackView.tree.selection.currentIndex = e.frameIndex; + stackView.tree.view.selection.currentIndex = e.frameIndex; stackView.tree.invalidate(); } } @@ -2172,9 +2167,9 @@ function sv_getcx(cx) } console.views.stack.getCellProperties = -function sv_cellprops (index, colID, properties) +function sv_cellprops (index, col, properties) { - if (colID != "stack:col-0") + if (col.id != "stack:col-0") return; var row = this.childData.locateChildByVisualRow(index); @@ -3661,21 +3656,21 @@ function sv_click (e) if (target.localName == "treechildren") { var row = new Object(); - var colID = new Object(); + var col = new Object(); var childElt = new Object(); var treeBox = console.views.source.tree; - treeBox.getCellAt(e.clientX, e.clientY, row, colID, childElt); + treeBox.getCellAt(e.clientX, e.clientY, row, col, childElt); if (row.value == -1) return; - colID = colID.value; + colID = col.value.id; row = row.value; if (colID == "source:col-0") { if ("onMarginClick" in console.views.source.childData) - console.views.source.childData.onMarginClick (e, row + 1); + console.views.source.childData.onMarginClick (e, row.value + 1); } } @@ -3685,7 +3680,7 @@ console.views.source.onSelect = function sv_select (e) { var sourceView = console.views.source; - sourceView.currentLine = sourceView.tree.selection.currentIndex + 1; + sourceView.currentLine = sourceView.tree.view.selection.currentIndex + 1; console.views.source.syncHeader(); } @@ -3955,7 +3950,7 @@ function sv_rowprops (row, properties) /* nsITreeView */ console.views.source.getCellProperties = -function sv_cellprops (row, colID, properties) +function sv_cellprops (row, col, properties) { if (!("childData" in this) || !this.childData.isLoaded || row < 0 || row >= this.childData.lines.length) @@ -3965,7 +3960,7 @@ function sv_cellprops (row, colID, properties) if (!line) return; - if (colID == "source:col-0") + if (col.id == "source:col-0") { if ("lineMap" in this.childData && row in this.childData.lineMap) { @@ -4008,17 +4003,17 @@ function sv_cellprops (row, colID, properties) /* nsITreeView */ console.views.source.getCellText = -function sv_getcelltext (row, colID) +function sv_getcelltext (row, col) { if (!this.childData.isLoaded || row < 0 || row > this.childData.lines.length) return ""; - var ary = colID.match (/:(.*)/); + var ary = col.id.match (/:(.*)/); if (ary) - colID = ary[1]; + col = ary[1]; - switch (colID) + switch (col) { case "col-2": return this.childData.lines[row]; @@ -4126,9 +4121,9 @@ function onHide() } console.views.watches.getCellProperties = -function wv_cellprops (index, colID, properties) +function wv_cellprops (index, col, properties) { - if (colID != "watches:col-0") + if (col.id != "watches:col-0") return null; var row = this.childData.locateChildByVisualRow(index); @@ -4450,9 +4445,9 @@ function winv_hide () } console.views.windows.getCellProperties = -function winv_cellprops (index, colID, properties) +function winv_cellprops (index, col, properties) { - if (colID == "windows:col-0") + if (col.id == "windows:col-0") { var row = this.childData.locateChildByVisualRow(index); if (row) diff --git a/mozilla/extensions/wallet/cookieviewer/resources/content/CookieViewer.js b/mozilla/extensions/wallet/cookieviewer/resources/content/CookieViewer.js index 714a2bbd917..8a2b0219bd0 100644 --- a/mozilla/extensions/wallet/cookieviewer/resources/content/CookieViewer.js +++ b/mozilla/extensions/wallet/cookieviewer/resources/content/CookieViewer.js @@ -170,7 +170,7 @@ var cookiesTreeView = { getCellValue : function(row,column) {}, getCellText : function(row,column){ var rv=""; - switch (column) { + switch (column.id) { case "domainCol": rv = cookies[row].rawHost; break; @@ -189,10 +189,10 @@ var cookiesTreeView = { isSeparator : function(index) {return false;}, isSorted: function() { return false; }, isContainer : function(index) {return false;}, - cycleHeader : function(aColId, aElt) {}, - getRowProperties : function(row,column,prop){}, - getColumnProperties : function(column,columnElement,prop){}, - getCellProperties : function(row,prop){} + cycleHeader : function(aCol) {}, + getRowProperties : function(row,prop) {}, + getColumnProperties : function(column,prop) {}, + getCellProperties : function(row,column,prop) {} }; var cookiesTree; @@ -468,9 +468,9 @@ var permissionsTreeView = { getCellValue : function(row,column) {}, getCellText : function(row,column){ var rv=""; - if (column=="siteCol") { + if (column.id=="siteCol") { rv = permissions[row].rawHost; - } else if (column=="capabilityCol") { + } else if (column.id=="capabilityCol") { rv = permissions[row].capability; } return rv; @@ -478,10 +478,10 @@ var permissionsTreeView = { isSeparator : function(index) {return false;}, isSorted: function() { return false; }, isContainer : function(index) {return false;}, - cycleHeader : function(aColId, aElt) {}, - getRowProperties : function(row,column,prop){}, - getColumnProperties : function(column,columnElement,prop){}, - getCellProperties : function(row,prop){} + cycleHeader : function(aCol) {}, + getRowProperties : function(row,prop) {}, + getColumnProperties : function(column,prop) {}, + getCellProperties : function(row,column,prop) {} }; var permissionsTree; diff --git a/mozilla/extensions/wallet/cookieviewer/resources/content/nsWalletTreeUtils.js b/mozilla/extensions/wallet/cookieviewer/resources/content/nsWalletTreeUtils.js index 20e56086d81..b2441ca611b 100644 --- a/mozilla/extensions/wallet/cookieviewer/resources/content/nsWalletTreeUtils.js +++ b/mozilla/extensions/wallet/cookieviewer/resources/content/nsWalletTreeUtils.js @@ -44,7 +44,7 @@ function DeleteSelectedItemFromTree (tree, view, table, deletedTable, removeButton, removeAllButton) { // Turn off tree selection notifications during the deletion - tree.treeBoxObject.view.selection.selectEventsSuppressed = true; + tree.view.selection.selectEventsSuppressed = true; // remove selected items from list (by setting them to null) and place in deleted list var selections = GetTreeSelections(tree); @@ -72,7 +72,7 @@ function DeleteSelectedItemFromTree // update selection var nextSelection = (selections[0] < table.length) ? selections[0] : table.length-1; - tree.treeBoxObject.view.selection.select(nextSelection); + tree.view.selection.select(nextSelection); tree.treeBoxObject.ensureRowIsVisible(nextSelection); } else { @@ -83,12 +83,12 @@ function DeleteSelectedItemFromTree } - tree.treeBoxObject.view.selection.selectEventsSuppressed = false; + tree.view.selection.selectEventsSuppressed = false; } function GetTreeSelections(tree) { var selections = []; - var select = tree.treeBoxObject.selection; + var select = tree.view.selection; if (select) { var count = select.getRangeCount(); var min = new Object(); @@ -143,8 +143,8 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, if (table[s].number == selectedNumber) { // update selection // note: we need to deselect before reselecting in order to trigger ...Selected() - tree.treeBoxObject.view.selection.select(-1); - tree.treeBoxObject.view.selection.select(s); + tree.view.selection.select(-1); + tree.view.selection.select(s); selectedRow = s; break; } diff --git a/mozilla/extensions/wallet/signonviewer/resources/content/SignonViewer.js b/mozilla/extensions/wallet/signonviewer/resources/content/SignonViewer.js index 1d5ba20ddeb..a3548c2c1c8 100644 --- a/mozilla/extensions/wallet/signonviewer/resources/content/SignonViewer.js +++ b/mozilla/extensions/wallet/signonviewer/resources/content/SignonViewer.js @@ -209,9 +209,9 @@ var signonsTreeView = { getCellValue : function(row,column) {}, getCellText : function(row,column) { var rv=""; - if (column=="siteCol") { + if (column.id=="siteCol") { rv = signons[row].host; - } else if (column=="userCol") { + } else if (column.id=="userCol") { rv = signons[row].user; } else if (column=="passwordCol") { rv = signons[row].password; @@ -221,10 +221,10 @@ var signonsTreeView = { isSeparator : function(index) { return false; }, isSorted : function() { return false; }, isContainer : function(index) { return false; }, - cycleHeader : function(aColId, aElt) {}, - getRowProperties : function(row,column,prop) {}, - getColumnProperties : function(column,columnElement,prop) {}, - getCellProperties : function(row,prop) {} + cycleHeader : function(column) {}, + getRowProperties : function(row,prop) {}, + getColumnProperties : function(column,prop) {}, + getCellProperties : function(row,column,prop) {} }; var signonsTree; @@ -400,7 +400,7 @@ var rejectsTreeView = { getCellValue : function(row,column) {}, getCellText : function(row,column){ var rv=""; - if (column=="rejectCol") { + if (column.id=="rejectCol") { rv = rejects[row].host; } return rv; @@ -408,10 +408,10 @@ var rejectsTreeView = { isSeparator : function(index) {return false;}, isSorted: function() { return false; }, isContainer : function(index) {return false;}, - cycleHeader : function(aColId, aElt) {}, - getRowProperties : function(row,column,prop){}, - getColumnProperties : function(column,columnElement,prop){}, - getCellProperties : function(row,prop){} + cycleHeader : function(column) {}, + getRowProperties : function(row,prop) {}, + getColumnProperties : function(column,prop) {}, + getCellProperties : function(row,column,prop) {} }; var rejectsTree; @@ -497,7 +497,7 @@ var nopreviewsTreeView = { getCellValue : function(row,column) {}, getCellText : function(row,column){ var rv=""; - if (column=="nopreviewCol") { + if (column.id=="nopreviewCol") { rv = nopreviews[row].host; } return rv; @@ -505,10 +505,10 @@ var nopreviewsTreeView = { isSeparator : function(index) {return false;}, isSorted: function() { return false; }, isContainer : function(index) {return false;}, - cycleHeader : function(aColId, aElt) {}, - getRowProperties : function(row,column,prop){}, - getColumnProperties : function(column,columnElement,prop){}, - getCellProperties : function(row,prop){} + cycleHeader : function(column) {}, + getRowProperties : function(row,prop) {}, + getColumnProperties : function(column,prop) {}, + getCellProperties : function(row,column,prop) {} }; var nopreviewsTree; @@ -602,7 +602,7 @@ var nocapturesTreeView = { getCellValue : function(row,column) {}, getCellText : function(row,column){ var rv=""; - if (column=="nocaptureCol") { + if (column.id=="nocaptureCol") { rv = nocaptures[row].host; } return rv; @@ -610,10 +610,10 @@ var nocapturesTreeView = { isSeparator : function(index) {return false;}, isSorted: function() { return false; }, isContainer : function(index) {return false;}, - cycleHeader : function(aColId, aElt) {}, - getRowProperties : function(row,column,prop){}, - getColumnProperties : function(column,columnElement,prop){}, - getCellProperties : function(row,prop){} + cycleHeader : function(column) {}, + getRowProperties : function(row,prop) {}, + getColumnProperties : function(column,prop) {}, + getCellProperties : function(row,column,prop) {} }; var nocapturesTree; diff --git a/mozilla/layout/forms/resources/content/select.xml b/mozilla/layout/forms/resources/content/select.xml index 44320da2572..64a4b6982a1 100644 --- a/mozilla/layout/forms/resources/content/select.xml +++ b/mozilla/layout/forms/resources/content/select.xml @@ -58,7 +58,7 @@ var obj = {}; var select = this.parentNode.parentNode.parentNode; var box = select.treeBoxObject; - var selection = box.selection; + var selection = box.view.selection; box.getCellAt(event.clientX, event.clientY, row, col, obj); // save off the last selected row @@ -86,7 +86,7 @@ var obj = {}; var select = this.parentNode.parentNode.parentNode; var box = select.treeBoxObject; - var selection = box.selection; + var selection = box.view.selection; box.getCellAt(event.clientX, event.clientY, row, col, obj); if (row.value == -1 || select.contentView.getItemAtIndex(row.value).disabled) @@ -171,8 +171,8 @@ onget="return this.QueryInterface(Components.interfaces.nsISelectElement);" readonly="true"/> + onget="return this.view.selection.currentIndex;" + onset="return this.view.selection.currentIndex=val;"/> @@ -223,7 +223,7 @@ var f = this.treeBoxObject.getFirstVisibleRow(); var i = 0; if (f > 0) { - var p = this.treeBoxObject.getPageCount(); + var p = this.treeBoxObject.getPageLength(); if (f - p >= 0) i = aCurrentIndex - p; else @@ -237,7 +237,7 @@ + onget="return this.view.selection.currentIndex;" + onset="return this.view.selection.currentIndex=val;"/> @@ -223,7 +223,7 @@ var f = this.treeBoxObject.getFirstVisibleRow(); var i = 0; if (f > 0) { - var p = this.treeBoxObject.getPageCount(); + var p = this.treeBoxObject.getPageLength(); if (f - p >= 0) i = aCurrentIndex - p; else @@ -237,7 +237,7 @@ GetClientX(&x); aMouseEvent->GetClientY(&y); PRInt32 row; - nsXPIDLString colId, obj; + nsCOMPtr col; + nsCAutoString obj; + + obx->GetCellAt(x, y, &row, getter_AddRefs(col), obj); - obx->GetCellAt(x, y, &row, getter_Copies(colId), getter_Copies(obj)); - // determine if we are going to need a titletip // XXX check the disabletitletips attribute on the tree content mNeedTitletip = PR_FALSE; - if (row >= 0 && obj.Equals(NS_LITERAL_STRING("text"))) { + if (row >= 0 && obj.Equals(NS_LITERAL_CSTRING("text"))) { nsCOMPtr view; obx->GetView(getter_AddRefs(view)); PRBool isCropped; - obx->IsCellCropped(row, colId, &isCropped); + obx->IsCellCropped(row, col, &isCropped); mNeedTitletip = isCropped; } - if (mCurrentTooltip && - (row != mLastTreeRow || !mLastTreeCol.Equals(colId))) { + if (mCurrentTooltip && (row != mLastTreeRow || col != mLastTreeCol)) { HideTooltip(); } mLastTreeRow = row; - mLastTreeCol.Assign(colId); + mLastTreeCol = col; } } #endif @@ -390,7 +390,7 @@ nsXULTooltipListener::ShowTooltip() #ifdef MOZ_XUL if (!mIsSourceTree) { mLastTreeRow = -1; - mLastTreeCol.Truncate(); + mLastTreeCol = nsnull; } #endif @@ -439,11 +439,10 @@ nsXULTooltipListener::ShowTooltip() #ifdef DEBUG_crap static void GetTreeCellCoords(nsITreeBoxObject* aTreeBox, nsIContent* aSourceNode, - PRInt32 aRow, nsAutoString aCol, PRInt32* aX, PRInt32* aY) + PRInt32 aRow, nsITreeColumn* aCol, PRInt32* aX, PRInt32* aY) { PRInt32 junk; - const PRUnichar empty[] = {'\0'}; - aTreeBox->GetCoordsForCellItem(aRow, aCol.get(), empty, aX, aY, &junk, &junk); + aTreeBox->GetCoordsForCellItem(aRow, aCol, NS_LITERAL_CSTRING(""), aX, aY, &junk, &junk); nsCOMPtr xulEl(do_QueryInterface(aSourceNode)); nsCOMPtr bx; xulEl->GetBoxObject(getter_AddRefs(bx)); @@ -457,13 +456,13 @@ GetTreeCellCoords(nsITreeBoxObject* aTreeBox, nsIContent* aSourceNode, static void SetTitletipLabel(nsITreeBoxObject* aTreeBox, nsIContent* aTooltip, - PRInt32 aRow, nsAutoString aCol) + PRInt32 aRow, nsITreeColumn* aCol) { nsCOMPtr view; aTreeBox->GetView(getter_AddRefs(view)); nsAutoString label; - view->GetCellText(aRow, aCol.get(), label); + view->GetCellText(aRow, aCol, label); aTooltip->SetAttr(nsnull, nsXULAtoms::label, label, PR_TRUE); } @@ -493,7 +492,7 @@ nsXULTooltipListener::LaunchTooltip(nsIContent* aTarget, PRInt32 aX, PRInt32 aY) GetSourceTreeBoxObject(getter_AddRefs(obx)); #ifdef DEBUG_crap GetTreeCellCoords(obx, mSourceNode, - mLastTreeRow, mLastTreeCol, &x, &y); + mLastTreeRow, mLastTreeCol, &x, &y); #endif SetTitletipLabel(obx, mCurrentTooltip, mLastTreeRow, mLastTreeCol); diff --git a/mozilla/layout/xul/base/src/nsXULTooltipListener.h b/mozilla/layout/xul/base/src/nsXULTooltipListener.h index ba94d9d2a40..ba5711bc422 100644 --- a/mozilla/layout/xul/base/src/nsXULTooltipListener.h +++ b/mozilla/layout/xul/base/src/nsXULTooltipListener.h @@ -52,6 +52,7 @@ #include "nsString.h" #ifdef MOZ_XUL #include "nsITreeBoxObject.h" +#include "nsITreeColumns.h" #endif class nsXULTooltipListener : public nsIDOMMouseListener, @@ -151,7 +152,7 @@ protected: PRBool mIsSourceTree; PRBool mNeedTitletip; PRInt32 mLastTreeRow; - nsAutoString mLastTreeCol; + nsCOMPtr mLastTreeCol; #endif }; diff --git a/mozilla/layout/xul/base/src/tree/public/Makefile.in b/mozilla/layout/xul/base/src/tree/public/Makefile.in index 8e819a9812a..7917182c742 100644 --- a/mozilla/layout/xul/base/src/tree/public/Makefile.in +++ b/mozilla/layout/xul/base/src/tree/public/Makefile.in @@ -29,8 +29,9 @@ include $(DEPTH)/config/autoconf.mk MODULE = layout XPIDL_MODULE = layout_xul_tree -XPIDLSRCS= nsITreeView.idl \ - nsITreeSelection.idl \ +XPIDLSRCS= nsITreeColumns.idl \ + nsITreeView.idl \ + nsITreeSelection.idl \ nsITreeBoxObject.idl \ nsITreeContentView.idl \ $(NULL) diff --git a/mozilla/layout/xul/base/src/tree/public/nsITreeBoxObject.idl b/mozilla/layout/xul/base/src/tree/public/nsITreeBoxObject.idl index 0782d772f39..d6412df36ce 100644 --- a/mozilla/layout/xul/base/src/tree/public/nsITreeBoxObject.idl +++ b/mozilla/layout/xul/base/src/tree/public/nsITreeBoxObject.idl @@ -21,7 +21,8 @@ * * Contributor(s): * Original Author: David W. Hyatt (hyatt@netscape.com) - * Ben Goodger + * Ben Goodger + * Jan Varga * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -42,11 +43,17 @@ interface nsITreeView; interface nsITreeSelection; -interface nsIDOMEvent; +interface nsITreeColumn; +interface nsITreeColumns; [scriptable, uuid(44481385-B1DA-480a-9026-1F0232C4EE59)] interface nsITreeBoxObject : nsISupports { + /** + * Obtain the columns. + */ + readonly attribute nsITreeColumns columns; + /** * The view that backs the tree and that supplies it with its data. * It is dynamically settable, either using a view attribute on the @@ -64,31 +71,11 @@ interface nsITreeBoxObject : nsISupports */ readonly attribute nsIDOMElement treeBody; - /** - * Obtains the selection from the view. - */ - readonly attribute nsITreeSelection selection; - /** * Obtain the height of a row. */ readonly attribute long rowHeight; - /** - * Get the index of the specified column. - */ - long getColumnIndex(in wstring colID); - - /** - * Get the ID of the specified column. - */ - AString getColumnID(in long colIndex); - - /** - * Get the index of the primary column. - */ - long getKeyColumnIndex(); - /** * Get the index of the first visible row. */ @@ -102,7 +89,7 @@ interface nsITreeBoxObject : nsISupports /** * Gets the number of possible visible rows. */ - long getPageCount(); + long getPageLength(); /** * Ensures that a row at a given index is visible. @@ -133,10 +120,9 @@ interface nsITreeBoxObject : nsISupports * Invalidation methods for fine-grained painting control. */ void invalidate(); - void invalidateColumn(in wstring colID); + void invalidateColumn(in nsITreeColumn col); void invalidateRow(in long index); - void invalidateCell(in long row, in wstring colID); - void invalidatePrimaryCell(in long row); + void invalidateCell(in long row, in nsITreeColumn col); void invalidateRange(in long startIndex, in long endIndex); /** @@ -151,18 +137,18 @@ interface nsITreeBoxObject : nsISupports * ChildElt is the pseudoelement hit: this can have values of * "cell", "twisty", "image", and "text". */ - void getCellAt(in long x, in long y, out long row, out wstring colID, out wstring childElt); + void getCellAt(in long x, in long y, out long row, out nsITreeColumn col, out ACString childElt); /** * Find the coordinates of an element within a specific cell. */ - void getCoordsForCellItem(in long row, in wstring colID, in wstring element, + void getCoordsForCellItem(in long row, in nsITreeColumn col, in ACString element, out long x, out long y, out long width, out long height); /** * Determine if the text of a cell is being cropped or not. */ - boolean isCellCropped(in long row, in AString colID); + boolean isCellCropped(in long row, in nsITreeColumn col); /** * The view is responsible for calling these notification methods when @@ -185,21 +171,8 @@ interface nsITreeBoxObject : nsISupports */ void endUpdateBatch(); - /** - * Drag handlers, installed from XBL, called when drags occur to handle painting - */ - void onDragEnter ( in nsIDOMEvent event ) ; - void onDragExit ( in nsIDOMEvent event ) ; - void onDragOver ( in nsIDOMEvent event) ; - void onDragDrop ( in nsIDOMEvent event ) ; - /** * Called on a theme switch to flush out the tree's style and image caches. */ void clearStyleAndImageCaches(); }; - -%{C++ -// Initializer, -%} - diff --git a/mozilla/layout/xul/base/src/tree/public/nsITreeColumns.idl b/mozilla/layout/xul/base/src/tree/public/nsITreeColumns.idl new file mode 100644 index 00000000000..fff42500c1f --- /dev/null +++ b/mozilla/layout/xul/base/src/tree/public/nsITreeColumns.idl @@ -0,0 +1,119 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Jan Varga. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsITreeColumns; +interface nsIDOMElement; +interface nsIAtom; + +[scriptable, uuid(58a8574d-15a8-4678-99a5-e1be56104093)] +interface nsITreeColumn : nsISupports +{ + readonly attribute nsIDOMElement element; + + readonly attribute nsITreeColumns columns; + + readonly attribute long x; + readonly attribute long width; + + readonly attribute AString id; + [noscript] void getIdConst([shared] out wstring idConst); + [noscript] readonly attribute nsIAtom atom; + + readonly attribute long index; + + readonly attribute boolean primary; + readonly attribute boolean cycler; + readonly attribute boolean editable; + + const short TYPE_TEXT = 1; + const short TYPE_CHECKBOX = 2; + const short TYPE_PROGRESSMETER = 3; + readonly attribute short type; + + nsITreeColumn getNext(); + nsITreeColumn getPrevious(); + + void invalidate(); +}; + +interface nsITreeBoxObject; + +[scriptable, uuid(fcc7b6b5-f7d7-4e57-abd1-080602deb21d)] +interface nsITreeColumns : nsISupports +{ + /** + * The tree widget for these columns. + */ + readonly attribute nsITreeBoxObject tree; + + /** + * The number of columns. + */ + readonly attribute long count; + + /** + * Get the first/last column. + */ + nsITreeColumn getFirstColumn(); + nsITreeColumn getLastColumn(); + + /** + * Attribute based column getters. + */ + nsITreeColumn getPrimaryColumn(); + nsITreeColumn getSortedColumn(); + nsITreeColumn getKeyColumn(); + + /** + * Get the column for the given element. + */ + nsITreeColumn getColumnFor(in nsIDOMElement element); + + /** + * Parametric column getters. + */ + nsITreeColumn getNamedColumn(in AString id); + nsITreeColumn getColumnAt(in long index); + + /** + * This method is called whenever a treecol is added or removed and + * the column cache needs to be rebuilt. + */ + void invalidateColumns(); + + void restoreNaturalOrder(); +}; diff --git a/mozilla/layout/xul/base/src/tree/public/nsITreeContentView.idl b/mozilla/layout/xul/base/src/tree/public/nsITreeContentView.idl index 1a0aa5d71db..c80f25441e7 100644 --- a/mozilla/layout/xul/base/src/tree/public/nsITreeContentView.idl +++ b/mozilla/layout/xul/base/src/tree/public/nsITreeContentView.idl @@ -42,11 +42,6 @@ [scriptable, uuid(972AE9FF-C7B3-4b60-A51E-A20A9DE36947)] interface nsITreeContentView : nsISupports { - /** - * The element in the DOM which this view uses as root content. - */ - readonly attribute nsIDOMElement root; - /** * Retrieve the content item associated with the specified index. */ diff --git a/mozilla/layout/xul/base/src/tree/public/nsITreeSelection.idl b/mozilla/layout/xul/base/src/tree/public/nsITreeSelection.idl index c34b94766bc..aa8bf796525 100644 --- a/mozilla/layout/xul/base/src/tree/public/nsITreeSelection.idl +++ b/mozilla/layout/xul/base/src/tree/public/nsITreeSelection.idl @@ -21,7 +21,7 @@ * * Contributor(s): * Original Author: David W. Hyatt (hyatt@netscape.com) - * Håkan Waara (hwaara@chello.se) + * HÃ¥kan Waara (hwaara@chello.se) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -144,8 +144,3 @@ interface nsITreeSelection : nsISupports */ readonly attribute long shiftSelectPivot; }; - -%{C++ -// Initializer, -%} - diff --git a/mozilla/layout/xul/base/src/tree/public/nsITreeView.idl b/mozilla/layout/xul/base/src/tree/public/nsITreeView.idl index dc752a85a0d..1218b19d9b8 100644 --- a/mozilla/layout/xul/base/src/tree/public/nsITreeView.idl +++ b/mozilla/layout/xul/base/src/tree/public/nsITreeView.idl @@ -19,8 +19,9 @@ * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * - * Contributor(s): * Original Author: David W. Hyatt (hyatt@netscape.com) + * Contributor(s): + * Jan Varga * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -41,11 +42,12 @@ #include "domstubs.idl" interface nsITreeSelection; +interface nsITreeColumn; [scriptable, uuid(58A53734-1837-4f30-9BFD-EE58F63CA049)] interface nsITreeView : nsISupports { - /** + /** * The total number of rows in the tree (including the offscreen rows). */ readonly attribute long rowCount; @@ -62,20 +64,20 @@ interface nsITreeView : nsISupports */ void getRowProperties(in long index, in nsISupportsArray properties); - /** + /** * An atomized list of properties for a given cell. Each property, x, that * the view gives back will cause the pseudoclass :moz-tree-cell-x * to be matched on the ::moz-tree-cell pseudoelement. */ - void getCellProperties(in long row, in wstring colID, in nsISupportsArray properties); + void getCellProperties(in long row, in nsITreeColumn col, in nsISupportsArray properties); - /** + /** * Called to get properties to paint a column background. For shading the sort * column, etc. */ - void getColumnProperties(in wstring colID, in nsIDOMElement colElt, in nsISupportsArray properties); + void getColumnProperties(in nsITreeColumn col, in nsISupportsArray properties); - /** + /** * Methods that can be used to test whether or not a twisty should be drawn, * and if so, whether an open or closed twisty should be used. */ @@ -83,11 +85,10 @@ interface nsITreeView : nsISupports boolean isContainerOpen(in long index); boolean isContainerEmpty(in long index); - /** + /** * isSeparator is used to determine if the row at index is a separator. - * A value of true will result in the tree drawing a horizontal line. - * The tree uses the border properties on the ::moz-tree-separator - * pseudoclass to draw the separator. + * A value of true will result in the tree drawing a horizontal separator. + * The tree uses the ::moz-tree-separator pseudoclass to draw the separator. */ boolean isSeparator(in long index); @@ -97,79 +98,79 @@ interface nsITreeView : nsISupports */ boolean isSorted(); + const short DROP_BEFORE = -1; + const short DROP_ON = 0; + const short DROP_AFTER = 1; /** * Methods used by the drag feedback code to determine if a drag is allowable at * the current location. To get the behavior where drops are only allowed on - * items, such as the mailNews folder pane, always return false from |canDropBeforeAfter()|. + * items, such as the mailNews folder pane, always return false when + * the orientation is not DROP_ON. */ - boolean canDropOn (in long index); - boolean canDropBeforeAfter (in long index, in boolean before); + boolean canDrop(in long index, in long orientation); /** * Called when the user drops something on this view. The |orientation| param * specifies before/on/after the given |row|. */ - const short inDropBefore = 0; - const short inDropOn = 1; - const short inDropAfter = 2; void drop(in long row, in long orientation); - /** - * Methods used by the tree to draw vertical lines in the tree. + /** + * Methods used by the tree to draw thread lines in the tree. * getParentIndex is used to obtain the index of a parent row. * If there is no parent row, getParentIndex returns -1. */ long getParentIndex(in long rowIndex); - /** - * HasNextSibling is used to determine if the row at rowIndex has a nextSibling + /** + * hasNextSibling is used to determine if the row at rowIndex has a nextSibling * that occurs *after* the index specified by afterIndex. Code that is forced * to march down the view looking at levels can optimize the march by starting * at afterIndex+1. */ boolean hasNextSibling(in long rowIndex, in long afterIndex); - /** + /** * The level is an integer value that represents * the level of indentation. It is multiplied by the width specified in the * :moz-tree-indentation pseudoelement to compute the exact indendation. */ long getLevel(in long index); - /** + /** * The image path for a given cell. For defining an icon for a cell. * If the empty string is returned, the :moz-tree-image pseudoelement * will be used. */ - AString getImageSrc(in long row, in wstring colID); + AString getImageSrc(in long row, in nsITreeColumn col); /** * The progress mode for a given cell. This method is only called for * columns of type |progressmeter|. */ - const short progressNormal = 1; - const short progressUndetermined = 2; - const short progressNone = 3; - long getProgressMode(in long row, in wstring colID); + const short PROGRESS_NORMAL = 1; + const short PROGRESS_UNDETERMINED = 2; + const short PROGRESS_NONE = 3; + long getProgressMode(in long row, in nsITreeColumn col); - /** + /** * The value for a given cell. This method is only called for columns * of type other than |text|. */ - AString getCellValue(in long row, in wstring colID); + AString getCellValue(in long row, in nsITreeColumn col); - /** + /** * The text for a given cell. If a column consists only of an image, then * the empty string is returned. */ - AString getCellText(in long row, in wstring colID); + AString getCellText(in long row, in nsITreeColumn col); /** * Called during initialization to link the view to the front end box object. */ void setTree(in nsITreeBoxObject tree); - /** + /** * Called on the view when an item is opened or closed. */ void toggleOpenState(in long index); @@ -177,50 +178,50 @@ interface nsITreeView : nsISupports /** * Called on the view when a header is clicked. */ - void cycleHeader(in wstring colID, in nsIDOMElement elt); + void cycleHeader(in nsITreeColumn col); - /** + /** * Should be called from a XUL onselect handler whenever the selection changes. - * XXX Should this be done automatically? */ void selectionChanged(); - /** + /** * Called on the view when a cell in a non-selectable cycling column (e.g., unread/flag/etc.) is clicked. */ - void cycleCell(in long row, in wstring colID); + void cycleCell(in long row, in nsITreeColumn col); - /** - * isEditable is called to ask the view if the cell contents are editable. + /** + * isEditable is called to ask the view if the cell contents are editable. * A value of true will result in the tree popping up a text field when * the user tries to inline edit the cell. */ - boolean isEditable(in long row, in wstring colID); + boolean isEditable(in long row, in nsITreeColumn col); - /** + /** + * setCellValue is called when the value of the cell has been set by the user. + * This method is only called for columns of type other than |text|. + */ + void setCellValue(in long row, in nsITreeColumn col, in AString value); + + /** * setCellText is called when the contents of the cell have been edited by the user. */ - void setCellText(in long row, in wstring colID, in wstring value); + void setCellText(in long row, in nsITreeColumn col, in AString value); - /** + /** * A command API that can be used to invoke commands on the selection. The tree * will automatically invoke this method when certain keys are pressed. For example, * when the DEL key is pressed, performAction will be called with the "delete" string. */ void performAction(in wstring action); - /** + /** * A command API that can be used to invoke commands on a specific row. */ void performActionOnRow(in wstring action, in long row); - /** + /** * A command API that can be used to invoke commands on a specific cell. */ - void performActionOnCell(in wstring action, in long row, in wstring colID); + void performActionOnCell(in wstring action, in long row, in nsITreeColumn col); }; - -%{C++ -// Initializer, -%} - diff --git a/mozilla/layout/xul/base/src/tree/src/Makefile.in b/mozilla/layout/xul/base/src/tree/src/Makefile.in index 459e1b867db..d77338a03d5 100644 --- a/mozilla/layout/xul/base/src/tree/src/Makefile.in +++ b/mozilla/layout/xul/base/src/tree/src/Makefile.in @@ -45,22 +45,22 @@ REQUIRES = xpcom \ webshell \ $(NULL) -CPPSRCS = \ - nsTreeBodyFrame.cpp \ - nsTreeBoxObject.cpp \ - nsTreeColFrame.cpp \ - nsTreeSelection.cpp \ - nsTreeUtils.cpp \ - nsTreeContentView.cpp \ - $(NULL) +CPPSRCS = \ + nsTreeBodyFrame.cpp \ + nsTreeBoxObject.cpp \ + nsTreeColFrame.cpp \ + nsTreeColumns.cpp \ + nsTreeContentView.cpp \ + nsTreeImageListener.cpp \ + nsTreeSelection.cpp \ + nsTreeStyleCache.cpp \ + nsTreeUtils.cpp \ + $(NULL) -EXPORTS = \ - nsTreeBodyFrame.h \ - nsTreeColFrame.h \ - nsTreeSelection.h \ - nsTreeUtils.h \ - nsTreeContentView.h \ - $(NULL) +EXPORTS = \ + nsTreeColFrame.h \ + nsTreeUtils.h \ + $(NULL) LOCAL_INCLUDES = \ -I$(srcdir) \ diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 59bbc8fc086..c8a580e730f 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -94,7 +94,6 @@ #include "imgIContainer.h" #include "imgIContainerObserver.h" #include "imgILoader.h" -#include "nsStyleSet.h" #ifdef IBMBIDI #include "nsBidiPresUtils.h" @@ -102,6 +101,8 @@ #define ELLIPSIS "..." +static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); + // Enumeration function that cancels all the image requests in our cache PR_STATIC_CALLBACK(PRBool) CancelImageRequest(nsHashKey* aKey, void* aData, void* aClosure) @@ -117,190 +118,6 @@ CancelImageRequest(nsHashKey* aKey, void* aData, void* aClosure) return PR_TRUE; } -// The style context cache impl -nsStyleContext* -nsTreeStyleCache::GetStyleContext(nsICSSPseudoComparator* aComparator, - nsIPresContext* aPresContext, - nsIContent* aContent, - nsStyleContext* aContext, - nsIAtom* aPseudoElement, - nsISupportsArray* aInputWord) -{ - PRUint32 count; - aInputWord->Count(&count); - nsDFAState startState(0); - nsDFAState* currState = &startState; - - // Go ahead and init the transition table. - if (!mTransitionTable) { - // Automatic miss. Build the table - mTransitionTable = - new nsObjectHashtable(nsnull, nsnull, DeleteDFAState, nsnull); - if (!mTransitionTable) - return nsnull; - } - - // The first transition is always made off the supplied pseudo-element. - nsTransitionKey key(currState->GetStateID(), aPseudoElement); - currState = NS_STATIC_CAST(nsDFAState*, mTransitionTable->Get(&key)); - - if (!currState) { - // We had a miss. Make a new state and add it to our hash. - currState = new nsDFAState(mNextState); - if (!currState) - return nsnull; - mNextState++; - mTransitionTable->Put(&key, currState); - } - - for (PRUint32 i = 0; i < count; i++) - { - nsCOMPtr pseudo = getter_AddRefs(NS_STATIC_CAST(nsIAtom*, aInputWord->ElementAt(i))); - nsTransitionKey key(currState->GetStateID(), pseudo); - currState = NS_STATIC_CAST(nsDFAState*, mTransitionTable->Get(&key)); - - if (!currState) { - // We had a miss. Make a new state and add it to our hash. - currState = new nsDFAState(mNextState); - if (!currState) - return nsnull; - - mNextState++; - mTransitionTable->Put(&key, currState); - } - } - - // We're in a final state. - // Look up our style context for this state. - nsStyleContext* result = nsnull; - if (mCache) - result = NS_STATIC_CAST(nsStyleContext*, mCache->Get(currState)); - if (!result) { - // We missed the cache. Resolve this pseudo-style. - result = aPresContext->StyleSet()-> - ResolvePseudoStyleFor(aContent, aPseudoElement, - aContext, aComparator).get(); - - // Put the style context in our table, transferring the owning reference to the table. - if (!mCache) { - mCache = new nsObjectHashtable(nsnull, nsnull, ReleaseStyleContext, nsnull); - if (!mCache) - return nsnull; - } - mCache->Put(currState, result); - } - - return result; -} - -/* static */ PRBool PR_CALLBACK -nsTreeStyleCache::DeleteDFAState(nsHashKey *aKey, - void *aData, - void *closure) -{ - nsDFAState* entry = NS_STATIC_CAST(nsDFAState*, aData); - delete entry; - return PR_TRUE; -} - -/* static */ PRBool PR_CALLBACK -nsTreeStyleCache::ReleaseStyleContext(nsHashKey *aKey, - void *aData, - void *closure) -{ - nsStyleContext* context = NS_STATIC_CAST(nsStyleContext*, aData); - context->Release(); - return PR_TRUE; -} - -// Column class that caches all the info about our column. -nsTreeColumn::nsTreeColumn(nsIContent* aColElement, nsIFrame* aFrame) -:mNext(nsnull) -{ - mColFrame = aFrame; - mColElement = aColElement; - - // Fetch the ID. - mColElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, mID); - - // If we have an ID, cache the ID as an atom. - if (!mID.IsEmpty()) { - mIDAtom = do_GetAtom(mID); - } - - const nsStyleVisibility* vis = aFrame->GetStyleVisibility(); - - // Fetch the crop style. - mCropStyle = 0; - nsAutoString crop; - mColElement->GetAttr(kNameSpaceID_None, nsXULAtoms::crop, crop); - if (crop.Equals(NS_LITERAL_STRING("center"))) - mCropStyle = 1; - else if (crop.Equals(NS_LITERAL_STRING("left")) || - crop.Equals(NS_LITERAL_STRING("start"))) - mCropStyle = 2; - - // Cache our text alignment policy. - const nsStyleText* textStyle = aFrame->GetStyleText(); - - mTextAlignment = textStyle->mTextAlign; - if (mTextAlignment == 0 || mTextAlignment == 2) { // Left or Right - if (vis->mDirection == NS_STYLE_DIRECTION_RTL) - mTextAlignment = 2 - mTextAlignment; // Right becomes left, left becomes right. - } - - // Figure out if we're the primary column (that has to have indentation - // and twisties drawn. - mIsPrimaryCol = PR_FALSE; - nsAutoString primary; - mColElement->GetAttr(kNameSpaceID_None, nsXULAtoms::primary, primary); - if (primary.Equals(NS_LITERAL_STRING("true"))) - mIsPrimaryCol = PR_TRUE; - - // Figure out if we're a cycling column (one that doesn't cause a selection - // to happen). - mIsCyclerCol = PR_FALSE; - nsAutoString cycler; - mColElement->GetAttr(kNameSpaceID_None, nsXULAtoms::cycler, cycler); - if (cycler.Equals(NS_LITERAL_STRING("true"))) - mIsCyclerCol = PR_TRUE; - - // Figure out our column type. Default type is text. - mType = eText; - nsAutoString type; - mColElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, type); - if (type.Equals(NS_LITERAL_STRING("checkbox"))) - mType = eCheckbox; - else if (type.Equals(NS_LITERAL_STRING("progressmeter"))) - mType = eProgressMeter; - - // Cache our index. - mColIndex = -1; - nsIContent* parent = mColElement->GetParent(); - PRUint32 count = parent->GetChildCount(); - PRInt32 j = 0; - for (PRUint32 i = 0; i < count; i++) { - nsIContent *child = parent->GetChildAt(i); - nsINodeInfo *ni = child->GetNodeInfo(); - - if (ni && ni->Equals(nsXULAtoms::treecol, kNameSpaceID_XUL)) { - if (child == mColElement) { - mColIndex = j; - break; - } - j++; - } - } -} - -inline nscoord nsTreeColumn::GetWidth() -{ - if (mColFrame) { - return mColFrame->GetSize().width; - } - return 0; -} - // // NS_NewTreeFrame // @@ -338,12 +155,12 @@ NS_INTERFACE_MAP_END_INHERITING(nsLeafBoxFrame) // Constructor nsTreeBodyFrame::nsTreeBodyFrame(nsIPresShell* aPresShell) :nsLeafBoxFrame(aPresShell), mPresContext(nsnull), mTreeBoxObject(nsnull), mImageCache(nsnull), - mColumns(nsnull), mScrollbar(nsnull), mTopRowIndex(0), mRowHeight(0), mIndentation(0), mStringWidth(-1), - mFocused(PR_FALSE), mColumnsDirty(PR_TRUE), mDropAllowed(PR_FALSE), mHasFixedRowCount(PR_FALSE), - mVerticalOverflow(PR_FALSE), mImageGuard(PR_FALSE), mReflowCallbackPosted(PR_FALSE), - mDropRow(-1), mDropOrient(-1), mScrollLines(0), mTimer(nsnull), mValueArray(~PRInt32(0)), - mUpdateBatchNest(0), mRowCount(0) + mScrollbar(nsnull), mTopRowIndex(0), mRowHeight(0), mIndentation(0), mStringWidth(-1), + mFocused(PR_FALSE), mHasFixedRowCount(PR_FALSE), + mVerticalOverflow(PR_FALSE), mReflowCallbackPosted(PR_FALSE), + mUpdateBatchNest(0), mRowCount(0), mSlots(nsnull) { + mColumns = new nsTreeColumns(nsnull); NS_NewISupportsArray(getter_AddRefs(mScratchArray)); } @@ -354,6 +171,7 @@ nsTreeBodyFrame::~nsTreeBodyFrame() mImageCache->Enumerate(CancelImageRequest); delete mImageCache; } + delete mSlots; } NS_IMETHODIMP_(nsrefcnt) @@ -406,19 +224,16 @@ AdjustForBorderPadding(nsStyleContext* aContext, nsRect& aRect) NS_IMETHODIMP nsTreeBodyFrame::Init(nsIPresContext* aPresContext, nsIContent* aContent, - nsIFrame* aParent, nsStyleContext* aContext, nsIFrame* aPrevInFlow) + nsIFrame* aParent, nsStyleContext* aContext, nsIFrame* aPrevInFlow) { mPresContext = aPresContext; nsresult rv = nsLeafBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); nsBoxFrame::CreateViewForFrame(aPresContext, this, aContext, PR_TRUE); - nsIView* ourView = nsLeafBoxFrame::GetView(); + nsLeafBoxFrame::GetView()->CreateWidget(kWidgetCID); - static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); - - ourView->CreateWidget(kWidgetCID); - mTreeWidget = ourView->GetWidget(); mIndentation = GetIndentation(); mRowHeight = GetRowHeight(); + return rv; } @@ -427,25 +242,25 @@ nsTreeBodyFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize) { EnsureView(); - nsCOMPtr baseElement; - GetBaseElement(getter_AddRefs(baseElement)); + nsIContent* baseElement = GetBaseElement(); PRInt32 desiredRows; if (baseElement->Tag() == nsHTMLAtoms::select && baseElement->IsContentOfType(nsIContent::eHTML)) { - aSize.width = CalcMaxRowWidth(aBoxLayoutState); + aSize.width = CalcMaxRowWidth(); nsAutoString size; baseElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::size, size); if (!size.IsEmpty()) { PRInt32 err; desiredRows = size.ToInteger(&err); mHasFixedRowCount = PR_TRUE; - mPageCount = desiredRows; + mPageLength = desiredRows; } else { desiredRows = 1; } - } else { + } + else { // tree aSize.width = 0; nsAutoString rows; @@ -453,7 +268,7 @@ nsTreeBodyFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize) if (!rows.IsEmpty()) { PRInt32 err; desiredRows = rows.ToInteger(&err); - mPageCount = desiredRows; + mPageLength = desiredRows; } else { desiredRows = 0; @@ -470,7 +285,7 @@ nsTreeBodyFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize) } nscoord -nsTreeBodyFrame::CalcMaxRowWidth(nsBoxLayoutState& aState) +nsTreeBodyFrame::CalcMaxRowWidth() { if (mStringWidth != -1) return mStringWidth; @@ -484,18 +299,17 @@ nsTreeBodyFrame::CalcMaxRowWidth(nsBoxLayoutState& aState) nscoord rowWidth; nsTreeColumn* col; - EnsureColumns(); nsCOMPtr rc; mPresContext->PresShell()->CreateRenderingContext(this, getter_AddRefs(rc)); for (PRInt32 row = 0; row < mRowCount; ++row) { rowWidth = 0; - col = mColumns; + col = mColumns->GetFirstColumn(); while (col) { nscoord desiredWidth, currentWidth; - GetCellWidth(row, col->GetID(), rc, desiredWidth, currentWidth); + GetCellWidth(row, col, rc, desiredWidth, currentWidth); rowWidth += desiredWidth; col = col->GetNext(); } @@ -517,10 +331,9 @@ nsTreeBodyFrame::Destroy(nsIPresContext* aPresContext) mReflowCallbackPosted = PR_FALSE; } - // Delete our column structures. - delete mColumns; - mColumns = nsnull; - + if (mColumns) + mColumns->SetTree(nsnull); + // Save off our info into the box object. EnsureBoxObject(); if (mTreeBoxObject) { @@ -555,9 +368,7 @@ void nsTreeBodyFrame::EnsureBoxObject() { if (!mTreeBoxObject) { - nsCOMPtr parent; - GetBaseElement(getter_AddRefs(parent)); - + nsIContent* parent = GetBaseElement(); if (parent) { nsCOMPtr nsDoc = do_QueryInterface(parent->GetDocument()); if (!nsDoc) // there may be no document, if we're called from Destroy() @@ -567,8 +378,8 @@ nsTreeBodyFrame::EnsureBoxObject() nsDoc->GetBoxObjectFor(domElem, getter_AddRefs(box)); if (box) { - nsCOMPtr treeBox(do_QueryInterface(box)); - SetBoxObject(treeBox); + mTreeBoxObject = do_QueryInterface(box); + mColumns->SetTree(mTreeBoxObject); } } } @@ -621,7 +432,7 @@ nsTreeBodyFrame::EnsureView() view = do_QueryInterface(builder); if (!view) { - // No tree builder, create an tree content view. + // No tree builder, create a tree content view. nsCOMPtr contentView; NS_NewTreeContentView(getter_AddRefs(contentView)); if (contentView) @@ -654,9 +465,9 @@ nsTreeBodyFrame::ReflowFinished(nsIPresShell* aPresShell, PRBool* aFlushFlag) if (mView) { CalcInnerBox(); if (!mHasFixedRowCount) - mPageCount = mInnerBox.height / mRowHeight; + mPageLength = mInnerBox.height / mRowHeight; - PRInt32 lastPageTopRow = PR_MAX(0, mRowCount - mPageCount); + PRInt32 lastPageTopRow = PR_MAX(0, mRowCount - mPageLength); if (mTopRowIndex > lastPageTopRow) ScrollToRow(lastPageTopRow); @@ -685,8 +496,7 @@ nsTreeBodyFrame::ReflowFinished(nsIPresShell* aPresShell, PRBool* aFlushFlag) NS_IMETHODIMP nsTreeBodyFrame::GetView(nsITreeView * *aView) { EnsureView(); - *aView = mView; - NS_IF_ADDREF(*aView); + NS_IF_ADDREF(*aView = mView); return NS_OK; } @@ -709,8 +519,6 @@ NS_IMETHODIMP nsTreeBodyFrame::SetView(nsITreeView * aView) // Only reset the top row index and delete the columns if we had an old non-null view. mTopRowIndex = 0; - delete mColumns; - mColumns = nsnull; } // Tree, meet the view. @@ -727,7 +535,8 @@ NS_IMETHODIMP nsTreeBodyFrame::SetView(nsITreeView * aView) mView->GetSelection(getter_AddRefs(sel)); if (sel) { sel->SetTree(mTreeBoxObject); - } else { + } + else { NS_NewTreeSelection(mTreeBoxObject, getter_AddRefs(sel)); mView->SetSelection(sel); } @@ -782,210 +591,121 @@ nsTreeBodyFrame::GetTreeBody(nsIDOMElement** aElement) return mContent->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aElement); } -NS_IMETHODIMP nsTreeBodyFrame::GetSelection(nsITreeSelection** aSelection) +NS_IMETHODIMP +nsTreeBodyFrame::GetColumns(nsITreeColumns** aColumns) { - if (mView) - return mView->GetSelection(aSelection); - - *aSelection = nsnull; + NS_IF_ADDREF(*aColumns = mColumns); return NS_OK; } -NS_IMETHODIMP nsTreeBodyFrame::GetRowHeight(PRInt32* _retval) +NS_IMETHODIMP +nsTreeBodyFrame::GetRowHeight(PRInt32* _retval) { - float t2p; - t2p = mPresContext->TwipsToPixels(); + float t2p = mPresContext->TwipsToPixels(); *_retval = NSToCoordRound((float) mRowHeight * t2p); return NS_OK; } -NS_IMETHODIMP nsTreeBodyFrame::GetColumnIndex(const PRUnichar *aColID, PRInt32 *_retval) -{ - *_retval = -1; - for (nsTreeColumn* currCol = mColumns; currCol; currCol = currCol->GetNext()) { - if (currCol->GetID().Equals(aColID)) { - *_retval = currCol->GetColIndex(); - break; - } - } - - return NS_OK; -} - -NS_IMETHODIMP nsTreeBodyFrame::GetColumnID(PRInt32 colIndex, nsAString & _retval) -{ - _retval.Truncate(); - for (nsTreeColumn* currCol = mColumns; currCol; currCol = currCol->GetNext()) { - if (currCol->GetColIndex() == colIndex) { - _retval = currCol->GetID(); - break; - } - } - - return NS_OK; -} - -NS_IMETHODIMP nsTreeBodyFrame::GetKeyColumnIndex(PRInt32 *_retval) -{ - nsAutoString attr; - PRInt32 first, primary, sorted; - - EnsureColumns(); - first = primary = sorted = -1; - for (nsTreeColumn* currCol = mColumns; currCol; currCol = currCol->GetNext()) { - // Skip hidden column - currCol->GetElement()->GetAttr(kNameSpaceID_None, nsHTMLAtoms::hidden, attr); - if (attr.Equals(NS_LITERAL_STRING("true"))) - continue; - - // Skip non-text column - if (currCol->GetType() != nsTreeColumn::eText) - continue; - - if (first == -1) - first = currCol->GetColIndex(); - - currCol->GetElement()->GetAttr(kNameSpaceID_None, nsXULAtoms::sortDirection, attr); - if (!attr.IsEmpty()) { // Use sorted column as the primary - sorted = currCol->GetColIndex(); - break; - } - - if (currCol->IsPrimary()) - if (primary == -1) - primary = currCol->GetColIndex(); - } - - if (sorted >= 0) - *_retval = sorted; - else if (primary >= 0) - *_retval = primary; - else - *_retval = first; - - return NS_OK; -} - -NS_IMETHODIMP nsTreeBodyFrame::GetFirstVisibleRow(PRInt32 *_retval) +NS_IMETHODIMP +nsTreeBodyFrame::GetFirstVisibleRow(PRInt32 *_retval) { *_retval = mTopRowIndex; return NS_OK; } -NS_IMETHODIMP nsTreeBodyFrame::GetLastVisibleRow(PRInt32 *_retval) +NS_IMETHODIMP +nsTreeBodyFrame::GetLastVisibleRow(PRInt32 *_retval) { - *_retval = mTopRowIndex + mPageCount; + *_retval = GetLastVisibleRow(); return NS_OK; } -NS_IMETHODIMP nsTreeBodyFrame::GetPageCount(PRInt32 *_retval) +NS_IMETHODIMP +nsTreeBodyFrame::GetPageLength(PRInt32 *_retval) { - *_retval = mPageCount; + *_retval = mPageLength; return NS_OK; } - -NS_IMETHODIMP nsTreeBodyFrame::Invalidate() +NS_IMETHODIMP +nsTreeBodyFrame::Invalidate() { if (mUpdateBatchNest) return NS_OK; + nsIFrame::Invalidate(GetOutlineRect(), PR_FALSE); + return NS_OK; } -NS_IMETHODIMP nsTreeBodyFrame::InvalidateColumn(const PRUnichar *aColID) +NS_IMETHODIMP +nsTreeBodyFrame::InvalidateColumn(nsITreeColumn* aCol) { if (mUpdateBatchNest) return NS_OK; - nscoord currX = mInnerBox.x; - for (nsTreeColumn* currCol = mColumns; currCol && currX < mInnerBox.x+mInnerBox.width; - currCol = currCol->GetNext()) { - if (currCol->GetID().Equals(aColID)) { - nsRect columnRect(currX, mInnerBox.y, currCol->GetWidth(), mInnerBox.height); - nsIFrame::Invalidate(columnRect, PR_FALSE); - break; - } - currX += currCol->GetWidth(); + + nsTreeColumn* col = NS_STATIC_CAST(nsTreeColumn*, aCol); + if (col) { + nsRect columnRect(col->GetX(), mInnerBox.y, col->GetWidth(), mInnerBox.height); + nsIFrame::Invalidate(columnRect, PR_FALSE); } return NS_OK; } -NS_IMETHODIMP nsTreeBodyFrame::InvalidateRow(PRInt32 aIndex) +NS_IMETHODIMP +nsTreeBodyFrame::InvalidateRow(PRInt32 aIndex) { if (mUpdateBatchNest) return NS_OK; - if (aIndex < mTopRowIndex || aIndex > mTopRowIndex + mPageCount + 1) + + aIndex -= mTopRowIndex; + if (aIndex < 0 || aIndex > mPageLength) return NS_OK; - nsRect rowRect(mInnerBox.x, mInnerBox.y+mRowHeight*(aIndex-mTopRowIndex), mInnerBox.width, mRowHeight); - nsIFrame::Invalidate(rowRect, PR_FALSE); - return NS_OK; -} - -NS_IMETHODIMP nsTreeBodyFrame::InvalidateCell(PRInt32 aIndex, const PRUnichar *aColID) -{ - if (mUpdateBatchNest) - return NS_OK; - if (aIndex < mTopRowIndex || aIndex > mTopRowIndex + mPageCount + 1) - return NS_OK; - - if (mImageGuard) - return NS_OK; - - nscoord currX = mInnerBox.x; - nscoord yPos = mInnerBox.y+mRowHeight*(aIndex-mTopRowIndex); - for (nsTreeColumn* currCol = mColumns; currCol && currX < mInnerBox.x+mInnerBox.width; - currCol = currCol->GetNext()) { - - if (currCol->GetID().Equals(aColID)) { - nsRect cellRect(currX, yPos, currCol->GetWidth(), mRowHeight); - nsIFrame::Invalidate(cellRect, PR_FALSE); - break; - } - currX += currCol->GetWidth(); - } - return NS_OK; -} - -NS_IMETHODIMP nsTreeBodyFrame::InvalidatePrimaryCell(PRInt32 aIndex) -{ - if (mUpdateBatchNest) - return NS_OK; - if (aIndex < mTopRowIndex || aIndex > mTopRowIndex + mPageCount + 1) - return NS_OK; - - nscoord currX = mInnerBox.x; - nscoord yPos = mInnerBox.y+mRowHeight*(aIndex-mTopRowIndex); - for (nsTreeColumn* currCol = mColumns; currCol && currX < mInnerBox.x+mInnerBox.width; - currCol = currCol->GetNext()) { - - if (currCol->IsPrimary()) { - nsRect cellRect(currX, yPos, currCol->GetWidth(), mRowHeight); + nsRect rowRect(mInnerBox.x, mInnerBox.y+mRowHeight*aIndex, mInnerBox.width, mRowHeight); #if defined(XP_MAC) || defined(XP_MACOSX) - // Mac can't process the event loop during a drag, so if we're dragging, - // invalidate synchronously. - nsIFrame::Invalidate(cellRect, mDragSession != nsnull); + // Mac can't process the event loop during a drag, so if we're dragging, + // invalidate synchronously. + nsLeafBoxFrame::Invalidate(rowRect, mSlots && mSlots->mDragSession ? PR_TRUE : PR_FALSE); #else - nsIFrame::Invalidate(cellRect, PR_FALSE); + nsLeafBoxFrame::Invalidate(rowRect, PR_FALSE); #endif - break; - } - currX += currCol->GetWidth(); - } + return NS_OK; } -NS_IMETHODIMP nsTreeBodyFrame::InvalidateRange(PRInt32 aStart, PRInt32 aEnd) +NS_IMETHODIMP +nsTreeBodyFrame::InvalidateCell(PRInt32 aIndex, nsITreeColumn* aCol) { if (mUpdateBatchNest) return NS_OK; + + aIndex -= mTopRowIndex; + if (aIndex < 0 || aIndex > mPageLength) + return NS_OK; + + nsTreeColumn* col = NS_STATIC_CAST(nsTreeColumn*, aCol); + if (col) { + nscoord yPos = mInnerBox.y+mRowHeight*aIndex; + nsRect cellRect(col->GetX(), yPos, col->GetWidth(), mRowHeight); + nsIFrame::Invalidate(cellRect, PR_FALSE); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsTreeBodyFrame::InvalidateRange(PRInt32 aStart, PRInt32 aEnd) +{ + if (mUpdateBatchNest) + return NS_OK; + if (aStart == aEnd) return InvalidateRow(aStart); - PRInt32 last; - GetLastVisibleRow(&last); + PRInt32 last = GetLastVisibleRow(); if (aEnd < mTopRowIndex || aStart > last) return NS_OK; @@ -1006,9 +726,9 @@ nsTreeBodyFrame::EnsureScrollbar() { if (!mScrollbar) { // Try to find it. - nsCOMPtr parContent; - GetBaseElement(getter_AddRefs(parContent)); + nsIContent* parContent = GetBaseElement(); nsIFrame* treeFrame; + mPresContext->PresShell()->GetPrimaryFrameFor(parContent, &treeFrame); if (treeFrame) mScrollbar = InitScrollbarFrame(mPresContext, treeFrame, this); @@ -1024,8 +744,7 @@ nsTreeBodyFrame::UpdateScrollbar() // Update the scrollbar. if (!EnsureScrollbar()) return; - float t2p; - t2p = mPresContext->TwipsToPixels(); + float t2p = mPresContext->TwipsToPixels(); nscoord rowHeightAsPixels = NSToCoordRound((float)mRowHeight*t2p); nsAutoString curPos; @@ -1033,15 +752,16 @@ nsTreeBodyFrame::UpdateScrollbar() mScrollbar->GetContent()->SetAttr(kNameSpaceID_None, nsXULAtoms::curpos, curPos, PR_TRUE); } -nsresult nsTreeBodyFrame::CheckVerticalOverflow() +void +nsTreeBodyFrame::CheckVerticalOverflow() { PRBool verticalOverflowChanged = PR_FALSE; - if (!mVerticalOverflow && mRowCount > mPageCount) { + if (!mVerticalOverflow && mRowCount > mPageLength) { mVerticalOverflow = PR_TRUE; verticalOverflowChanged = PR_TRUE; } - else if (mVerticalOverflow && mRowCount <= mPageCount) { + else if (mVerticalOverflow && mRowCount <= mPageLength) { mVerticalOverflow = PR_FALSE; verticalOverflowChanged = PR_TRUE; } @@ -1054,29 +774,27 @@ nsresult nsTreeBodyFrame::CheckVerticalOverflow() nsEventStatus status = nsEventStatus_eIgnore; mContent->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } - - return NS_OK; } -void nsTreeBodyFrame::InvalidateScrollbar() +void +nsTreeBodyFrame::InvalidateScrollbar() { - if (mUpdateBatchNest || !mView || mRowCount <= mPageCount || !EnsureScrollbar()) + if (mUpdateBatchNest || !mView || mRowCount <= mPageLength || !EnsureScrollbar()) return; nsIContent* scrollbar = mScrollbar->GetContent(); nsAutoString maxposStr; - float t2p; - t2p = mPresContext->TwipsToPixels(); + float t2p = mPresContext->TwipsToPixels(); nscoord rowHeightAsPixels = NSToCoordRound((float)mRowHeight*t2p); - PRInt32 size = rowHeightAsPixels*(mRowCount-mPageCount); + PRInt32 size = rowHeightAsPixels*(mRowCount-mPageLength); maxposStr.AppendInt(size); scrollbar->SetAttr(kNameSpaceID_None, nsXULAtoms::maxpos, maxposStr, PR_TRUE); // Also set our page increment and decrement. - nscoord pageincrement = mPageCount*rowHeightAsPixels; + nscoord pageincrement = mPageLength*rowHeightAsPixels; nsAutoString pageStr; pageStr.AppendInt(pageincrement); scrollbar->SetAttr(kNameSpaceID_None, nsXULAtoms::pageincrement, pageStr, PR_TRUE); @@ -1089,8 +807,7 @@ void nsTreeBodyFrame::AdjustEventCoordsToBoxCoordSpace (PRInt32 aX, PRInt32 aY, PRInt32* aResultX, PRInt32* aResultY) { // Convert our x and y coords to twips. - float pixelsToTwips = 0.0; - pixelsToTwips = mPresContext->PixelsToTwips(); + float pixelsToTwips = mPresContext->PixelsToTwips(); aX = NSToIntRound(aX * pixelsToTwips); aY = NSToIntRound(aY * pixelsToTwips); @@ -1137,14 +854,15 @@ nsTreeBodyFrame::AdjustEventCoordsToBoxCoordSpace (PRInt32 aX, PRInt32 aY, PRInt *aResultY = y; } // AdjustEventCoordsToBoxCoordSpace -NS_IMETHODIMP nsTreeBodyFrame::GetRowAt(PRInt32 aX, PRInt32 aY, PRInt32* _retval) +NS_IMETHODIMP +nsTreeBodyFrame::GetRowAt(PRInt32 aX, PRInt32 aY, PRInt32* _retval) { if (!mView) return NS_OK; PRInt32 x; PRInt32 y; - AdjustEventCoordsToBoxCoordSpace (aX, aY, &x, &y); + AdjustEventCoordsToBoxCoordSpace(aX, aY, &x, &y); // Check if the coordinates are above our visible space. if (y < 0) { @@ -1152,26 +870,21 @@ NS_IMETHODIMP nsTreeBodyFrame::GetRowAt(PRInt32 aX, PRInt32 aY, PRInt32* _retval return NS_OK; } - // Now just mod by our total inner box height and add to our top row index. - *_retval = (y/mRowHeight)+mTopRowIndex; - - // Check if the coordinates are below our visible space (or within - // our visible space but below any row). - if (*_retval > PR_MIN(mTopRowIndex+mPageCount, mRowCount - 1)) - *_retval = -1; + *_retval = GetRowAt(x, y); return NS_OK; } -NS_IMETHODIMP nsTreeBodyFrame::GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aRow, PRUnichar** aColID, - PRUnichar** aChildElt) +NS_IMETHODIMP +nsTreeBodyFrame::GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aRow, nsITreeColumn** aCol, + nsACString& aChildElt) { if (!mView) return NS_OK; PRInt32 x; PRInt32 y; - AdjustEventCoordsToBoxCoordSpace (aX, aY, &x, &y); + AdjustEventCoordsToBoxCoordSpace(aX, aY, &x, &y); // Check if the coordinates are above our visible space. if (y < 0) { @@ -1179,38 +892,20 @@ NS_IMETHODIMP nsTreeBodyFrame::GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aRow, return NS_OK; } - // Now just mod by our total inner box height and add to our top row index. - *aRow = (y/mRowHeight)+mTopRowIndex; + nsTreeColumn* col; + nsIAtom* child; + GetCellAt(x, y, aRow, &col, &child); - // Check if the coordinates are below our visible space (or within - // our visible space but below any row). - if (*aRow > PR_MIN(mTopRowIndex+mPageCount, mRowCount - 1)) { - *aRow = -1; - return NS_OK; - } - - // Determine the column hit. - nscoord currX = mInnerBox.x; - for (nsTreeColumn* currCol = mColumns; currCol && currX < mInnerBox.x+mInnerBox.width; - currCol = currCol->GetNext()) { - nsRect cellRect(currX, mInnerBox.y+mRowHeight*(*aRow-mTopRowIndex), currCol->GetWidth(), mRowHeight); - PRInt32 overflow = cellRect.x+cellRect.width-(mInnerBox.x+mInnerBox.width); - if (overflow > 0) - cellRect.width -= overflow; - - if (x >= cellRect.x && x < cellRect.x + cellRect.width) { - // We know the column hit now. - *aColID = ToNewUnicode(currCol->GetID()); - - if (currCol->IsCycler()) - // Cyclers contain only images. Fill this in immediately and return. - *aChildElt = ToNewUnicode(NS_LITERAL_STRING("image")); - else - GetItemWithinCellAt(x, cellRect, *aRow, currCol, aChildElt); - break; - } - - currX += cellRect.width; + if (col) { + NS_ADDREF(*aCol = col); + if (child == nsCSSAnonBoxes::moztreecell) + aChildElt = NS_LITERAL_CSTRING("cell"); + else if (child == nsCSSAnonBoxes::moztreetwisty) + aChildElt = NS_LITERAL_CSTRING("twisty"); + else if (child == nsCSSAnonBoxes::moztreeimage) + aChildElt = NS_LITERAL_CSTRING("image"); + else if (child == nsCSSAnonBoxes::moztreecelltext) + aChildElt = NS_LITERAL_CSTRING("text"); } return NS_OK; @@ -1239,8 +934,8 @@ NS_IMETHODIMP nsTreeBodyFrame::GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aRow, // You need to make sure to add in the image's margins as well. // NS_IMETHODIMP -nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, const PRUnichar *aCellItem, - PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight) +nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, nsITreeColumn* aCol, const nsACString& aElement, + PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight) { *aX = 0; *aY = 0; @@ -1252,7 +947,7 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con // The Rect for the requested item. nsRect theRect; - for (nsTreeColumn* currCol = mColumns; currCol && currX < mInnerBox.x + mInnerBox.width; + for (nsTreeColumn* currCol = mColumns->GetFirstColumn(); currCol && currX < mInnerBox.x + mInnerBox.width; currCol = currCol->GetNext()) { // The Rect for the current cell. @@ -1260,14 +955,14 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con // Check the ID of the current column to see if it matches. If it doesn't // increment the current X value and continue to the next column. - if (!currCol->GetID().Equals(aColID)) { + if (currCol != aCol) { currX += cellRect.width; continue; } // Now obtain the properties for our cell. PrefillPropertyArray(aRow, currCol); - mView->GetCellProperties(aRow, currCol->GetID().get(), mScratchArray); + mView->GetCellProperties(aRow, currCol, mScratchArray); nsStyleContext* rowContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreerow); @@ -1278,8 +973,8 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con nsStyleContext* cellContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreecell); - NS_NAMED_LITERAL_STRING(cell, "cell"); - if (currCol->IsCycler() || cell.Equals(aCellItem)) { + NS_NAMED_LITERAL_CSTRING(cell, "cell"); + if (currCol->IsCycler() || cell.Equals(aElement)) { // If the current Column is a Cycler, then the Rect is just the cell - the margins. // Similarly, if we're just being asked for the cell rect, provide it. @@ -1325,10 +1020,10 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con // Find the twisty rect by computing its size. nsStyleContext* twistyContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreetwisty); - // |GetImageSize| returns the rect of the twisty image, including the - // borders and padding. - nsRect twistyImageRect = GetImageSize(aRow, currCol->GetID().get(), PR_TRUE, twistyContext); - if (NS_LITERAL_STRING("twisty").Equals(aCellItem)) { + // |GetImageSize| returns the rect of the twisty image, including the + // borders and padding. + nsRect twistyImageRect = GetImageSize(aRow, currCol, PR_TRUE, twistyContext); + if (NS_LITERAL_CSTRING("twisty").Equals(aElement)) { // If we're looking for the twisty Rect, just return the result of |GetImageSize| theRect = twistyImageRect; break; @@ -1348,8 +1043,8 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con // Cell Image nsStyleContext* imageContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeimage); - nsRect imageSize = GetImageSize(aRow, currCol->GetID().get(), PR_FALSE, imageContext); - if (NS_LITERAL_STRING("image").Equals(aCellItem)) { + nsRect imageSize = GetImageSize(aRow, currCol, PR_FALSE, imageContext); + if (NS_LITERAL_CSTRING("image").Equals(aElement)) { theRect = imageSize; theRect.x = cellX; theRect.y = cellRect.y; @@ -1366,7 +1061,7 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con // Cell Text nsAutoString cellText; - mView->GetCellText(aRow, currCol->GetID().get(), cellText); + mView->GetCellText(aRow, currCol, cellText); // Create a scratch rect to represent the text rectangle, with the current // X and Y coords, and a guess at the width and height. The width is the @@ -1392,8 +1087,7 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con textRect.height = height + bp.top + bp.bottom; nsCOMPtr rc; - mPresContext->PresShell()->CreateRenderingContext(this, - getter_AddRefs(rc)); + mPresContext->PresShell()->CreateRenderingContext(this, getter_AddRefs(rc)); rc->SetFont(fm); nscoord width; rc->GetWidth(cellText, width); @@ -1408,8 +1102,7 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con theRect = textRect; } - float t2p = 0.0; - t2p = mPresContext->TwipsToPixels(); + float t2p = mPresContext->TwipsToPixels(); *aX = NSToIntRound(theRect.x * t2p); *aY = NSToIntRound(theRect.y * t2p); @@ -1419,14 +1112,28 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, const PRUnichar *aColID, con return NS_OK; } -nsresult +PRInt32 +nsTreeBodyFrame::GetRowAt(PRInt32 aX, PRInt32 aY) +{ + // Now just mod by our total inner box height and add to our top row index. + PRInt32 row = (aY/mRowHeight)+mTopRowIndex; + + // Check if the coordinates are below our visible space (or within our visible + // space but below any row). + if (row > mTopRowIndex + mPageLength || row >= mRowCount) + return -1; + + return row; +} + +nsIAtom* nsTreeBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, - PRInt32 aRowIndex, - nsTreeColumn* aColumn, PRUnichar** aChildElt) + PRInt32 aRowIndex, + nsTreeColumn* aColumn) { // Obtain the properties for our cell. PrefillPropertyArray(aRowIndex, aColumn); - mView->GetCellProperties(aRowIndex, aColumn->GetID().get(), mScratchArray); + mView->GetCellProperties(aRowIndex, aColumn, mScratchArray); // Resolve style for the cell. nsStyleContext* cellContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreecell); @@ -1443,8 +1150,7 @@ nsTreeBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX < cellRect.x || aX >= cellRect.x + cellRect.width) { // The user clicked within the cell's margins/borders/padding. This constitutes a click on the cell. - *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); - return NS_OK; + return nsCSSAnonBoxes::moztreecell; } nscoord currX = cellRect.x; @@ -1462,8 +1168,7 @@ nsTreeBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX < currX) { // The user clicked within the indentation. - *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); - return NS_OK; + return nsCSSAnonBoxes::moztreecell; } // Always leave space for the twisty. @@ -1484,7 +1189,7 @@ nsTreeBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, // We will treat a click as hitting the twisty if it happens on the margins, borders, padding, // or content of the twisty object. By allowing a "slop" into the margin, we make it a little // bit easier for a user to hit the twisty. (We don't want to be too picky here.) - nsRect imageSize = GetImageSize(aRowIndex, aColumn->GetID().get(), PR_TRUE, twistyContext); + nsRect imageSize = GetImageSize(aRowIndex, aColumn, PR_TRUE, twistyContext); nsMargin twistyMargin; twistyContext->GetStyleMargin()->GetMargin(twistyMargin); imageSize.Inflate(twistyMargin); @@ -1495,10 +1200,9 @@ nsTreeBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, // then we return "cell". if (aX >= twistyRect.x && aX < twistyRect.x + twistyRect.width) { if (hasTwisty) - *aChildElt = ToNewUnicode(NS_LITERAL_STRING("twisty")); + return nsCSSAnonBoxes::moztreetwisty; else - *aChildElt = ToNewUnicode(NS_LITERAL_STRING("cell")); - return NS_OK; + return nsCSSAnonBoxes::moztreecell; } currX += twistyRect.width; @@ -1511,7 +1215,7 @@ nsTreeBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, // Resolve style for the image. nsStyleContext* imageContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeimage); - nsRect iconSize = GetImageSize(aRowIndex, aColumn->GetID().get(), PR_FALSE, imageContext); + nsRect iconSize = GetImageSize(aRowIndex, aColumn, PR_FALSE, imageContext); nsMargin imageMargin; imageContext->GetStyleMargin()->GetMargin(imageMargin); iconSize.Inflate(imageMargin); @@ -1519,31 +1223,56 @@ nsTreeBodyFrame::GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, if (aX >= iconRect.x && aX < iconRect.x + iconRect.width) { // The user clicked on the image. - *aChildElt = ToNewUnicode(NS_LITERAL_STRING("image")); - return NS_OK; + return nsCSSAnonBoxes::moztreeimage; } // Just assume "text". // XXX For marquee selection, we'll have to make this more precise and do text measurement. - *aChildElt = ToNewUnicode(NS_LITERAL_STRING("text")); - return NS_OK; + return nsCSSAnonBoxes::moztreecelltext; } void -nsTreeBodyFrame::GetCellWidth(PRInt32 aRow, const nsAString& aColID, +nsTreeBodyFrame::GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aRow, nsTreeColumn** aCol, + nsIAtom** aChildElt) +{ + *aCol = nsnull; + *aChildElt = nsnull; + + *aRow = GetRowAt(aX, aY); + if (*aRow < 0) + return; + + // Determine the column hit. + for (nsTreeColumn* currCol = mColumns->GetFirstColumn(); currCol && currCol->GetX() < mInnerBox.x+mInnerBox.width; + currCol = currCol->GetNext()) { + nsRect cellRect(currCol->GetX(), mInnerBox.y+mRowHeight*(*aRow-mTopRowIndex), currCol->GetWidth(), mRowHeight); + PRInt32 overflow = cellRect.x+cellRect.width-(mInnerBox.x+mInnerBox.width); + if (overflow > 0) + cellRect.width -= overflow; + + if (aX >= cellRect.x && aX < cellRect.x + cellRect.width) { + // We know the column hit now. + if (aCol) + *aCol = currCol; + + if (currCol->IsCycler()) + // Cyclers contain only images. Fill this in immediately and return. + *aChildElt = nsCSSAnonBoxes::moztreeimage; + else + *aChildElt = GetItemWithinCellAt(aX, cellRect, *aRow, currCol); + break; + } + } +} + +void +nsTreeBodyFrame::GetCellWidth(PRInt32 aRow, nsTreeColumn* aCol, nsIRenderingContext* aRenderingContext, nscoord& aDesiredSize, nscoord& aCurrentSize) { - nsTreeColumn* currCol = nsnull; - // Keep looping until we find a column with a matching Id. - for (currCol = mColumns; currCol; currCol = currCol->GetNext()) { - if (currCol->GetID().Equals(aColID)) - break; - } - - if (currCol) { + if (aCol) { // The rect for the current cell. - nsRect cellRect(0, 0, currCol->GetWidth(), mRowHeight); + nsRect cellRect(0, 0, aCol->GetWidth(), mRowHeight); PRInt32 overflow = cellRect.x+cellRect.width-(mInnerBox.x+mInnerBox.width); if (overflow > 0) cellRect.width -= overflow; @@ -1556,7 +1285,7 @@ nsTreeBodyFrame::GetCellWidth(PRInt32 aRow, const nsAString& aColID, aCurrentSize = cellRect.width; aDesiredSize = bp.left + bp.right; - if (currCol->IsPrimary()) { + if (aCol->IsPrimary()) { // If the current Column is a Primary, then we need to take into account // the indentation and possibly a twisty. @@ -1570,7 +1299,7 @@ nsTreeBodyFrame::GetCellWidth(PRInt32 aRow, const nsAString& aColID, // |GetImageSize| returns the rect of the twisty image, including the // borders and padding. - nsRect twistyImageRect = GetImageSize(aRow, currCol->GetID().get(), PR_TRUE, twistyContext); + nsRect twistyImageRect = GetImageSize(aRow, aCol, PR_TRUE, twistyContext); // Add in the margins of the twisty element. nsMargin twistyMargin; @@ -1583,7 +1312,7 @@ nsTreeBodyFrame::GetCellWidth(PRInt32 aRow, const nsAString& aColID, nsStyleContext* imageContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeimage); // Account for the width of the cell image. - nsRect imageSize = GetImageSize(aRow, currCol->GetID().get(), PR_FALSE, imageContext); + nsRect imageSize = GetImageSize(aRow, aCol, PR_FALSE, imageContext); // Add in the margins of the cell image. nsMargin imageMargin; imageContext->GetStyleMargin()->GetMargin(imageMargin); @@ -1593,7 +1322,7 @@ nsTreeBodyFrame::GetCellWidth(PRInt32 aRow, const nsAString& aColID, // Get the cell text. nsAutoString cellText; - mView->GetCellText(aRow, currCol->GetID().get(), cellText); + mView->GetCellText(aRow, aCol, cellText); nsStyleContext* textContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreecelltext); @@ -1612,13 +1341,17 @@ nsTreeBodyFrame::GetCellWidth(PRInt32 aRow, const nsAString& aColID, } NS_IMETHODIMP -nsTreeBodyFrame::IsCellCropped(PRInt32 aRow, const nsAString& aColID, PRBool *_retval) +nsTreeBodyFrame::IsCellCropped(PRInt32 aRow, nsITreeColumn* aCol, PRBool *_retval) { nscoord currentSize, desiredSize; nsCOMPtr rc; mPresContext->PresShell()->CreateRenderingContext(this, getter_AddRefs(rc)); - GetCellWidth(aRow, aColID, rc, desiredSize, currentSize); + nsTreeColumn* col = NS_STATIC_CAST(nsTreeColumn*, aCol); + if (!col) + return NS_ERROR_FAILURE; + + GetCellWidth(aRow, col, rc, desiredSize, currentSize); *_retval = desiredSize > currentSize; return NS_OK; @@ -1627,8 +1360,7 @@ nsTreeBodyFrame::IsCellCropped(PRInt32 aRow, const nsAString& aColID, PRBool *_r void nsTreeBodyFrame::MarkDirtyIfSelect() { - nsCOMPtr baseElement; - GetBaseElement(getter_AddRefs(baseElement)); + nsIContent* baseElement = GetBaseElement(); if (baseElement->Tag() == nsHTMLAtoms::select && baseElement->IsContentOfType(nsIContent::eHTML)) { @@ -1649,7 +1381,6 @@ nsTreeBodyFrame::CreateTimer(const nsILookAndFeel::nsMetricID aID, { // Get the delay from the look and feel service. PRInt32 delay = 0; - nsCOMPtr lookAndFeel; mPresContext->LookAndFeel()->GetMetric(aID, delay); nsCOMPtr timer; @@ -1694,8 +1425,7 @@ NS_IMETHODIMP nsTreeBodyFrame::RowCountChanged(PRInt32 aIndex, PRInt32 aCount) #endif PRInt32 count = PR_ABS(aCount); - PRInt32 last; - GetLastVisibleRow(&last); + PRInt32 last = GetLastVisibleRow(); if (aIndex >= mTopRowIndex && aIndex <= last) InvalidateRange(aIndex, last); @@ -1724,8 +1454,8 @@ NS_IMETHODIMP nsTreeBodyFrame::RowCountChanged(PRInt32 aIndex, PRInt32 aCount) } else if (mTopRowIndex >= aIndex) { // This is a full-blown invalidate. - if (mTopRowIndex + mPageCount > mRowCount - 1) { - mTopRowIndex = PR_MAX(0, mRowCount - 1 - mPageCount); + if (mTopRowIndex + mPageLength > mRowCount - 1) { + mTopRowIndex = PR_MAX(0, mRowCount - 1 - mPageLength); UpdateScrollbar(); } Invalidate(); @@ -1756,8 +1486,8 @@ NS_IMETHODIMP nsTreeBodyFrame::EndUpdateBatch() PRInt32 countBeforeUpdate = mRowCount; mView->GetRowCount(&mRowCount); if (countBeforeUpdate != mRowCount) { - if (mTopRowIndex + mPageCount > mRowCount - 1) { - mTopRowIndex = PR_MAX(0, mRowCount - 1 - mPageCount); + if (mTopRowIndex + mPageLength > mRowCount - 1) { + mTopRowIndex = PR_MAX(0, mRowCount - 1 - mPageLength); UpdateScrollbar(); } InvalidateScrollbar(); @@ -1785,7 +1515,7 @@ nsTreeBodyFrame::PrefillPropertyArray(PRInt32 aRowIndex, nsTreeColumn* aCol) mScratchArray->AppendElement(nsXULAtoms::sorted); // drag session - if (mDragSession) + if (mSlots && mSlots->mDragSession) mScratchArray->AppendElement(nsXULAtoms::dragSession); if (aRowIndex != -1) { @@ -1825,12 +1555,12 @@ nsTreeBodyFrame::PrefillPropertyArray(PRInt32 aRowIndex, nsTreeColumn* aCol) } // drop orientation - if (mDropAllowed && mDropRow == aRowIndex) { - if (mDropOrient == nsITreeView::inDropBefore) + if (mSlots && mSlots->mDropAllowed && mSlots->mDropRow == aRowIndex) { + if (mSlots->mDropOrient == nsITreeView::DROP_BEFORE) mScratchArray->AppendElement(nsXULAtoms::dropBefore); - else if (mDropOrient == nsITreeView::inDropOn) + else if (mSlots->mDropOrient == nsITreeView::DROP_ON) mScratchArray->AppendElement(nsXULAtoms::dropOn); - else if (mDropOrient == nsITreeView::inDropAfter) + else if (mSlots->mDropOrient == nsITreeView::DROP_AFTER) mScratchArray->AppendElement(nsXULAtoms::dropAfter); } @@ -1842,37 +1572,54 @@ nsTreeBodyFrame::PrefillPropertyArray(PRInt32 aRowIndex, nsTreeColumn* aCol) } if (aCol) { - nsCOMPtr colID; - aCol->GetIDAtom(getter_AddRefs(colID)); - mScratchArray->AppendElement(colID); + mScratchArray->AppendElement(aCol->GetAtom()); if (aCol->IsPrimary()) mScratchArray->AppendElement(nsXULAtoms::primary); - if (aCol->GetType() == nsTreeColumn::eProgressMeter) { + if (aCol->GetType() == nsITreeColumn::TYPE_CHECKBOX) { + mScratchArray->AppendElement(nsXULAtoms::checkbox); + + if (aRowIndex != -1) { + nsAutoString value; + mView->GetCellValue(aRowIndex, aCol, value); + if (value.Equals(NS_LITERAL_STRING("true"))) + mScratchArray->AppendElement(nsXULAtoms::checked); + } + } + else if (aCol->GetType() == nsITreeColumn::TYPE_PROGRESSMETER) { mScratchArray->AppendElement(nsXULAtoms::progressmeter); - PRInt32 state = nsITreeView::progressNone; - if (aRowIndex != -1) - mView->GetProgressMode(aRowIndex, aCol->GetID().get(), &state); - if (state == nsITreeView::progressNormal) - mScratchArray->AppendElement(nsXULAtoms::progressNormal); - else if (state == nsITreeView::progressUndetermined) - mScratchArray->AppendElement(nsXULAtoms::progressUndetermined); - else if (state == nsITreeView::progressNone) - mScratchArray->AppendElement(nsXULAtoms::progressNone); + if (aRowIndex != -1) { + PRInt32 state; + mView->GetProgressMode(aRowIndex, aCol, &state); + if (state == nsITreeView::PROGRESS_NORMAL) + mScratchArray->AppendElement(nsXULAtoms::progressNormal); + else if (state == nsITreeView::PROGRESS_UNDETERMINED) + mScratchArray->AppendElement(nsXULAtoms::progressUndetermined); + } } + + // Read special properties from attributes on the column content node + nsAutoString attr; + aCol->GetContent()->GetAttr(kNameSpaceID_None, nsXULAtoms::insertbefore, attr); + if (attr.Equals(NS_LITERAL_STRING("true"))) + mScratchArray->AppendElement(nsXULAtoms::insertbefore); + attr.Truncate(); + aCol->GetContent()->GetAttr(kNameSpaceID_None, nsXULAtoms::insertafter, attr); + if (attr.Equals(NS_LITERAL_STRING("true"))) + mScratchArray->AppendElement(nsXULAtoms::insertafter); } } nsresult -nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUseContext, +nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, nsTreeColumn* aCol, PRBool aUseContext, nsStyleContext* aStyleContext, PRBool& aAllowImageRegions, imgIContainer** aResult) { *aResult = nsnull; nsAutoString imageSrc; - mView->GetImageSrc(aRowIndex, aColID, imageSrc); + mView->GetImageSrc(aRowIndex, aCol, imageSrc); if (!aUseContext && !imageSrc.IsEmpty()) { aAllowImageRegions = PR_FALSE; } @@ -1906,7 +1653,7 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUs imgReq->GetDecoderObserver(getter_AddRefs(obs)); nsCOMPtr listener(do_QueryInterface(obs)); if (listener) - listener->AddRow(aRowIndex); + listener->AddCell(aRowIndex, aCol); return NS_OK; } } @@ -1915,11 +1662,11 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUs if (!*aResult) { // Create a new nsTreeImageListener object and pass it our row and column // information. - nsTreeImageListener* listener = new nsTreeImageListener(mTreeBoxObject, aColID); + nsTreeImageListener* listener = new nsTreeImageListener(mTreeBoxObject); if (!listener) return NS_ERROR_OUT_OF_MEMORY; - listener->AddRow(aRowIndex); + listener->AddCell(aRowIndex, aCol); nsCOMPtr imgDecoderObserver = listener; nsCOMPtr baseURI; @@ -1942,12 +1689,11 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUs if (NS_FAILED(rv)) return rv; - mImageGuard = PR_TRUE; // XXX: initialDocumentURI is NULL! rv = il->LoadImage(srcURI, nsnull, doc->GetDocumentURI(), nsnull, imgDecoderObserver, doc, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(imageRequest)); - mImageGuard = PR_FALSE; + listener->UnsuppressInvalidation(); if (!imageRequest) return NS_ERROR_FAILURE; @@ -1967,7 +1713,7 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUs return NS_OK; } -nsRect nsTreeBodyFrame::GetImageSize(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUseContext, +nsRect nsTreeBodyFrame::GetImageSize(PRInt32 aRowIndex, nsTreeColumn* aCol, PRBool aUseContext, nsStyleContext* aStyleContext) { // XXX We should respond to visibility rules for collapsed vs. hidden. @@ -1990,7 +1736,7 @@ nsRect nsTreeBodyFrame::GetImageSize(PRInt32 aRowIndex, const PRUnichar* aColID, // Don't change this, otherwise things start to go crazy. PRBool useImageRegion = PR_TRUE; nsCOMPtr image; - GetImage(aRowIndex, aColID, aUseContext, aStyleContext, useImageRegion, getter_AddRefs(image)); + GetImage(aRowIndex, aCol, aUseContext, aStyleContext, useImageRegion, getter_AddRefs(image)); const nsStylePosition* myPosition = aStyleContext->GetStylePosition(); const nsStyleList* myList = aStyleContext->GetStyleList(); @@ -2021,8 +1767,7 @@ nsRect nsTreeBodyFrame::GetImageSize(PRInt32 aRowIndex, const PRUnichar* aColID, if (image) { if (needWidth || needHeight) { // Get the natural image size. - float p2t; - p2t = mPresContext->PixelsToTwips(); + float p2t = mPresContext->PixelsToTwips(); if (needWidth) { // Get the size from the image. @@ -2063,12 +1808,10 @@ PRInt32 nsTreeBodyFrame::GetRowHeight() height = minHeight; if (height > 0) { - float t2p; - t2p = mPresContext->TwipsToPixels(); + float t2p = mPresContext->TwipsToPixels(); height = NSTwipsToIntPixels(height, t2p); height += height % 2; - float p2t; - p2t = mPresContext->PixelsToTwips(); + float p2t = mPresContext->PixelsToTwips(); height = NSIntPixelsToTwips(height, p2t); // XXX Check box-sizing to determine if border/padding should augment the height @@ -2082,8 +1825,7 @@ PRInt32 nsTreeBodyFrame::GetRowHeight() } } - float p2t; - p2t = mPresContext->PixelsToTwips(); + float p2t = mPresContext->PixelsToTwips(); return NSIntPixelsToTwips(18, p2t); // As good a default as any. } @@ -2099,8 +1841,7 @@ PRInt32 nsTreeBodyFrame::GetIndentation() return val; } } - float p2t; - p2t = mPresContext->PixelsToTwips(); + float p2t = mPresContext->PixelsToTwips(); return NSIntPixelsToTwips(16, p2t); // As good a default as any. } @@ -2110,6 +1851,199 @@ void nsTreeBodyFrame::CalcInnerBox() AdjustForBorderPadding(mStyleContext, mInnerBox); } +NS_IMETHODIMP +nsTreeBodyFrame::GetCursor(nsIPresContext* aPresContext, + nsPoint& aPoint, + PRInt32& aCursor) +{ + if (mView) { + PRInt32 row; + nsTreeColumn* col; + nsIAtom* child; + GetCellAt(aPoint.x, aPoint.y, &row, &col, &child); + + if (child) { + // Our scratch array is already prefilled. + nsStyleContext* childContext = GetPseudoStyleContext(child); + + aCursor = childContext->GetStyleUserInterface()->mCursor; + if (aCursor == NS_STYLE_CURSOR_AUTO) + aCursor = NS_STYLE_CURSOR_DEFAULT; + + return NS_OK; + } + } + + return nsLeafBoxFrame::GetCursor(aPresContext, aPoint, aCursor); +} + +NS_IMETHODIMP +nsTreeBodyFrame::HandleEvent(nsIPresContext* aPresContext, + nsGUIEvent* aEvent, + nsEventStatus* aEventStatus) +{ + if (aEvent->message == NS_DRAGDROP_ENTER) { + if (!mSlots) + mSlots = new Slots(); + + // Cache several things we'll need throughout the course of our work. These + // will all get released on a drag exit. + + if (mSlots->mTimer) { + mSlots->mTimer->Cancel(); + mSlots->mTimer = nsnull; + } + + // Cache the drag session. + nsCOMPtr dragService = + do_GetService("@mozilla.org/widget/dragservice;1"); + nsCOMPtr dragSession; + dragService->GetCurrentSession(getter_AddRefs(mSlots->mDragSession)); + NS_ASSERTION(mSlots->mDragSession, "can't get drag session"); + } + else if (aEvent->message == NS_DRAGDROP_OVER) { + // The mouse is hovering over this tree. If we determine things are + // different from the last time, invalidate the drop feedback at the old + // position, query the view to see if the current location is droppable, + // and then invalidate the drop feedback at the new location if it is. + // The mouse may or may not have changed position from the last time + // we were called, so optimize out a lot of the extra notifications by + // checking if anything changed first. For drop feedback we use drop, + // dropBefore and dropAfter property. + + if (! mView) + return NS_OK; + + // Save last values, we will need them. + PRInt32 lastDropRow = mSlots->mDropRow; + PRInt16 lastDropOrient = mSlots->mDropOrient; + PRInt16 lastScrollLines = mSlots->mScrollLines; + + // Compute the row mouse is over and the above/below/on state. + // Below we'll use this to see if anything changed. + // Also check if we want to auto-scroll. + ComputeDropPosition(aEvent, &mSlots->mDropRow, &mSlots->mDropOrient, &mSlots->mScrollLines); + + // While we're here, handle tracking of scrolling during a drag. + if (mSlots->mScrollLines) { + if (mSlots->mDropAllowed) { + // Invalidate primary cell at old location. + mSlots->mDropAllowed = PR_FALSE; + InvalidateDropFeedback(lastDropRow, lastDropOrient); + } +#if !defined(XP_MAC) && !defined(XP_MACOSX) + if (!lastScrollLines) { + // Cancel any previosly initialized timer. + if (mSlots->mTimer) { + mSlots->mTimer->Cancel(); + mSlots->mTimer = nsnull; + } + + // Set a timer to trigger the tree scrolling. + CreateTimer(nsILookAndFeel::eMetric_TreeLazyScrollDelay, + LazyScrollCallback, nsITimer::TYPE_ONE_SHOT, + getter_AddRefs(mSlots->mTimer)); + } +#else + ScrollByLines(mSlots->mScrollLines); +#endif + // Bail out to prevent spring loaded timer and feedback line settings. + return NS_OK; + } + + // If changed from last time, invalidate primary cell at the old location and if allowed, + // invalidate primary cell at the new location. If nothing changed, just bail. + if (mSlots->mDropRow != lastDropRow || mSlots->mDropOrient != lastDropOrient) { + // Invalidate row at the old location. + if (mSlots->mDropAllowed) { + mSlots->mDropAllowed = PR_FALSE; + InvalidateDropFeedback(lastDropRow, lastDropOrient); + } + + if (mSlots->mTimer) { + // Timer is active but for a different row than the current one, kill it. + mSlots->mTimer->Cancel(); + mSlots->mTimer = nsnull; + } + + if (mSlots->mDropRow >= 0) { + if (!mSlots->mTimer && mSlots->mDropOrient == nsITreeView::DROP_ON) { + // Either there wasn't a timer running or it was just killed above. + // If over a folder, start up a timer to open the folder. + PRBool isContainer = PR_FALSE; + mView->IsContainer(mSlots->mDropRow, &isContainer); + if (isContainer) { + PRBool isOpen = PR_FALSE; + mView->IsContainerOpen(mSlots->mDropRow, &isOpen); + if (!isOpen) { + // This node isn't expanded, set a timer to expand it. + CreateTimer(nsILookAndFeel::eMetric_TreeOpenDelay, + OpenCallback, nsITimer::TYPE_ONE_SHOT, + getter_AddRefs(mSlots->mTimer)); + } + } + } + + PRBool canDropAtNewLocation = PR_FALSE; + mView->CanDrop(mSlots->mDropRow, mSlots->mDropOrient, &canDropAtNewLocation); + + if (canDropAtNewLocation) { + // Invalidate row at the new location. + mSlots->mDropAllowed = canDropAtNewLocation; + InvalidateDropFeedback(mSlots->mDropRow, mSlots->mDropOrient); + } + } + } + + // Alert the drag session we accept the drop. We have to do this every time + // since the |canDrop| attribute is reset before we're called. + if (mSlots->mDropAllowed && mSlots->mDragSession) + mSlots->mDragSession->SetCanDrop(PR_TRUE); + } + else if (aEvent->message == NS_DRAGDROP_DROP) { + // Tell the view where the drop happened. + + // Remove the drop folder and all its parents from the array. + PRInt32 parentIndex; + nsresult rv = mView->GetParentIndex(mSlots->mDropRow, &parentIndex); + while (NS_SUCCEEDED(rv) && parentIndex >= 0) { + mSlots->mValueArray.RemoveValue(parentIndex); + rv = mView->GetParentIndex(parentIndex, &parentIndex); + } + + mView->Drop(mSlots->mDropRow, mSlots->mDropOrient); + } + else if (aEvent->message == NS_DRAGDROP_EXIT) { + // Clear out all our tracking vars. + + if (mSlots->mDropAllowed) { + mSlots->mDropAllowed = PR_FALSE; + InvalidateDropFeedback(mSlots->mDropRow, mSlots->mDropOrient); + } + else + mSlots->mDropAllowed = PR_FALSE; + mSlots->mDropRow = -1; + mSlots->mDropOrient = -1; + mSlots->mDragSession = nsnull; + mSlots->mScrollLines = 0; + + if (mSlots->mTimer) { + mSlots->mTimer->Cancel(); + mSlots->mTimer = nsnull; + } + + if (mSlots->mValueArray.Count()) { + // Close all spring loaded folders except the drop folder. + CreateTimer(nsILookAndFeel::eMetric_TreeCloseDelay, + CloseCallback, nsITimer::TYPE_ONE_SHOT, + getter_AddRefs(mSlots->mTimer)); + } + } + + return NS_OK; +} + + nsLineStyle nsTreeBodyFrame::ConvertBorderStyleToLineStyle(PRUint8 aBorderStyle) { switch (aBorderStyle) { @@ -2149,11 +2083,11 @@ nsTreeBodyFrame::Paint(nsIPresContext* aPresContext, // Update our available height and our page count. CalcInnerBox(); - PRInt32 oldPageCount = mPageCount; + PRInt32 oldPageCount = mPageLength; if (!mHasFixedRowCount) - mPageCount = mInnerBox.height/mRowHeight; + mPageLength = mInnerBox.height/mRowHeight; - if (oldPageCount != mPageCount) { + if (oldPageCount != mPageLength) { // Schedule a ResizeReflow that will update our page count properly. nsBoxLayoutState state(mPresContext); MarkDirty(state); @@ -2165,34 +2099,31 @@ nsTreeBodyFrame::Paint(nsIPresContext* aPresContext, NS_ASSERTION(mRowCount == rowCount, "row count changed unexpectedly"); #endif - // Ensure our column info is built. - EnsureColumns(); - // Loop through our columns and paint them (e.g., for sorting). This is only // relevant when painting backgrounds, since columns contain no content. Content // is contained in the rows. - nscoord currX = mInnerBox.x; - for (nsTreeColumn* currCol = mColumns; currCol && currX < mInnerBox.x+mInnerBox.width; + for (nsTreeColumn* currCol = mColumns->GetFirstColumn(); currCol && currCol->GetX() < mInnerBox.x+mInnerBox.width; currCol = currCol->GetNext()) { - nsRect colRect(currX, mInnerBox.y, currCol->GetWidth(), mInnerBox.height); - PRInt32 overflow = colRect.x+colRect.width-(mInnerBox.x+mInnerBox.width); - if (overflow > 0) - colRect.width -= overflow; - nsRect dirtyRect; - if (dirtyRect.IntersectRect(aDirtyRect, colRect)) { - PaintColumn(currCol, colRect, aPresContext, aRenderingContext, aDirtyRect); + // Don't paint hidden columns. + if (currCol->GetWidth()) { + nsRect colRect(currCol->GetX(), mInnerBox.y, currCol->GetWidth(), mInnerBox.height); + PRInt32 overflow = colRect.x+colRect.width-(mInnerBox.x+mInnerBox.width); + if (overflow > 0) + colRect.width -= overflow; + nsRect dirtyRect; + if (dirtyRect.IntersectRect(aDirtyRect, colRect)) { + PaintColumn(currCol, colRect, aPresContext, aRenderingContext, aDirtyRect); + } } - currX += currCol->GetWidth(); } - // Loop through our on-screen rows. - for (PRInt32 i = mTopRowIndex; i < mRowCount && i < mTopRowIndex+mPageCount+1; i++) { + for (PRInt32 i = mTopRowIndex; i < mRowCount && i <= mTopRowIndex+mPageLength; i++) { nsRect rowRect(mInnerBox.x, mInnerBox.y+mRowHeight*(i-mTopRowIndex), mInnerBox.width, mRowHeight); nsRect dirtyRect; if (dirtyRect.IntersectRect(aDirtyRect, rowRect) && rowRect.y < (mInnerBox.y+mInnerBox.height)) { PRBool clip = (rowRect.y + rowRect.height > mInnerBox.y + mInnerBox.height); if (clip) { - // We need to clip the last row, since it extends outside our inner box. Push + // We need to clip the last row, since it extends outside our inner box. Push // a clip rect down. PRInt32 overflow = (rowRect.y+rowRect.height) - (mInnerBox.y+mInnerBox.height); nsRect clipRect(rowRect.x, rowRect.y, mInnerBox.width, mRowHeight-overflow); @@ -2207,10 +2138,11 @@ nsTreeBodyFrame::Paint(nsIPresContext* aPresContext, } } - if (mDropAllowed && (mDropOrient == nsITreeView::inDropBefore || - mDropOrient == nsITreeView::inDropAfter)) { - nsRect feedbackRect(mInnerBox.x, mInnerBox.y+mRowHeight*(mDropRow-mTopRowIndex), mInnerBox.width, mRowHeight); - if (mDropOrient == nsITreeView::inDropAfter) + if (mSlots && mSlots->mDropAllowed && (mSlots->mDropOrient == nsITreeView::DROP_BEFORE || + mSlots->mDropOrient == nsITreeView::DROP_AFTER)) { + nscoord yPos = mInnerBox.y + mRowHeight * (mSlots->mDropRow - mTopRowIndex) - mRowHeight / 2; + nsRect feedbackRect(mInnerBox.x, yPos, mInnerBox.width, mRowHeight); + if (mSlots->mDropOrient == nsITreeView::DROP_AFTER) feedbackRect.y += mRowHeight; nsRect dirtyRect; @@ -2223,32 +2155,17 @@ nsTreeBodyFrame::Paint(nsIPresContext* aPresContext, return NS_OK; } -nsresult +void nsTreeBodyFrame::PaintColumn(nsTreeColumn* aColumn, const nsRect& aColumnRect, nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { - if (aColumnRect.width == 0) - return NS_OK; // Don't paint hidden columns. - // Now obtain the properties for our cell. - // XXX Automatically fill in the following props: open, closed, container, leaf, selected, focused, and the col ID. PrefillPropertyArray(-1, aColumn); - nsCOMPtr elt(do_QueryInterface(aColumn->GetElement())); - mView->GetColumnProperties(aColumn->GetID().get(), elt, mScratchArray); + mView->GetColumnProperties(aColumn, mScratchArray); - // Read special properties from attributes on the column content node - nsAutoString attr; - aColumn->GetElement()->GetAttr(kNameSpaceID_None, nsXULAtoms::insertbefore, attr); - if (attr.Equals(NS_LITERAL_STRING("true"))) - mScratchArray->AppendElement(nsXULAtoms::insertbefore); - attr.Truncate(); - aColumn->GetElement()->GetAttr(kNameSpaceID_None, nsXULAtoms::insertafter, attr); - if (attr.Equals(NS_LITERAL_STRING("true"))) - mScratchArray->AppendElement(nsXULAtoms::insertafter); - // Resolve style for the column. It contains all the info we need to lay ourselves // out and to paint. nsStyleContext* colContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreecolumn); @@ -2261,11 +2178,9 @@ nsTreeBodyFrame::PaintColumn(nsTreeColumn* aColumn, colRect.Deflate(colMargin); PaintBackgroundLayer(colContext, aPresContext, aRenderingContext, colRect, aDirtyRect); - - return NS_OK; } -nsresult +void nsTreeBodyFrame::PaintRow(PRInt32 aRowIndex, const nsRect& aRowRect, nsIPresContext* aPresContext, @@ -2277,7 +2192,7 @@ nsTreeBodyFrame::PaintRow(PRInt32 aRowIndex, // Without a view, we have no data. Check for this up front. if (!mView) - return NS_OK; + return; // Now obtain the properties for our row. // XXX Automatically fill in the following props: open, closed, container, leaf, selected, focused @@ -2301,19 +2216,19 @@ nsTreeBodyFrame::PaintRow(PRInt32 aRowIndex, PRBool useTheme = PR_FALSE; nsCOMPtr theme; const nsStyleDisplay* displayData = rowContext->GetStyleDisplay(); - if ( displayData->mAppearance ) { + if (displayData->mAppearance) { aPresContext->GetTheme(getter_AddRefs(theme)); if (theme && theme->ThemeSupportsWidget(aPresContext, nsnull, displayData->mAppearance)) useTheme = PR_TRUE; } PRBool isSelected = PR_FALSE; nsCOMPtr selection; - GetSelection(getter_AddRefs(selection)); - if ( selection ) + mView->GetSelection(getter_AddRefs(selection)); + if (selection) selection->IsSelected(aRowIndex, &isSelected); - if ( useTheme && !isSelected ) + if (useTheme && !isSelected) theme->DrawWidgetBackground(&aRenderingContext, this, - displayData->mAppearance, rowRect, aDirtyRect); + displayData->mAppearance, rowRect, aDirtyRect); else PaintBackgroundLayer(rowContext, aPresContext, aRenderingContext, rowRect, aDirtyRect); @@ -2323,108 +2238,118 @@ nsTreeBodyFrame::PaintRow(PRInt32 aRowIndex, PRBool isSeparator = PR_FALSE; mView->IsSeparator(aRowIndex, &isSeparator); if (isSeparator) { - // The row is a separator. Paint only a double horizontal line. + // The row is a separator. - // Find the primary cell. - nscoord currX, primaryX1, primaryX2; - currX = primaryX1 = primaryX2 = rowRect.x; - for (nsTreeColumn* currCol = mColumns; currCol && currX < mInnerBox.x+mInnerBox.width; - currCol = currCol->GetNext()) { - if (currCol->IsPrimary()) { - nsRect cellRect(currX, rowRect.y, currCol->GetWidth(), rowRect.height); - PRInt32 overflow = cellRect.x+cellRect.width-(mInnerBox.x+mInnerBox.width); - if (overflow > 0) - cellRect.width -= overflow; - nsRect dirtyRect; - if (dirtyRect.IntersectRect(aDirtyRect, cellRect)) - PaintCell(aRowIndex, currCol, cellRect, aPresContext, aRenderingContext, aDirtyRect, primaryX2); - - primaryX1 = currX; - PRInt32 level; - mView->GetLevel(aRowIndex, &level); - if (level == 0) { - primaryX1 += mIndentation; - } - - break; - } - currX += currCol->GetWidth(); - } - - // Resolve style for the separator. - nsStyleContext* separatorContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeseparator); - PRBool useTheme = PR_FALSE; - nsCOMPtr theme; - const nsStyleDisplay* displayData = separatorContext->GetStyleDisplay(); - if ( displayData->mAppearance ) { - aPresContext->GetTheme(getter_AddRefs(theme)); - if (theme && theme->ThemeSupportsWidget(aPresContext, nsnull, displayData->mAppearance)) - useTheme = PR_TRUE; - } - - // use -moz-appearance if provided. - if (useTheme) { - if (primaryX1 > rowRect.x) { - // XXX We should draw the left side of the native separator here. - // The problem is that Mac native theme implementation is too smart - // and draws a vertical line if the separator is too narrow. - } - rowRect.width -= primaryX2 - rowRect.x; - rowRect.x = primaryX2; - theme->DrawWidgetBackground(&aRenderingContext, this, - displayData->mAppearance, rowRect, aDirtyRect); - } - else { - // Get border style - const nsStyleBorder* borderStyle = separatorContext->GetStyleBorder(); - - aRenderingContext.PushState(); - - PRUint8 side = NS_SIDE_TOP; - nscoord currY = rowRect.y + rowRect.height / 2; - for (PRInt32 i = 0; i < 2; i++) { - nscolor color; - PRBool transparent; PRBool foreground; - borderStyle->GetBorderColor(side, color, transparent, foreground); - aRenderingContext.SetColor(color); - PRUint8 style; - style = borderStyle->GetBorderStyle(side); - aRenderingContext.SetLineStyle(ConvertBorderStyleToLineStyle(style)); - - if (primaryX1 > rowRect.x) { - aRenderingContext.DrawLine(rowRect.x, currY, primaryX1, currY); - } - aRenderingContext.DrawLine(primaryX2, currY, rowRect.x + rowRect.width, currY); - - side = NS_SIDE_BOTTOM; - currY += 16; - } - - PRBool clipState; - aRenderingContext.PopState(clipState); - } - } - else { - // Now loop over our cells. Only paint a cell if it intersects with our dirty rect. - nscoord currX = rowRect.x; - for (nsTreeColumn* currCol = mColumns; currCol && currX < mInnerBox.x+mInnerBox.width; - currCol = currCol->GetNext()) { - nsRect cellRect(currX, rowRect.y, currCol->GetWidth(), rowRect.height); + nscoord primaryX = rowRect.x; + nsTreeColumn* primaryCol = mColumns->GetPrimaryColumn(); + if (primaryCol) { + // Paint the primary cell. + nsRect cellRect(primaryCol->GetX(), rowRect.y, primaryCol->GetWidth(), rowRect.height); PRInt32 overflow = cellRect.x+cellRect.width-(mInnerBox.x+mInnerBox.width); if (overflow > 0) cellRect.width -= overflow; nsRect dirtyRect; - nscoord dummy; if (dirtyRect.IntersectRect(aDirtyRect, cellRect)) - PaintCell(aRowIndex, currCol, cellRect, aPresContext, aRenderingContext, aDirtyRect, dummy); - currX += currCol->GetWidth(); + PaintCell(aRowIndex, primaryCol, cellRect, aPresContext, aRenderingContext, aDirtyRect, primaryX); + + // Paint the left side of the separator. + nscoord currX; + nsTreeColumn* previousCol = primaryCol->GetPrevious(); + if (previousCol) + currX = previousCol->GetX() + previousCol->GetWidth(); + else + currX = rowRect.x; + + PRInt32 level; + mView->GetLevel(aRowIndex, &level); + if (level == 0) + currX += mIndentation; + + if (currX > rowRect.x) { + nsRect separatorRect(rowRect); + separatorRect.width -= rowRect.x + rowRect.width - currX; + PaintSeparator(aRowIndex, separatorRect, aPresContext, aRenderingContext, aDirtyRect); + } + } + + // Paint the right side (whole) separator. + nsRect separatorRect(rowRect); + if (primaryX > rowRect.x) { + separatorRect.width -= primaryX - rowRect.x; + separatorRect.x += primaryX - rowRect.x; + } + PaintSeparator(aRowIndex, separatorRect, aPresContext, aRenderingContext, aDirtyRect); + } + else { + // Now loop over our cells. Only paint a cell if it intersects with our dirty rect. + for (nsTreeColumn* currCol = mColumns->GetFirstColumn(); currCol && currCol->GetX() < mInnerBox.x + mInnerBox.width; + currCol = currCol->GetNext()) { + // Don't paint cells in hidden columns. + if (currCol->GetWidth()) { + nsRect cellRect(currCol->GetX(), rowRect.y, currCol->GetWidth(), rowRect.height); + PRInt32 overflow = cellRect.x+cellRect.width-(mInnerBox.x+mInnerBox.width); + if (overflow > 0) + cellRect.width -= overflow; + nsRect dirtyRect; + nscoord dummy; + if (dirtyRect.IntersectRect(aDirtyRect, cellRect)) + PaintCell(aRowIndex, currCol, cellRect, aPresContext, aRenderingContext, aDirtyRect, dummy); + } } } - - return NS_OK; } -nsresult +void +nsTreeBodyFrame::PaintSeparator(PRInt32 aRowIndex, + const nsRect& aSeparatorRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + // Resolve style for the separator. + nsStyleContext* separatorContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeseparator); + PRBool useTheme = PR_FALSE; + nsCOMPtr theme; + const nsStyleDisplay* displayData = separatorContext->GetStyleDisplay(); + if ( displayData->mAppearance ) { + aPresContext->GetTheme(getter_AddRefs(theme)); + if (theme && theme->ThemeSupportsWidget(aPresContext, nsnull, displayData->mAppearance)) + useTheme = PR_TRUE; + } + + // use -moz-appearance if provided. + if (useTheme) { + theme->DrawWidgetBackground(&aRenderingContext, this, + displayData->mAppearance, aSeparatorRect, aDirtyRect); + } + else { + const nsStylePosition* stylePosition = separatorContext->GetStylePosition(); + + // Obtain the height for the separator or use the default value. + nscoord height; + if (stylePosition->mHeight.GetUnit() == eStyleUnit_Coord) + height = stylePosition->mHeight.GetCoordValue(); + else { + // Use default height 2px. + float p2t = mPresContext->PixelsToTwips(); + height = NSIntPixelsToTwips(2, p2t); + } + + // Obtain the margins for the separator and then deflate our rect by that + // amount. The separator is assumed to be contained within the deflated rect. + nsRect separatorRect(aSeparatorRect.x, aSeparatorRect.y, aSeparatorRect.width, height); + nsMargin separatorMargin; + separatorContext->GetStyleMargin()->GetMargin(separatorMargin); + separatorRect.Deflate(separatorMargin); + + // Center the separator. + separatorRect.y += (aSeparatorRect.height - height) / 2; + + PaintBackgroundLayer(separatorContext, aPresContext, aRenderingContext, separatorRect, aDirtyRect); + } +} + +void nsTreeBodyFrame::PaintCell(PRInt32 aRowIndex, nsTreeColumn* aColumn, const nsRect& aCellRect, @@ -2433,13 +2358,10 @@ nsTreeBodyFrame::PaintCell(PRInt32 aRowIndex, const nsRect& aDirtyRect, nscoord& aCurrX) { - if (aCellRect.width == 0) - return NS_OK; // Don't paint cells in hidden columns. - // Now obtain the properties for our cell. // XXX Automatically fill in the following props: open, closed, container, leaf, selected, focused, and the col ID. PrefillPropertyArray(aRowIndex, aColumn); - mView->GetCellProperties(aRowIndex, aColumn->GetID().get(), mScratchArray); + mView->GetCellProperties(aRowIndex, aColumn, mScratchArray); // Resolve style for the cell. It contains all the info we need to lay ourselves // out and to paint. @@ -2481,14 +2403,14 @@ nsTreeBodyFrame::PaintCell(PRInt32 aRowIndex, nsStyleContext* lineContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeline); if (lineContext->GetStyleVisibility()->IsVisibleOrCollapsed() && level) { - // Paint the connecting lines. + // Paint the thread lines. // Get the size of the twisty. We don't want to paint the twisty // before painting of connecting lines since it would paint lines over // the twisty. But we need to leave a place for it. nsStyleContext* twistyContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreetwisty); - nsRect twistySize = GetImageSize(aRowIndex, aColumn->GetID().get(), PR_TRUE, twistyContext); + nsRect twistySize = GetImageSize(aRowIndex, aColumn, PR_TRUE, twistyContext); nsMargin twistyMargin; twistyContext->GetStyleMargin()->GetMargin(twistyMargin); @@ -2573,21 +2495,21 @@ nsTreeBodyFrame::PaintCell(PRInt32 aRowIndex, nsRect dirtyRect; if (dirtyRect.IntersectRect(aDirtyRect, elementRect)) { switch (aColumn->GetType()) { - case nsTreeColumn::eText: + case nsITreeColumn::TYPE_TEXT: PaintText(aRowIndex, aColumn, elementRect, aPresContext, aRenderingContext, aDirtyRect, currX); break; - case nsTreeColumn::eCheckbox: + case nsITreeColumn::TYPE_CHECKBOX: PaintCheckbox(aRowIndex, aColumn, elementRect, aPresContext, aRenderingContext, aDirtyRect); break; - case nsTreeColumn::eProgressMeter: + case nsITreeColumn::TYPE_PROGRESSMETER: PRInt32 state; - mView->GetProgressMode(aRowIndex, aColumn->GetID().get(), &state); + mView->GetProgressMode(aRowIndex, aColumn, &state); switch (state) { - case nsITreeView::progressNormal: - case nsITreeView::progressUndetermined: + case nsITreeView::PROGRESS_NORMAL: + case nsITreeView::PROGRESS_UNDETERMINED: PaintProgressMeter(aRowIndex, aColumn, elementRect, aPresContext, aRenderingContext, aDirtyRect); break; - case nsITreeView::progressNone: + case nsITreeView::PROGRESS_NONE: default: PaintText(aRowIndex, aColumn, elementRect, aPresContext, aRenderingContext, aDirtyRect, currX); break; @@ -2598,11 +2520,9 @@ nsTreeBodyFrame::PaintCell(PRInt32 aRowIndex, } aCurrX = currX; - - return NS_OK; } -nsresult +void nsTreeBodyFrame::PaintTwisty(PRInt32 aRowIndex, nsTreeColumn* aColumn, const nsRect& aTwistyRect, @@ -2648,7 +2568,7 @@ nsTreeBodyFrame::PaintTwisty(PRInt32 aRowIndex, // If the image hasn't loaded and if no width is specified, then we just bail. If there is // a -moz-apperance involved, adjust the rect by the minimum widget size provided by // the theme implementation. - nsRect imageSize = GetImageSize(aRowIndex, aColumn->GetID().get(), PR_TRUE, twistyContext); + nsRect imageSize = GetImageSize(aRowIndex, aColumn, PR_TRUE, twistyContext); if (imageSize.height > twistyRect.height) imageSize.height = twistyRect.height; if (imageSize.width > twistyRect.width) @@ -2699,7 +2619,7 @@ nsTreeBodyFrame::PaintTwisty(PRInt32 aRowIndex, // Get the image for drawing. nsCOMPtr image; PRBool useImageRegion = PR_TRUE; - GetImage(aRowIndex, aColumn->GetID().get(), PR_TRUE, twistyContext, useImageRegion, getter_AddRefs(image)); + GetImage(aRowIndex, aColumn, PR_TRUE, twistyContext, useImageRegion, getter_AddRefs(image)); if (image) { nsPoint p(twistyRect.x, twistyRect.y); @@ -2713,11 +2633,9 @@ nsTreeBodyFrame::PaintTwisty(PRInt32 aRowIndex, } } } - - return NS_OK; } -nsresult +void nsTreeBodyFrame::PaintImage(PRInt32 aRowIndex, nsTreeColumn* aColumn, const nsRect& aImageRect, @@ -2742,7 +2660,7 @@ nsTreeBodyFrame::PaintImage(PRInt32 aRowIndex, // examining the style context for a width first. If it has one, we use that. If it doesn't, // we use the image's natural width. // If the image hasn't loaded and if no width is specified, then we just bail. - nsRect imageSize = GetImageSize(aRowIndex, aColumn->GetID().get(), PR_FALSE, imageContext); + nsRect imageSize = GetImageSize(aRowIndex, aColumn, PR_FALSE, imageContext); if (imageSize.height > imageRect.height) imageSize.height = imageRect.height; @@ -2760,7 +2678,7 @@ nsTreeBodyFrame::PaintImage(PRInt32 aRowIndex, // Get the image for drawing. PRBool useImageRegion = PR_TRUE; nsCOMPtr image; - GetImage(aRowIndex, aColumn->GetID().get(), PR_FALSE, imageContext, useImageRegion, getter_AddRefs(image)); + GetImage(aRowIndex, aColumn, PR_FALSE, imageContext, useImageRegion, getter_AddRefs(image)); if (image) { // Paint our borders and background for our image rect PaintBackgroundLayer(imageContext, aPresContext, aRenderingContext, imageRect, aDirtyRect); @@ -2776,10 +2694,6 @@ nsTreeBodyFrame::PaintImage(PRInt32 aRowIndex, // Center the image. XXX Obey vertical-align style prop? - float t2p, p2t; - t2p = mPresContext->TwipsToPixels(); - p2t = mPresContext->PixelsToTwips(); - if (imageSize.height < imageRect.height) { p.y += (imageRect.height - imageSize.height)/2; } @@ -2792,11 +2706,9 @@ nsTreeBodyFrame::PaintImage(PRInt32 aRowIndex, // Paint the image. aRenderingContext.DrawImage(image, &imageSize, &p); } - - return NS_OK; } -nsresult +void nsTreeBodyFrame::PaintText(PRInt32 aRowIndex, nsTreeColumn* aColumn, const nsRect& aTextRect, @@ -2807,10 +2719,10 @@ nsTreeBodyFrame::PaintText(PRInt32 aRowIndex, { // Now obtain the text for our cell. nsAutoString text; - mView->GetCellText(aRowIndex, aColumn->GetID().get(), text); + mView->GetCellText(aRowIndex, aColumn, text); if (text.Length() == 0) - return NS_OK; // Don't paint an empty string. XXX What about background/borders? Still paint? + return; // Don't paint an empty string. XXX What about background/borders? Still paint? // Resolve style for the text. It contains all the info we need to lay ourselves // out and to paint. @@ -2831,8 +2743,7 @@ nsTreeBodyFrame::PaintText(PRInt32 aRowIndex, // Compute our text size. nsCOMPtr fontMet; aPresContext->DeviceContext()-> - GetMetricsFor(textContext->GetStyleFont()->mFont, - *getter_AddRefs(fontMet)); + GetMetricsFor(textContext->GetStyleFont()->mFont, *getter_AddRefs(fontMet)); nscoord height, baseline; fontMet->GetHeight(height); @@ -3009,11 +2920,9 @@ nsTreeBodyFrame::PaintText(PRInt32 aRowIndex, NS_TIMELINE_STOP_TIMER("Render Outline Text"); NS_TIMELINE_MARK_TIMER("Render Outline Text"); #endif - - return NS_OK; } -nsresult +void nsTreeBodyFrame::PaintCheckbox(PRInt32 aRowIndex, nsTreeColumn* aColumn, const nsRect& aCheckboxRect, @@ -3021,10 +2930,53 @@ nsTreeBodyFrame::PaintCheckbox(PRInt32 aRowIndex, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { - return NS_OK; + // Resolve style for the checkbox. + nsStyleContext* checkboxContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreecheckbox); + + // Obtain the margins for the checkbox and then deflate our rect by that + // amount. The checkbox is assumed to be contained within the deflated rect. + nsRect checkboxRect(aCheckboxRect); + nsMargin checkboxMargin; + checkboxContext->GetStyleMargin()->GetMargin(checkboxMargin); + checkboxRect.Deflate(checkboxMargin); + + nsRect imageSize = GetImageSize(aRowIndex, aColumn, PR_TRUE, checkboxContext); + + if (imageSize.height > checkboxRect.height) + imageSize.height = checkboxRect.height; + if (imageSize.width > checkboxRect.width) + imageSize.width = checkboxRect.width; + + // Paint our borders and background for our image rect. + PaintBackgroundLayer(checkboxContext, aPresContext, aRenderingContext, checkboxRect, aDirtyRect); + + // Time to paint the checkbox. + // Adjust the rect for its border and padding. + nsMargin bp(0,0,0,0); + GetBorderPadding(checkboxContext, bp); + checkboxRect.Deflate(bp); + + // Get the image for drawing. + nsCOMPtr image; + PRBool useImageRegion = PR_TRUE; + GetImage(aRowIndex, aColumn, PR_TRUE, checkboxContext, useImageRegion, getter_AddRefs(image)); + if (image) { + nsPoint p(checkboxRect.x, checkboxRect.y); + + if (imageSize.height < checkboxRect.height) { + p.y += (checkboxRect.height - imageSize.height)/2; + } + + if (imageSize.width < checkboxRect.width) { + p.x += (checkboxRect.width - imageSize.width)/2; + } + + // Paint the image. + aRenderingContext.DrawImage(image, &imageSize, &p); + } } -nsresult +void nsTreeBodyFrame::PaintProgressMeter(PRInt32 aRowIndex, nsTreeColumn* aColumn, const nsRect& aProgressMeterRect, @@ -3050,8 +3002,8 @@ nsTreeBodyFrame::PaintProgressMeter(PRInt32 aRowIndex, // Time to paint our progress. PRInt32 state; - mView->GetProgressMode(aRowIndex, aColumn->GetID().get(), &state); - if (state == nsITreeView::progressNormal) { + mView->GetProgressMode(aRowIndex, aColumn, &state); + if (state == nsITreeView::PROGRESS_NORMAL) { // Adjust the rect for its border and padding. AdjustForBorderPadding(meterContext, meterRect); @@ -3060,7 +3012,7 @@ nsTreeBodyFrame::PaintProgressMeter(PRInt32 aRowIndex, // Now obtain the value for our cell. nsAutoString value; - mView->GetCellValue(aRowIndex, aColumn->GetID().get(), value); + mView->GetCellValue(aRowIndex, aColumn, value); PRInt32 rv; PRInt32 intValue = value.ToInteger(&rv); @@ -3072,28 +3024,26 @@ nsTreeBodyFrame::PaintProgressMeter(PRInt32 aRowIndex, meterRect.width = NSToCoordRound((float)intValue / 100 * meterRect.width); PRBool useImageRegion = PR_TRUE; nsCOMPtr image; - GetImage(aRowIndex, aColumn->GetID().get(), PR_TRUE, meterContext, useImageRegion, getter_AddRefs(image)); + GetImage(aRowIndex, aColumn, PR_TRUE, meterContext, useImageRegion, getter_AddRefs(image)); if (image) aRenderingContext.DrawTile(image, 0, 0, &meterRect); else aRenderingContext.FillRect(meterRect); } - else if (state == nsITreeView::progressUndetermined) { + else if (state == nsITreeView::PROGRESS_UNDETERMINED) { // Adjust the rect for its border and padding. AdjustForBorderPadding(meterContext, meterRect); PRBool useImageRegion = PR_TRUE; nsCOMPtr image; - GetImage(aRowIndex, aColumn->GetID().get(), PR_TRUE, meterContext, useImageRegion, getter_AddRefs(image)); + GetImage(aRowIndex, aColumn, PR_TRUE, meterContext, useImageRegion, getter_AddRefs(image)); if (image) aRenderingContext.DrawTile(image, 0, 0, &meterRect); } - - return NS_OK; } -nsresult +void nsTreeBodyFrame::PaintDropFeedback(const nsRect& aDropFeedbackRect, nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, @@ -3101,16 +3051,16 @@ nsTreeBodyFrame::PaintDropFeedback(const nsRect& aDropFeedbackRect, { // Paint the drop feedback in between rows. - // Find the primary cell. - nscoord currX = aDropFeedbackRect.x; - nsTreeColumn* currCol; - for (currCol = mColumns; currCol && currX < mInnerBox.x+mInnerBox.width; - currCol = currCol->GetNext()) { - if (currCol->IsPrimary()) - break; - currX += currCol->GetWidth(); - } - PrefillPropertyArray(mDropRow, currCol); + nscoord currX; + + // Adjust for the primary cell. + nsTreeColumn* primaryCol = mColumns->GetPrimaryColumn(); + if (primaryCol) + currX = primaryCol->GetX(); + else + currX = aDropFeedbackRect.x; + + PrefillPropertyArray(mSlots->mDropRow, primaryCol); // Resolve the style to use for the drop feedback. nsStyleContext* feedbackContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreedropfeedback); @@ -3118,22 +3068,22 @@ nsTreeBodyFrame::PaintDropFeedback(const nsRect& aDropFeedbackRect, // Paint only if it is visible. if (feedbackContext->GetStyleVisibility()->IsVisibleOrCollapsed()) { PRInt32 level; - mView->GetLevel(mDropRow, &level); + mView->GetLevel(mSlots->mDropRow, &level); // If our previous or next row has greater level use that for // correct visual indentation. - if (mDropOrient == nsITreeView::inDropBefore) { - if (mDropRow > 0) { + if (mSlots->mDropOrient == nsITreeView::DROP_BEFORE) { + if (mSlots->mDropRow > 0) { PRInt32 previousLevel; - mView->GetLevel(mDropRow - 1, &previousLevel); + mView->GetLevel(mSlots->mDropRow - 1, &previousLevel); if (previousLevel > level) level = previousLevel; } } else { - if (mDropRow < mRowCount - 1) { + if (mSlots->mDropRow < mRowCount - 1) { PRInt32 nextLevel; - mView->GetLevel(mDropRow + 1, &nextLevel); + mView->GetLevel(mSlots->mDropRow + 1, &nextLevel); if (nextLevel > level) level = nextLevel; } @@ -3142,7 +3092,7 @@ nsTreeBodyFrame::PaintDropFeedback(const nsRect& aDropFeedbackRect, currX += mIndentation * level; nsStyleContext* twistyContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreetwisty); - nsRect twistySize = GetImageSize(mDropRow, currCol->GetID().get(), PR_TRUE, twistyContext); + nsRect twistySize = GetImageSize(mSlots->mDropRow, primaryCol, PR_TRUE, twistyContext); nsMargin twistyMargin; twistyContext->GetStyleMargin()->GetMargin(twistyMargin); twistySize.Inflate(twistyMargin); @@ -3156,8 +3106,7 @@ nsTreeBodyFrame::PaintDropFeedback(const nsRect& aDropFeedbackRect, width = stylePosition->mWidth.GetCoordValue(); else { // Use default width 50px. - float p2t; - p2t = mPresContext->PixelsToTwips(); + float p2t = mPresContext->PixelsToTwips(); width = NSIntPixelsToTwips(50, p2t); } @@ -3167,8 +3116,7 @@ nsTreeBodyFrame::PaintDropFeedback(const nsRect& aDropFeedbackRect, height = stylePosition->mHeight.GetCoordValue(); else { // Use default height 2px. - float p2t; - p2t = mPresContext->PixelsToTwips(); + float p2t = mPresContext->PixelsToTwips(); height = NSIntPixelsToTwips(2, p2t); } @@ -3179,14 +3127,14 @@ nsTreeBodyFrame::PaintDropFeedback(const nsRect& aDropFeedbackRect, feedbackContext->GetStyleMargin()->GetMargin(margin); feedbackRect.Deflate(margin); + feedbackRect.y += (aDropFeedbackRect.height - height) / 2; + // Finally paint the drop feedback. PaintBackgroundLayer(feedbackContext, aPresContext, aRenderingContext, feedbackRect, aDirtyRect); } - - return NS_OK; } -nsresult +void nsTreeBodyFrame::PaintBackgroundLayer(nsStyleContext* aStyleContext, nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, @@ -3209,8 +3157,6 @@ nsTreeBodyFrame::PaintBackgroundLayer(nsStyleContext* aStyleContext, nsCSSRendering::PaintOutline(aPresContext, aRenderingContext, this, aDirtyRect, aRect, *myBorder, *myOutline, aStyleContext, 0); - - return NS_OK; } // Scrolling @@ -3219,14 +3165,14 @@ NS_IMETHODIMP nsTreeBodyFrame::EnsureRowIsVisible(PRInt32 aRow) if (!mView) return NS_OK; - if (mTopRowIndex <= aRow && mTopRowIndex+mPageCount > aRow) + if (mTopRowIndex <= aRow && mTopRowIndex+mPageLength > aRow) return NS_OK; if (aRow < mTopRowIndex) ScrollToRow(aRow); else { // Bring it just on-screen. - PRInt32 distance = aRow - (mTopRowIndex+mPageCount)+1; + PRInt32 distance = aRow - (mTopRowIndex+mPageLength)+1; ScrollToRow(mTopRowIndex+distance); } @@ -3242,9 +3188,9 @@ NS_IMETHODIMP nsTreeBodyFrame::ScrollToRow(PRInt32 aRow) // mac can't process the event loop during a drag, so if we're dragging, // grab the scroll widget and make it paint synchronously. This is // sorta slow (having to paint the entire tree), but it works. - if ( mDragSession ) { + if (mSlots && mSlots->mDragSession) { nsIWidget* scrollWidget = mScrollbar->GetWindow(); - if ( scrollWidget ) + if (scrollWidget) scrollWidget->Invalidate(PR_TRUE); } #endif @@ -3261,7 +3207,7 @@ NS_IMETHODIMP nsTreeBodyFrame::ScrollByLines(PRInt32 aNumLines) if (newIndex < 0) newIndex = 0; else { - PRInt32 lastPageTopRow = mRowCount - mPageCount; + PRInt32 lastPageTopRow = mRowCount - mPageLength; if (newIndex > lastPageTopRow) newIndex = lastPageTopRow; } @@ -3275,11 +3221,11 @@ NS_IMETHODIMP nsTreeBodyFrame::ScrollByPages(PRInt32 aNumPages) if (!mView) return NS_OK; - PRInt32 newIndex = mTopRowIndex + aNumPages * mPageCount; + PRInt32 newIndex = mTopRowIndex + aNumPages * mPageLength; if (newIndex < 0) newIndex = 0; else { - PRInt32 lastPageTopRow = mRowCount - mPageCount; + PRInt32 lastPageTopRow = mRowCount - mPageLength; if (newIndex > lastPageTopRow) newIndex = lastPageTopRow; } @@ -3297,7 +3243,7 @@ nsTreeBodyFrame::ScrollInternal(PRInt32 aRow) PRInt32 delta = aRow - mTopRowIndex; if (delta > 0) { - if (mTopRowIndex == (mRowCount - mPageCount + 1)) + if (mTopRowIndex == (mRowCount - mPageLength + 1)) return NS_OK; } else { @@ -3307,8 +3253,7 @@ nsTreeBodyFrame::ScrollInternal(PRInt32 aRow) mTopRowIndex += delta; - float t2p; - t2p = mPresContext->TwipsToPixels(); + float t2p = mPresContext->TwipsToPixels(); nscoord rowHeightAsPixels = NSToCoordRound((float)mRowHeight*t2p); // See if we have a background image. If we do, then we cannot blit. @@ -3317,8 +3262,11 @@ nsTreeBodyFrame::ScrollInternal(PRInt32 aRow) PRInt32 absDelta = PR_ABS(delta); if (hasBackground || absDelta*mRowHeight >= mRect.height) Invalidate(); - else if (mTreeWidget) - mTreeWidget->Scroll(0, -delta*rowHeightAsPixels, nsnull); + else { + nsIWidget* widget = nsLeafBoxFrame::GetView()->GetWidget(); + if (widget) + widget->Scroll(0, -delta*rowHeightAsPixels, nsnull); + } return NS_OK; } @@ -3339,8 +3287,7 @@ nsTreeBodyFrame::PositionChanged(PRInt32 aOldIndex, PRInt32& aNewIndex) if (!EnsureScrollbar()) return NS_ERROR_UNEXPECTED; - float t2p; - t2p = mPresContext->TwipsToPixels(); + float t2p = mPresContext->TwipsToPixels(); nscoord rh = NSToCoordRound((float)mRowHeight*t2p); nscoord oldrow = aOldIndex/rh; @@ -3395,103 +3342,8 @@ nsTreeBodyFrame::PseudoMatches(nsIAtom* aTag, nsCSSSelector* aSelector, PRBool* return NS_OK; } -void -nsTreeBodyFrame::InvalidateColumnCache() -{ - mColumnsDirty = PR_TRUE; -} - -void -nsTreeBodyFrame::EnsureColumns() -{ - if (!mColumns || mColumnsDirty) { - delete mColumns; - mColumns = nsnull; - mColumnsDirty = PR_FALSE; - - nsCOMPtr parent; - GetBaseElement(getter_AddRefs(parent)); - - if (!parent) - return; - - nsIPresShell *shell = mPresContext->PresShell(); - - // Note: this is dependent on the anonymous content for select - // defined in select.xml - if (parent->Tag() == nsHTMLAtoms::select && - parent->IsContentOfType(nsIContent::eHTML)) { - // We can avoid crawling the content nodes in this case, since we know - // that we have a single column, and we know where it's at. - - ChildIterator iter, last; - ChildIterator::Init(parent, &iter, &last); - nsCOMPtr treeCols = *iter; - - nsIContent *column = treeCols->GetChildAt(0); - - nsIFrame* colFrame = nsnull; - shell->GetPrimaryFrameFor(column, &colFrame); - mColumns = new nsTreeColumn(column, colFrame); - return; - } - - nsCOMPtr colsContent; - nsTreeUtils::GetImmediateChild(parent, nsXULAtoms::treecols, getter_AddRefs(colsContent)); - if (!colsContent) - return; - - nsIFrame* colsFrame = nsnull; - shell->GetPrimaryFrameFor(colsContent, &colsFrame); - if (!colsFrame) - return; - - const nsStyleVisibility* vis = GetStyleVisibility(); - PRBool normalDirection = (vis->mDirection == NS_STYLE_DIRECTION_LTR); - - nsIBox* colsBox; - CallQueryInterface(colsFrame, &colsBox); - nsIBox* colBox = nsnull; - colsBox->GetChildBox(&colBox); - nsTreeColumn* currCol = nsnull; - while (colBox) { - nsIFrame* frame = nsnull; - colBox->GetFrame(&frame); - nsIContent* content = frame->GetContent(); - - nsINodeInfo *ni = content->GetNodeInfo(); - if (ni && ni->Equals(nsXULAtoms::treecol, kNameSpaceID_XUL)) { - // Create a new column structure. - nsTreeColumn* col = new nsTreeColumn(content, frame); - if (!col) { - /* XXX What should happen if we can't make a tree column? - * We could destroy the tree and mark it dirty, but that - * risks an infinite loop. For now we'll just finish trying - * to build the tree and hope nothing else misbehaves when - * it isn't given enough memory. - */ - } else { - if (normalDirection) { - if (currCol) - currCol->SetNext(col); - else - mColumns = col; - currCol = col; - } - else { - col->SetNext(mColumns); - mColumns = col; - } - } - } - - colBox->GetNextBox(&colBox); - } - } -} - -nsresult -nsTreeBodyFrame::GetBaseElement(nsIContent** aContent) +nsIContent* +nsTreeBodyFrame::GetBaseElement() { nsINodeInfo *ni; nsIContent* parent = mContent; @@ -3507,8 +3359,7 @@ nsTreeBodyFrame::GetBaseElement(nsIContent** aContent) parent = parent->GetParent(); } - NS_IF_ADDREF(*aContent = parent); - return NS_OK; + return parent; } NS_IMETHODIMP @@ -3524,164 +3375,6 @@ nsTreeBodyFrame::ClearStyleAndImageCaches() return NS_OK; } -#ifdef XP_MAC -#pragma mark - -#endif - -// Tell the view where the drop happened -NS_IMETHODIMP -nsTreeBodyFrame::OnDragDrop (nsIDOMEvent* aEvent) -{ - // Remove the drop folder and all its parents from the array. - PRInt32 parentIndex; - nsresult rv = mView->GetParentIndex(mDropRow, &parentIndex); - while (NS_SUCCEEDED(rv) && parentIndex >= 0) { - mValueArray.RemoveValue(parentIndex); - rv = mView->GetParentIndex(parentIndex, &parentIndex); - } - - mView->Drop(mDropRow, mDropOrient); - - return rv; -} // OnDragDrop - -// Clear out all our tracking vars. -NS_IMETHODIMP -nsTreeBodyFrame::OnDragExit(nsIDOMEvent* aEvent) -{ - if (mDropAllowed) { - mDropAllowed = PR_FALSE; - InvalidatePrimaryCell(mDropRow + (mDropOrient == nsITreeView::inDropAfter ? 1 : 0)); - } - else - mDropAllowed = PR_FALSE; - mDropRow = -1; - mDropOrient = -1; - mDragSession = nsnull; - mScrollLines = 0; - - if (mTimer) { - mTimer->Cancel(); - mTimer = nsnull; - } - - if (mValueArray.Count()) { - // Close all spring loaded folders except the drop folder. - CreateTimer(nsILookAndFeel::eMetric_TreeCloseDelay, - CloseCallback, nsITimer::TYPE_ONE_SHOT, - getter_AddRefs(mTimer)); - } - - return NS_OK; -} // OnDragExit - -// The mouse is hovering over this tree. If we determine things are different from the -// last time, invalidate primary cell at the old position, query the view to see if the current location is -// droppable, and then invalidate primary cell at the new location if it is. The mouse may or may -// not have changed position from the last time we were called, so optimize out a lot of -// the extra notifications by checking if anything changed first. -// For drop feedback we use drop, dropBefore and dropAfter property. -NS_IMETHODIMP -nsTreeBodyFrame::OnDragOver(nsIDOMEvent* aEvent) -{ - if (! mView) - return NS_OK; - - // Save last values, we will need them. - PRInt32 lastDropRow = mDropRow; - PRInt16 lastDropOrient = mDropOrient; - PRInt16 lastScrollLines = mScrollLines; - - // Compute the row mouse is over and the above/below/on state. - // Below we'll use this to see if anything changed. - // Also check if we want to auto-scroll. - ComputeDropPosition(aEvent, &mDropRow, &mDropOrient, &mScrollLines); - - // While we're here, handle tracking of scrolling during a drag. - if (mScrollLines) { - if (mDropAllowed) { - // Invalidate primary cell at old location. - mDropAllowed = PR_FALSE; - InvalidatePrimaryCell(lastDropRow + (lastDropOrient == nsITreeView::inDropAfter ? 1 : 0)); - } -#if !defined(XP_MAC) && !defined(XP_MACOSX) - if (!lastScrollLines) { - // Cancel any previosly initialized timer. - if (mTimer) { - mTimer->Cancel(); - mTimer = nsnull; - } - - // Set a timer to trigger the tree scrolling. - CreateTimer(nsILookAndFeel::eMetric_TreeLazyScrollDelay, - LazyScrollCallback, nsITimer::TYPE_ONE_SHOT, - getter_AddRefs(mTimer)); - } -#else - ScrollByLines(mScrollLines); -#endif - // Bail out to prevent spring loaded timer and feedback line settings. - return NS_OK; - } - - // If changed from last time, invalidate primary cell at the old location and if allowed, - // invalidate primary cell at the new location. If nothing changed, just bail. - if (mDropRow != lastDropRow || mDropOrient != lastDropOrient) { - // Invalidate row at the old location. - if (mDropAllowed) { - mDropAllowed = PR_FALSE; - InvalidatePrimaryCell(lastDropRow + (lastDropOrient == nsITreeView::inDropAfter ? 1 : 0)); - } - - if (mTimer) { - // Timer is active but for a different row than the current one, kill it. - mTimer->Cancel(); - mTimer = nsnull; - } - - if (mDropRow >= 0) { - if (!mTimer && mDropOrient == nsITreeView::inDropOn) { - // Either there wasn't a timer running or it was just killed above. - // If over a folder, start up a timer to open the folder. - PRBool isContainer = PR_FALSE; - mView->IsContainer(mDropRow, &isContainer); - if (isContainer) { - PRBool isOpen = PR_FALSE; - mView->IsContainerOpen(mDropRow, &isOpen); - if (!isOpen) { - // This node isn't expanded, set a timer to expand it. - CreateTimer(nsILookAndFeel::eMetric_TreeOpenDelay, - OpenCallback, nsITimer::TYPE_ONE_SHOT, - getter_AddRefs(mTimer)); - } - } - } - - PRBool canDropAtNewLocation = PR_FALSE; - if (mDropOrient == nsITreeView::inDropOn) - mView->CanDropOn(mDropRow, &canDropAtNewLocation); - else - mView->CanDropBeforeAfter(mDropRow, mDropOrient == nsITreeView::inDropBefore, &canDropAtNewLocation); - - if (canDropAtNewLocation) { - // Invalidate row at the new location. - mDropAllowed = canDropAtNewLocation; - InvalidatePrimaryCell(mDropRow + (mDropOrient == nsITreeView::inDropAfter ? 1 : 0)); - } - } - } - - // alert the drag session we accept the drop. We have to do this every time - // since the |canDrop| attribute is reset before we're called. - if (mDropAllowed && mDragSession) - mDragSession->SetCanDrop(PR_TRUE); - - // Prevent default handler to fire. - aEvent->PreventDefault(); - - return NS_OK; -} // OnDragOver - PRBool nsTreeBodyFrame::CanAutoScroll(PRInt32 aRowIndex) { @@ -3709,105 +3402,74 @@ nsTreeBodyFrame::CanAutoScroll(PRInt32 aRowIndex) // For non-containers, if the mouse is in the top 50% of the row, the drop is // _before_ and the bottom 50% _after_ void -nsTreeBodyFrame::ComputeDropPosition(nsIDOMEvent* aEvent, PRInt32* aRow, PRInt16* aOrient, +nsTreeBodyFrame::ComputeDropPosition(nsGUIEvent* aEvent, PRInt32* aRow, PRInt16* aOrient, PRInt16* aScrollLines) { - *aRow = -1; *aOrient = -1; *aScrollLines = 0; - nsCOMPtr mouseEvent (do_QueryInterface(aEvent)); - if (mouseEvent) { - PRInt32 x = 0; - PRInt32 y = 0; - mouseEvent->GetClientX(&x); - mouseEvent->GetClientY(&y); - - PRInt32 xTwips; - PRInt32 yTwips; - AdjustEventCoordsToBoxCoordSpace (x, y, &xTwips, &yTwips); + PRInt32 xTwips = aEvent->point.y; + PRInt32 yTwips = aEvent->point.y; - GetRowAt(x, y, aRow); - if (*aRow >=0) { - // Compute the top/bottom of the row in question. - PRInt32 yOffset = yTwips - mRowHeight * (*aRow - mTopRowIndex); + *aRow = GetRowAt(xTwips, yTwips); + if (*aRow >=0) { + // Compute the top/bottom of the row in question. + PRInt32 yOffset = yTwips - mRowHeight * (*aRow - mTopRowIndex); - PRBool isContainer = PR_FALSE; - mView->IsContainer (*aRow, &isContainer); - if (isContainer) { - // for a container, use a 25%/50%/25% breakdown - if (yOffset < mRowHeight / 4) - *aOrient = nsITreeView::inDropBefore; - else if (yOffset > mRowHeight - (mRowHeight / 4)) - *aOrient = nsITreeView::inDropAfter; - else - *aOrient = nsITreeView::inDropOn; - } - else { - // for a non-container use a 50%/50% breakdown - if (yOffset < mRowHeight / 2) - *aOrient = nsITreeView::inDropBefore; - else - *aOrient = nsITreeView::inDropAfter; - } + PRBool isContainer = PR_FALSE; + mView->IsContainer (*aRow, &isContainer); + if (isContainer) { + // for a container, use a 25%/50%/25% breakdown + if (yOffset < mRowHeight / 4) + *aOrient = nsITreeView::DROP_BEFORE; + else if (yOffset > mRowHeight - (mRowHeight / 4)) + *aOrient = nsITreeView::DROP_AFTER; + else + *aOrient = nsITreeView::DROP_ON; } + else { + // for a non-container use a 50%/50% breakdown + if (yOffset < mRowHeight / 2) + *aOrient = nsITreeView::DROP_BEFORE; + else + *aOrient = nsITreeView::DROP_AFTER; + } + } - if (CanAutoScroll(*aRow)) { - // Get the max value from the look and feel service. - PRInt32 scrollLinesMax = 0; - mPresContext->LookAndFeel()-> - GetMetric(nsILookAndFeel::eMetric_TreeScrollLinesMax, scrollLinesMax); - scrollLinesMax--; - if (scrollLinesMax < 0) - scrollLinesMax = 0; + if (CanAutoScroll(*aRow)) { + // Get the max value from the look and feel service. + PRInt32 scrollLinesMax = 0; + mPresContext->LookAndFeel()-> + GetMetric(nsILookAndFeel::eMetric_TreeScrollLinesMax, scrollLinesMax); + scrollLinesMax--; + if (scrollLinesMax < 0) + scrollLinesMax = 0; - // Determine if we're w/in a margin of the top/bottom of the tree during a drag. - // This will ultimately cause us to scroll, but that's done elsewhere. - nscoord height = (3 * mRowHeight) / 4; - if (yTwips < height) { - // scroll up - *aScrollLines = NSToIntRound(-scrollLinesMax * (1 - (float)yTwips / height) - 1); - } - else if (yTwips > mRect.height - height) { - // scroll down - *aScrollLines = NSToIntRound(scrollLinesMax * (1 - (float)(mRect.height - yTwips) / height) + 1); - } + // Determine if we're w/in a margin of the top/bottom of the tree during a drag. + // This will ultimately cause us to scroll, but that's done elsewhere. + nscoord height = (3 * mRowHeight) / 4; + if (yTwips < height) { + // scroll up + *aScrollLines = NSToIntRound(-scrollLinesMax * (1 - (float)yTwips / height) - 1); + } + else if (yTwips > mRect.height - height) { + // scroll down + *aScrollLines = NSToIntRound(scrollLinesMax * (1 - (float)(mRect.height - yTwips) / height) + 1); } } } // ComputeDropPosition -// Cache several things we'll need throughout the course of our work. These -// will all get released on a drag exit -NS_IMETHODIMP -nsTreeBodyFrame::OnDragEnter(nsIDOMEvent* aEvent) -{ - if (mTimer) { - mTimer->Cancel(); - mTimer = nsnull; - } - - // cache the drag session - nsresult rv; - nsCOMPtr dragService = - do_GetService("@mozilla.org/widget/dragservice;1", &rv); - nsCOMPtr dragSession; - dragService->GetCurrentSession(getter_AddRefs(mDragSession)); - NS_ASSERTION(mDragSession, "can't get drag session"); - - return NS_OK; -} // OnDragEnter - void nsTreeBodyFrame::OpenCallback(nsITimer *aTimer, void *aClosure) { nsTreeBodyFrame* self = NS_STATIC_CAST(nsTreeBodyFrame*, aClosure); if (self) { aTimer->Cancel(); - self->mTimer = nsnull; + self->mSlots->mTimer = nsnull; - if (self->mDropRow >= 0) { - self->mValueArray.AppendValue(self->mDropRow); - self->mView->ToggleOpenState(self->mDropRow); + if (self->mSlots->mDropRow >= 0) { + self->mSlots->mValueArray.AppendValue(self->mSlots->mDropRow); + self->mView->ToggleOpenState(self->mSlots->mDropRow); } } } @@ -3818,12 +3480,12 @@ nsTreeBodyFrame::CloseCallback(nsITimer *aTimer, void *aClosure) nsTreeBodyFrame* self = NS_STATIC_CAST(nsTreeBodyFrame*, aClosure); if (self) { aTimer->Cancel(); - self->mTimer = nsnull; + self->mSlots->mTimer = nsnull; - for (PRInt32 i = self->mValueArray.Count() - 1; i >= 0; i--) { + for (PRInt32 i = self->mSlots->mValueArray.Count() - 1; i >= 0; i--) { if (self->mView) - self->mView->ToggleOpenState(self->mValueArray[i]); - self->mValueArray.RemoveValueAt(i); + self->mView->ToggleOpenState(self->mSlots->mValueArray[i]); + self->mSlots->mValueArray.RemoveValueAt(i); } } } @@ -3834,14 +3496,14 @@ nsTreeBodyFrame::LazyScrollCallback(nsITimer *aTimer, void *aClosure) nsTreeBodyFrame* self = NS_STATIC_CAST(nsTreeBodyFrame*, aClosure); if (self) { aTimer->Cancel(); - self->mTimer = nsnull; + self->mSlots->mTimer = nsnull; if (self->mView) { - self->ScrollByLines(self->mScrollLines); + self->ScrollByLines(self->mSlots->mScrollLines); // Set a new timer to scroll the tree repeatedly. self->CreateTimer(nsILookAndFeel::eMetric_TreeScrollDelay, ScrollCallback, nsITimer::TYPE_REPEATING_SLACK, - getter_AddRefs(self->mTimer)); + getter_AddRefs(self->mSlots->mTimer)); } } } @@ -3852,113 +3514,12 @@ nsTreeBodyFrame::ScrollCallback(nsITimer *aTimer, void *aClosure) nsTreeBodyFrame* self = NS_STATIC_CAST(nsTreeBodyFrame*, aClosure); if (self) { // Don't scroll if we are already at the top or bottom of the view. - if (self->mView && self->CanAutoScroll(self->mDropRow)) { - self->ScrollByLines(self->mScrollLines); + if (self->mView && self->CanAutoScroll(self->mSlots->mDropRow)) { + self->ScrollByLines(self->mSlots->mScrollLines); } else { aTimer->Cancel(); - self->mTimer = nsnull; + self->mSlots->mTimer = nsnull; } } } - -#ifdef XP_MAC -#pragma mark - -#endif - - -// ============================================================================== -// The ImageListener implementation -// ============================================================================== - -NS_IMPL_ISUPPORTS3(nsTreeImageListener, imgIDecoderObserver, imgIContainerObserver, nsITreeImageListener) - -nsTreeImageListener::nsTreeImageListener(nsITreeBoxObject* aTree, const PRUnichar* aColID) -{ - mTree = aTree; - mColID = aColID; - mMin = -1; // min should start out "undefined" - mMax = 0; -} - -nsTreeImageListener::~nsTreeImageListener() -{ -} - -NS_IMETHODIMP nsTreeImageListener::OnStartDecode(imgIRequest *aRequest) -{ - return NS_OK; -} - -NS_IMETHODIMP nsTreeImageListener::OnStartContainer(imgIRequest *aRequest, - imgIContainer *aImage) -{ - // Ensure the animation (if any) is started - aImage->StartAnimation(); - return NS_OK; -} - -NS_IMETHODIMP nsTreeImageListener::OnStartFrame(imgIRequest *aRequest, - gfxIImageFrame *aFrame) -{ - return NS_OK; -} - -NS_IMETHODIMP nsTreeImageListener::OnDataAvailable(imgIRequest *aRequest, - gfxIImageFrame *aFrame, - const nsRect *aRect) -{ - Invalidate(); - return NS_OK; -} - -NS_IMETHODIMP nsTreeImageListener::OnStopFrame(imgIRequest *aRequest, - gfxIImageFrame *aFrame) -{ - return NS_OK; -} - -NS_IMETHODIMP nsTreeImageListener::OnStopContainer(imgIRequest *aRequest, - imgIContainer *aImage) -{ - return NS_OK; -} - -NS_IMETHODIMP nsTreeImageListener::OnStopDecode(imgIRequest *aRequest, - nsresult status, - const PRUnichar *statusArg) -{ - return NS_OK; -} - -NS_IMETHODIMP nsTreeImageListener::FrameChanged(imgIContainer *aContainer, - gfxIImageFrame *newframe, - nsRect * dirtyRect) -{ - Invalidate(); - return NS_OK; -} - -NS_IMETHODIMP -nsTreeImageListener::AddRow(int aIndex) -{ - if (mMin == -1) - mMin = mMax = aIndex; - else if (aIndex < mMin) - mMin = aIndex; - else if (aIndex > mMax) - mMax = aIndex; - - return NS_OK; -} - -NS_IMETHODIMP -nsTreeImageListener::Invalidate() -{ - // Loop from min to max, invalidating each cell that was listening for this image. - for (PRInt32 i = mMin; i <= mMax; i++) { - mTree->InvalidateCell(i, mColID.get()); - } - - return NS_OK; -} diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.h b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.h index 0bf5fb3e41e..7b3904f5ad7 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.h +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.h @@ -22,8 +22,9 @@ * Original Author: David W. Hyatt (hyatt@netscape.com) * * Contributor(s): - * Dean Tessman - * Brian Ryner + * Dean Tessman + * Brian Ryner + * Jan Varga * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -39,211 +40,32 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nscore.h" #include "nsLeafBoxFrame.h" #include "nsITreeBoxObject.h" #include "nsITreeView.h" #include "nsICSSPseudoComparator.h" #include "nsIScrollbarMediator.h" -#include "nsIRenderingContext.h" #include "nsIDragSession.h" -#include "nsIWidget.h" -#include "nsHashtable.h" #include "nsITimer.h" #include "nsIReflowCallback.h" #include "nsILookAndFeel.h" #include "nsValueArray.h" - -#include "imgIDecoderObserver.h" - -class nsSupportsHashtable; - -class nsDFAState : public nsHashKey -{ -public: - PRUint32 mStateID; - - nsDFAState(PRUint32 aID) :mStateID(aID) {}; - - PRUint32 GetStateID() { return mStateID; }; - - PRUint32 HashCode(void) const { - return mStateID; - } - - PRBool Equals(const nsHashKey *aKey) const { - nsDFAState* key = (nsDFAState*)aKey; - return key->mStateID == mStateID; - } - - nsHashKey *Clone(void) const { - return new nsDFAState(mStateID); - } -}; - -class nsTransitionKey : public nsHashKey -{ -public: - PRUint32 mState; - nsCOMPtr mInputSymbol; - - nsTransitionKey(PRUint32 aState, nsIAtom* aSymbol) :mState(aState), mInputSymbol(aSymbol) {}; - - PRUint32 HashCode(void) const { - // Make a 32-bit integer that combines the low-order 16 bits of the state and the input symbol. - PRInt32 hb = mState << 16; - PRInt32 lb = (NS_PTR_TO_INT32(mInputSymbol.get()) << 16) >> 16; - return hb+lb; - } - - PRBool Equals(const nsHashKey *aKey) const { - nsTransitionKey* key = (nsTransitionKey*)aKey; - return key->mState == mState && key->mInputSymbol == mInputSymbol; - } - - nsHashKey *Clone(void) const { - return new nsTransitionKey(mState, mInputSymbol); - } -}; - -class nsTreeStyleCache -{ -public: - nsTreeStyleCache() :mTransitionTable(nsnull), mCache(nsnull), mNextState(0) {}; - virtual ~nsTreeStyleCache() { Clear(); }; - - void Clear() { delete mTransitionTable; mTransitionTable = nsnull; delete mCache; mCache = nsnull; mNextState = 0; }; - - nsStyleContext* GetStyleContext(nsICSSPseudoComparator* aComparator, - nsIPresContext* aPresContext, - nsIContent* aContent, - nsStyleContext* aContext, - nsIAtom* aPseudoElement, - nsISupportsArray* aInputWord); - - static PRBool PR_CALLBACK DeleteDFAState(nsHashKey *aKey, void *aData, void *closure); - - static PRBool PR_CALLBACK ReleaseStyleContext(nsHashKey *aKey, void *aData, void *closure); - -protected: - // A transition table for a deterministic finite automaton. The DFA - // takes as its input a single pseudoelement and an ordered set of properties. - // It transitions on an input word that is the concatenation of the pseudoelement supplied - // with the properties in the array. - // - // It transitions from state to state by looking up entries in the transition table (which is - // a mapping from (S,i)->S', where S is the current state, i is the next - // property in the input word, and S' is the state to transition to. - // - // If S' is not found, it is constructed and entered into the hashtable - // under the key (S,i). - // - // Once the entire word has been consumed, the final state is used - // to reference the cache table to locate the style context. - nsObjectHashtable* mTransitionTable; - - // The cache of all active style contexts. This is a hash from - // a final state in the DFA, Sf, to the resultant style context. - nsObjectHashtable* mCache; - - // An integer counter that is used when we need to make new states in the - // DFA. - PRUint32 mNextState; -}; - -// This class is our column info. We use it to iterate our columns and to obtain -// information about each column. -class nsTreeColumn { -public: - nsTreeColumn(nsIContent* aColElement, nsIFrame* aFrame); - virtual ~nsTreeColumn() { delete mNext; }; - - void SetNext(nsTreeColumn* aNext) { mNext = aNext; }; - nsTreeColumn* GetNext() { return mNext; }; - - nsIContent* GetElement() { return mColElement; }; - - nscoord GetWidth(); - const nsAFlatString& GetID() { return mID; }; - - void GetIDAtom(nsIAtom** aResult) { *aResult = mIDAtom; NS_IF_ADDREF(*aResult); }; - - PRBool IsPrimary() { return mIsPrimaryCol; }; - PRBool IsCycler() { return mIsCyclerCol; }; - - enum Type { - eText = 0, - eCheckbox = 1, - eProgressMeter = 2 - }; - Type GetType() { return mType; }; - - PRInt32 GetCropStyle() { return mCropStyle; }; - PRInt32 GetTextAlignment() { return mTextAlignment; }; - - PRInt32 GetColIndex() { return mColIndex; }; - -private: - nsTreeColumn* mNext; - - nsString mID; - nsCOMPtr mIDAtom; - - PRUint32 mCropStyle; - PRUint32 mTextAlignment; - - PRPackedBool mIsPrimaryCol; - PRPackedBool mIsCyclerCol; - Type mType; - - nsIFrame* mColFrame; - nsIContent* mColElement; - - PRInt32 mColIndex; -}; - -// The interface for our image listener. -// {90586540-2D50-403e-8DCE-981CAA778444} -#define NS_ITREEIMAGELISTENER_IID \ -{ 0x90586540, 0x2d50, 0x403e, { 0x8d, 0xce, 0x98, 0x1c, 0xaa, 0x77, 0x84, 0x44 } } - -class nsITreeImageListener : public nsISupports -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITREEIMAGELISTENER_IID) - -public: - NS_IMETHOD AddRow(int aIndex)=0; - NS_IMETHOD Invalidate()=0; -}; - -// This class handles image load observation. -class nsTreeImageListener : public imgIDecoderObserver, public nsITreeImageListener -{ -public: - nsTreeImageListener(nsITreeBoxObject* aTree, const PRUnichar* aColID); - virtual ~nsTreeImageListener(); - - NS_DECL_ISUPPORTS - NS_DECL_IMGIDECODEROBSERVER - NS_DECL_IMGICONTAINEROBSERVER - - NS_IMETHOD AddRow(int aIndex); - NS_IMETHOD Invalidate(); - -private: - int mMin; - int mMax; - nsString mColID; - nsITreeBoxObject* mTree; -}; +#include "nsTreeStyleCache.h" +#include "nsTreeColumns.h" +#include "nsTreeImageListener.h" +#include "nsAutoPtr.h" // The actual frame that paints the cells and rows. -class nsTreeBodyFrame : public nsLeafBoxFrame, public nsITreeBoxObject, public nsICSSPseudoComparator, +class nsTreeBodyFrame : public nsLeafBoxFrame, + public nsITreeBoxObject, + public nsICSSPseudoComparator, public nsIScrollbarMediator, public nsIReflowCallback { public: + nsTreeBodyFrame(nsIPresShell* aPresShell); + virtual ~nsTreeBodyFrame(); + NS_DECL_ISUPPORTS NS_DECL_NSITREEBOXOBJECT @@ -266,6 +88,13 @@ public: NS_IMETHOD Init(nsIPresContext* aPresContext, nsIContent* aContent, nsIFrame* aParent, nsStyleContext* aContext, nsIFrame* aPrevInFlow); NS_IMETHOD Destroy(nsIPresContext* aPresContext); + NS_IMETHOD GetCursor(nsIPresContext* aPresContext, + nsPoint& aPoint, + PRInt32& aCursor); + + NS_IMETHOD HandleEvent(nsIPresContext* aPresContext, + nsGUIEvent* aEvent, + nsEventStatus* aEventStatus); // Painting methods. // Paint is the generic nsIFrame paint method. We override this method @@ -277,114 +106,120 @@ public: PRUint32 aFlags = 0); // This method paints a specific column background of the tree. - nsresult PaintColumn(nsTreeColumn* aColumn, - const nsRect& aColumnRect, - nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); + void PaintColumn(nsTreeColumn* aColumn, + const nsRect& aColumnRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); // This method paints a single row in the tree. - nsresult PaintRow(PRInt32 aRowIndex, - const nsRect& aRowRect, - nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); + void PaintRow(PRInt32 aRowIndex, + const nsRect& aRowRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); - // This method paints a specific cell in a given row of the tree. - nsresult PaintCell(PRInt32 aRowIndex, - nsTreeColumn* aColumn, - const nsRect& aCellRect, - nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nscoord& aCurrX); - - // This method paints the twisty inside a cell in the primary column of an tree. - nsresult PaintTwisty(PRInt32 aRowIndex, - nsTreeColumn* aColumn, - const nsRect& aTwistyRect, - nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nscoord& aRemainingWidth, - nscoord& aCurrX); - - // This method paints the image inside the cell of an tree. - nsresult PaintImage(PRInt32 aRowIndex, - nsTreeColumn* aColumn, - const nsRect& aImageRect, + // This method paints a single separator in the tree. + void PaintSeparator(PRInt32 aRowIndex, + const nsRect& aSeparatorRect, nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nscoord& aRemainingWidth, - nscoord& aCurrX); + const nsRect& aDirtyRect); + + // This method paints a specific cell in a given row of the tree. + void PaintCell(PRInt32 aRowIndex, + nsTreeColumn* aColumn, + const nsRect& aCellRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nscoord& aCurrX); + + // This method paints the twisty inside a cell in the primary column of an tree. + void PaintTwisty(PRInt32 aRowIndex, + nsTreeColumn* aColumn, + const nsRect& aTwistyRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nscoord& aRemainingWidth, + nscoord& aCurrX); + + // This method paints the image inside the cell of an tree. + void PaintImage(PRInt32 aRowIndex, + nsTreeColumn* aColumn, + const nsRect& aImageRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nscoord& aRemainingWidth, + nscoord& aCurrX); // This method paints the text string inside a particular cell of the tree. - nsresult PaintText(PRInt32 aRowIndex, - nsTreeColumn* aColumn, - const nsRect& aTextRect, - nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nscoord& aCurrX); + void PaintText(PRInt32 aRowIndex, + nsTreeColumn* aColumn, + const nsRect& aTextRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nscoord& aCurrX); // This method paints the checkbox inside a particular cell of the tree. - nsresult PaintCheckbox(PRInt32 aRowIndex, - nsTreeColumn* aColumn, - const nsRect& aCheckboxRect, + void PaintCheckbox(PRInt32 aRowIndex, + nsTreeColumn* aColumn, + const nsRect& aCheckboxRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); + + // This method paints the progress meter inside a particular cell of the tree. + void PaintProgressMeter(PRInt32 aRowIndex, + nsTreeColumn* aColumn, + const nsRect& aProgressMeterRect, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); + + // This method paints a drop feedback of the tree. + void PaintDropFeedback(const nsRect& aDropFeedbackRect, nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); - // This method paints the progress meter inside a particular cell of the tree. - nsresult PaintProgressMeter(PRInt32 aRowIndex, - nsTreeColumn* aColumn, - const nsRect& aProgressMeterRect, - nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); - - // This method paints a drop feedback of the tree. - nsresult PaintDropFeedback(const nsRect& aDropFeedbackRect, - nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); - // This method is called with a specific style context and rect to // paint the background rect as if it were a full-blown frame. - nsresult PaintBackgroundLayer(nsStyleContext* aStyleContext, - nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aRect, - const nsRect& aDirtyRect); - - // This method is called whenever an treecol is added or removed and - // the column cache needs to be rebuilt. - void InvalidateColumnCache(); + void PaintBackgroundLayer(nsStyleContext* aStyleContext, + nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aRect, + const nsRect& aDirtyRect); friend nsresult NS_NewTreeBodyFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame); - friend class nsTreeBoxObject; - protected: - nsTreeBodyFrame(nsIPresShell* aPresShell); - virtual ~nsTreeBodyFrame(); + PRInt32 GetLastVisibleRow() { + return mTopRowIndex + mPageLength; + }; - // Caches our box object. - void SetBoxObject(nsITreeBoxObject* aBoxObject) { mTreeBoxObject = aBoxObject; }; + // An internal hit test. + PRInt32 GetRowAt(PRInt32 aX, PRInt32 aY); // A helper used when hit testing. - nsresult GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, PRInt32 aRowIndex, - nsTreeColumn* aColumn, PRUnichar** aChildElt); + nsIAtom* GetItemWithinCellAt(PRInt32 aX, const nsRect& aCellRect, PRInt32 aRowIndex, + nsTreeColumn* aColumn); + + // An internal hit test. + void GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aRow, nsTreeColumn** aCol, + nsIAtom** aChildElt); // Fetch an image from the image cache. - nsresult GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUseContext, + nsresult GetImage(PRInt32 aRowIndex, nsTreeColumn* aCol, PRBool aUseContext, nsStyleContext* aStyleContext, PRBool& aAllowImageRegions, imgIContainer** aResult); // Returns the size of a given image. This size *includes* border and // padding. It does not include margins. - nsRect GetImageSize(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUseContext, nsStyleContext* aStyleContext); + nsRect GetImageSize(PRInt32 aRowIndex, nsTreeColumn* aCol, PRBool aUseContext, nsStyleContext* aStyleContext); // Returns the height of rows in the tree. PRInt32 GetRowHeight(); @@ -399,9 +234,6 @@ protected: // the pseudo-styles passed in and place them into the cache. nsStyleContext* GetPseudoStyleContext(nsIAtom* aPseudoElement); - // Builds our cache of column info. - void EnsureColumns(); - // Makes |mScrollbar| non-null if at all possible, and returns it. nsIFrame* EnsureScrollbar(); @@ -412,7 +244,7 @@ protected: void InvalidateScrollbar(); // Check vertical overflow. - nsresult CheckVerticalOverflow(); + void CheckVerticalOverflow(); // Use to auto-fill some of the common properties without the view having to do it. // Examples include container, open, selected, and focus. @@ -422,7 +254,7 @@ protected: nsresult ScrollInternal(PRInt32 aRow); // Convert pixels, probably from an event, into twips in our coordinate space. - void AdjustEventCoordsToBoxCoordSpace (PRInt32 aX, PRInt32 aY, PRInt32* aResultX, PRInt32* aResultY); + void AdjustEventCoordsToBoxCoordSpace(PRInt32 aX, PRInt32 aY, PRInt32* aResultX, PRInt32* aResultY); // Convert a border style into line style. nsLineStyle ConvertBorderStyleToLineStyle(PRUint8 aBorderStyle); @@ -433,12 +265,12 @@ protected: void EnsureView(); // Get the base element, or