1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef __inDOMView_h__
8 #define __inDOMView_h__
9 
10 #include "inIDOMView.h"
11 
12 #include "nsITreeView.h"
13 #include "nsITreeSelection.h"
14 #include "nsStubMutationObserver.h"
15 #include "nsIDOMNode.h"
16 #include "nsIDOMDocument.h"
17 #include "nsTArray.h"
18 #include "nsCOMArray.h"
19 #include "nsCOMPtr.h"
20 
21 class inDOMViewNode;
22 class nsDOMAttributeMap;
23 
24 class inDOMView : public inIDOMView,
25                   public nsITreeView,
26                   public nsStubMutationObserver {
27  public:
28   NS_DECL_ISUPPORTS
29   NS_DECL_INIDOMVIEW
30   NS_DECL_NSITREEVIEW
31 
32   inDOMView();
33 
34   // nsIMutationObserver
35   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
36   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
37   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
38   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
39   NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
40 
41  protected:
42   virtual ~inDOMView();
43 
44   nsCOMPtr<nsITreeBoxObject> mTree;
45   nsCOMPtr<nsITreeSelection> mSelection;
46 
47   bool mShowAnonymous;
48   bool mShowSubDocuments;
49   bool mShowWhitespaceNodes;
50   bool mShowAccessibleNodes;
51   uint32_t mWhatToShow;
52 
53   nsCOMPtr<nsIDOMNode> mRootNode;
54   nsCOMPtr<nsIDOMDocument> mRootDocument;
55 
56   nsTArray<inDOMViewNode*> mNodes;
57 
58   inDOMViewNode* GetNodeAt(int32_t aIndex);
59   int32_t GetRowCount();
60   int32_t NodeToRow(inDOMViewNode* aNode);
61   bool RowOutOfBounds(int32_t aRow, int32_t aCount);
62   inDOMViewNode* CreateNode(nsIDOMNode* aNode, inDOMViewNode* aParent);
63   void AppendNode(inDOMViewNode* aNode);
64   void InsertNode(inDOMViewNode* aNode, int32_t aIndex);
65   void RemoveNode(int32_t aIndex);
66   void ReplaceNode(inDOMViewNode* aNode, int32_t aIndex);
67   void InsertNodes(nsTArray<inDOMViewNode*>& aNodes, int32_t aIndex);
68   void RemoveNodes(int32_t aIndex, int32_t aCount);
69   void RemoveAllNodes();
70   void ExpandNode(int32_t aRow);
71   void CollapseNode(int32_t aRow);
72 
73   nsresult RowToNode(int32_t aRow, inDOMViewNode** aNode);
74   nsresult NodeToRow(nsIDOMNode* aNode, int32_t* aRow);
75 
76   void InsertLinkAfter(inDOMViewNode* aNode, inDOMViewNode* aInsertAfter);
77   void InsertLinkBefore(inDOMViewNode* aNode, inDOMViewNode* aInsertBefore);
78   void RemoveLink(inDOMViewNode* aNode);
79   void ReplaceLink(inDOMViewNode* aNewNode, inDOMViewNode* aOldNode);
80 
81   nsresult GetChildNodesFor(nsIDOMNode* aNode, nsCOMArray<nsIDOMNode>& aResult);
82   void AppendKidsToArray(nsINodeList* aKids, nsCOMArray<nsIDOMNode>& aArray);
83   nsresult AppendAttrsToArray(nsDOMAttributeMap* aKids,
84                               nsCOMArray<nsIDOMNode>& aArray);
85   nsresult GetFirstDescendantOf(inDOMViewNode* aNode, int32_t aRow,
86                                 int32_t* aResult);
87   nsresult GetLastDescendantOf(inDOMViewNode* aNode, int32_t aRow,
88                                int32_t* aResult);
89 };
90 
91 // {FB5C1775-1BBD-4b9c-ABB0-AE7ACD29E87E}
92 #define IN_DOMVIEW_CID                               \
93   {                                                  \
94     0xfb5c1775, 0x1bbd, 0x4b9c, {                    \
95       0xab, 0xb0, 0xae, 0x7a, 0xcd, 0x29, 0xe8, 0x7e \
96     }                                                \
97   }
98 
99 #endif  // __inDOMView_h__
100