accessible/src/generic/ImageAccessible.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/generic/ImageAccessible.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     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_ImageAccessible_h__
    1.10 +#define mozilla_a11y_ImageAccessible_h__
    1.11 +
    1.12 +#include "BaseAccessibles.h"
    1.13 +#include "nsIAccessibleImage.h"
    1.14 +
    1.15 +class nsGenericHTMLElement;
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace a11y {
    1.19 +
    1.20 +/* Accessible for supporting images
    1.21 + * supports:
    1.22 + * - gets name, role
    1.23 + * - support basic state
    1.24 + */
    1.25 +class ImageAccessible : public LinkableAccessible,
    1.26 +                        public nsIAccessibleImage
    1.27 +{
    1.28 +public:
    1.29 +  ImageAccessible(nsIContent* aContent, DocAccessible* aDoc);
    1.30 +
    1.31 +  // nsISupports
    1.32 +  NS_DECL_ISUPPORTS_INHERITED
    1.33 +
    1.34 +  // nsIAccessible
    1.35 +  NS_IMETHOD GetActionName(uint8_t aIndex, nsAString& aName);
    1.36 +  NS_IMETHOD DoAction(uint8_t index);
    1.37 +
    1.38 +  // nsIAccessibleImage
    1.39 +  NS_DECL_NSIACCESSIBLEIMAGE
    1.40 +
    1.41 +  // Accessible
    1.42 +  virtual a11y::role NativeRole();
    1.43 +  virtual uint64_t NativeState();
    1.44 +  virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() MOZ_OVERRIDE;
    1.45 +
    1.46 +  // ActionAccessible
    1.47 +  virtual uint8_t ActionCount();
    1.48 +
    1.49 +protected:
    1.50 +  // Accessible
    1.51 +  virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
    1.52 +
    1.53 +private:
    1.54 +  /**
    1.55 +   * Return whether the element has a longdesc URI.
    1.56 +   */
    1.57 +  bool HasLongDesc() const
    1.58 +  {
    1.59 +    nsCOMPtr<nsIURI> uri = GetLongDescURI();
    1.60 +    return uri;
    1.61 +  }
    1.62 +
    1.63 +  /**
    1.64 +   * Return an URI for showlongdesc action if any.
    1.65 +   */
    1.66 +  already_AddRefed<nsIURI> GetLongDescURI() const;
    1.67 +
    1.68 +  /**
    1.69 +   * Used by GetActionName and DoAction to ensure the index for opening the
    1.70 +   * longdesc URL is valid.
    1.71 +   * It is always assumed that the highest possible index opens the longdesc.
    1.72 +   * This doesn't check that there is actually a longdesc, just that the index
    1.73 +   * would be correct if there was one.
    1.74 +   *
    1.75 +   * @param aIndex  The 0-based index to be tested.
    1.76 +   *
    1.77 +   * @returns  true if index is valid for longdesc action.
    1.78 +   */
    1.79 +  inline bool IsLongDescIndex(uint8_t aIndex);
    1.80 +
    1.81 +};
    1.82 +
    1.83 +////////////////////////////////////////////////////////////////////////////////
    1.84 +// Accessible downcasting method
    1.85 +
    1.86 +inline ImageAccessible*
    1.87 +Accessible::AsImage()
    1.88 +{
    1.89 +  return IsImage() ? static_cast<ImageAccessible*>(this) : nullptr;
    1.90 +}
    1.91 +
    1.92 +} // namespace a11y
    1.93 +} // namespace mozilla
    1.94 +
    1.95 +#endif
    1.96 +

mercurial