accessible/src/generic/ImageAccessible.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:9999d7e0779d
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
6 #ifndef mozilla_a11y_ImageAccessible_h__
7 #define mozilla_a11y_ImageAccessible_h__
8
9 #include "BaseAccessibles.h"
10 #include "nsIAccessibleImage.h"
11
12 class nsGenericHTMLElement;
13
14 namespace mozilla {
15 namespace a11y {
16
17 /* Accessible for supporting images
18 * supports:
19 * - gets name, role
20 * - support basic state
21 */
22 class ImageAccessible : public LinkableAccessible,
23 public nsIAccessibleImage
24 {
25 public:
26 ImageAccessible(nsIContent* aContent, DocAccessible* aDoc);
27
28 // nsISupports
29 NS_DECL_ISUPPORTS_INHERITED
30
31 // nsIAccessible
32 NS_IMETHOD GetActionName(uint8_t aIndex, nsAString& aName);
33 NS_IMETHOD DoAction(uint8_t index);
34
35 // nsIAccessibleImage
36 NS_DECL_NSIACCESSIBLEIMAGE
37
38 // Accessible
39 virtual a11y::role NativeRole();
40 virtual uint64_t NativeState();
41 virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() MOZ_OVERRIDE;
42
43 // ActionAccessible
44 virtual uint8_t ActionCount();
45
46 protected:
47 // Accessible
48 virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
49
50 private:
51 /**
52 * Return whether the element has a longdesc URI.
53 */
54 bool HasLongDesc() const
55 {
56 nsCOMPtr<nsIURI> uri = GetLongDescURI();
57 return uri;
58 }
59
60 /**
61 * Return an URI for showlongdesc action if any.
62 */
63 already_AddRefed<nsIURI> GetLongDescURI() const;
64
65 /**
66 * Used by GetActionName and DoAction to ensure the index for opening the
67 * longdesc URL is valid.
68 * It is always assumed that the highest possible index opens the longdesc.
69 * This doesn't check that there is actually a longdesc, just that the index
70 * would be correct if there was one.
71 *
72 * @param aIndex The 0-based index to be tested.
73 *
74 * @returns true if index is valid for longdesc action.
75 */
76 inline bool IsLongDescIndex(uint8_t aIndex);
77
78 };
79
80 ////////////////////////////////////////////////////////////////////////////////
81 // Accessible downcasting method
82
83 inline ImageAccessible*
84 Accessible::AsImage()
85 {
86 return IsImage() ? static_cast<ImageAccessible*>(this) : nullptr;
87 }
88
89 } // namespace a11y
90 } // namespace mozilla
91
92 #endif
93

mercurial