Bug 1651705: Part 6 - Update Android a11y to work with `NativeWeakPtr`; r=eeejay

This patch is similar to part 4 but for Android a11y.

Conversions over to `NativeWeakPtr` are pretty straight forward thanks to the
type system. Basically we take a `NativeWeakPtr`, call `Access()` on it, and
if the accessor is truthy, then we call whatever methods we need to call.

Creation of new pointers is done using `NativeWeakPtrHolder::Attach()` and
detaching of strong references is done by `NativeWeakPtr::Detach()`.

Differential Revision: https://phabricator.services.mozilla.com/D87365
This commit is contained in:
Aaron Klotz 2020-09-01 14:34:37 +00:00
Родитель 84f766366c
Коммит 6a34c1e45b
5 изменённых файлов: 38 добавлений и 30 удалений

Просмотреть файл

@ -146,7 +146,7 @@ void DocAccessibleWrap::CacheViewportCallback(nsITimer* aTimer,
}
ipcDoc->SendBatch(eBatch_Viewport, cacheData);
} else if (SessionAccessibility* sessionAcc =
} else if (RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(docAcc)) {
nsTArray<AccessibleWrap*> accessibles(inViewAccs.Count());
for (auto iter = inViewAccs.Iter(); !iter.Done(); iter.Next()) {
@ -177,7 +177,7 @@ void DocAccessibleWrap::CacheViewportCallback(nsITimer* aTimer,
ipcDoc->GetPlatformExtension()->SendSetPivotBoundaries(
firstDoc, UNIQUE_ID(first), lastDoc, UNIQUE_ID(last));
}
} else if (SessionAccessibility* sessionAcc =
} else if (RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(docAcc)) {
sessionAcc->UpdateAccessibleFocusBoundaries(
first ? static_cast<AccessibleWrap*>(first) : docAcc,
@ -243,7 +243,7 @@ void DocAccessibleWrap::CacheFocusPath(AccessibleWrap* aAccessible) {
}
ipcDoc->SendBatch(eBatch_FocusPath, cacheData);
} else if (SessionAccessibility* sessionAcc =
} else if (RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(this)) {
nsTArray<AccessibleWrap*> accessibles;
for (AccessibleWrap* acc = aAccessible; acc && acc != this->Parent();
@ -280,7 +280,7 @@ void DocAccessibleWrap::UpdateFocusPathBounds() {
}
ipcDoc->SendBatch(eBatch_BoundsUpdate, boundsData);
} else if (SessionAccessibility* sessionAcc =
} else if (RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(this)) {
nsTArray<AccessibleWrap*> accessibles(mFocusPath.Count());
for (auto iter = mFocusPath.Iter(); !iter.Done(); iter.Next()) {

Просмотреть файл

@ -53,7 +53,7 @@ void a11y::ProxyDestroyed(ProxyAccessible* aProxy) {
}
void a11y::ProxyEvent(ProxyAccessible* aTarget, uint32_t aEventType) {
SessionAccessibility* sessionAcc =
RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(aTarget);
if (!sessionAcc) {
return;
@ -68,7 +68,7 @@ void a11y::ProxyEvent(ProxyAccessible* aTarget, uint32_t aEventType) {
void a11y::ProxyStateChangeEvent(ProxyAccessible* aTarget, uint64_t aState,
bool aEnabled) {
SessionAccessibility* sessionAcc =
RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(aTarget);
if (!sessionAcc) {
@ -100,7 +100,7 @@ void a11y::ProxyStateChangeEvent(ProxyAccessible* aTarget, uint64_t aState,
void a11y::ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset,
bool aIsSelectionCollapsed) {
SessionAccessibility* sessionAcc =
RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(aTarget);
if (sessionAcc) {
@ -111,7 +111,7 @@ void a11y::ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset,
void a11y::ProxyTextChangeEvent(ProxyAccessible* aTarget, const nsString& aStr,
int32_t aStart, uint32_t aLen, bool aIsInsert,
bool aFromUser) {
SessionAccessibility* sessionAcc =
RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(aTarget);
if (sessionAcc) {
@ -163,7 +163,7 @@ void a11y::ProxyScrollingEvent(ProxyAccessible* aTarget, uint32_t aEventType,
uint32_t aScrollX, uint32_t aScrollY,
uint32_t aMaxScrollX, uint32_t aMaxScrollY) {
if (aEventType == nsIAccessibleEvent::EVENT_SCROLLING) {
SessionAccessibility* sessionAcc =
RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(aTarget);
if (sessionAcc) {
@ -176,7 +176,7 @@ void a11y::ProxyScrollingEvent(ProxyAccessible* aTarget, uint32_t aEventType,
void a11y::ProxyAnnouncementEvent(ProxyAccessible* aTarget,
const nsString& aAnnouncement,
uint16_t aPriority) {
SessionAccessibility* sessionAcc =
RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(aTarget);
if (sessionAcc) {
@ -188,7 +188,7 @@ void a11y::ProxyAnnouncementEvent(ProxyAccessible* aTarget,
void a11y::ProxyBatch(ProxyAccessible* aDocument, const uint64_t aBatchType,
const nsTArray<ProxyAccessible*>& aAccessibles,
const nsTArray<BatchData>& aData) {
SessionAccessibility* sessionAcc =
RefPtr<SessionAccessibility> sessionAcc =
SessionAccessibility::GetInstanceFor(aDocument);
if (!sessionAcc) {
return;
@ -253,4 +253,4 @@ bool a11y::LocalizeString(const char* aToken, nsAString& aLocalized,
NS_WARNING("Failed to localize string");
aLocalized.AssignLiteral("");
return false;
}
}

Просмотреть файл

@ -21,6 +21,7 @@
#include "mozilla/a11y/DocAccessibleParent.h"
#include "mozilla/a11y/DocManager.h"
#include "mozilla/jni/GeckoBundleUtils.h"
#include "mozilla/widget/GeckoViewSupport.h"
#ifdef DEBUG
# include <android/log.h>
@ -42,10 +43,6 @@
acc->funcname(__VA_ARGS__); \
}
template <>
const char nsWindow::NativePtr<mozilla::a11y::SessionAccessibility>::sName[] =
"SessionAccessibility";
using namespace mozilla::a11y;
class Settings final
@ -60,6 +57,13 @@ class Settings final
}
};
SessionAccessibility::SessionAccessibility(
jni::NativeWeakPtr<widget::GeckoViewSupport> aWindow,
java::SessionAccessibility::NativeProvider::Param aSessionAccessibility)
: mWindow(aWindow), mSessionAccessibility(aSessionAccessibility) {
SetAttached(true, nullptr);
}
void SessionAccessibility::SetAttached(bool aAttached,
already_AddRefed<Runnable> aRunnable) {
if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
@ -101,11 +105,17 @@ mozilla::jni::Object::LocalRef SessionAccessibility::GetNodeInfo(int32_t aID) {
}
RootAccessibleWrap* SessionAccessibility::GetRoot() {
if (!mWindow) {
auto acc(mWindow.Access());
if (!acc) {
return nullptr;
}
return static_cast<RootAccessibleWrap*>(mWindow->GetRootAccessible());
nsWindow* gkWindow = acc->GetNsWindow();
if (!gkWindow) {
return nullptr;
}
return static_cast<RootAccessibleWrap*>(gkWindow->GetRootAccessible());
}
void SessionAccessibility::SetText(int32_t aID, jni::String::Param aText) {
@ -150,7 +160,7 @@ void SessionAccessibility::Paste(int32_t aID) {
FORWARD_ACTION_TO_ACCESSIBLE(Paste);
}
SessionAccessibility* SessionAccessibility::GetInstanceFor(
RefPtr<SessionAccessibility> SessionAccessibility::GetInstanceFor(
ProxyAccessible* aAccessible) {
auto tab =
static_cast<dom::BrowserParent*>(aAccessible->Document()->Manager());
@ -164,7 +174,7 @@ SessionAccessibility* SessionAccessibility::GetInstanceFor(
return chromeDoc ? GetInstanceFor(chromeDoc) : nullptr;
}
SessionAccessibility* SessionAccessibility::GetInstanceFor(
RefPtr<SessionAccessibility> SessionAccessibility::GetInstanceFor(
Accessible* aAccessible) {
RootAccessible* rootAcc = aAccessible->RootAccessible();
nsViewManager* vm = rootAcc->PresShellPtr()->GetViewManager();

Просмотреть файл

@ -7,6 +7,7 @@
#define mozilla_a11y_SessionAccessibility_h_
#include "mozilla/java/SessionAccessibilityNatives.h"
#include "mozilla/widget/GeckoViewSupport.h"
#include "nsAppShell.h"
#include "nsThreadUtils.h"
#include "nsWindow.h"
@ -28,13 +29,10 @@ class SessionAccessibility final
Base;
SessionAccessibility(
nsWindow::NativePtr<SessionAccessibility>* aPtr, nsWindow* aWindow,
java::SessionAccessibility::NativeProvider::Param aSessionAccessibility)
: mWindow(aPtr, aWindow), mSessionAccessibility(aSessionAccessibility) {
SetAttached(true, nullptr);
}
jni::NativeWeakPtr<widget::GeckoViewSupport> aWindow,
java::SessionAccessibility::NativeProvider::Param aSessionAccessibility);
void OnDetach(already_AddRefed<Runnable> aDisposer) {
void OnWeakNonIntrusiveDetach(already_AddRefed<Runnable> aDisposer) {
SetAttached(false, std::move(aDisposer));
}
@ -44,8 +42,8 @@ class SessionAccessibility final
}
static void Init();
static SessionAccessibility* GetInstanceFor(ProxyAccessible* aAccessible);
static SessionAccessibility* GetInstanceFor(Accessible* aAccessible);
static RefPtr<SessionAccessibility> GetInstanceFor(ProxyAccessible* aAccessible);
static RefPtr<SessionAccessibility> GetInstanceFor(Accessible* aAccessible);
// Native implementations
using Base::AttachNative;
@ -109,7 +107,7 @@ class SessionAccessibility final
void SetAttached(bool aAttached, already_AddRefed<Runnable> aRunnable);
RootAccessibleWrap* GetRoot();
nsWindow::WindowPtr<SessionAccessibility> mWindow; // Parent only
jni::NativeWeakPtr<widget::GeckoViewSupport> mWindow; // Parent only
java::SessionAccessibility::NativeProvider::GlobalRef mSessionAccessibility;
};

Просмотреть файл

@ -20,7 +20,7 @@ mozilla::ipc::IPCResult DocAccessiblePlatformExtParent::RecvSetPivotBoundaries(
MOZ_ASSERT(aFirstDoc);
MOZ_ASSERT(aLastDoc);
SessionAccessibility* sessionAcc = SessionAccessibility::GetInstanceFor(
RefPtr<SessionAccessibility> sessionAcc = SessionAccessibility::GetInstanceFor(
static_cast<DocAccessibleParent*>(Manager()));
if (!sessionAcc) {
return IPC_OK();