content/xul/templates/src/nsXULSortService.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 5 *
michael@0 6 * This Original Code has been modified by IBM Corporation.
michael@0 7 * Modifications made by IBM described herein are
michael@0 8 * Copyright (c) International Business Machines
michael@0 9 * Corporation, 2000
michael@0 10 *
michael@0 11 * Modifications to Mozilla code or documentation
michael@0 12 * identified per MPL Section 3.3
michael@0 13 *
michael@0 14 * Date Modified by Description of modification
michael@0 15 * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
michael@0 16 * use in OS2
michael@0 17 */
michael@0 18
michael@0 19 /*
michael@0 20 This sort service is used to sort template built content or content by attribute.
michael@0 21 */
michael@0 22
michael@0 23 #ifndef nsXULTemplateResultSetRDF_h
michael@0 24 #define nsXULTemplateResultSetRDF_h
michael@0 25
michael@0 26 #include "nsCOMPtr.h"
michael@0 27 #include "nsCOMArray.h"
michael@0 28 #include "nsTArray.h"
michael@0 29 #include "nsIContent.h"
michael@0 30 #include "nsIXULTemplateResult.h"
michael@0 31 #include "nsIXULTemplateQueryProcessor.h"
michael@0 32 #include "nsIXULSortService.h"
michael@0 33 #include "nsCycleCollectionParticipant.h"
michael@0 34
michael@0 35 enum nsSortState_direction {
michael@0 36 nsSortState_descending,
michael@0 37 nsSortState_ascending,
michael@0 38 nsSortState_natural
michael@0 39 };
michael@0 40
michael@0 41 // the sort state holds info about the current sort
michael@0 42 struct nsSortState
michael@0 43 {
michael@0 44 bool initialized;
michael@0 45 bool invertSort;
michael@0 46 bool inbetweenSeparatorSort;
michael@0 47 bool sortStaticsLast;
michael@0 48 bool isContainerRDFSeq;
michael@0 49
michael@0 50 uint32_t sortHints;
michael@0 51
michael@0 52 nsSortState_direction direction;
michael@0 53 nsAutoString sort;
michael@0 54 nsCOMArray<nsIAtom> sortKeys;
michael@0 55
michael@0 56 nsCOMPtr<nsIXULTemplateQueryProcessor> processor;
michael@0 57 nsCOMPtr<nsIContent> lastContainer;
michael@0 58 bool lastWasFirst, lastWasLast;
michael@0 59
michael@0 60 nsSortState()
michael@0 61 : initialized(false),
michael@0 62 sortHints(0)
michael@0 63 {
michael@0 64 }
michael@0 65 void Traverse(nsCycleCollectionTraversalCallback &cb) const
michael@0 66 {
michael@0 67 cb.NoteXPCOMChild(processor);
michael@0 68 cb.NoteXPCOMChild(lastContainer);
michael@0 69 }
michael@0 70 };
michael@0 71
michael@0 72 // information about a particular item to be sorted
michael@0 73 struct contentSortInfo {
michael@0 74 nsCOMPtr<nsIContent> content;
michael@0 75 nsCOMPtr<nsIContent> parent;
michael@0 76 nsCOMPtr<nsIXULTemplateResult> result;
michael@0 77 void swap(contentSortInfo& other)
michael@0 78 {
michael@0 79 content.swap(other.content);
michael@0 80 parent.swap(other.parent);
michael@0 81 result.swap(other.result);
michael@0 82 }
michael@0 83 };
michael@0 84
michael@0 85 ////////////////////////////////////////////////////////////////////////
michael@0 86 // ServiceImpl
michael@0 87 //
michael@0 88 // This is the sort service.
michael@0 89 //
michael@0 90 class XULSortServiceImpl : public nsIXULSortService
michael@0 91 {
michael@0 92 protected:
michael@0 93 XULSortServiceImpl(void) {}
michael@0 94 virtual ~XULSortServiceImpl(void) {}
michael@0 95
michael@0 96 friend nsresult NS_NewXULSortService(nsIXULSortService** mgr);
michael@0 97
michael@0 98 private:
michael@0 99
michael@0 100 public:
michael@0 101 // nsISupports
michael@0 102 NS_DECL_ISUPPORTS
michael@0 103
michael@0 104 // nsISortService
michael@0 105 NS_DECL_NSIXULSORTSERVICE
michael@0 106
michael@0 107 /**
michael@0 108 * Set sort and sortDirection attributes when a sort is done.
michael@0 109 */
michael@0 110 void
michael@0 111 SetSortHints(nsIContent *aNode, nsSortState* aSortState);
michael@0 112
michael@0 113 /**
michael@0 114 * Set sortActive and sortDirection attributes on a tree column when a sort
michael@0 115 * is done. The column to change is the one with a sort attribute that
michael@0 116 * matches the sort key. The sort attributes are removed from the other
michael@0 117 * columns.
michael@0 118 */
michael@0 119 void
michael@0 120 SetSortColumnHints(nsIContent *content,
michael@0 121 const nsAString &sortResource,
michael@0 122 const nsAString &sortDirection);
michael@0 123
michael@0 124 /**
michael@0 125 * Determine the list of items which need to be sorted. This is determined
michael@0 126 * in the following way:
michael@0 127 * - for elements that have a content builder, get its list of generated
michael@0 128 * results
michael@0 129 * - otherwise, for trees, get the child treeitems
michael@0 130 * - otherwise, get the direct children
michael@0 131 */
michael@0 132 nsresult
michael@0 133 GetItemsToSort(nsIContent *aContainer,
michael@0 134 nsSortState* aSortState,
michael@0 135 nsTArray<contentSortInfo>& aSortItems);
michael@0 136
michael@0 137 /**
michael@0 138 * Get the list of items to sort for template built content
michael@0 139 */
michael@0 140 nsresult
michael@0 141 GetTemplateItemsToSort(nsIContent* aContainer,
michael@0 142 nsIXULTemplateBuilder* aBuilder,
michael@0 143 nsSortState* aSortState,
michael@0 144 nsTArray<contentSortInfo>& aSortItems);
michael@0 145
michael@0 146 /**
michael@0 147 * Sort a container using the supplied sort state details.
michael@0 148 */
michael@0 149 nsresult
michael@0 150 SortContainer(nsIContent *aContainer, nsSortState* aSortState);
michael@0 151
michael@0 152 /**
michael@0 153 * Given a list of sortable items, reverse the list. This is done
michael@0 154 * when simply changing the sort direction for the same key.
michael@0 155 */
michael@0 156 nsresult
michael@0 157 InvertSortInfo(nsTArray<contentSortInfo>& aData,
michael@0 158 int32_t aStart, int32_t aNumItems);
michael@0 159
michael@0 160 /**
michael@0 161 * Initialize sort information from attributes specified on the container,
michael@0 162 * the sort key and sort direction.
michael@0 163 *
michael@0 164 * @param aRootElement the element that contains sort attributes
michael@0 165 * @param aContainer the container to sort, usually equal to aRootElement
michael@0 166 * @param aSortKey space separated list of sort keys
michael@0 167 * @param aSortDirection direction to sort in
michael@0 168 * @param aSortState structure filled in with sort data
michael@0 169 */
michael@0 170 static nsresult
michael@0 171 InitializeSortState(nsIContent* aRootElement,
michael@0 172 nsIContent* aContainer,
michael@0 173 const nsAString& aSortKey,
michael@0 174 const nsAString& aSortDirection,
michael@0 175 nsSortState* aSortState);
michael@0 176
michael@0 177 /**
michael@0 178 * Compares aLeft and aRight and returns < 0, 0, or > 0. The sort
michael@0 179 * hints are checked for case matching and integer sorting.
michael@0 180 */
michael@0 181 static int32_t CompareValues(const nsAString& aLeft,
michael@0 182 const nsAString& aRight,
michael@0 183 uint32_t aSortHints);
michael@0 184 };
michael@0 185
michael@0 186 #endif

mercurial