accessible/src/xul/XULTreeAccessible.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/xul/XULTreeAccessible.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,283 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_a11y_XULTreeAccessible_h__
    1.10 +#define mozilla_a11y_XULTreeAccessible_h__
    1.11 +
    1.12 +#include "nsITreeBoxObject.h"
    1.13 +#include "nsITreeView.h"
    1.14 +#include "nsITreeColumns.h"
    1.15 +#include "XULListboxAccessible.h"
    1.16 +
    1.17 +class nsTreeBodyFrame;
    1.18 +
    1.19 +namespace mozilla {
    1.20 +namespace a11y {
    1.21 +
    1.22 +/*
    1.23 + * A class the represents the XUL Tree widget.
    1.24 + */
    1.25 +const uint32_t kMaxTreeColumns = 100;
    1.26 +const uint32_t kDefaultTreeCacheSize = 256;
    1.27 +
    1.28 +/**
    1.29 + * Accessible class for XUL tree element.
    1.30 + */
    1.31 +
    1.32 +class XULTreeAccessible : public AccessibleWrap
    1.33 +{
    1.34 +public:
    1.35 +  using Accessible::GetChildAt;
    1.36 +
    1.37 +  XULTreeAccessible(nsIContent* aContent, DocAccessible* aDoc,
    1.38 +                    nsTreeBodyFrame* aTreeframe);
    1.39 +
    1.40 +  // nsISupports and cycle collection
    1.41 +  NS_DECL_ISUPPORTS_INHERITED
    1.42 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeAccessible, Accessible)
    1.43 +
    1.44 +  // Accessible
    1.45 +  virtual void Shutdown();
    1.46 +  virtual void Value(nsString& aValue);
    1.47 +  virtual a11y::role NativeRole();
    1.48 +  virtual uint64_t NativeState();
    1.49 +  virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY,
    1.50 +                                   EWhichChildAtPoint aWhichChild);
    1.51 +
    1.52 +  virtual Accessible* GetChildAt(uint32_t aIndex) const MOZ_OVERRIDE;
    1.53 +  virtual uint32_t ChildCount() const MOZ_OVERRIDE;
    1.54 +  virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE;
    1.55 +
    1.56 +  // SelectAccessible
    1.57 +  virtual already_AddRefed<nsIArray> SelectedItems();
    1.58 +  virtual uint32_t SelectedItemCount();
    1.59 +  virtual Accessible* GetSelectedItem(uint32_t aIndex);
    1.60 +  virtual bool IsItemSelected(uint32_t aIndex);
    1.61 +  virtual bool AddItemToSelection(uint32_t aIndex);
    1.62 +  virtual bool RemoveItemFromSelection(uint32_t aIndex);
    1.63 +  virtual bool SelectAll();
    1.64 +  virtual bool UnselectAll();
    1.65 +
    1.66 +  // Widgets
    1.67 +  virtual bool IsWidget() const;
    1.68 +  virtual bool IsActiveWidget() const;
    1.69 +  virtual bool AreItemsOperable() const;
    1.70 +  virtual Accessible* CurrentItem();
    1.71 +  virtual void SetCurrentItem(Accessible* aItem);
    1.72 +
    1.73 +  virtual Accessible* ContainerWidget() const;
    1.74 +
    1.75 +  // XULTreeAccessible
    1.76 +
    1.77 +  /**
    1.78 +   * Return tree item accessible at the givem row. If accessible doesn't exist
    1.79 +   * in the cache then create and cache it.
    1.80 +   *
    1.81 +   * @param aRow         [in] the given row index
    1.82 +   */
    1.83 +  Accessible* GetTreeItemAccessible(int32_t aRow) const;
    1.84 +
    1.85 +  /**
    1.86 +   * Invalidates the number of cached treeitem accessibles.
    1.87 +   *
    1.88 +   * @param aRow    [in] row index the invalidation starts from
    1.89 +   * @param aCount  [in] the number of treeitem accessibles to invalidate,
    1.90 +   *                 the number sign specifies whether rows have been
    1.91 +   *                 inserted (plus) or removed (minus)
    1.92 +   */
    1.93 +  void InvalidateCache(int32_t aRow, int32_t aCount);
    1.94 +
    1.95 +  /**
    1.96 +   * Fires name change events for invalidated area of tree.
    1.97 +   *
    1.98 +   * @param aStartRow  [in] row index invalidation starts from
    1.99 +   * @param aEndRow    [in] row index invalidation ends, -1 means last row index
   1.100 +   * @param aStartCol  [in] column index invalidation starts from
   1.101 +   * @param aEndCol    [in] column index invalidation ends, -1 mens last column
   1.102 +   *                    index
   1.103 +   */
   1.104 +  void TreeViewInvalidated(int32_t aStartRow, int32_t aEndRow,
   1.105 +                           int32_t aStartCol, int32_t aEndCol);
   1.106 +
   1.107 +  /**
   1.108 +   * Invalidates children created for previous tree view.
   1.109 +   */
   1.110 +  void TreeViewChanged(nsITreeView* aView);
   1.111 +
   1.112 +protected:
   1.113 +  /**
   1.114 +   * Creates tree item accessible for the given row index.
   1.115 +   */
   1.116 +  virtual already_AddRefed<Accessible>
   1.117 +    CreateTreeItemAccessible(int32_t aRow) const;
   1.118 +
   1.119 +  nsCOMPtr<nsITreeBoxObject> mTree;
   1.120 +  nsITreeView* mTreeView;
   1.121 +  mutable AccessibleHashtable mAccessibleCache;
   1.122 +};
   1.123 +
   1.124 +/**
   1.125 + * Base class for tree item accessibles.
   1.126 + */
   1.127 +
   1.128 +#define XULTREEITEMBASEACCESSIBLE_IMPL_CID            \
   1.129 +{  /* 1ab79ae7-766a-443c-940b-b1e6b0831dfc */         \
   1.130 +  0x1ab79ae7,                                         \
   1.131 +  0x766a,                                             \
   1.132 +  0x443c,                                             \
   1.133 +  { 0x94, 0x0b, 0xb1, 0xe6, 0xb0, 0x83, 0x1d, 0xfc }  \
   1.134 +}
   1.135 +
   1.136 +class XULTreeItemAccessibleBase : public AccessibleWrap
   1.137 +{
   1.138 +public:
   1.139 +  using Accessible::GetParent;
   1.140 +
   1.141 +  XULTreeItemAccessibleBase(nsIContent* aContent, DocAccessible* aDoc,
   1.142 +                            Accessible* aParent, nsITreeBoxObject* aTree,
   1.143 +                            nsITreeView* aTreeView, int32_t aRow);
   1.144 +
   1.145 +  // nsISupports and cycle collection
   1.146 +  NS_DECL_ISUPPORTS_INHERITED
   1.147 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessibleBase,
   1.148 +                                           AccessibleWrap)
   1.149 +
   1.150 +  // nsIAccessible
   1.151 +  NS_IMETHOD GetBounds(int32_t *aX, int32_t *aY,
   1.152 +                       int32_t *aWidth, int32_t *aHeight);
   1.153 +
   1.154 +  NS_IMETHOD SetSelected(bool aSelect);
   1.155 +  NS_IMETHOD TakeFocus();
   1.156 +
   1.157 +  NS_IMETHOD GetActionName(uint8_t aIndex, nsAString& aName);
   1.158 +  NS_IMETHOD DoAction(uint8_t aIndex);
   1.159 +
   1.160 +  // Accessible
   1.161 +  virtual void Shutdown();
   1.162 +  virtual GroupPos GroupPosition();
   1.163 +  virtual uint64_t NativeState();
   1.164 +  virtual uint64_t NativeInteractiveState() const;
   1.165 +  virtual int32_t IndexInParent() const;
   1.166 +  virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE;
   1.167 +  virtual Accessible* FocusedChild();
   1.168 +
   1.169 +  // ActionAccessible
   1.170 +  virtual uint8_t ActionCount();
   1.171 +
   1.172 +  // Widgets
   1.173 +  virtual Accessible* ContainerWidget() const;
   1.174 +
   1.175 +  // XULTreeItemAccessibleBase
   1.176 +  NS_DECLARE_STATIC_IID_ACCESSOR(XULTREEITEMBASEACCESSIBLE_IMPL_CID)
   1.177 +
   1.178 +  /**
   1.179 +   * Return row index associated with the accessible.
   1.180 +   */
   1.181 +  int32_t GetRowIndex() const { return mRow; }
   1.182 +
   1.183 +  /**
   1.184 +   * Return cell accessible for the given column. If XUL tree accessible is not
   1.185 +   * accessible table then return null.
   1.186 +   */
   1.187 +  virtual Accessible* GetCellAccessible(nsITreeColumn* aColumn) const
   1.188 +    { return nullptr; }
   1.189 +
   1.190 +  /**
   1.191 +   * Proccess row invalidation. Used to fires name change events.
   1.192 +   */
   1.193 +  virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) = 0;
   1.194 +
   1.195 +protected:
   1.196 +  enum { eAction_Click = 0, eAction_Expand = 1 };
   1.197 +
   1.198 +  // Accessible
   1.199 +  virtual void DispatchClickEvent(nsIContent *aContent, uint32_t aActionIndex);
   1.200 +  virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
   1.201 +                                         nsresult *aError = nullptr) const;
   1.202 +
   1.203 +  // XULTreeItemAccessibleBase
   1.204 +
   1.205 +  /**
   1.206 +   * Return true if the tree item accessible is expandable (contains subrows).
   1.207 +   */
   1.208 +  bool IsExpandable();
   1.209 +
   1.210 +  /**
   1.211 +   * Return name for cell at the given column.
   1.212 +   */
   1.213 +  void GetCellName(nsITreeColumn* aColumn, nsAString& aName);
   1.214 +
   1.215 +  nsCOMPtr<nsITreeBoxObject> mTree;
   1.216 +  nsITreeView* mTreeView;
   1.217 +  int32_t mRow;
   1.218 +};
   1.219 +
   1.220 +NS_DEFINE_STATIC_IID_ACCESSOR(XULTreeItemAccessibleBase,
   1.221 +                              XULTREEITEMBASEACCESSIBLE_IMPL_CID)
   1.222 +
   1.223 +
   1.224 +/**
   1.225 + * Accessible class for items for XUL tree.
   1.226 + */
   1.227 +class XULTreeItemAccessible : public XULTreeItemAccessibleBase
   1.228 +{
   1.229 +public:
   1.230 +  XULTreeItemAccessible(nsIContent* aContent, DocAccessible* aDoc,
   1.231 +                        Accessible* aParent, nsITreeBoxObject* aTree,
   1.232 +                        nsITreeView* aTreeView, int32_t aRow);
   1.233 +
   1.234 +  // nsISupports and cycle collection
   1.235 +  NS_DECL_ISUPPORTS_INHERITED
   1.236 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessible,
   1.237 +                                           XULTreeItemAccessibleBase)
   1.238 +
   1.239 +  // Accessible
   1.240 +  virtual void Shutdown();
   1.241 +  virtual ENameValueFlag Name(nsString& aName);
   1.242 +  virtual a11y::role NativeRole();
   1.243 +
   1.244 +  // XULTreeItemAccessibleBase
   1.245 +  virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx);
   1.246 +
   1.247 +protected:
   1.248 +
   1.249 +  // Accessible
   1.250 +  virtual void CacheChildren();
   1.251 +
   1.252 +  // XULTreeItemAccessible
   1.253 +  nsCOMPtr<nsITreeColumn> mColumn;
   1.254 +  nsString mCachedName;
   1.255 +};
   1.256 +
   1.257 +
   1.258 +/**
   1.259 + * Accessible class for columns element of XUL tree.
   1.260 + */
   1.261 +class XULTreeColumAccessible : public XULColumAccessible
   1.262 +{
   1.263 +public:
   1.264 +  XULTreeColumAccessible(nsIContent* aContent, DocAccessible* aDoc);
   1.265 +
   1.266 +protected:
   1.267 +
   1.268 +  // Accessible
   1.269 +  virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
   1.270 +                                         nsresult *aError = nullptr) const;
   1.271 +};
   1.272 +
   1.273 +
   1.274 +////////////////////////////////////////////////////////////////////////////////
   1.275 +// Accessible downcasting method
   1.276 +
   1.277 +inline XULTreeAccessible*
   1.278 +Accessible::AsXULTree()
   1.279 +{
   1.280 +  return IsXULTree() ? static_cast<XULTreeAccessible*>(this) : nullptr;
   1.281 +}
   1.282 +
   1.283 +} // namespace a11y
   1.284 +} // namespace mozilla
   1.285 +
   1.286 +#endif

mercurial