LCOV - code coverage report
Current view: top level - dom/xul/templates - nsXULTreeBuilder.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 14 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
       6             : #ifndef nsXULTreeBuilder_h__
       7             : #define nsXULTreeBuilder_h__
       8             : 
       9             : #include "nsCOMPtr.h"
      10             : #include "nsITreeView.h"
      11             : #include "nsTreeRows.h"
      12             : #include "nsXULTemplateBuilder.h"
      13             : 
      14             : class nsIContent;
      15             : class nsIRDFResource;
      16             : class nsITreeSelection;
      17             : class nsIXULStore;
      18             : class nsIXULTemplateResult;
      19             : class nsTreeColumn;
      20             : 
      21             : namespace mozilla {
      22             : namespace dom {
      23             : 
      24             : class DataTransfer;
      25             : class TreeBoxObject;
      26             : class XULTreeBuilderObserver;
      27             : 
      28             : } // namespace dom
      29             : } // namespace mozilla
      30             : 
      31             : /**
      32             :  * A XUL template builder that serves as an tree view, allowing
      33             :  * (pretty much) arbitrary RDF to be presented in an tree.
      34             :  */
      35             : class nsXULTreeBuilder : public nsXULTemplateBuilder,
      36             :                          public nsIXULTreeBuilder,
      37             :                          public nsINativeTreeView
      38             : {
      39             : public:
      40             :     explicit nsXULTreeBuilder(Element* aElement);
      41             : 
      42             :     // nsISupports
      43             :     NS_DECL_ISUPPORTS_INHERITED
      44           0 :     NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULTreeBuilder,
      45             :                                              nsXULTemplateBuilder)
      46             : 
      47             :     virtual JSObject* WrapObject(JSContext* aCx,
      48             :                                  JS::Handle<JSObject*> aGivenProto) override;
      49             : 
      50             :     already_AddRefed<nsIRDFResource>
      51             :       GetResourceAtIndex(int32_t aIndex, mozilla::ErrorResult& aError);
      52             :     int32_t GetIndexOfResource(nsIRDFResource* aResource,
      53             :                                mozilla::ErrorResult& aError);
      54             :     void AddObserver(mozilla::dom::XULTreeBuilderObserver& aObserver);
      55             :     void RemoveObserver(mozilla::dom::XULTreeBuilderObserver& aObserver);
      56             :     void Sort(Element&);
      57             : 
      58           0 :     int32_t RowCount()
      59             :     {
      60           0 :         return mRows.Count();
      61             :     }
      62           0 :     nsITreeSelection* GetSelection()
      63             :     {
      64           0 :         return mSelection;
      65             :     }
      66             :     void SetSelection(nsITreeSelection* aSelection,
      67             :                       mozilla::ErrorResult& aError);
      68             :     void GetRowProperties(int32_t aRow, nsAString& aProperties,
      69             :                           mozilla::ErrorResult& aError);
      70             :     void GetCellProperties(int32_t aRow, nsTreeColumn& aColumn,
      71             :                            nsAString& aProperties, mozilla::ErrorResult& aError);
      72           0 :     void GetColumnProperties(nsTreeColumn& aColumn, nsAString& aProperties)
      73             :     {
      74           0 :     }
      75             :     bool IsContainer(int32_t aRow, mozilla::ErrorResult& aError);
      76             :     bool IsContainerOpen(int32_t aRow, mozilla::ErrorResult& aError);
      77             :     bool IsContainerEmpty(int32_t aRow, mozilla::ErrorResult& aError);
      78             :     bool IsSeparator(int32_t aRow, mozilla::ErrorResult& aError);
      79           0 :     bool IsSorted()
      80             :     {
      81           0 :         return mSortVariable != nullptr;
      82             :     }
      83             :     bool CanDrop(int32_t aRow, int32_t aOrientation,
      84             :                  mozilla::dom::DataTransfer* aDataTransfer,
      85             :                  mozilla::ErrorResult& aError);
      86             :     void Drop(int32_t aRow, int32_t aOrientation,
      87             :               mozilla::dom::DataTransfer* aDataTransfer,
      88             :               mozilla::ErrorResult& aError);
      89             :     int32_t GetParentIndex(int32_t aRow, mozilla::ErrorResult& aError);
      90             :     bool HasNextSibling(int32_t aRow, int32_t aAfterIndex,
      91             :                         mozilla::ErrorResult& aError);
      92             :     int32_t GetLevel(int32_t aRow, mozilla::ErrorResult& aError);
      93             :     void GetImageSrc(int32_t aRow, nsTreeColumn& aColumn, nsAString& aSrc,
      94             :                      mozilla::ErrorResult& aError);
      95             :     int32_t GetProgressMode(int32_t aRow, nsTreeColumn& aColumn,
      96             :                             mozilla::ErrorResult& aError);
      97             :     void GetCellValue(int32_t aRow, nsTreeColumn& aColumn, nsAString& aValue,
      98             :                       mozilla::ErrorResult& aError);
      99             :     void GetCellText(int32_t aRow, nsTreeColumn& aColumn, nsAString& aText,
     100             :                      mozilla::ErrorResult& aError);
     101             :     void SetTree(mozilla::dom::TreeBoxObject* aTree,
     102             :                  mozilla::ErrorResult& aError);
     103             :     void ToggleOpenState(int32_t aRow, mozilla::ErrorResult& aError);
     104             :     void CycleHeader(nsTreeColumn& aColumn, mozilla::ErrorResult& aError);
     105             :     // XPCOM SelectionChanged() is OK
     106             :     void CycleCell(int32_t aRow, nsTreeColumn& aColumn);
     107             :     bool IsEditable(int32_t aRow, nsTreeColumn& aColumn,
     108             :                     mozilla::ErrorResult& aError);
     109             :     bool IsSelectable(int32_t aRow, nsTreeColumn& aColumn,
     110             :                       mozilla::ErrorResult& aError);
     111           0 :     void SetCellValue(int32_t aRow, nsTreeColumn& aColumn,
     112             :                       const nsAString& aValue, mozilla::ErrorResult& aError)
     113             :     {
     114           0 :     }
     115           0 :     void SetCellText(int32_t aRow, nsTreeColumn& aColumn,
     116             :                       const nsAString& aText, mozilla::ErrorResult& aError)
     117             :     {
     118           0 :     }
     119             :     void PerformAction(const nsAString& aAction);
     120             :     void PerformActionOnRow(const nsAString& aAction, int32_t aRow);
     121             :     void PerformActionOnCell(const nsAString& aAction, int32_t aRow,
     122             :                              nsTreeColumn& aColumn);
     123             : 
     124             :     using nsIXULTemplateBuilder::HasGeneratedContent;
     125             :     virtual bool HasGeneratedContent(nsIRDFResource* aResource,
     126             :                                      const nsAString& aTag,
     127             :                                      mozilla::ErrorResult& aError) override;
     128             : 
     129             :     // nsIXULTreeBuilder
     130             :     NS_DECL_NSIXULTREEBUILDER
     131             : 
     132             :     // nsITreeView
     133             :     NS_DECL_NSITREEVIEW
     134             :     // nsINativeTreeView: Untrusted code can use us
     135           0 :     NS_IMETHOD EnsureNative() override { return NS_OK; }
     136             : 
     137             :     // nsIMutationObserver
     138             :     NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
     139             : 
     140             : protected:
     141             :     friend struct ResultComparator;
     142             : 
     143             :     ~nsXULTreeBuilder();
     144             : 
     145             :     /**
     146             :      * Uninitialize the template builder
     147             :      */
     148             :     virtual void Uninit(bool aIsFinal) override;
     149             : 
     150             :     /**
     151             :      * Get sort variables from the active <treecol>
     152             :      */
     153             :     nsresult
     154             :     EnsureSortVariables();
     155             : 
     156             :     virtual nsresult
     157             :     RebuildAll() override;
     158             : 
     159             :     /**
     160             :      * Given a row, use the row's match to figure out the appropriate
     161             :      * <treerow> in the rule's <action>.
     162             :      */
     163             :     nsresult
     164             :     GetTemplateActionRowFor(int32_t aRow, nsIContent** aResult);
     165             : 
     166             :     /**
     167             :      * Given a row and a column ID, use the row's match to figure out
     168             :      * the appropriate <treecell> in the rule's <action>.
     169             :      */
     170             :     nsIContent*
     171             :     GetTemplateActionCellFor(int32_t aRow, nsTreeColumn& aCol);
     172             : 
     173             :     /**
     174             :      * Return the resource corresponding to a row in the tree.
     175             :      */
     176             :     nsresult
     177             :     GetResourceFor(int32_t aRow, nsIRDFResource** aResource);
     178             : 
     179             :     /**
     180             :      * Open a container row, inserting the container's children into
     181             :      * the view.
     182             :      */
     183             :     nsresult
     184             :     OpenContainer(int32_t aIndex, nsIXULTemplateResult* aResult);
     185             : 
     186             :     /**
     187             :      * Helper for OpenContainer, recursively open subtrees, remembering
     188             :      * persisted ``open'' state
     189             :      */
     190             :     nsresult
     191             :     OpenSubtreeOf(nsTreeRows::Subtree* aSubtree,
     192             :                   int32_t aIndex,
     193             :                   nsIXULTemplateResult *aResult,
     194             :                   int32_t* aDelta);
     195             : 
     196             :     nsresult
     197             :     OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
     198             :                            int32_t aIndex,
     199             :                            nsIXULTemplateResult *aResult,
     200             :                            nsTemplateQuerySet* aQuerySet,
     201             :                            int32_t* aDelta,
     202             :                            nsTArray<int32_t>& open);
     203             : 
     204             :     /**
     205             :      * Close a container row, removing the container's childrem from
     206             :      * the view.
     207             :      */
     208             :     nsresult
     209             :     CloseContainer(int32_t aIndex);
     210             : 
     211             :     /**
     212             :      * Remove the matches for the rows in a subtree
     213             :      */
     214             :     nsresult
     215             :     RemoveMatchesFor(nsTreeRows::Subtree& subtree);
     216             : 
     217             :     /**
     218             :      * Helper method that determines if the specified container is open.
     219             :      */
     220             :     bool
     221             :     IsContainerOpen(nsIXULTemplateResult* aResource);
     222             : 
     223             :     /**
     224             :      * A sorting callback for NS_QuickSort().
     225             :      */
     226             :     static int
     227             :     Compare(const void* aLeft, const void* aRight, void* aClosure);
     228             : 
     229             :     /**
     230             :      * The real sort routine
     231             :      */
     232             :     int32_t
     233             :     CompareResults(nsIXULTemplateResult* aLeft, nsIXULTemplateResult* aRight);
     234             : 
     235             :     /**
     236             :      * Sort the specified subtree, and recursively sort any subtrees
     237             :      * beneath it.
     238             :      */
     239             :     nsresult
     240             :     SortSubtree(nsTreeRows::Subtree* aSubtree);
     241             : 
     242             :     // GetInsertionLocations, ReplaceMatch and SynchronizeResult are inherited
     243             :     // from nsXULTemplateBuilder
     244             : 
     245             :     /**
     246             :      * Return true if the result can be inserted into the template as a new
     247             :      * row.
     248             :      */
     249             :     bool
     250             :     GetInsertionLocations(nsIXULTemplateResult* aResult,
     251             :                           nsCOMArray<nsIContent>** aLocations) override;
     252             : 
     253             :     /**
     254             :      * Implement result replacement
     255             :      */
     256             :     virtual nsresult
     257             :     ReplaceMatch(nsIXULTemplateResult* aOldResult,
     258             :                  nsTemplateMatch* aNewMatch,
     259             :                  nsTemplateRule* aNewMatchRule,
     260             :                  void* aContext) override;
     261             : 
     262             :     /**
     263             :      * Implement match synchronization
     264             :      */
     265             :     virtual nsresult
     266             :     SynchronizeResult(nsIXULTemplateResult* aResult) override;
     267             : 
     268             :     bool IsValidRowIndex(int32_t aRowIndex);
     269             : 
     270             :     /**
     271             :      * The tree's box object, used to communicate with the front-end.
     272             :      */
     273             :     nsCOMPtr<nsITreeBoxObject> mBoxObject;
     274             : 
     275             :     /**
     276             :      * The tree's selection object.
     277             :      */
     278             :     nsCOMPtr<nsITreeSelection> mSelection;
     279             : 
     280             :     /**
     281             :      * The datasource that's used to persist open folder information
     282             :      */
     283             :     nsCOMPtr<nsIRDFDataSource> mPersistStateStore;
     284             : 
     285             :     /**
     286             :      * The rows in the view
     287             :      */
     288             :     nsTreeRows mRows;
     289             : 
     290             :     /**
     291             :      * The currently active sort variable
     292             :      */
     293             :     nsCOMPtr<nsIAtom> mSortVariable;
     294             : 
     295             :     enum Direction {
     296             :         eDirection_Descending = -1,
     297             :         eDirection_Natural    =  0,
     298             :         eDirection_Ascending  = +1
     299             :     };
     300             : 
     301             :     /**
     302             :      * The currently active sort order
     303             :      */
     304             :     Direction mSortDirection;
     305             : 
     306             :     /*
     307             :      * Sort hints (compare case, etc)
     308             :      */
     309             :     uint32_t mSortHints;
     310             : 
     311             :     /**
     312             :      * The builder observers.
     313             :      */
     314             :     nsTArray<nsCOMPtr<nsIXULTreeBuilderObserver>> mObservers;
     315             : 
     316             :     /*
     317             :      * XUL store for holding open container state
     318             :      */
     319             :     nsCOMPtr<nsIXULStore> mLocalStore;
     320             : };
     321             : 
     322             : #endif // nsXULTreeBuilder_h__

Generated by: LCOV version 1.13