nsTreeContentView.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsTreeContentView_h__
  6. #define nsTreeContentView_h__
  7. #include "nsCycleCollectionParticipant.h"
  8. #include "nsTArray.h"
  9. #include "nsStubDocumentObserver.h"
  10. #include "nsITreeBoxObject.h"
  11. #include "nsITreeColumns.h"
  12. #include "nsITreeView.h"
  13. #include "nsITreeContentView.h"
  14. #include "nsITreeSelection.h"
  15. #include "mozilla/Attributes.h"
  16. #include "mozilla/UniquePtr.h"
  17. class nsIDocument;
  18. class Row;
  19. nsresult NS_NewTreeContentView(nsITreeView** aResult);
  20. class nsTreeContentView final : public nsINativeTreeView,
  21. public nsITreeContentView,
  22. public nsStubDocumentObserver
  23. {
  24. public:
  25. nsTreeContentView(void);
  26. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  27. NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTreeContentView,
  28. nsINativeTreeView)
  29. NS_DECL_NSITREEVIEW
  30. // nsINativeTreeView: Untrusted code can use us
  31. NS_IMETHOD EnsureNative() override { return NS_OK; }
  32. NS_DECL_NSITREECONTENTVIEW
  33. // nsIDocumentObserver
  34. NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
  35. NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
  36. NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
  37. NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
  38. NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
  39. static bool CanTrustTreeSelection(nsISupports* aValue);
  40. protected:
  41. ~nsTreeContentView(void);
  42. // Recursive methods which deal with serializing of nested content.
  43. void Serialize(nsIContent* aContent, int32_t aParentIndex, int32_t* aIndex,
  44. nsTArray<mozilla::UniquePtr<Row>>& aRows);
  45. void SerializeItem(nsIContent* aContent, int32_t aParentIndex,
  46. int32_t* aIndex, nsTArray<mozilla::UniquePtr<Row>>& aRows);
  47. void SerializeSeparator(nsIContent* aContent, int32_t aParentIndex,
  48. int32_t* aIndex, nsTArray<mozilla::UniquePtr<Row>>& aRows);
  49. void GetIndexInSubtree(nsIContent* aContainer, nsIContent* aContent, int32_t* aResult);
  50. // Helper methods which we use to manage our plain array of rows.
  51. int32_t EnsureSubtree(int32_t aIndex);
  52. int32_t RemoveSubtree(int32_t aIndex);
  53. int32_t InsertRow(int32_t aParentIndex, int32_t aIndex, nsIContent* aContent);
  54. void InsertRowFor(nsIContent* aParent, nsIContent* aChild);
  55. int32_t RemoveRow(int32_t aIndex);
  56. void ClearRows();
  57. void OpenContainer(int32_t aIndex);
  58. void CloseContainer(int32_t aIndex);
  59. int32_t FindContent(nsIContent* aContent);
  60. void UpdateSubtreeSizes(int32_t aIndex, int32_t aCount);
  61. void UpdateParentIndexes(int32_t aIndex, int32_t aSkip, int32_t aCount);
  62. // Content helpers.
  63. nsIContent* GetCell(nsIContent* aContainer, nsITreeColumn* aCol);
  64. private:
  65. nsCOMPtr<nsITreeBoxObject> mBoxObject;
  66. nsCOMPtr<nsITreeSelection> mSelection;
  67. nsCOMPtr<nsIContent> mRoot;
  68. nsCOMPtr<nsIContent> mBody;
  69. nsIDocument* mDocument; // WEAK
  70. nsTArray<mozilla::UniquePtr<Row>> mRows;
  71. };
  72. #endif // nsTreeContentView_h__