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_HTMLTableAccessible_h__ michael@0: #define mozilla_a11y_HTMLTableAccessible_h__ michael@0: michael@0: #include "HyperTextAccessibleWrap.h" michael@0: #include "nsIAccessibleTable.h" michael@0: #include "TableAccessible.h" michael@0: #include "TableCellAccessible.h" michael@0: #include "xpcAccessibleTable.h" michael@0: #include "xpcAccessibleTableCell.h" michael@0: michael@0: class nsITableLayout; michael@0: class nsITableCellLayout; michael@0: michael@0: namespace mozilla { michael@0: namespace a11y { michael@0: michael@0: /** michael@0: * HTML table cell accessible (html:td). michael@0: */ michael@0: class HTMLTableCellAccessible : public HyperTextAccessibleWrap, michael@0: public nsIAccessibleTableCell, michael@0: public TableCellAccessible, michael@0: public xpcAccessibleTableCell michael@0: { michael@0: public: michael@0: HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc); michael@0: michael@0: // nsISupports michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: // nsIAccessibleTableCell michael@0: NS_FORWARD_NSIACCESSIBLETABLECELL(xpcAccessibleTableCell::) michael@0: michael@0: // Accessible michael@0: virtual TableCellAccessible* AsTableCell() { return this; } michael@0: virtual void Shutdown(); michael@0: virtual a11y::role NativeRole(); michael@0: virtual uint64_t NativeState(); michael@0: virtual uint64_t NativeInteractiveState() const; michael@0: virtual already_AddRefed NativeAttributes() MOZ_OVERRIDE; michael@0: michael@0: // TableCellAccessible michael@0: virtual TableAccessible* Table() const MOZ_OVERRIDE; michael@0: virtual uint32_t ColIdx() const MOZ_OVERRIDE; michael@0: virtual uint32_t RowIdx() const MOZ_OVERRIDE; michael@0: virtual uint32_t ColExtent() const MOZ_OVERRIDE; michael@0: virtual uint32_t RowExtent() const MOZ_OVERRIDE; michael@0: virtual void ColHeaderCells(nsTArray* aCells) MOZ_OVERRIDE; michael@0: virtual void RowHeaderCells(nsTArray* aCells) MOZ_OVERRIDE; michael@0: virtual bool Selected() MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: /** michael@0: * Return host table accessible. michael@0: */ michael@0: already_AddRefed GetTableAccessible(); michael@0: michael@0: /** michael@0: * Return nsITableCellLayout of the table cell frame. michael@0: */ michael@0: nsITableCellLayout* GetCellLayout() const; michael@0: michael@0: /** michael@0: * Return row and column indices of the cell. michael@0: */ michael@0: nsresult GetCellIndexes(int32_t& aRowIdx, int32_t& aColIdx) const; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * HTML table row/column header accessible (html:th or html:td@scope). michael@0: */ michael@0: class HTMLTableHeaderCellAccessible : public HTMLTableCellAccessible michael@0: { michael@0: public: michael@0: HTMLTableHeaderCellAccessible(nsIContent* aContent, DocAccessible* aDoc); michael@0: michael@0: // Accessible michael@0: virtual a11y::role NativeRole(); michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * HTML table row accessible (html:tr). michael@0: */ michael@0: class HTMLTableRowAccessible : public AccessibleWrap michael@0: { michael@0: public: michael@0: HTMLTableRowAccessible(nsIContent* aContent, DocAccessible* aDoc) : michael@0: AccessibleWrap(aContent, aDoc) michael@0: { michael@0: mType = eHTMLTableRowType; michael@0: mGenericTypes |= eTableRow; michael@0: } michael@0: virtual ~HTMLTableRowAccessible() { } michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: // Accessible michael@0: virtual a11y::role NativeRole(); michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * HTML table accessible (html:table). michael@0: */ michael@0: michael@0: // To turn on table debugging descriptions define SHOW_LAYOUT_HEURISTIC michael@0: // This allow release trunk builds to be used by testers to refine the michael@0: // data vs. layout heuristic michael@0: // #define SHOW_LAYOUT_HEURISTIC michael@0: michael@0: class HTMLTableAccessible : public AccessibleWrap, michael@0: public xpcAccessibleTable, michael@0: public nsIAccessibleTable, michael@0: public TableAccessible michael@0: { michael@0: public: michael@0: HTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc) : michael@0: AccessibleWrap(aContent, aDoc), xpcAccessibleTable(this) michael@0: { michael@0: mType = eHTMLTableType; michael@0: mGenericTypes |= eTable; michael@0: } michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: // nsIAccessible Table michael@0: NS_FORWARD_NSIACCESSIBLETABLE(xpcAccessibleTable::) michael@0: michael@0: // TableAccessible michael@0: virtual Accessible* Caption(); michael@0: virtual void Summary(nsString& aSummary); michael@0: virtual uint32_t ColCount(); michael@0: virtual uint32_t RowCount(); michael@0: virtual Accessible* CellAt(uint32_t aRowIndex, uint32_t aColumnIndex); michael@0: virtual int32_t CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx); michael@0: virtual int32_t ColIndexAt(uint32_t aCellIdx); michael@0: virtual int32_t RowIndexAt(uint32_t aCellIdx); michael@0: virtual void RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx, michael@0: int32_t* aColIdx); michael@0: virtual uint32_t ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx); michael@0: virtual uint32_t RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx); michael@0: virtual bool IsColSelected(uint32_t aColIdx); michael@0: virtual bool IsRowSelected(uint32_t aRowIdx); michael@0: virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx); michael@0: virtual uint32_t SelectedCellCount(); michael@0: virtual uint32_t SelectedColCount(); michael@0: virtual uint32_t SelectedRowCount(); michael@0: virtual void SelectedCells(nsTArray* aCells); michael@0: virtual void SelectedCellIndices(nsTArray* aCells); michael@0: virtual void SelectedColIndices(nsTArray* aCols); michael@0: virtual void SelectedRowIndices(nsTArray* aRows); michael@0: virtual void SelectCol(uint32_t aColIdx); michael@0: virtual void SelectRow(uint32_t aRowIdx); michael@0: virtual void UnselectCol(uint32_t aColIdx); michael@0: virtual void UnselectRow(uint32_t aRowIdx); michael@0: virtual bool IsProbablyLayoutTable(); michael@0: virtual Accessible* AsAccessible() { return this; } michael@0: michael@0: // Accessible michael@0: virtual void Shutdown(); michael@0: virtual TableAccessible* AsTable() { return this; } michael@0: virtual void Description(nsString& aDescription); michael@0: virtual a11y::role NativeRole(); michael@0: virtual uint64_t NativeState(); michael@0: virtual already_AddRefed NativeAttributes() MOZ_OVERRIDE; michael@0: virtual Relation RelationByType(RelationType aRelationType) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: // Accessible michael@0: virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE; michael@0: virtual void CacheChildren(); michael@0: michael@0: // HTMLTableAccessible michael@0: michael@0: /** michael@0: * Add row or column to selection. michael@0: * michael@0: * @param aIndex [in] index of row or column to be selected michael@0: * @param aTarget [in] indicates what should be selected, either row or column michael@0: * (see nsISelectionPrivate) michael@0: */ michael@0: nsresult AddRowOrColumnToSelection(int32_t aIndex, uint32_t aTarget); michael@0: michael@0: /** michael@0: * Removes rows or columns at the given index or outside it from selection. michael@0: * michael@0: * @param aIndex [in] row or column index michael@0: * @param aTarget [in] indicates whether row or column should unselected michael@0: * @param aIsOuter [in] indicates whether all rows or column excepting michael@0: * the given one should be unselected or the given one michael@0: * should be unselected only michael@0: */ michael@0: nsresult RemoveRowsOrColumnsFromSelection(int32_t aIndex, michael@0: uint32_t aTarget, michael@0: bool aIsOuter); michael@0: michael@0: /** michael@0: * Return true if table has an element with the given tag name. michael@0: * michael@0: * @param aTagName [in] tag name of searched element michael@0: * @param aAllowEmpty [in, optional] points if found element can be empty michael@0: * or contain whitespace text only. michael@0: */ michael@0: bool HasDescendant(const nsAString& aTagName, bool aAllowEmpty = true); michael@0: michael@0: #ifdef SHOW_LAYOUT_HEURISTIC michael@0: nsString mLayoutHeuristic; michael@0: #endif michael@0: }; michael@0: michael@0: /** michael@0: * HTML caption accessible (html:caption). michael@0: */ michael@0: class HTMLCaptionAccessible : public HyperTextAccessibleWrap michael@0: { michael@0: public: michael@0: HTMLCaptionAccessible(nsIContent* aContent, DocAccessible* aDoc) : michael@0: HyperTextAccessibleWrap(aContent, aDoc) { } michael@0: virtual ~HTMLCaptionAccessible() { } michael@0: michael@0: // nsIAccessible michael@0: michael@0: // Accessible michael@0: virtual a11y::role NativeRole(); michael@0: virtual Relation RelationByType(RelationType aRelationType) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: } // namespace a11y michael@0: } // namespace mozilla michael@0: michael@0: #endif