/* 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/. */

#include "nsISupports.idl"

typedef short PivotMoveReason;

interface nsIAccessible;
interface nsIAccessibleTraversalRule;

/**
 * The pivot interface encapsulates a reference to a single place in an accessible
 * subtree. The pivot is a point or a range in the accessible tree. This interface
 * provides traversal methods to move the pivot to next/prev state that complies
 * to a given rule.
 */
[scriptable, uuid(81fe5144-059b-42db-bd3a-f6ce3158d5e9)]
interface nsIAccessiblePivot : nsISupports
{
  /**
   * Move pivot to next object, from current position or given anchor,
   * complying to given traversal rule.
   *
   * @param aRule            [in] traversal rule to use.
   * @param aAnchor          [in] accessible to start search from, if not provided,
   *                           current position will be used.
   * @param aIncludeStart    [in] include anchor accessible in search.
   * @return next accessible node that matches rule in preorder.
   */
  [optional_argc] nsIAccessible next(in nsIAccessible aAnchor,
                                     in nsIAccessibleTraversalRule aRule,
                                     [optional] in boolean aIncludeStart);

  /**
   * Move pivot to previous object, from current position or given anchor,
   * complying to given traversal rule.
   *
   * @param aRule            [in] traversal rule to use.
   * @param aAnchor          [in] accessible to start search from, if not provided,
   *                           current position will be used.
   * @param aIncludeStart    [in] include anchor accessible in search.
   * @return previous accessible node that matches rule in preorder.
   */
  [optional_argc] nsIAccessible prev(in nsIAccessible aAnchor,
                                     in nsIAccessibleTraversalRule aRule,
                                     [optional] in boolean aIncludeStart);

  /**
   * Move pivot to first object in subtree complying to given traversal rule.
   *
   * @param aRule            [in] traversal rule to use.
   * @return first accessible node in subtree that matches rule in preorder.
   */
  nsIAccessible first(in nsIAccessibleTraversalRule aRule);

  /**
   * Move pivot to last object in subtree complying to given traversal rule.
   *
   * @param aRule            [in] traversal rule to use.
   * @return last accessible node in subtree that matches rule in preorder.
   */
  nsIAccessible last(in nsIAccessibleTraversalRule aRule);

  /**
   * Move pivot to given coordinate in screen pixels.
   *
   * @param aX               [in]  screen's x coordinate
   * @param aY               [in]  screen's y coordinate
   * @param aRule            [in]  raversal rule to use.
   * @return highest accessible in subtree that matches rule at given point.
   */
  nsIAccessible atPoint(in long aX, in long aY,
                        in nsIAccessibleTraversalRule aRule);
};

[scriptable, uuid(e197460d-1eff-4247-b4bb-a43be1840dae)]
interface nsIAccessibleTraversalRule : nsISupports
{
  /* Ignore this accessible object */
  const unsigned short FILTER_IGNORE = 0x0;
  /* Accept this accessible object */
  const unsigned short FILTER_MATCH = 0x1;
  /* Don't traverse accessibles children */
  const unsigned short FILTER_IGNORE_SUBTREE = 0x2;

  /**
   * Determines if a given accessible is to be accepted in our traversal rule
   *
   * @param aAccessible [in] accessible to examine.
   * @return a bitfield of FILTER_MATCH and FILTER_IGNORE_SUBTREE.
   */
  unsigned short match(in nsIAccessible aAccessible);
};
