Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions shell/platform/darwin/ios/framework/Source/SemanticsObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ CGPoint ConvertPointToGlobal(SemanticsObject* reference, CGPoint local_point) {
// `rect` is in the physical pixel coordinate system. iOS expects the accessibility frame in
// the logical pixel coordinate system. Therefore, we divide by the `scale` (pixel ratio) to
// convert.
CGFloat scale = [[[reference bridge]->view() window] screen].scale;
UIScreen* screen = [[[reference bridge]->view() window] screen];
// Screen can be nil if the FlutterView is covered by another native view.
CGFloat scale = screen == nil ? [UIScreen mainScreen].scale : screen.scale;
auto result = CGPointMake(point.x() / scale, point.y() / scale);
return [[reference bridge]->view() convertPoint:result toView:nil];
}
Expand All @@ -80,7 +82,9 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
// `rect` is in the physical pixel coordinate system. iOS expects the accessibility frame in
// the logical pixel coordinate system. Therefore, we divide by the `scale` (pixel ratio) to
// convert.
CGFloat scale = [[[reference bridge]->view() window] screen].scale;
UIScreen* screen = [[[reference bridge]->view() window] screen];
// Screen can be nil if the FlutterView is covered by another native view.
CGFloat scale = screen == nil ? [UIScreen mainScreen].scale : screen.scale;
auto result =
CGRectMake(rect.x() / scale, rect.y() / scale, rect.width() / scale, rect.height() / scale);
return UIAccessibilityConvertFrameToScreenCoordinates(result, [reference bridge]->view());
Expand Down
70 changes: 70 additions & 0 deletions shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,36 @@ void AccessibilityObjectDidLoseFocus(int32_t id) override {}
UIView* view_;
UIWindow* window_;
};

class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos {
public:
MockAccessibilityBridgeNoWindow() : observations({}) {
view_ = [[UIView alloc] initWithFrame:kScreenSize];
}
bool isVoiceOverRunning() const override { return isVoiceOverRunningValue; }
UIView* view() const override { return view_; }
UIView<UITextInput>* textInputView() override { return nil; }
void DispatchSemanticsAction(int32_t id, SemanticsAction action) override {
SemanticsActionObservation observation(id, action);
observations.push_back(observation);
}
void DispatchSemanticsAction(int32_t id,
SemanticsAction action,
fml::MallocMapping args) override {
SemanticsActionObservation observation(id, action);
observations.push_back(observation);
}
void AccessibilityObjectDidBecomeFocused(int32_t id) override {}
void AccessibilityObjectDidLoseFocus(int32_t id) override {}
std::shared_ptr<FlutterPlatformViewsController> GetPlatformViewsController() const override {
return nil;
}
std::vector<SemanticsActionObservation> observations;
bool isVoiceOverRunningValue;

private:
UIView* view_;
};
} // namespace
} // namespace flutter

Expand Down Expand Up @@ -208,6 +238,46 @@ - (void)testVerticalFlutterScrollableSemanticsObject {
CGPointMake(0, scrollPosition * effectivelyScale)));
}

- (void)testVerticalFlutterScrollableSemanticsObjectNoWindow {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
new flutter::MockAccessibilityBridgeNoWindow());
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();

float transformScale = 0.5f;
float screenScale =
[UIScreen mainScreen].scale; // Flutter view without window uses [UIScreen mainScreen];
float effectivelyScale = transformScale / screenScale;
float x = 10;
float y = 10;
float w = 100;
float h = 200;
float scrollExtentMax = 500.0;
float scrollPosition = 150.0;

flutter::SemanticsNode node;
node.flags = static_cast<int32_t>(flutter::SemanticsFlags::kHasImplicitScrolling);
node.actions = flutter::kVerticalScrollSemanticsActions;
node.rect = SkRect::MakeXYWH(x, y, w, h);
node.scrollExtentMax = scrollExtentMax;
node.scrollPosition = scrollPosition;
node.transform = {
transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, transformScale, 0, 0, 0, 0, 1.0};
FlutterSemanticsObject* delegate = [[FlutterSemanticsObject alloc] initWithBridge:bridge uid:0];
FlutterScrollableSemanticsObject* scrollable =
[[FlutterScrollableSemanticsObject alloc] initWithSemanticsObject:delegate];
SemanticsObject* scrollable_object = static_cast<SemanticsObject*>(scrollable);
[scrollable_object setSemanticsNode:&node];
[scrollable_object accessibilityBridgeDidFinishUpdate];
XCTAssertTrue(
CGRectEqualToRect(scrollable.frame, CGRectMake(x * effectivelyScale, y * effectivelyScale,
w * effectivelyScale, h * effectivelyScale)));
XCTAssertTrue(CGSizeEqualToSize(
scrollable.contentSize,
CGSizeMake(w * effectivelyScale, (h + scrollExtentMax) * effectivelyScale)));
XCTAssertTrue(CGPointEqualToPoint(scrollable.contentOffset,
CGPointMake(0, scrollPosition * effectivelyScale)));
}

- (void)testHorizontalFlutterScrollableSemanticsObject {
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
new flutter::MockAccessibilityBridge());
Expand Down