Skip to content

Commit

Permalink
Fixed accessibility frame calculation on macOS. (ChartsOrg#1060)
Browse files Browse the repository at this point in the history
Added a workaround for non updating accessibility frame when resizing
windows and using Charts on macOS by using setAccessibilityFrameInParent() in Platform+Accessibility. See inline comments for details.
  • Loading branch information
mathewa6 authored and Shineeth Hamza committed Oct 31, 2018
1 parent 3251cda commit 44e9ee6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion Source/Charts/Utils/Platform+Accessibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,22 @@ open class NSUIAccessibilityElement: NSAccessibilityElement
set
{
let bounds = NSAccessibilityFrameInView(containerView, newValue)
setAccessibilityFrame(bounds)

// This works, but won't auto update if the window is resized or moved.
// setAccessibilityFrame(bounds)

// using FrameInParentSpace allows for automatic updating of frame when windows are moved and resized.
// However, there seems to be a bug right now where using it causes an offset in the frame.
// This is a slightly hacky workaround that calculates the offset and removes it from frame calculation.
setAccessibilityFrameInParentSpace(bounds)
let axFrame = accessibilityFrame()
let widthOffset = fabs(axFrame.origin.x - bounds.origin.x)
let heightOffset = fabs(axFrame.origin.y - bounds.origin.y)
let rect = NSRect(x: bounds.origin.x - widthOffset,
y: bounds.origin.y - heightOffset,
width: bounds.width,
height: bounds.height)
setAccessibilityFrameInParentSpace(rect)
}
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Charts/Utils/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple

open class NSUIView: NSView
{
/// A private constant to set the accessibility role during initialization
/// A private constant to set the accessibility role during initialization.
/// It ensures parity with the iOS element ordering as well as numbered counts of chart components.
/// (See Platform+Accessibility for details)
private let role: NSAccessibilityRole = .list

Expand Down

0 comments on commit 44e9ee6

Please sign in to comment.