accessible/generic/ARIAGridAccessible-inl.h
author Birunthan Mohanathas <birunthan@mohanathas.com>
Mon, 23 Jun 2014 16:27:43 -0700
changeset 190602 fdd74c065e5d743bd4d1a3044b2e76727dfb60f0
parent 190354 85b4fe3a7fa90caa702aa36f6985c667d9e01b02
child 274387 18039b7d024d89f7d136940dcb14682e777c8c9c
permissions -rw-r--r--
Bug 1028565 - Part 5: Flatten editor/{idl,public}/ directories. r=ehsan

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_a11y_ARIAGridAccessible_inl_h__
#define mozilla_a11y_ARIAGridAccessible_inl_h__

#include "ARIAGridAccessible.h"

#include "AccIterator.h"

namespace mozilla {
namespace a11y {

inline Accessible*
ARIAGridCellAccessible::TableFor(Accessible* aRow) const
{
  if (aRow) {
    Accessible* table = aRow->Parent();
    if (table) {
      roles::Role tableRole = table->Role();
      if (tableRole == roles::GROUPING) { // if there's a rowgroup.
        table = table->Parent();
        if (table)
          tableRole = table->Role();
      }

      return tableRole == roles::TABLE || tableRole == roles::TREE_TABLE ?
        table : nullptr;
    }
  }

  return nullptr;
}

inline int32_t
ARIAGridCellAccessible::RowIndexFor(Accessible* aRow) const
{
  Accessible* table = TableFor(aRow);
  if (table) {
    int32_t rowIdx = 0;
    Accessible* row = nullptr;
    AccIterator rowIter(table, filters::GetRow);
    while ((row = rowIter.Next()) && row != aRow)
      rowIdx++;

    if (row)
      return rowIdx;
  }

  return -1;
}

} // namespace a11y
} // namespace mozilla

#endif