Skip to content

Commit e5ff3fa

Browse files
authored
[WIP] Add Control Type Information to UIA Tree (#11876)
* Add Support for ControlType Specification * Change files * Format * Fix Switch Statement * Format * Remove Dup
1 parent fd428d8 commit e5ff3fa

16 files changed

+58
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Add Support for ControlType Specification",
4+
"packageName": "react-native-windows",
5+
"email": "34109996+chiaramooney@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,8 @@ bool ActivityIndicatorComponentView::focusable() const noexcept {
126126
return false;
127127
}
128128

129+
std::string ActivityIndicatorComponentView::DefaultControlType() const noexcept {
130+
return "progressbar";
131+
}
132+
129133
} // namespace Microsoft::ReactNative

vnext/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct ActivityIndicatorComponentView : CompositionBaseComponentView {
4040
facebook::react::Tag hitTest(facebook::react::Point pt, facebook::react::Point &localPt, bool ignorePointerEvents)
4141
const noexcept override;
4242
winrt::Microsoft::ReactNative::Composition::IVisual Visual() const noexcept override;
43+
virtual std::string DefaultControlType() const noexcept;
4344

4445
private:
4546
ActivityIndicatorComponentView(

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ long GetControlType(const std::string &role) noexcept {
182182
return UIA_TabItemControlTypeId;
183183
} else if (role == "tablist") {
184184
return UIA_TabControlTypeId;
185+
} else if (role == "textinput" || role == "searchbox") {
186+
return UIA_EditControlTypeId;
185187
} else if (role == "toolbar") {
186188
return UIA_ToolBarControlTypeId;
187189
} else if (role == "tree") {
@@ -205,12 +207,16 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPropertyValue(PROPERT
205207
if (props == nullptr)
206208
return UIA_E_ELEMENTNOTAVAILABLE;
207209

210+
auto baseView = std::static_pointer_cast<::Microsoft::ReactNative::CompositionBaseComponentView>(strongView);
211+
if (baseView == nullptr)
212+
return UIA_E_ELEMENTNOTAVAILABLE;
213+
208214
auto hr = S_OK;
209215

210216
switch (propertyId) {
211217
case UIA_ControlTypePropertyId: {
212218
pRetVal->vt = VT_I4;
213-
auto role = props->accessibilityRole;
219+
auto role = props->accessibilityRole == "" ? baseView.get()->DefaultControlType() : props->accessibilityRole;
214220
pRetVal->lVal = GetControlType(role);
215221
break;
216222
}

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,9 @@ void CompositionBaseComponentView::updateAccessibilityProps(
10911091
UIA_IsEnabledPropertyId,
10921092
!oldViewProps.accessibilityState.disabled,
10931093
!newViewProps.accessibilityState.disabled);
1094+
1095+
winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
1096+
provider, UIA_ControlTypePropertyId, oldViewProps.accessibilityRole, newViewProps.accessibilityRole);
10941097
}
10951098

10961099
void CompositionBaseComponentView::updateBorderLayoutMetrics(
@@ -1212,6 +1215,10 @@ bool CompositionBaseComponentView::focusable() const noexcept {
12121215
return false;
12131216
}
12141217

1218+
std::string CompositionBaseComponentView::DefaultControlType() const noexcept {
1219+
return "group";
1220+
}
1221+
12151222
CompositionViewComponentView::CompositionViewComponentView(
12161223
const winrt::Microsoft::ReactNative::Composition::ICompositionContext &compContext,
12171224
facebook::react::Tag tag)
@@ -1413,6 +1420,10 @@ bool CompositionViewComponentView::focusable() const noexcept {
14131420
return m_props->focusable;
14141421
}
14151422

1423+
std::string CompositionViewComponentView::DefaultControlType() const noexcept {
1424+
return "group";
1425+
}
1426+
14161427
IComponentView *lastDeepChild(IComponentView &view) noexcept {
14171428
auto current = &view;
14181429
while (current) {

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ struct CompositionBaseComponentView : public IComponentView,
6666

6767
winrt::IInspectable EnsureUiaProvider() noexcept override;
6868

69+
virtual std::string DefaultControlType() const noexcept;
70+
6971
protected:
7072
std::array<winrt::Microsoft::ReactNative::Composition::SpriteVisual, SpecialBorderLayerCount>
7173
FindSpecialBorderLayers() const noexcept;
@@ -116,6 +118,7 @@ struct CompositionViewComponentView : public CompositionBaseComponentView {
116118
void finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept override;
117119
void prepareForRecycle() noexcept override;
118120
bool focusable() const noexcept override;
121+
std::string DefaultControlType() const noexcept override;
119122

120123
facebook::react::Props::Shared props() noexcept override;
121124

vnext/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ bool ImageComponentView::focusable() const noexcept {
409409
return m_props->focusable;
410410
}
411411

412+
std::string ImageComponentView::DefaultControlType() const noexcept {
413+
return "image";
414+
}
415+
412416
std::shared_ptr<ImageComponentView> ImageComponentView::Create(
413417
const winrt::Microsoft::ReactNative::Composition::ICompositionContext &compContext,
414418
facebook::react::Tag tag,

vnext/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct ImageComponentView : CompositionBaseComponentView {
5353
const noexcept override;
5454
winrt::Microsoft::ReactNative::Composition::IVisual Visual() const noexcept override;
5555
bool focusable() const noexcept override;
56+
virtual std::string DefaultControlType() const noexcept;
5657

5758
private:
5859
ImageComponentView(

vnext/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ void ParagraphComponentView::DrawText() noexcept {
474474
}
475475
}
476476

477+
std::string ParagraphComponentView::DefaultControlType() const noexcept {
478+
return "text";
479+
}
480+
477481
winrt::Microsoft::ReactNative::Composition::IVisual ParagraphComponentView::Visual() const noexcept {
478482
return m_visual;
479483
}

vnext/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct ParagraphComponentView : CompositionBaseComponentView {
4242
facebook::react::SharedTouchEventEmitter touchEventEmitterAtPoint(facebook::react::Point pt) noexcept override;
4343

4444
winrt::Microsoft::ReactNative::Composition::IVisual Visual() const noexcept override;
45+
virtual std::string DefaultControlType() const noexcept;
4546

4647
private:
4748
ParagraphComponentView(

0 commit comments

Comments
 (0)