Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 | #ifndef mozilla_a11y_XULTreeAccessible_h__ |
michael@0 | 7 | #define mozilla_a11y_XULTreeAccessible_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsITreeBoxObject.h" |
michael@0 | 10 | #include "nsITreeView.h" |
michael@0 | 11 | #include "nsITreeColumns.h" |
michael@0 | 12 | #include "XULListboxAccessible.h" |
michael@0 | 13 | |
michael@0 | 14 | class nsTreeBodyFrame; |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace a11y { |
michael@0 | 18 | |
michael@0 | 19 | /* |
michael@0 | 20 | * A class the represents the XUL Tree widget. |
michael@0 | 21 | */ |
michael@0 | 22 | const uint32_t kMaxTreeColumns = 100; |
michael@0 | 23 | const uint32_t kDefaultTreeCacheSize = 256; |
michael@0 | 24 | |
michael@0 | 25 | /** |
michael@0 | 26 | * Accessible class for XUL tree element. |
michael@0 | 27 | */ |
michael@0 | 28 | |
michael@0 | 29 | class XULTreeAccessible : public AccessibleWrap |
michael@0 | 30 | { |
michael@0 | 31 | public: |
michael@0 | 32 | using Accessible::GetChildAt; |
michael@0 | 33 | |
michael@0 | 34 | XULTreeAccessible(nsIContent* aContent, DocAccessible* aDoc, |
michael@0 | 35 | nsTreeBodyFrame* aTreeframe); |
michael@0 | 36 | |
michael@0 | 37 | // nsISupports and cycle collection |
michael@0 | 38 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 39 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeAccessible, Accessible) |
michael@0 | 40 | |
michael@0 | 41 | // Accessible |
michael@0 | 42 | virtual void Shutdown(); |
michael@0 | 43 | virtual void Value(nsString& aValue); |
michael@0 | 44 | virtual a11y::role NativeRole(); |
michael@0 | 45 | virtual uint64_t NativeState(); |
michael@0 | 46 | virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY, |
michael@0 | 47 | EWhichChildAtPoint aWhichChild); |
michael@0 | 48 | |
michael@0 | 49 | virtual Accessible* GetChildAt(uint32_t aIndex) const MOZ_OVERRIDE; |
michael@0 | 50 | virtual uint32_t ChildCount() const MOZ_OVERRIDE; |
michael@0 | 51 | virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE; |
michael@0 | 52 | |
michael@0 | 53 | // SelectAccessible |
michael@0 | 54 | virtual already_AddRefed<nsIArray> SelectedItems(); |
michael@0 | 55 | virtual uint32_t SelectedItemCount(); |
michael@0 | 56 | virtual Accessible* GetSelectedItem(uint32_t aIndex); |
michael@0 | 57 | virtual bool IsItemSelected(uint32_t aIndex); |
michael@0 | 58 | virtual bool AddItemToSelection(uint32_t aIndex); |
michael@0 | 59 | virtual bool RemoveItemFromSelection(uint32_t aIndex); |
michael@0 | 60 | virtual bool SelectAll(); |
michael@0 | 61 | virtual bool UnselectAll(); |
michael@0 | 62 | |
michael@0 | 63 | // Widgets |
michael@0 | 64 | virtual bool IsWidget() const; |
michael@0 | 65 | virtual bool IsActiveWidget() const; |
michael@0 | 66 | virtual bool AreItemsOperable() const; |
michael@0 | 67 | virtual Accessible* CurrentItem(); |
michael@0 | 68 | virtual void SetCurrentItem(Accessible* aItem); |
michael@0 | 69 | |
michael@0 | 70 | virtual Accessible* ContainerWidget() const; |
michael@0 | 71 | |
michael@0 | 72 | // XULTreeAccessible |
michael@0 | 73 | |
michael@0 | 74 | /** |
michael@0 | 75 | * Return tree item accessible at the givem row. If accessible doesn't exist |
michael@0 | 76 | * in the cache then create and cache it. |
michael@0 | 77 | * |
michael@0 | 78 | * @param aRow [in] the given row index |
michael@0 | 79 | */ |
michael@0 | 80 | Accessible* GetTreeItemAccessible(int32_t aRow) const; |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Invalidates the number of cached treeitem accessibles. |
michael@0 | 84 | * |
michael@0 | 85 | * @param aRow [in] row index the invalidation starts from |
michael@0 | 86 | * @param aCount [in] the number of treeitem accessibles to invalidate, |
michael@0 | 87 | * the number sign specifies whether rows have been |
michael@0 | 88 | * inserted (plus) or removed (minus) |
michael@0 | 89 | */ |
michael@0 | 90 | void InvalidateCache(int32_t aRow, int32_t aCount); |
michael@0 | 91 | |
michael@0 | 92 | /** |
michael@0 | 93 | * Fires name change events for invalidated area of tree. |
michael@0 | 94 | * |
michael@0 | 95 | * @param aStartRow [in] row index invalidation starts from |
michael@0 | 96 | * @param aEndRow [in] row index invalidation ends, -1 means last row index |
michael@0 | 97 | * @param aStartCol [in] column index invalidation starts from |
michael@0 | 98 | * @param aEndCol [in] column index invalidation ends, -1 mens last column |
michael@0 | 99 | * index |
michael@0 | 100 | */ |
michael@0 | 101 | void TreeViewInvalidated(int32_t aStartRow, int32_t aEndRow, |
michael@0 | 102 | int32_t aStartCol, int32_t aEndCol); |
michael@0 | 103 | |
michael@0 | 104 | /** |
michael@0 | 105 | * Invalidates children created for previous tree view. |
michael@0 | 106 | */ |
michael@0 | 107 | void TreeViewChanged(nsITreeView* aView); |
michael@0 | 108 | |
michael@0 | 109 | protected: |
michael@0 | 110 | /** |
michael@0 | 111 | * Creates tree item accessible for the given row index. |
michael@0 | 112 | */ |
michael@0 | 113 | virtual already_AddRefed<Accessible> |
michael@0 | 114 | CreateTreeItemAccessible(int32_t aRow) const; |
michael@0 | 115 | |
michael@0 | 116 | nsCOMPtr<nsITreeBoxObject> mTree; |
michael@0 | 117 | nsITreeView* mTreeView; |
michael@0 | 118 | mutable AccessibleHashtable mAccessibleCache; |
michael@0 | 119 | }; |
michael@0 | 120 | |
michael@0 | 121 | /** |
michael@0 | 122 | * Base class for tree item accessibles. |
michael@0 | 123 | */ |
michael@0 | 124 | |
michael@0 | 125 | #define XULTREEITEMBASEACCESSIBLE_IMPL_CID \ |
michael@0 | 126 | { /* 1ab79ae7-766a-443c-940b-b1e6b0831dfc */ \ |
michael@0 | 127 | 0x1ab79ae7, \ |
michael@0 | 128 | 0x766a, \ |
michael@0 | 129 | 0x443c, \ |
michael@0 | 130 | { 0x94, 0x0b, 0xb1, 0xe6, 0xb0, 0x83, 0x1d, 0xfc } \ |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | class XULTreeItemAccessibleBase : public AccessibleWrap |
michael@0 | 134 | { |
michael@0 | 135 | public: |
michael@0 | 136 | using Accessible::GetParent; |
michael@0 | 137 | |
michael@0 | 138 | XULTreeItemAccessibleBase(nsIContent* aContent, DocAccessible* aDoc, |
michael@0 | 139 | Accessible* aParent, nsITreeBoxObject* aTree, |
michael@0 | 140 | nsITreeView* aTreeView, int32_t aRow); |
michael@0 | 141 | |
michael@0 | 142 | // nsISupports and cycle collection |
michael@0 | 143 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 144 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessibleBase, |
michael@0 | 145 | AccessibleWrap) |
michael@0 | 146 | |
michael@0 | 147 | // nsIAccessible |
michael@0 | 148 | NS_IMETHOD GetBounds(int32_t *aX, int32_t *aY, |
michael@0 | 149 | int32_t *aWidth, int32_t *aHeight); |
michael@0 | 150 | |
michael@0 | 151 | NS_IMETHOD SetSelected(bool aSelect); |
michael@0 | 152 | NS_IMETHOD TakeFocus(); |
michael@0 | 153 | |
michael@0 | 154 | NS_IMETHOD GetActionName(uint8_t aIndex, nsAString& aName); |
michael@0 | 155 | NS_IMETHOD DoAction(uint8_t aIndex); |
michael@0 | 156 | |
michael@0 | 157 | // Accessible |
michael@0 | 158 | virtual void Shutdown(); |
michael@0 | 159 | virtual GroupPos GroupPosition(); |
michael@0 | 160 | virtual uint64_t NativeState(); |
michael@0 | 161 | virtual uint64_t NativeInteractiveState() const; |
michael@0 | 162 | virtual int32_t IndexInParent() const; |
michael@0 | 163 | virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE; |
michael@0 | 164 | virtual Accessible* FocusedChild(); |
michael@0 | 165 | |
michael@0 | 166 | // ActionAccessible |
michael@0 | 167 | virtual uint8_t ActionCount(); |
michael@0 | 168 | |
michael@0 | 169 | // Widgets |
michael@0 | 170 | virtual Accessible* ContainerWidget() const; |
michael@0 | 171 | |
michael@0 | 172 | // XULTreeItemAccessibleBase |
michael@0 | 173 | NS_DECLARE_STATIC_IID_ACCESSOR(XULTREEITEMBASEACCESSIBLE_IMPL_CID) |
michael@0 | 174 | |
michael@0 | 175 | /** |
michael@0 | 176 | * Return row index associated with the accessible. |
michael@0 | 177 | */ |
michael@0 | 178 | int32_t GetRowIndex() const { return mRow; } |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * Return cell accessible for the given column. If XUL tree accessible is not |
michael@0 | 182 | * accessible table then return null. |
michael@0 | 183 | */ |
michael@0 | 184 | virtual Accessible* GetCellAccessible(nsITreeColumn* aColumn) const |
michael@0 | 185 | { return nullptr; } |
michael@0 | 186 | |
michael@0 | 187 | /** |
michael@0 | 188 | * Proccess row invalidation. Used to fires name change events. |
michael@0 | 189 | */ |
michael@0 | 190 | virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) = 0; |
michael@0 | 191 | |
michael@0 | 192 | protected: |
michael@0 | 193 | enum { eAction_Click = 0, eAction_Expand = 1 }; |
michael@0 | 194 | |
michael@0 | 195 | // Accessible |
michael@0 | 196 | virtual void DispatchClickEvent(nsIContent *aContent, uint32_t aActionIndex); |
michael@0 | 197 | virtual Accessible* GetSiblingAtOffset(int32_t aOffset, |
michael@0 | 198 | nsresult *aError = nullptr) const; |
michael@0 | 199 | |
michael@0 | 200 | // XULTreeItemAccessibleBase |
michael@0 | 201 | |
michael@0 | 202 | /** |
michael@0 | 203 | * Return true if the tree item accessible is expandable (contains subrows). |
michael@0 | 204 | */ |
michael@0 | 205 | bool IsExpandable(); |
michael@0 | 206 | |
michael@0 | 207 | /** |
michael@0 | 208 | * Return name for cell at the given column. |
michael@0 | 209 | */ |
michael@0 | 210 | void GetCellName(nsITreeColumn* aColumn, nsAString& aName); |
michael@0 | 211 | |
michael@0 | 212 | nsCOMPtr<nsITreeBoxObject> mTree; |
michael@0 | 213 | nsITreeView* mTreeView; |
michael@0 | 214 | int32_t mRow; |
michael@0 | 215 | }; |
michael@0 | 216 | |
michael@0 | 217 | NS_DEFINE_STATIC_IID_ACCESSOR(XULTreeItemAccessibleBase, |
michael@0 | 218 | XULTREEITEMBASEACCESSIBLE_IMPL_CID) |
michael@0 | 219 | |
michael@0 | 220 | |
michael@0 | 221 | /** |
michael@0 | 222 | * Accessible class for items for XUL tree. |
michael@0 | 223 | */ |
michael@0 | 224 | class XULTreeItemAccessible : public XULTreeItemAccessibleBase |
michael@0 | 225 | { |
michael@0 | 226 | public: |
michael@0 | 227 | XULTreeItemAccessible(nsIContent* aContent, DocAccessible* aDoc, |
michael@0 | 228 | Accessible* aParent, nsITreeBoxObject* aTree, |
michael@0 | 229 | nsITreeView* aTreeView, int32_t aRow); |
michael@0 | 230 | |
michael@0 | 231 | // nsISupports and cycle collection |
michael@0 | 232 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 233 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessible, |
michael@0 | 234 | XULTreeItemAccessibleBase) |
michael@0 | 235 | |
michael@0 | 236 | // Accessible |
michael@0 | 237 | virtual void Shutdown(); |
michael@0 | 238 | virtual ENameValueFlag Name(nsString& aName); |
michael@0 | 239 | virtual a11y::role NativeRole(); |
michael@0 | 240 | |
michael@0 | 241 | // XULTreeItemAccessibleBase |
michael@0 | 242 | virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx); |
michael@0 | 243 | |
michael@0 | 244 | protected: |
michael@0 | 245 | |
michael@0 | 246 | // Accessible |
michael@0 | 247 | virtual void CacheChildren(); |
michael@0 | 248 | |
michael@0 | 249 | // XULTreeItemAccessible |
michael@0 | 250 | nsCOMPtr<nsITreeColumn> mColumn; |
michael@0 | 251 | nsString mCachedName; |
michael@0 | 252 | }; |
michael@0 | 253 | |
michael@0 | 254 | |
michael@0 | 255 | /** |
michael@0 | 256 | * Accessible class for columns element of XUL tree. |
michael@0 | 257 | */ |
michael@0 | 258 | class XULTreeColumAccessible : public XULColumAccessible |
michael@0 | 259 | { |
michael@0 | 260 | public: |
michael@0 | 261 | XULTreeColumAccessible(nsIContent* aContent, DocAccessible* aDoc); |
michael@0 | 262 | |
michael@0 | 263 | protected: |
michael@0 | 264 | |
michael@0 | 265 | // Accessible |
michael@0 | 266 | virtual Accessible* GetSiblingAtOffset(int32_t aOffset, |
michael@0 | 267 | nsresult *aError = nullptr) const; |
michael@0 | 268 | }; |
michael@0 | 269 | |
michael@0 | 270 | |
michael@0 | 271 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 272 | // Accessible downcasting method |
michael@0 | 273 | |
michael@0 | 274 | inline XULTreeAccessible* |
michael@0 | 275 | Accessible::AsXULTree() |
michael@0 | 276 | { |
michael@0 | 277 | return IsXULTree() ? static_cast<XULTreeAccessible*>(this) : nullptr; |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | } // namespace a11y |
michael@0 | 281 | } // namespace mozilla |
michael@0 | 282 | |
michael@0 | 283 | #endif |