Skip to content

Commit

Permalink
AX: VoiceOver reports the datetime value in the wrong time zone.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269999
<rdar://problem/123522296>

Reviewed by Chris Fleizach.

VoiceOver expects the value of dateTime elements to be in local time zone. Since we store those values in GMT, we need to convert them to local times before returning them.

* Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(gmtToLocalTimeOffset):
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):

Canonical link: https://commits.webkit.org/275265@main
  • Loading branch information
AndresGonzalezApple committed Feb 24, 2024
1 parent a224746 commit 26acc63
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,14 @@ - (NSArray *)_transformSpecialChildrenCases:(RefPtr<AXCoreObject>)backingObject
return nil;
}

// VoiceOver expects the datetime value in the local time zone. Since we store it in GMT, we need to convert it to local before returning it to VoiceOver.
// This helper funtion computes the offset to go from local to GMT and returns its opposite.
static inline NSInteger gmtToLocalTimeOffset()
{
NSDate *now = [NSDate date];
return -1 * [[NSTimeZone localTimeZone] secondsFromGMTForDate:now];
}

// FIXME: split up this function in a better way.
// suggestions: Use a hash table that maps attribute names to function calls,
// or maybe pointers to member functions
Expand Down Expand Up @@ -1705,8 +1713,10 @@ - (id)accessibilityAttributeValue:(NSString*)attributeName
[] (float& typedValue) -> id { return @(typedValue); },
[] (String& typedValue) -> id { return (NSString *)typedValue; },
[] (WallTime& typedValue) -> id {
RetainPtr date = [NSDate dateWithTimeIntervalSince1970:typedValue.secondsSinceEpoch().value()];
return date.autorelease();
NSInteger offset = gmtToLocalTimeOffset();
auto time = typedValue.secondsSinceEpoch().value();
NSDate *gmtDate = [NSDate dateWithTimeIntervalSince1970:time];
return [NSDate dateWithTimeInterval:offset sinceDate:gmtDate];
},
[] (AccessibilityButtonState& typedValue) -> id { return @((unsigned)typedValue); },
[] (AXCoreObject*& typedValue) { return typedValue ? (id)typedValue->wrapper() : nil; },
Expand Down

0 comments on commit 26acc63

Please sign in to comment.