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/. */
6 #ifndef mozilla_a11y_SessionAccessibility_h_
7 #define mozilla_a11y_SessionAccessibility_h_
9 #include "mozilla/java/SessionAccessibilityNatives.h"
10 #include "mozilla/widget/GeckoViewSupport.h"
11 #include "nsAppShell.h"
12 #include "nsThreadUtils.h"
14 #include "AccessibleWrap.h"
22 class RemoteAccessible
;
23 class RootAccessibleWrap
;
26 class SessionAccessibility final
27 : public java::SessionAccessibility::NativeProvider::Natives
<
28 SessionAccessibility
> {
30 typedef java::SessionAccessibility::NativeProvider::Natives
<
35 jni::NativeWeakPtr
<widget::GeckoViewSupport
> aWindow
,
36 java::SessionAccessibility::NativeProvider::Param aSessionAccessibility
);
38 void OnWeakNonIntrusiveDetach(already_AddRefed
<Runnable
> aDisposer
) {
39 SetAttached(false, std::move(aDisposer
));
42 const java::SessionAccessibility::NativeProvider::Ref
&
43 GetJavaAccessibility() {
44 return mSessionAccessibility
;
48 static RefPtr
<SessionAccessibility
> GetInstanceFor(Accessible
* aAccessible
);
49 static RefPtr
<SessionAccessibility
> GetInstanceFor(PresShell
* aPresShell
);
51 // Native implementations
52 using Base::AttachNative
;
53 using Base::DisposeNative
;
54 void GetNodeInfo(int32_t aID
, mozilla::jni::Object::Param aNodeInfo
);
55 int GetNodeClassName(int32_t aID
);
56 void SetText(int32_t aID
, jni::String::Param aText
);
57 void Click(int32_t aID
);
58 bool Pivot(int32_t aID
, int32_t aGranularity
, bool aForward
, bool aInclusive
);
59 void ExploreByTouch(int32_t aID
, float aX
, float aY
);
60 bool NavigateText(int32_t aID
, int32_t aGranularity
, int32_t aStartOffset
,
61 int32_t aEndOffset
, bool aForward
, bool aSelect
);
62 void SetSelection(int32_t aID
, int32_t aStart
, int32_t aEnd
);
63 void Cut(int32_t aID
);
64 void Copy(int32_t aID
);
65 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void Paste(int32_t aID
);
66 void StartNativeAccessibility();
69 void SendFocusEvent(Accessible
* aAccessible
);
70 void SendScrollingEvent(Accessible
* aAccessible
, int32_t aScrollX
,
71 int32_t aScrollY
, int32_t aMaxScrollX
,
73 MOZ_CAN_RUN_SCRIPT_BOUNDARY
74 void SendAccessibilityFocusedEvent(Accessible
* aAccessible
);
75 void SendHoverEnterEvent(Accessible
* aAccessible
);
76 void SendTextSelectionChangedEvent(Accessible
* aAccessible
,
77 int32_t aCaretOffset
);
78 void SendTextTraversedEvent(Accessible
* aAccessible
, int32_t aStartOffset
,
80 void SendTextChangedEvent(Accessible
* aAccessible
, const nsAString
& aStr
,
81 int32_t aStart
, uint32_t aLen
, bool aIsInsert
,
83 void SendSelectedEvent(Accessible
* aAccessible
, bool aSelected
);
84 void SendClickedEvent(Accessible
* aAccessible
, uint32_t aFlags
);
85 void SendWindowContentChangedEvent();
86 void SendWindowStateChangedEvent(Accessible
* aAccessible
);
87 void SendAnnouncementEvent(Accessible
* aAccessible
,
88 const nsAString
& aAnnouncement
,
91 Accessible
* GetAccessibleByID(int32_t aID
) const;
93 static const int32_t kNoID
= -1;
94 static const int32_t kUnsetID
= 0;
96 static void RegisterAccessible(Accessible
* aAccessible
);
97 static void UnregisterAccessible(Accessible
* aAccessible
);
98 static void UnregisterAll(PresShell
* aPresShell
);
100 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SessionAccessibility
)
103 ~SessionAccessibility() {}
105 void PopulateNodeInfo(Accessible
* aAccessible
,
106 mozilla::jni::Object::Param aNodeInfo
);
108 void SetAttached(bool aAttached
, already_AddRefed
<Runnable
> aRunnable
);
110 bool DoNavigateText(Accessible
* aAccessible
, int32_t aGranularity
,
111 int32_t aStartOffset
, int32_t aEndOffset
, bool aForward
,
114 jni::NativeWeakPtr
<widget::GeckoViewSupport
> mWindow
; // Parent only
115 java::SessionAccessibility::NativeProvider::GlobalRef mSessionAccessibility
;
117 class IDMappingEntry
{
119 explicit IDMappingEntry(Accessible
* aAccessible
);
121 IDMappingEntry
& operator=(Accessible
* aAccessible
);
123 operator Accessible
*() const;
126 // A strong reference to a DocAccessible or DocAccessibleParent. They don't
127 // share any useful base class except nsISupports, so we use that.
128 // When we retrieve the document from this reference we cast it to
129 // LocalAccessible in the DocAccessible case because DocAccessible has
130 // multiple inheritance paths for nsISupports.
131 RefPtr
<nsISupports
> mDoc
;
132 // The ID of the accessible as used in the internal doc mapping.
133 // We rely on this ID being pointer derived and therefore divisible by two
134 // so we can use the first bit to mark if it is remote or not.
135 uint64_t mInternalID
;
137 static const uintptr_t IS_REMOTE
= 0x1;
141 * This provides a mapping from 32 bit id to accessible objects.
143 nsBaseHashtable
<nsUint32HashKey
, IDMappingEntry
, Accessible
*>
148 } // namespace mozilla