michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_a11y_XULTreeAccessible_h__ michael@0: #define mozilla_a11y_XULTreeAccessible_h__ michael@0: michael@0: #include "nsITreeBoxObject.h" michael@0: #include "nsITreeView.h" michael@0: #include "nsITreeColumns.h" michael@0: #include "XULListboxAccessible.h" michael@0: michael@0: class nsTreeBodyFrame; michael@0: michael@0: namespace mozilla { michael@0: namespace a11y { michael@0: michael@0: /* michael@0: * A class the represents the XUL Tree widget. michael@0: */ michael@0: const uint32_t kMaxTreeColumns = 100; michael@0: const uint32_t kDefaultTreeCacheSize = 256; michael@0: michael@0: /** michael@0: * Accessible class for XUL tree element. michael@0: */ michael@0: michael@0: class XULTreeAccessible : public AccessibleWrap michael@0: { michael@0: public: michael@0: using Accessible::GetChildAt; michael@0: michael@0: XULTreeAccessible(nsIContent* aContent, DocAccessible* aDoc, michael@0: nsTreeBodyFrame* aTreeframe); michael@0: michael@0: // nsISupports and cycle collection michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeAccessible, Accessible) michael@0: michael@0: // Accessible michael@0: virtual void Shutdown(); michael@0: virtual void Value(nsString& aValue); michael@0: virtual a11y::role NativeRole(); michael@0: virtual uint64_t NativeState(); michael@0: virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY, michael@0: EWhichChildAtPoint aWhichChild); michael@0: michael@0: virtual Accessible* GetChildAt(uint32_t aIndex) const MOZ_OVERRIDE; michael@0: virtual uint32_t ChildCount() const MOZ_OVERRIDE; michael@0: virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE; michael@0: michael@0: // SelectAccessible michael@0: virtual already_AddRefed SelectedItems(); michael@0: virtual uint32_t SelectedItemCount(); michael@0: virtual Accessible* GetSelectedItem(uint32_t aIndex); michael@0: virtual bool IsItemSelected(uint32_t aIndex); michael@0: virtual bool AddItemToSelection(uint32_t aIndex); michael@0: virtual bool RemoveItemFromSelection(uint32_t aIndex); michael@0: virtual bool SelectAll(); michael@0: virtual bool UnselectAll(); michael@0: michael@0: // Widgets michael@0: virtual bool IsWidget() const; michael@0: virtual bool IsActiveWidget() const; michael@0: virtual bool AreItemsOperable() const; michael@0: virtual Accessible* CurrentItem(); michael@0: virtual void SetCurrentItem(Accessible* aItem); michael@0: michael@0: virtual Accessible* ContainerWidget() const; michael@0: michael@0: // XULTreeAccessible michael@0: michael@0: /** michael@0: * Return tree item accessible at the givem row. If accessible doesn't exist michael@0: * in the cache then create and cache it. michael@0: * michael@0: * @param aRow [in] the given row index michael@0: */ michael@0: Accessible* GetTreeItemAccessible(int32_t aRow) const; michael@0: michael@0: /** michael@0: * Invalidates the number of cached treeitem accessibles. michael@0: * michael@0: * @param aRow [in] row index the invalidation starts from michael@0: * @param aCount [in] the number of treeitem accessibles to invalidate, michael@0: * the number sign specifies whether rows have been michael@0: * inserted (plus) or removed (minus) michael@0: */ michael@0: void InvalidateCache(int32_t aRow, int32_t aCount); michael@0: michael@0: /** michael@0: * Fires name change events for invalidated area of tree. michael@0: * michael@0: * @param aStartRow [in] row index invalidation starts from michael@0: * @param aEndRow [in] row index invalidation ends, -1 means last row index michael@0: * @param aStartCol [in] column index invalidation starts from michael@0: * @param aEndCol [in] column index invalidation ends, -1 mens last column michael@0: * index michael@0: */ michael@0: void TreeViewInvalidated(int32_t aStartRow, int32_t aEndRow, michael@0: int32_t aStartCol, int32_t aEndCol); michael@0: michael@0: /** michael@0: * Invalidates children created for previous tree view. michael@0: */ michael@0: void TreeViewChanged(nsITreeView* aView); michael@0: michael@0: protected: michael@0: /** michael@0: * Creates tree item accessible for the given row index. michael@0: */ michael@0: virtual already_AddRefed michael@0: CreateTreeItemAccessible(int32_t aRow) const; michael@0: michael@0: nsCOMPtr mTree; michael@0: nsITreeView* mTreeView; michael@0: mutable AccessibleHashtable mAccessibleCache; michael@0: }; michael@0: michael@0: /** michael@0: * Base class for tree item accessibles. michael@0: */ michael@0: michael@0: #define XULTREEITEMBASEACCESSIBLE_IMPL_CID \ michael@0: { /* 1ab79ae7-766a-443c-940b-b1e6b0831dfc */ \ michael@0: 0x1ab79ae7, \ michael@0: 0x766a, \ michael@0: 0x443c, \ michael@0: { 0x94, 0x0b, 0xb1, 0xe6, 0xb0, 0x83, 0x1d, 0xfc } \ michael@0: } michael@0: michael@0: class XULTreeItemAccessibleBase : public AccessibleWrap michael@0: { michael@0: public: michael@0: using Accessible::GetParent; michael@0: michael@0: XULTreeItemAccessibleBase(nsIContent* aContent, DocAccessible* aDoc, michael@0: Accessible* aParent, nsITreeBoxObject* aTree, michael@0: nsITreeView* aTreeView, int32_t aRow); michael@0: michael@0: // nsISupports and cycle collection michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessibleBase, michael@0: AccessibleWrap) michael@0: michael@0: // nsIAccessible michael@0: NS_IMETHOD GetBounds(int32_t *aX, int32_t *aY, michael@0: int32_t *aWidth, int32_t *aHeight); michael@0: michael@0: NS_IMETHOD SetSelected(bool aSelect); michael@0: NS_IMETHOD TakeFocus(); michael@0: michael@0: NS_IMETHOD GetActionName(uint8_t aIndex, nsAString& aName); michael@0: NS_IMETHOD DoAction(uint8_t aIndex); michael@0: michael@0: // Accessible michael@0: virtual void Shutdown(); michael@0: virtual GroupPos GroupPosition(); michael@0: virtual uint64_t NativeState(); michael@0: virtual uint64_t NativeInteractiveState() const; michael@0: virtual int32_t IndexInParent() const; michael@0: virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE; michael@0: virtual Accessible* FocusedChild(); michael@0: michael@0: // ActionAccessible michael@0: virtual uint8_t ActionCount(); michael@0: michael@0: // Widgets michael@0: virtual Accessible* ContainerWidget() const; michael@0: michael@0: // XULTreeItemAccessibleBase michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(XULTREEITEMBASEACCESSIBLE_IMPL_CID) michael@0: michael@0: /** michael@0: * Return row index associated with the accessible. michael@0: */ michael@0: int32_t GetRowIndex() const { return mRow; } michael@0: michael@0: /** michael@0: * Return cell accessible for the given column. If XUL tree accessible is not michael@0: * accessible table then return null. michael@0: */ michael@0: virtual Accessible* GetCellAccessible(nsITreeColumn* aColumn) const michael@0: { return nullptr; } michael@0: michael@0: /** michael@0: * Proccess row invalidation. Used to fires name change events. michael@0: */ michael@0: virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) = 0; michael@0: michael@0: protected: michael@0: enum { eAction_Click = 0, eAction_Expand = 1 }; michael@0: michael@0: // Accessible michael@0: virtual void DispatchClickEvent(nsIContent *aContent, uint32_t aActionIndex); michael@0: virtual Accessible* GetSiblingAtOffset(int32_t aOffset, michael@0: nsresult *aError = nullptr) const; michael@0: michael@0: // XULTreeItemAccessibleBase michael@0: michael@0: /** michael@0: * Return true if the tree item accessible is expandable (contains subrows). michael@0: */ michael@0: bool IsExpandable(); michael@0: michael@0: /** michael@0: * Return name for cell at the given column. michael@0: */ michael@0: void GetCellName(nsITreeColumn* aColumn, nsAString& aName); michael@0: michael@0: nsCOMPtr mTree; michael@0: nsITreeView* mTreeView; michael@0: int32_t mRow; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(XULTreeItemAccessibleBase, michael@0: XULTREEITEMBASEACCESSIBLE_IMPL_CID) michael@0: michael@0: michael@0: /** michael@0: * Accessible class for items for XUL tree. michael@0: */ michael@0: class XULTreeItemAccessible : public XULTreeItemAccessibleBase michael@0: { michael@0: public: michael@0: XULTreeItemAccessible(nsIContent* aContent, DocAccessible* aDoc, michael@0: Accessible* aParent, nsITreeBoxObject* aTree, michael@0: nsITreeView* aTreeView, int32_t aRow); michael@0: michael@0: // nsISupports and cycle collection michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessible, michael@0: XULTreeItemAccessibleBase) michael@0: michael@0: // Accessible michael@0: virtual void Shutdown(); michael@0: virtual ENameValueFlag Name(nsString& aName); michael@0: virtual a11y::role NativeRole(); michael@0: michael@0: // XULTreeItemAccessibleBase michael@0: virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx); michael@0: michael@0: protected: michael@0: michael@0: // Accessible michael@0: virtual void CacheChildren(); michael@0: michael@0: // XULTreeItemAccessible michael@0: nsCOMPtr mColumn; michael@0: nsString mCachedName; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Accessible class for columns element of XUL tree. michael@0: */ michael@0: class XULTreeColumAccessible : public XULColumAccessible michael@0: { michael@0: public: michael@0: XULTreeColumAccessible(nsIContent* aContent, DocAccessible* aDoc); michael@0: michael@0: protected: michael@0: michael@0: // Accessible michael@0: virtual Accessible* GetSiblingAtOffset(int32_t aOffset, michael@0: nsresult *aError = nullptr) const; michael@0: }; michael@0: michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Accessible downcasting method michael@0: michael@0: inline XULTreeAccessible* michael@0: Accessible::AsXULTree() michael@0: { michael@0: return IsXULTree() ? static_cast(this) : nullptr; michael@0: } michael@0: michael@0: } // namespace a11y michael@0: } // namespace mozilla michael@0: michael@0: #endif