Bug 1758592 - P2: Return a value when pivoting and use it in parent-side traversal. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D140684
This commit is contained in:
Eitan Isaacson 2022-03-10 00:11:40 +00:00
parent 22a62daa19
commit 0a81a46878
7 changed files with 56 additions and 10 deletions

View File

@ -294,7 +294,7 @@ bool AccessibleWrap::GetSelectionBounds(int32_t* aStartOffset,
return false;
}
void AccessibleWrap::PivotTo(int32_t aGranularity, bool aForward,
bool AccessibleWrap::PivotTo(int32_t aGranularity, bool aForward,
bool aInclusive) {
a11y::Pivot pivot(RootAccessible());
TraversalRule rule(aGranularity);
@ -326,7 +326,11 @@ void AccessibleWrap::PivotTo(int32_t aGranularity, bool aForward,
SessionAccessibility::GetInstanceFor(result);
sessionAcc->SendAccessibilityFocusedEvent(newPosition);
}
return true;
}
return false;
}
void AccessibleWrap::ExploreByTouch(float aX, float aY) {

View File

@ -37,7 +37,7 @@ class AccessibleWrap : public LocalAccessible {
virtual bool GetSelectionBounds(int32_t* aStartOffset, int32_t* aEndOffset);
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual void PivotTo(int32_t aGranularity, bool aForward, bool aInclusive);
virtual bool PivotTo(int32_t aGranularity, bool aForward, bool aInclusive);
virtual void NavigateText(int32_t aGranularity, int32_t aStartOffset,
int32_t aEndOffset, bool aForward, bool aSelect);

View File

@ -113,15 +113,16 @@ bool RemoteAccessibleWrap::GetSelectionBounds(int32_t* aStartOffset,
return Proxy()->SelectionBoundsAt(0, unused, aStartOffset, aEndOffset);
}
void RemoteAccessibleWrap::PivotTo(int32_t aGranularity, bool aForward,
bool RemoteAccessibleWrap::PivotTo(int32_t aGranularity, bool aForward,
bool aInclusive) {
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
AccessibleWrap::PivotTo(aGranularity, aForward, aInclusive);
return;
return AccessibleWrap::PivotTo(aGranularity, aForward, aInclusive);
}
Unused << Proxy()->Document()->GetPlatformExtension()->SendPivot(
Proxy()->ID(), aGranularity, aForward, aInclusive);
return true;
}
void RemoteAccessibleWrap::NavigateText(int32_t aGranularity,

View File

@ -61,7 +61,7 @@ class RemoteAccessibleWrap : public AccessibleWrap {
virtual bool GetSelectionBounds(int32_t* aStartOffset,
int32_t* aEndOffset) override;
virtual void PivotTo(int32_t aGranularity, bool aForward,
virtual bool PivotTo(int32_t aGranularity, bool aForward,
bool aInclusive) override;
virtual void NavigateText(int32_t aGranularity, int32_t aStartOffset,

View File

@ -134,6 +134,22 @@ void SessionAccessibility::Click(int32_t aID) {
FORWARD_ACTION_TO_ACCESSIBLE(DoAction, 0);
}
bool SessionAccessibility::CachedPivot(int32_t aID, int32_t aGranularity,
bool aForward, bool aInclusive) {
RefPtr<SessionAccessibility> self(this);
bool ret = false;
nsAppShell::SyncRunEvent(
[this, self, aID, aGranularity, aForward, aInclusive, &ret] {
if (RootAccessibleWrap* rootAcc = GetRoot()) {
if (AccessibleWrap* acc = rootAcc->FindAccessibleById(aID)) {
ret = acc->PivotTo(aGranularity, aForward, aInclusive);
}
}
});
return ret;
}
void SessionAccessibility::Pivot(int32_t aID, int32_t aGranularity,
bool aForward, bool aInclusive) {
FORWARD_ACTION_TO_ACCESSIBLE(PivotTo, aGranularity, aForward, aInclusive);

View File

@ -52,6 +52,8 @@ class SessionAccessibility final
void SetText(int32_t aID, jni::String::Param aText);
void Click(int32_t aID);
void Pivot(int32_t aID, int32_t aGranularity, bool aForward, bool aInclusive);
bool CachedPivot(int32_t aID, int32_t aGranularity, bool aForward,
bool aInclusive);
void ExploreByTouch(int32_t aID, float aX, float aY);
void NavigateText(int32_t aID, int32_t aGranularity, int32_t aStartOffset,
int32_t aEndOffset, bool aForward, bool aSelect);

View File

@ -955,16 +955,21 @@ public class SessionAccessibility {
private boolean pivot(
final int id, final String granularity, final boolean forward, final boolean inclusive) {
if (!forward && id == View.NO_ID) {
// If attempting to pivot backwards from the root view, return false.
return false;
}
if (nativeProvider.isCacheEnabled()) {
return cachedPivot(id, granularity, forward, inclusive);
}
final int gran = java.util.Arrays.asList(sHtmlGranularities).indexOf(granularity);
if (forward && id == mLastAccessibilityFocusable) {
return false;
}
if (!forward) {
if (id == View.NO_ID) {
return false;
}
if (id == mFirstAccessibilityFocusable) {
sendEvent(
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED,
@ -979,6 +984,20 @@ public class SessionAccessibility {
return true;
}
private boolean cachedPivot(
final int id, final String granularity, final boolean forward, final boolean inclusive) {
final int gran = java.util.Arrays.asList(sHtmlGranularities).indexOf(granularity);
final boolean success = nativeProvider.cachedPivotNative(id, gran, forward, inclusive);
if (!success && !forward) {
// If we failed to pivot backwards set the root view as the a11y focus.
sendEvent(
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, View.NO_ID, CLASSNAME_WEBVIEW, null);
return true;
}
return success;
}
/* package */ final class NativeProvider extends JNIObject {
@WrapForJNI(calledFrom = "ui")
private void setAttached(final boolean attached) {
@ -1006,6 +1025,10 @@ public class SessionAccessibility {
@WrapForJNI(dispatchTo = "gecko", stubName = "Pivot")
public native void pivotNative(int id, int granularity, boolean forward, boolean inclusive);
@WrapForJNI(dispatchTo = "current", stubName = "CachedPivot")
public native boolean cachedPivotNative(
int id, int granularity, boolean forward, boolean inclusive);
@WrapForJNI(dispatchTo = "gecko")
public native void exploreByTouch(int id, float x, float y);