ImageAccessible.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_a11y_ImageAccessible_h__
  6. #define mozilla_a11y_ImageAccessible_h__
  7. #include "BaseAccessibles.h"
  8. namespace mozilla {
  9. namespace a11y {
  10. /* Accessible for supporting images
  11. * supports:
  12. * - gets name, role
  13. * - support basic state
  14. */
  15. class ImageAccessible : public LinkableAccessible
  16. {
  17. public:
  18. ImageAccessible(nsIContent* aContent, DocAccessible* aDoc);
  19. // Accessible
  20. virtual a11y::role NativeRole() override;
  21. virtual uint64_t NativeState() override;
  22. virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override;
  23. // ActionAccessible
  24. virtual uint8_t ActionCount() override;
  25. virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
  26. virtual bool DoAction(uint8_t aIndex) override;
  27. // ImageAccessible
  28. nsIntPoint Position(uint32_t aCoordType);
  29. nsIntSize Size();
  30. protected:
  31. virtual ~ImageAccessible();
  32. // Accessible
  33. virtual ENameValueFlag NativeName(nsString& aName) override;
  34. private:
  35. /**
  36. * Return whether the element has a longdesc URI.
  37. */
  38. bool HasLongDesc() const
  39. {
  40. nsCOMPtr<nsIURI> uri = GetLongDescURI();
  41. return uri;
  42. }
  43. /**
  44. * Return an URI for showlongdesc action if any.
  45. */
  46. already_AddRefed<nsIURI> GetLongDescURI() const;
  47. /**
  48. * Used by ActionNameAt and DoAction to ensure the index for opening the
  49. * longdesc URL is valid.
  50. * It is always assumed that the highest possible index opens the longdesc.
  51. * This doesn't check that there is actually a longdesc, just that the index
  52. * would be correct if there was one.
  53. *
  54. * @param aIndex The 0-based index to be tested.
  55. *
  56. * @returns true if index is valid for longdesc action.
  57. */
  58. inline bool IsLongDescIndex(uint8_t aIndex);
  59. };
  60. ////////////////////////////////////////////////////////////////////////////////
  61. // Accessible downcasting method
  62. inline ImageAccessible*
  63. Accessible::AsImage()
  64. {
  65. return IsImage() ? static_cast<ImageAccessible*>(this) : nullptr;
  66. }
  67. } // namespace a11y
  68. } // namespace mozilla
  69. #endif