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"
20 class SessionAccessibility final
21 : public java::SessionAccessibility::NativeProvider::Natives
<
22 SessionAccessibility
> {
24 typedef java::SessionAccessibility::NativeProvider::Natives
<
29 jni::NativeWeakPtr
<widget::GeckoViewSupport
> aWindow
,
30 java::SessionAccessibility::NativeProvider::Param aSessionAccessibility
);
32 void OnWeakNonIntrusiveDetach(already_AddRefed
<Runnable
> aDisposer
) {
33 SetAttached(false, std::move(aDisposer
));
36 const java::SessionAccessibility::NativeProvider::Ref
&
37 GetJavaAccessibility() {
38 return mSessionAccessibility
;
42 static RefPtr
<SessionAccessibility
> GetInstanceFor(Accessible
* aAccessible
);
43 static RefPtr
<SessionAccessibility
> GetInstanceFor(PresShell
* aPresShell
);
45 // Native implementations
46 using Base::AttachNative
;
47 using Base::DisposeNative
;
48 void GetNodeInfo(int32_t aID
, mozilla::jni::Object::Param aNodeInfo
);
49 int GetNodeClassName(int32_t aID
);
50 void SetText(int32_t aID
, jni::String::Param aText
);
51 void Click(int32_t aID
);
52 bool Pivot(int32_t aID
, int32_t aGranularity
, bool aForward
, bool aInclusive
);
53 void ExploreByTouch(int32_t aID
, float aX
, float aY
);
54 bool NavigateText(int32_t aID
, int32_t aGranularity
, int32_t aStartOffset
,
55 int32_t aEndOffset
, bool aForward
, bool aSelect
);
56 void SetSelection(int32_t aID
, int32_t aStart
, int32_t aEnd
);
57 void Cut(int32_t aID
);
58 void Copy(int32_t aID
);
59 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void Paste(int32_t aID
);
60 void StartNativeAccessibility();
63 void SendFocusEvent(Accessible
* aAccessible
);
64 void SendScrollingEvent(Accessible
* aAccessible
, int32_t aScrollX
,
65 int32_t aScrollY
, int32_t aMaxScrollX
,
67 MOZ_CAN_RUN_SCRIPT_BOUNDARY
68 void SendAccessibilityFocusedEvent(Accessible
* aAccessible
,
69 bool aScrollIntoView
);
70 void SendHoverEnterEvent(Accessible
* aAccessible
);
71 void SendTextSelectionChangedEvent(Accessible
* aAccessible
,
72 int32_t aCaretOffset
);
73 void SendTextTraversedEvent(Accessible
* aAccessible
, int32_t aStartOffset
,
75 void SendTextChangedEvent(Accessible
* aAccessible
, const nsAString
& aStr
,
76 int32_t aStart
, uint32_t aLen
, bool aIsInsert
,
78 void SendSelectedEvent(Accessible
* aAccessible
, bool aSelected
);
79 void SendClickedEvent(Accessible
* aAccessible
, uint32_t aFlags
);
80 void SendWindowContentChangedEvent();
81 void SendWindowStateChangedEvent(Accessible
* aAccessible
);
82 void SendAnnouncementEvent(Accessible
* aAccessible
,
83 const nsAString
& aAnnouncement
,
86 Accessible
* GetAccessibleByID(int32_t aID
) const;
88 static const int32_t kNoID
= -1;
89 static const int32_t kUnsetID
= 0;
91 static void RegisterAccessible(Accessible
* aAccessible
);
92 static void UnregisterAccessible(Accessible
* aAccessible
);
93 static void UnregisterAll(PresShell
* aPresShell
);
95 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SessionAccessibility
)
98 ~SessionAccessibility() {}
100 void PopulateNodeInfo(Accessible
* aAccessible
,
101 mozilla::jni::Object::Param aNodeInfo
);
103 void SetAttached(bool aAttached
, already_AddRefed
<Runnable
> aRunnable
);
105 bool DoNavigateText(Accessible
* aAccessible
, int32_t aGranularity
,
106 int32_t aStartOffset
, int32_t aEndOffset
, bool aForward
,
109 jni::NativeWeakPtr
<widget::GeckoViewSupport
> mWindow
; // Parent only
110 java::SessionAccessibility::NativeProvider::GlobalRef mSessionAccessibility
;
112 class IDMappingEntry
{
114 explicit IDMappingEntry(Accessible
* aAccessible
);
116 IDMappingEntry
& operator=(Accessible
* aAccessible
);
118 operator Accessible
*() const;
121 // A strong reference to a DocAccessible or DocAccessibleParent. They don't
122 // share any useful base class except nsISupports, so we use that.
123 // When we retrieve the document from this reference we cast it to
124 // LocalAccessible in the DocAccessible case because DocAccessible has
125 // multiple inheritance paths for nsISupports.
126 RefPtr
<nsISupports
> mDoc
;
127 // The ID of the accessible as used in the internal doc mapping.
128 // We rely on this ID being pointer derived and therefore divisible by two
129 // so we can use the first bit to mark if it is remote or not.
130 uint64_t mInternalID
;
132 static const uintptr_t IS_REMOTE
= 0x1;
136 * This provides a mapping from 32 bit id to accessible objects.
138 nsBaseHashtable
<nsUint32HashKey
, IDMappingEntry
, Accessible
*>
143 } // namespace mozilla