Skip to content

Commit

Permalink
Add scrollIndex and scrollChildren to semantics, add Android implemen…
Browse files Browse the repository at this point in the history
…tation (flutter#6239)
  • Loading branch information
jonahwilliams authored Sep 13, 2018
1 parent 23fcc27 commit abd918e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -609,6 +611,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
int actions,
int textSelectionBase,
int textSelectionExtent,
int scrollChildren,
int scrollIndex,
double scrollPosition,
double scrollExtentMax,
double scrollExtentMin,
Expand All @@ -634,6 +638,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
actions,
textSelectionBase,
textSelectionExtent,
scrollChildren,
scrollIndex,
scrollPosition,
scrollExtentMax,
scrollExtentMin,
Expand All @@ -659,6 +665,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
int actions,
int textSelectionBase,
int textSelectionExtent,
int scrollChildren,
int scrollIndex,
double scrollPosition,
double scrollExtentMax,
double scrollExtentMin,
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/semantics/semantics_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down
4 changes: 4 additions & 0 deletions lib/ui/semantics/semantics_update_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void SemanticsUpdateBuilder::updateNode(
int actions,
int textSelectionBase,
int textSelectionExtent,
int scrollChildren,
int scrollIndex,
double scrollPosition,
double scrollExtentMax,
double scrollExtentMin,
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/semantics/semantics_update_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class SemanticsUpdateBuilder
int actions,
int textSelectionBase,
int textSelectionExtent,
int scrollChildren,
int scrollIndex,
double scrollPosition,
double scrollExtentMax,
double scrollExtentMin,
Expand Down
22 changes: 20 additions & 2 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
}

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);
Expand Down Expand Up @@ -717,6 +717,20 @@ void updateSemantics(ByteBuffer buffer, String[] strings) {
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)) {
Expand Down Expand Up @@ -947,6 +961,8 @@ private class SemanticsObject {
int actions;
int textSelectionBase;
int textSelectionExtent;
int scrollChildren;
int scrollIndex;
float scrollPosition;
float scrollExtentMax;
float scrollExtentMin;
Expand Down Expand Up @@ -1048,6 +1064,8 @@ void updateWith(ByteBuffer buffer, String[] strings) {
actions = buffer.getInt();
textSelectionBase = buffer.getInt();
textSelectionExtent = buffer.getInt();
scrollChildren = buffer.getInt();
scrollIndex = buffer.getInt();
scrollPosition = buffer.getFloat();
scrollExtentMax = buffer.getFloat();
scrollExtentMin = buffer.getFloat();
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit abd918e

Please sign in to comment.