mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add scrollIndex and scrollChildren to semantics, add Android implementation (#6239)
This commit is contained in:
parent
23fcc27718
commit
abd918eb61
@ -596,7 +596,9 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
|
||||
/// describe the maximum and minimum in-rage values that `scrollPosition` can
|
||||
/// be. Both or either may be infinity to indicate unbound scrolling. The
|
||||
/// value for `scrollPosition` can (temporarily) be outside this range, for
|
||||
/// example during an overscroll.
|
||||
/// example during an overscroll. `scrollChildren` is the count of the
|
||||
/// total number of child nodes that contribute semantics and `scrollIndex`
|
||||
/// is the index of the first visible child node that contributes semantics.
|
||||
///
|
||||
/// The `rect` is the region occupied by this node in its own coordinate
|
||||
/// system.
|
||||
@ -609,6 +611,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
|
||||
int actions,
|
||||
int textSelectionBase,
|
||||
int textSelectionExtent,
|
||||
int scrollChildren,
|
||||
int scrollIndex,
|
||||
double scrollPosition,
|
||||
double scrollExtentMax,
|
||||
double scrollExtentMin,
|
||||
@ -634,6 +638,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
|
||||
actions,
|
||||
textSelectionBase,
|
||||
textSelectionExtent,
|
||||
scrollChildren,
|
||||
scrollIndex,
|
||||
scrollPosition,
|
||||
scrollExtentMax,
|
||||
scrollExtentMin,
|
||||
@ -659,6 +665,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
|
||||
int actions,
|
||||
int textSelectionBase,
|
||||
int textSelectionExtent,
|
||||
int scrollChildren,
|
||||
int scrollIndex,
|
||||
double scrollPosition,
|
||||
double scrollExtentMax,
|
||||
double scrollExtentMin,
|
||||
|
||||
@ -79,6 +79,8 @@ struct SemanticsNode {
|
||||
int32_t actions = 0;
|
||||
int32_t textSelectionBase = -1;
|
||||
int32_t textSelectionExtent = -1;
|
||||
int32_t scrollChildren = 0;
|
||||
int32_t scrollIndex = 0;
|
||||
double scrollPosition = std::nan("");
|
||||
double scrollExtentMax = std::nan("");
|
||||
double scrollExtentMin = std::nan("");
|
||||
|
||||
@ -41,6 +41,8 @@ void SemanticsUpdateBuilder::updateNode(
|
||||
int actions,
|
||||
int textSelectionBase,
|
||||
int textSelectionExtent,
|
||||
int scrollChildren,
|
||||
int scrollIndex,
|
||||
double scrollPosition,
|
||||
double scrollExtentMax,
|
||||
double scrollExtentMin,
|
||||
@ -64,6 +66,8 @@ void SemanticsUpdateBuilder::updateNode(
|
||||
node.actions = actions;
|
||||
node.textSelectionBase = textSelectionBase;
|
||||
node.textSelectionExtent = textSelectionExtent;
|
||||
node.scrollChildren = scrollChildren;
|
||||
node.scrollIndex = scrollIndex;
|
||||
node.scrollPosition = scrollPosition;
|
||||
node.scrollExtentMax = scrollExtentMax;
|
||||
node.scrollExtentMin = scrollExtentMin;
|
||||
|
||||
@ -29,6 +29,8 @@ class SemanticsUpdateBuilder
|
||||
int actions,
|
||||
int textSelectionBase,
|
||||
int textSelectionExtent,
|
||||
int scrollChildren,
|
||||
int scrollIndex,
|
||||
double scrollPosition,
|
||||
double scrollExtentMax,
|
||||
double scrollExtentMin,
|
||||
|
||||
@ -144,8 +144,8 @@ class AccessibilityBridge
|
||||
}
|
||||
|
||||
AccessibilityNodeInfo result = AccessibilityNodeInfo.obtain(mOwner, virtualViewId);
|
||||
// Work around for https://github.com/flutter/flutter/issues/2101
|
||||
result.setViewIdResourceName("");
|
||||
// Work around for https://github.com/flutter/flutter/issues/2101
|
||||
result.setViewIdResourceName("");
|
||||
result.setPackageName(mOwner.getContext().getPackageName());
|
||||
result.setClassName("android.view.View");
|
||||
result.setSource(mOwner, virtualViewId);
|
||||
@ -717,6 +717,20 @@ class AccessibilityBridge
|
||||
event.setScrollX((int) position);
|
||||
event.setMaxScrollX((int) max);
|
||||
}
|
||||
if (object.scrollChildren > 0) {
|
||||
event.setItemCount(object.scrollChildren);
|
||||
event.setFromIndex(object.scrollIndex);
|
||||
int visibleChildren = object.childrenInHitTestOrder.size() - 1;
|
||||
// We assume that only children at the end of the list can be hidden.
|
||||
assert(!object.childrenInHitTestOrder.get(object.scrollIndex).hasFlag(Flag.IS_HIDDEN));
|
||||
for (; visibleChildren >= 0; visibleChildren--) {
|
||||
SemanticsObject child = object.childrenInHitTestOrder.get(visibleChildren);
|
||||
if (!child.hasFlag(Flag.IS_HIDDEN)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
event.setToIndex(object.scrollIndex + visibleChildren);
|
||||
}
|
||||
sendAccessibilityEvent(event);
|
||||
}
|
||||
if (object.hasFlag(Flag.IS_LIVE_REGION) && !object.hadFlag(Flag.IS_LIVE_REGION)) {
|
||||
@ -947,6 +961,8 @@ class AccessibilityBridge
|
||||
int actions;
|
||||
int textSelectionBase;
|
||||
int textSelectionExtent;
|
||||
int scrollChildren;
|
||||
int scrollIndex;
|
||||
float scrollPosition;
|
||||
float scrollExtentMax;
|
||||
float scrollExtentMin;
|
||||
@ -1048,6 +1064,8 @@ class AccessibilityBridge
|
||||
actions = buffer.getInt();
|
||||
textSelectionBase = buffer.getInt();
|
||||
textSelectionExtent = buffer.getInt();
|
||||
scrollChildren = buffer.getInt();
|
||||
scrollIndex = buffer.getInt();
|
||||
scrollPosition = buffer.getFloat();
|
||||
scrollExtentMax = buffer.getFloat();
|
||||
scrollExtentMin = buffer.getFloat();
|
||||
|
||||
@ -207,7 +207,7 @@ void PlatformViewAndroid::DispatchSemanticsAction(JNIEnv* env,
|
||||
void PlatformViewAndroid::UpdateSemantics(
|
||||
blink::SemanticsNodeUpdates update,
|
||||
blink::CustomAccessibilityActionUpdates actions) {
|
||||
constexpr size_t kBytesPerNode = 36 * sizeof(int32_t);
|
||||
constexpr size_t kBytesPerNode = 38 * sizeof(int32_t);
|
||||
constexpr size_t kBytesPerChild = sizeof(int32_t);
|
||||
constexpr size_t kBytesPerAction = 4 * sizeof(int32_t);
|
||||
|
||||
@ -243,6 +243,8 @@ void PlatformViewAndroid::UpdateSemantics(
|
||||
buffer_int32[position++] = node.actions;
|
||||
buffer_int32[position++] = node.textSelectionBase;
|
||||
buffer_int32[position++] = node.textSelectionExtent;
|
||||
buffer_int32[position++] = node.scrollChildren;
|
||||
buffer_int32[position++] = node.scrollIndex;
|
||||
buffer_float32[position++] = (float)node.scrollPosition;
|
||||
buffer_float32[position++] = (float)node.scrollExtentMax;
|
||||
buffer_float32[position++] = (float)node.scrollExtentMin;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user