- Revision
- 286298
- Author
- [email protected]
- Date
- 2021-11-30 08:20:02 -0800 (Tue, 30 Nov 2021)
Log Message
AX: Reduce repetition in retrieving typed attribute values in AccessibilityUIElementMac
https://bugs.webkit.org/show_bug.cgi?id=233603
Reviewed by Chris Fleizach.
We have a lot of functions in both the WebKitTestRunner and DumpRenderTree versions of
AccessibilityUIElementMac that repeat the same logic for getting a typed attribute value.
We can make this simpler.
* DumpRenderTree/AccessibilityUIElement.h:
* DumpRenderTree/mac/AccessibilityUIElementMac.mm:
(AccessibilityUIElement::stringAttributeValue):
Move core logic to new stringAttributeValue(NSString* attribute) function.
(AccessibilityUIElement::stringAttributeValue const): Added.
(AccessibilityUIElement::numberAttributeValue):
Move core logic to new numberAttributeValue(NSString* attribute) function.
(AccessibilityUIElement::numberAttributeValue const): Added.
(AccessibilityUIElement::boolAttributeValue const): Added.
(AccessibilityUIElement::boolAttributeValue):
Move core logic to new boolAttributeValue(NSString* attribute) function.
(AccessibilityUIElement::domIdentifier const):
(AccessibilityUIElement::intValue const):
(AccessibilityUIElement::minValue):
(AccessibilityUIElement::maxValue):
(AccessibilityUIElement::isEnabled):
(AccessibilityUIElement::isRequired const):
(AccessibilityUIElement::isFocused const):
(AccessibilityUIElement::isSelected const):
(AccessibilityUIElement::isExpanded const):
(AccessibilityUIElement::ariaIsGrabbed const):
(AccessibilityUIElement::documentEncoding):
(AccessibilityUIElement::documentURI):
(AccessibilityUIElement::isOnScreen const):
(AccessibilityUIElement::hasPopup const):
(AccessibilityUIElement::popupValue const):
(AccessibilityUIElement::hasDocumentRoleAncestor const):
(AccessibilityUIElement::hasWebApplicationAncestor const):
(AccessibilityUIElement::isInDescriptionListDetail const):
(AccessibilityUIElement::isInDescriptionListTerm const):
(AccessibilityUIElement::isInCell const):
Refactor to use new `NSString *attribute` convenience functions.
* WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
* WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
(WTR::AccessibilityUIElement::stringAttributeValue):
Move core logic to new stringAttributeValue(NSString* attribute) function.
(WTR::AccessibilityUIElement::stringAttributeValue const): Added.
(WTR::AccessibilityUIElement::numberAttributeValue):
Move core logic to new numberAttributeValue(NSString* attribute) function.
(WTR::AccessibilityUIElement::numberAttributeValue const): Added.
(WTR::AccessibilityUIElement::boolAttributeValue const): Added.
(WTR::AccessibilityUIElement::boolAttributeValue):
Move core logic to new boolAttributeValue(NSString* attribute) function.
(WTR::AccessibilityUIElement::domIdentifier const):
(WTR::AccessibilityUIElement::intValue const):
(WTR::AccessibilityUIElement::minValue):
(WTR::AccessibilityUIElement::maxValue):
(WTR::AccessibilityUIElement::isEnabled):
(WTR::AccessibilityUIElement::isRequired const):
(WTR::AccessibilityUIElement::isFocused const):
(WTR::AccessibilityUIElement::isExpanded const):
(WTR::AccessibilityUIElement::currentStateValue const):
(WTR::AccessibilityUIElement::sortDirection const):
(WTR::AccessibilityUIElement::ariaIsGrabbed const):
(WTR::AccessibilityUIElement::documentEncoding):
(WTR::AccessibilityUIElement::documentURI):
(WTR::AccessibilityUIElement::hasPopup const):
(WTR::AccessibilityUIElement::popupValue const):
(WTR::AccessibilityUIElement::hasDocumentRoleAncestor const):
(WTR::AccessibilityUIElement::hasWebApplicationAncestor const):
(WTR::AccessibilityUIElement::isInDescriptionListDetail const):
(WTR::AccessibilityUIElement::isInDescriptionListTerm const):
(WTR::AccessibilityUIElement::isInCell const):
Refactor to use new `NSString *attribute` convenience functions.
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (286297 => 286298)
--- trunk/Tools/ChangeLog 2021-11-30 16:09:22 UTC (rev 286297)
+++ trunk/Tools/ChangeLog 2021-11-30 16:20:02 UTC (rev 286298)
@@ -1,3 +1,85 @@
+2021-11-30 Tyler Wilcock <[email protected]>
+
+ AX: Reduce repetition in retrieving typed attribute values in AccessibilityUIElementMac
+ https://bugs.webkit.org/show_bug.cgi?id=233603
+
+ Reviewed by Chris Fleizach.
+
+ We have a lot of functions in both the WebKitTestRunner and DumpRenderTree versions of
+ AccessibilityUIElementMac that repeat the same logic for getting a typed attribute value.
+ We can make this simpler.
+
+ * DumpRenderTree/AccessibilityUIElement.h:
+ * DumpRenderTree/mac/AccessibilityUIElementMac.mm:
+ (AccessibilityUIElement::stringAttributeValue):
+ Move core logic to new stringAttributeValue(NSString* attribute) function.
+ (AccessibilityUIElement::stringAttributeValue const): Added.
+
+ (AccessibilityUIElement::numberAttributeValue):
+ Move core logic to new numberAttributeValue(NSString* attribute) function.
+ (AccessibilityUIElement::numberAttributeValue const): Added.
+
+ (AccessibilityUIElement::boolAttributeValue const): Added.
+ (AccessibilityUIElement::boolAttributeValue):
+ Move core logic to new boolAttributeValue(NSString* attribute) function.
+
+ (AccessibilityUIElement::domIdentifier const):
+ (AccessibilityUIElement::intValue const):
+ (AccessibilityUIElement::minValue):
+ (AccessibilityUIElement::maxValue):
+ (AccessibilityUIElement::isEnabled):
+ (AccessibilityUIElement::isRequired const):
+ (AccessibilityUIElement::isFocused const):
+ (AccessibilityUIElement::isSelected const):
+ (AccessibilityUIElement::isExpanded const):
+ (AccessibilityUIElement::ariaIsGrabbed const):
+ (AccessibilityUIElement::documentEncoding):
+ (AccessibilityUIElement::documentURI):
+ (AccessibilityUIElement::isOnScreen const):
+ (AccessibilityUIElement::hasPopup const):
+ (AccessibilityUIElement::popupValue const):
+ (AccessibilityUIElement::hasDocumentRoleAncestor const):
+ (AccessibilityUIElement::hasWebApplicationAncestor const):
+ (AccessibilityUIElement::isInDescriptionListDetail const):
+ (AccessibilityUIElement::isInDescriptionListTerm const):
+ (AccessibilityUIElement::isInCell const):
+ Refactor to use new `NSString *attribute` convenience functions.
+
+ * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+ * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+ (WTR::AccessibilityUIElement::stringAttributeValue):
+ Move core logic to new stringAttributeValue(NSString* attribute) function.
+ (WTR::AccessibilityUIElement::stringAttributeValue const): Added.
+
+ (WTR::AccessibilityUIElement::numberAttributeValue):
+ Move core logic to new numberAttributeValue(NSString* attribute) function.
+ (WTR::AccessibilityUIElement::numberAttributeValue const): Added.
+ (WTR::AccessibilityUIElement::boolAttributeValue const): Added.
+ (WTR::AccessibilityUIElement::boolAttributeValue):
+ Move core logic to new boolAttributeValue(NSString* attribute) function.
+
+ (WTR::AccessibilityUIElement::domIdentifier const):
+ (WTR::AccessibilityUIElement::intValue const):
+ (WTR::AccessibilityUIElement::minValue):
+ (WTR::AccessibilityUIElement::maxValue):
+ (WTR::AccessibilityUIElement::isEnabled):
+ (WTR::AccessibilityUIElement::isRequired const):
+ (WTR::AccessibilityUIElement::isFocused const):
+ (WTR::AccessibilityUIElement::isExpanded const):
+ (WTR::AccessibilityUIElement::currentStateValue const):
+ (WTR::AccessibilityUIElement::sortDirection const):
+ (WTR::AccessibilityUIElement::ariaIsGrabbed const):
+ (WTR::AccessibilityUIElement::documentEncoding):
+ (WTR::AccessibilityUIElement::documentURI):
+ (WTR::AccessibilityUIElement::hasPopup const):
+ (WTR::AccessibilityUIElement::popupValue const):
+ (WTR::AccessibilityUIElement::hasDocumentRoleAncestor const):
+ (WTR::AccessibilityUIElement::hasWebApplicationAncestor const):
+ (WTR::AccessibilityUIElement::isInDescriptionListDetail const):
+ (WTR::AccessibilityUIElement::isInDescriptionListTerm const):
+ (WTR::AccessibilityUIElement::isInCell const):
+ Refactor to use new `NSString *attribute` convenience functions.
+
2021-11-29 Jonathan Bedard <[email protected]>
[git-webkit] Use info log level instead of warning
Modified: trunk/Tools/DumpRenderTree/AccessibilityUIElement.h (286297 => 286298)
--- trunk/Tools/DumpRenderTree/AccessibilityUIElement.h 2021-11-30 16:09:22 UTC (rev 286297)
+++ trunk/Tools/DumpRenderTree/AccessibilityUIElement.h 2021-11-30 16:20:02 UTC (rev 286298)
@@ -31,6 +31,10 @@
#include <wtf/Platform.h>
#include <wtf/Vector.h>
+#if PLATFORM(MAC)
+OBJC_CLASS NSString;
+#endif
+
#if PLATFORM(COCOA)
#include <wtf/RetainPtr.h>
#elif PLATFORM(WIN)
@@ -109,8 +113,13 @@
JSRetainPtr<JSStringRef> stringAttributeValue(JSStringRef attribute);
double numberAttributeValue(JSStringRef attribute);
void uiElementArrayAttributeValue(JSStringRef attribute, Vector<AccessibilityUIElement>& elements) const;
- AccessibilityUIElement uiElementAttributeValue(JSStringRef attribute) const;
+ AccessibilityUIElement uiElementAttributeValue(JSStringRef attribute) const;
bool boolAttributeValue(JSStringRef attribute);
+#if PLATFORM(MAC)
+ bool boolAttributeValue(NSString *attribute) const;
+ JSRetainPtr<JSStringRef> stringAttributeValue(NSString *attribute) const;
+ double numberAttributeValue(NSString *attribute) const;
+#endif
void setBoolAttributeValue(JSStringRef attribute, bool value);
bool isAttributeSupported(JSStringRef attribute);
bool isAttributeSettable(JSStringRef attribute);
Modified: trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm (286297 => 286298)
--- trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm 2021-11-30 16:09:22 UTC (rev 286297)
+++ trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm 2021-11-30 16:20:02 UTC (rev 286298)
@@ -498,8 +498,13 @@
JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
{
+ return stringAttributeValue([NSString stringWithJSStringRef:attribute]);
+}
+
+JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(NSString *attribute) const
+{
BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
+ id value = [m_element accessibilityAttributeValue:attribute];
if ([value isKindOfClass:[NSString class]])
return [value createJSStringRef];
END_AX_OBJC_EXCEPTIONS
@@ -547,8 +552,13 @@
double AccessibilityUIElement::numberAttributeValue(JSStringRef attribute)
{
+ return numberAttributeValue([NSString stringWithJSStringRef:attribute]);
+}
+
+double AccessibilityUIElement::numberAttributeValue(NSString *attribute) const
+{
BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
+ id value = [m_element accessibilityAttributeValue:attribute];
if ([value isKindOfClass:[NSNumber class]])
return [value doubleValue];
END_AX_OBJC_EXCEPTIONS
@@ -556,10 +566,10 @@
return 0;
}
-bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
+bool AccessibilityUIElement::boolAttributeValue(NSString *attribute) const
{
BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
+ id value = [m_element accessibilityAttributeValue:attribute];
if ([value isKindOfClass:[NSNumber class]])
return [value boolValue];
END_AX_OBJC_EXCEPTIONS
@@ -567,6 +577,11 @@
return false;
}
+bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
+{
+ return boolAttributeValue([NSString stringWithJSStringRef:attribute]);
+}
+
void AccessibilityUIElement::setBoolAttributeValue(JSStringRef attribute, bool value)
{
BEGIN_AX_OBJC_EXCEPTIONS
@@ -666,13 +681,7 @@
JSRetainPtr<JSStringRef> AccessibilityUIElement::domIdentifier() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityDOMIdentifierAttribute];
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return nullptr;
+ return stringAttributeValue(NSAccessibilityDOMIdentifierAttribute);
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::orientation() const
@@ -778,35 +787,17 @@
double AccessibilityUIElement::intValue() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityValueAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
+ return numberAttributeValue(NSAccessibilityValueAttribute);
}
double AccessibilityUIElement::minValue()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityMinValueAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
+ return numberAttributeValue(NSAccessibilityMinValueAttribute);
}
double AccessibilityUIElement::maxValue()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityMaxValueAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0;
+ return numberAttributeValue(NSAccessibilityMaxValueAttribute);
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription()
@@ -863,57 +854,27 @@
bool AccessibilityUIElement::isEnabled()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityEnabledAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilityEnabledAttribute);
}
bool AccessibilityUIElement::isRequired() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXRequired"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXRequired");
}
bool AccessibilityUIElement::isFocused() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityFocusedAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilityFocusedAttribute);
}
bool AccessibilityUIElement::isSelected() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilitySelectedAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilitySelectedAttribute);
}
bool AccessibilityUIElement::isExpanded() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityExpandedAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilityExpandedAttribute);
}
bool AccessibilityUIElement::isChecked() const
@@ -967,13 +928,7 @@
bool AccessibilityUIElement::ariaIsGrabbed() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityGrabbedAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilityGrabbedAttribute);
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::embeddedImageDescription() const
@@ -1463,11 +1418,8 @@
JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXDocumentEncoding"];
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
+ if (auto result = stringAttributeValue(@"AXDocumentEncoding"))
+ return result;
return WTR::createJSString();
}
@@ -1474,11 +1426,8 @@
JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXDocumentURI"];
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
+ if (auto result = stringAttributeValue(@"AXDocumentURI"))
+ return result;
return WTR::createJSString();
}
@@ -1564,13 +1513,7 @@
bool AccessibilityUIElement::isOnScreen() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXIsOnScreen"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXIsOnScreen");
}
bool AccessibilityUIElement::isOffScreen() const
@@ -1619,22 +1562,13 @@
bool AccessibilityUIElement::hasPopup() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXHasPopup"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXHasPopup");
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::popupValue() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXPopupValue"];
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
+ if (auto result = stringAttributeValue(@"AXPopupValue"))
+ return result;
return [@"false" createJSStringRef];
}
@@ -1641,57 +1575,27 @@
bool AccessibilityUIElement::hasDocumentRoleAncestor() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXHasDocumentRoleAncestor"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXHasDocumentRoleAncestor");
}
bool AccessibilityUIElement::hasWebApplicationAncestor() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXHasWebApplicationAncestor"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXHasWebApplicationAncestor");
}
bool AccessibilityUIElement::isInDescriptionListDetail() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXIsInDescriptionListDetail"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXIsInDescriptionListDetail");
}
bool AccessibilityUIElement::isInDescriptionListTerm() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXIsInDescriptionListTerm"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXIsInDescriptionListTerm");
}
bool AccessibilityUIElement::isInCell() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXIsInCell"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXIsInCell");
}
void AccessibilityUIElement::takeFocus()
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h (286297 => 286298)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h 2021-11-30 16:09:22 UTC (rev 286297)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h 2021-11-30 16:20:02 UTC (rev 286298)
@@ -132,6 +132,9 @@
RefPtr<AccessibilityUIElement> uiElementAttributeValue(JSStringRef attribute) const;
bool boolAttributeValue(JSStringRef attribute);
#if PLATFORM(MAC)
+ bool boolAttributeValue(NSString *attribute) const;
+ JSRetainPtr<JSStringRef> stringAttributeValue(NSString *attribute) const;
+ double numberAttributeValue(NSString *attribute) const;
RetainPtr<id> attributeValue(NSString *) const;
void attributeValueAsync(JSStringRef attribute, JSValueRef callback);
#else
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm (286297 => 286298)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm 2021-11-30 16:09:22 UTC (rev 286297)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm 2021-11-30 16:20:02 UTC (rev 286298)
@@ -335,10 +335,7 @@
JSRetainPtr<JSStringRef> AccessibilityUIElement::domIdentifier() const
{
- auto value = attributeValue(NSAccessibilityDOMIdentifierAttribute);
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- return nullptr;
+ return stringAttributeValue(NSAccessibilityDOMIdentifierAttribute);
}
void AccessibilityUIElement::getLinkedUIElements(Vector<RefPtr<AccessibilityUIElement>>& elementVector)
@@ -607,17 +604,33 @@
JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
{
- auto value = attributeValue([NSString stringWithJSStringRef:attribute]);
+ return stringAttributeValue([NSString stringWithJSStringRef:attribute]);
+}
+
+JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(NSString *attribute) const
+{
+ BEGIN_AX_OBJC_EXCEPTIONS
+ auto value = attributeValue(attribute);
if ([value isKindOfClass:[NSString class]])
return [value createJSStringRef];
+ END_AX_OBJC_EXCEPTIONS
+
return nullptr;
}
double AccessibilityUIElement::numberAttributeValue(JSStringRef attribute)
{
- auto value = attributeValue([NSString stringWithJSStringRef:attribute]);
+ return numberAttributeValue([NSString stringWithJSStringRef:attribute]);
+}
+
+double AccessibilityUIElement::numberAttributeValue(NSString *attribute) const
+{
+ BEGIN_AX_OBJC_EXCEPTIONS
+ auto value = attributeValue(attribute);
if ([value isKindOfClass:[NSNumber class]])
return [value doubleValue];
+ END_AX_OBJC_EXCEPTIONS
+
return 0;
}
@@ -635,14 +648,22 @@
return nullptr;
}
-bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
+bool AccessibilityUIElement::boolAttributeValue(NSString *attribute) const
{
- auto value = attributeValue([NSString stringWithJSStringRef:attribute]);
+ BEGIN_AX_OBJC_EXCEPTIONS
+ auto value = attributeValue(attribute);
if ([value isKindOfClass:[NSNumber class]])
return [value boolValue];
+ END_AX_OBJC_EXCEPTIONS
+
return false;
}
+bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
+{
+ return boolAttributeValue([NSString stringWithJSStringRef:attribute]);
+}
+
void AccessibilityUIElement::attributeValueAsync(JSStringRef attribute, JSValueRef callback)
{
if (!attribute || !callback)
@@ -882,35 +903,17 @@
double AccessibilityUIElement::intValue() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(NSAccessibilityValueAttribute);
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
+ return numberAttributeValue(NSAccessibilityValueAttribute);
}
double AccessibilityUIElement::minValue()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(NSAccessibilityMinValueAttribute);
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
+ return numberAttributeValue(NSAccessibilityMinValueAttribute);
}
double AccessibilityUIElement::maxValue()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(NSAccessibilityMaxValueAttribute);
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0;
+ return numberAttributeValue(NSAccessibilityMaxValueAttribute);
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription()
@@ -967,24 +970,12 @@
bool AccessibilityUIElement::isEnabled()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(NSAccessibilityEnabledAttribute);
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilityEnabledAttribute);
}
bool AccessibilityUIElement::isRequired() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXRequired");
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXRequired");
}
RefPtr<AccessibilityUIElement> AccessibilityUIElement::focusedElement() const
@@ -999,13 +990,7 @@
bool AccessibilityUIElement::isFocused() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(NSAccessibilityFocusedAttribute);
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilityFocusedAttribute);
}
bool AccessibilityUIElement::isSelected() const
@@ -1034,13 +1019,7 @@
bool AccessibilityUIElement::isExpanded() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(NSAccessibilityExpandedAttribute);
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilityExpandedAttribute);
}
bool AccessibilityUIElement::isChecked() const
@@ -1051,18 +1030,12 @@
JSRetainPtr<JSStringRef> AccessibilityUIElement::currentStateValue() const
{
- auto value = attributeValue(NSAccessibilityARIACurrentAttribute);
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- return nullptr;
+ return stringAttributeValue(NSAccessibilityARIACurrentAttribute);
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::sortDirection() const
{
- auto value = attributeValue(NSAccessibilitySortDirectionAttribute);
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- return nullptr;
+ return stringAttributeValue(NSAccessibilitySortDirectionAttribute);
}
int AccessibilityUIElement::hierarchicalLevel() const
@@ -1110,13 +1083,7 @@
bool AccessibilityUIElement::ariaIsGrabbed() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(NSAccessibilityGrabbedAttribute);
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(NSAccessibilityGrabbedAttribute);
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::ariaDropEffects() const
@@ -1614,21 +1581,17 @@
JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXDocumentEncoding");
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
+ if (auto result = stringAttributeValue(@"AXDocumentEncoding"))
+ return result;
+
return createJSString();
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI()
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXDocumentURI");
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
+ if (auto result = stringAttributeValue(@"AXDocumentURI"))
+ return result;
+
return createJSString();
}
@@ -1761,22 +1724,13 @@
bool AccessibilityUIElement::hasPopup() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXHasPopup");
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXHasPopup");
}
JSRetainPtr<JSStringRef> AccessibilityUIElement::popupValue() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXPopupValue");
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
+ if (auto result = stringAttributeValue(@"AXPopupValue"))
+ return result;
return [@"false" createJSStringRef];
}
@@ -1783,57 +1737,27 @@
bool AccessibilityUIElement::hasDocumentRoleAncestor() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXHasDocumentRoleAncestor");
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXHasDocumentRoleAncestor");
}
bool AccessibilityUIElement::hasWebApplicationAncestor() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXHasWebApplicationAncestor");
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXHasWebApplicationAncestor");
}
bool AccessibilityUIElement::isInDescriptionListDetail() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXIsInDescriptionListDetail");
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXIsInDescriptionListDetail");
}
bool AccessibilityUIElement::isInDescriptionListTerm() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXIsInDescriptionListTerm");
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXIsInDescriptionListTerm");
}
bool AccessibilityUIElement::isInCell() const
{
- BEGIN_AX_OBJC_EXCEPTIONS
- auto value = attributeValue(@"AXIsInCell");
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
+ return boolAttributeValue(@"AXIsInCell");
}
void AccessibilityUIElement::takeFocus()