Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / xul / templates / src / nsXULSortService.h
blob8efdc1b0f2f25c7a58a341414da3e66d3567e6ad
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Scott Putterman <putterman@netscape.com>
24 * Pierre Phaneuf <pp@ludusdesign.com>
25 * Chase Tingley <tingley@sundell.net>
26 * Neil Deakin <enndeakin@sympatico.ca>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either of the GNU General Public License Version 2 or later (the "GPL"),
30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK *****
42 * This Original Code has been modified by IBM Corporation.
43 * Modifications made by IBM described herein are
44 * Copyright (c) International Business Machines
45 * Corporation, 2000
47 * Modifications to Mozilla code or documentation
48 * identified per MPL Section 3.3
50 * Date Modified by Description of modification
51 * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
52 * use in OS2
56 This sort service is used to sort template built content or content by attribute.
59 #include "nsCOMPtr.h"
60 #include "nsCOMArray.h"
61 #include "nsTArray.h"
62 #include "nsIContent.h"
63 #include "nsIXULTemplateResult.h"
64 #include "nsIXULTemplateQueryProcessor.h"
65 #include "nsIXULSortService.h"
66 #include "nsCycleCollectionParticipant.h"
68 enum nsSortState_direction {
69 nsSortState_descending,
70 nsSortState_ascending,
71 nsSortState_natural
74 // the sort state holds info about the current sort
75 struct nsSortState
77 PRBool initialized;
78 PRBool invertSort;
79 PRBool inbetweenSeparatorSort;
80 PRBool sortStaticsLast;
81 PRBool isContainerRDFSeq;
83 nsSortState_direction direction;
84 nsAutoString sort;
85 nsCOMArray<nsIAtom> sortKeys;
87 nsCOMPtr<nsIXULTemplateQueryProcessor> processor;
88 nsCOMPtr<nsIContent> lastContainer;
89 PRBool lastWasFirst, lastWasLast;
91 nsSortState()
92 : initialized(PR_FALSE)
95 void Traverse(nsCycleCollectionTraversalCallback &cb) const
97 cb.NoteXPCOMChild(processor);
98 cb.NoteXPCOMChild(lastContainer);
102 // information about a particular item to be sorted
103 struct contentSortInfo {
104 nsCOMPtr<nsIContent> content;
105 nsCOMPtr<nsIContent> parent;
106 nsCOMPtr<nsIXULTemplateResult> result;
107 void swap(contentSortInfo& other)
109 content.swap(other.content);
110 parent.swap(other.parent);
111 result.swap(other.result);
115 ////////////////////////////////////////////////////////////////////////
116 // ServiceImpl
118 // This is the sort service.
120 class XULSortServiceImpl : public nsIXULSortService
122 protected:
123 XULSortServiceImpl(void) {}
124 virtual ~XULSortServiceImpl(void) {}
126 friend nsresult NS_NewXULSortService(nsIXULSortService** mgr);
128 private:
130 public:
131 // nsISupports
132 NS_DECL_ISUPPORTS
134 // nsISortService
135 NS_DECL_NSIXULSORTSERVICE
138 * Set sort and sortDirection attributes when a sort is done.
140 void
141 SetSortHints(nsIContent *aNode, nsSortState* aSortState);
144 * Set sortActive and sortDirection attributes on a tree column when a sort
145 * is done. The column to change is the one with a sort attribute that
146 * matches the sort key. The sort attributes are removed from the other
147 * columns.
149 void
150 SetSortColumnHints(nsIContent *content,
151 const nsAString &sortResource,
152 const nsAString &sortDirection);
155 * Determine the list of items which need to be sorted. This is determined
156 * in the following way:
157 * - for elements that have a content builder, get its list of generated
158 * results
159 * - otherwise, for trees, get the child treeitems
160 * - otherwise, get the direct children
162 nsresult
163 GetItemsToSort(nsIContent *aContainer,
164 nsSortState* aSortState,
165 nsTArray<contentSortInfo>& aSortItems);
168 * Get the list of items to sort for template built content
170 nsresult
171 GetTemplateItemsToSort(nsIContent* aContainer,
172 nsIXULTemplateBuilder* aBuilder,
173 nsSortState* aSortState,
174 nsTArray<contentSortInfo>& aSortItems);
177 * Sort a container using the supplied sort state details.
179 nsresult
180 SortContainer(nsIContent *aContainer, nsSortState* aSortState);
183 * Given a list of sortable items, reverse the list. This is done
184 * when simply changing the sort direction for the same key.
186 nsresult
187 InvertSortInfo(nsTArray<contentSortInfo>& aData,
188 PRInt32 aStart, PRInt32 aNumItems);
191 * Initialize sort information from attributes specified on the container,
192 * the sort key and sort direction.
194 * @param aRootElement the element that contains sort attributes
195 * @param aContainer the container to sort, usually equal to aRootElement
196 * @param aSortKey space separated list of sort keys
197 * @param aSortDirection direction to sort in
198 * @param aSortState structure filled in with sort data
200 static nsresult
201 InitializeSortState(nsIContent* aRootElement,
202 nsIContent* aContainer,
203 const nsAString& aSortKey,
204 const nsAString& aSortDirection,
205 nsSortState* aSortState);