Skip to content

[WIP] Add Control Type Information to UIA Tree #11876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 18, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Add Support for ControlType Specification",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,8 @@ bool ActivityIndicatorComponentView::focusable() const noexcept {
return false;
}

std::string ActivityIndicatorComponentView::DefaultControlType() const noexcept {
return "progressbar";
}

} // namespace Microsoft::ReactNative
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct ActivityIndicatorComponentView : CompositionBaseComponentView {
facebook::react::Tag hitTest(facebook::react::Point pt, facebook::react::Point &localPt, bool ignorePointerEvents)
const noexcept override;
winrt::Microsoft::ReactNative::Composition::IVisual Visual() const noexcept override;
virtual std::string DefaultControlType() const noexcept;

private:
ActivityIndicatorComponentView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ long GetControlType(const std::string &role) noexcept {
return UIA_TabItemControlTypeId;
} else if (role == "tablist") {
return UIA_TabControlTypeId;
} else if (role == "textinput" || role == "searchbox") {
return UIA_EditControlTypeId;
} else if (role == "toolbar") {
return UIA_ToolBarControlTypeId;
} else if (role == "tree") {
Expand All @@ -205,12 +207,16 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPropertyValue(PROPERT
if (props == nullptr)
return UIA_E_ELEMENTNOTAVAILABLE;

auto baseView = std::static_pointer_cast<::Microsoft::ReactNative::CompositionBaseComponentView>(strongView);
if (baseView == nullptr)
return UIA_E_ELEMENTNOTAVAILABLE;

auto hr = S_OK;

switch (propertyId) {
case UIA_ControlTypePropertyId: {
pRetVal->vt = VT_I4;
auto role = props->accessibilityRole;
auto role = props->accessibilityRole == "" ? baseView.get()->DefaultControlType() : props->accessibilityRole;
pRetVal->lVal = GetControlType(role);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,9 @@ void CompositionBaseComponentView::updateAccessibilityProps(
UIA_IsEnabledPropertyId,
!oldViewProps.accessibilityState.disabled,
!newViewProps.accessibilityState.disabled);

winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
provider, UIA_ControlTypePropertyId, oldViewProps.accessibilityRole, newViewProps.accessibilityRole);
}

void CompositionBaseComponentView::updateBorderLayoutMetrics(
Expand Down Expand Up @@ -1212,6 +1215,10 @@ bool CompositionBaseComponentView::focusable() const noexcept {
return false;
}

std::string CompositionBaseComponentView::DefaultControlType() const noexcept {
return "group";
}

CompositionViewComponentView::CompositionViewComponentView(
const winrt::Microsoft::ReactNative::Composition::ICompositionContext &compContext,
facebook::react::Tag tag)
Expand Down Expand Up @@ -1413,6 +1420,10 @@ bool CompositionViewComponentView::focusable() const noexcept {
return m_props->focusable;
}

std::string CompositionViewComponentView::DefaultControlType() const noexcept {
return "group";
}

IComponentView *lastDeepChild(IComponentView &view) noexcept {
auto current = &view;
while (current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct CompositionBaseComponentView : public IComponentView,

winrt::IInspectable EnsureUiaProvider() noexcept override;

virtual std::string DefaultControlType() const noexcept;

protected:
std::array<winrt::Microsoft::ReactNative::Composition::SpriteVisual, SpecialBorderLayerCount>
FindSpecialBorderLayers() const noexcept;
Expand Down Expand Up @@ -116,6 +118,7 @@ struct CompositionViewComponentView : public CompositionBaseComponentView {
void finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept override;
void prepareForRecycle() noexcept override;
bool focusable() const noexcept override;
std::string DefaultControlType() const noexcept override;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ bool ImageComponentView::focusable() const noexcept {
return m_props->focusable;
}

std::string ImageComponentView::DefaultControlType() const noexcept {
return "image";
}

std::shared_ptr<ImageComponentView> ImageComponentView::Create(
const winrt::Microsoft::ReactNative::Composition::ICompositionContext &compContext,
facebook::react::Tag tag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct ImageComponentView : CompositionBaseComponentView {
const noexcept override;
winrt::Microsoft::ReactNative::Composition::IVisual Visual() const noexcept override;
bool focusable() const noexcept override;
virtual std::string DefaultControlType() const noexcept;

private:
ImageComponentView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ void ParagraphComponentView::DrawText() noexcept {
}
}

std::string ParagraphComponentView::DefaultControlType() const noexcept {
return "text";
}

winrt::Microsoft::ReactNative::Composition::IVisual ParagraphComponentView::Visual() const noexcept {
return m_visual;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct ParagraphComponentView : CompositionBaseComponentView {
facebook::react::SharedTouchEventEmitter touchEventEmitterAtPoint(facebook::react::Point pt) noexcept override;

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

private:
ParagraphComponentView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,8 @@ winrt::Microsoft::ReactNative::Composition::IVisual ScrollViewComponentView::Vis
return m_visual;
}

std::string ScrollViewComponentView::DefaultControlType() const noexcept {
return "scrollbar";
}

} // namespace Microsoft::ReactNative
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
bool ScrollWheel(facebook::react::Point pt, int32_t delta) noexcept override;

void StartBringIntoView(BringIntoViewOptions &&args) noexcept override;
virtual std::string DefaultControlType() const noexcept;

private:
ScrollViewComponentView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,8 @@ bool SwitchComponentView::focusable() const noexcept {
return m_props->focusable;
}

std::string SwitchComponentView::DefaultControlType() const noexcept {
return "switch";
}

} // namespace Microsoft::ReactNative
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct SwitchComponentView : CompositionBaseComponentView {
const noexcept override;
winrt::Microsoft::ReactNative::Composition::IVisual Visual() const noexcept override;
int64_t sendMessage(uint32_t msg, uint64_t wParam, int64_t lParam) noexcept override;
std::string DefaultControlType() const noexcept override;

private:
SwitchComponentView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ bool WindowsTextInputComponentView::focusable() const noexcept {
return m_props->focusable;
}

std::string WindowsTextInputComponentView::DefaultControlType() const noexcept {
return "textinput";
}

void WindowsTextInputComponentView::updateProps(
facebook::react::Props::Shared const &props,
facebook::react::Props::Shared const &oldProps) noexcept {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct WindowsTextInputComponentView : CompositionBaseComponentView {
void onFocusLost() noexcept override;
void onFocusGained() noexcept override;
bool focusable() const noexcept override;
std::string DefaultControlType() const noexcept override;

private:
WindowsTextInputComponentView(
Expand Down