Skip to content

Commit

Permalink
feat: Implement ScrollViewerAutomationPeer
Browse files Browse the repository at this point in the history
  • Loading branch information
morning4coffe-dev authored and MartinZikmund committed Jun 17, 2024
1 parent 2b3ab69 commit c1707ef
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Microsoft.UI.Xaml.Automation.Peers
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class ScrollBarAutomationPeer : global::Microsoft.UI.Xaml.Automation.Peers.RangeBaseAutomationPeer
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public ScrollBarAutomationPeer(global::Microsoft.UI.Xaml.Controls.Primitives.ScrollBar owner) : base(owner)
{
Expand Down
86 changes: 86 additions & 0 deletions src/Uno.UI/UI/Xaml/Automation/Peers/ScrollBarAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// MUX Reference ScrollBarAutomationPeer_Partial.cpp, tag winui3/release/1.4.2
using DirectUI;
using Windows.Foundation;

namespace Microsoft.UI.Xaml.Automation.Peers;

/// <summary>
/// Exposes ScrollBar types to UI Automation.
/// </summary>
public partial class ScrollBarAutomationPeer : RangeBaseAutomationPeer
{
private const string UIA_SCROLLBAR_HORIZONTAL = nameof(UIA_SCROLLBAR_HORIZONTAL);
private const string UIA_SCROLLBAR_VERTICAL = nameof(UIA_SCROLLBAR_VERTICAL);

public ScrollBarAutomationPeer(Controls.Primitives.ScrollBar owner) : base(owner)
{
}

protected override string GetClassNameCore() => nameof(Controls.Primitives.ScrollBar);

protected override AutomationControlType GetAutomationControlTypeCore()
=> AutomationControlType.ScrollBar;

protected override Point GetClickablePointCore()
=> new(DoubleUtil.NaN, DoubleUtil.NaN);

protected override AutomationOrientation GetOrientationCore()
{
var owner = Owner as Controls.Primitives.ScrollBar;

if (owner.Orientation == Controls.Orientation.Horizontal)
{
return AutomationOrientation.Horizontal;
}
else
{
return AutomationOrientation.Vertical;
}
}

protected override bool IsContentElementCore() => false;

private protected override bool ChildIsAcceptable(UIElement element)
{
var childIsAcceptable = base.ChildIsAcceptable(element);

if (childIsAcceptable)
{
var owner = Owner as Controls.Primitives.ScrollBar;

//UNO TODO: ElementHorizontalTemplate and ElementVerticalTemplate on ScrollBar
var elementHorizontalTemplate = owner.ElementHorizontalTemplate;
var elementVerticalTemplate = owner.ElementVerticalTemplate;

if (element == elementHorizontalTemplate || element == elementVerticalTemplate)
{
return element.Visibility == Visibility.Visible;
}
}

return childIsAcceptable;
}

protected override string GetNameCore()
{
var returnValue = base.GetNameCore();

if (string.IsNullOrEmpty(returnValue))
{
var owner = Owner as Controls.Primitives.ScrollBar;

if (owner.Orientation == Controls.Orientation.Horizontal)
{
return DXamlCore.Current.GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTAL);
}
else
{
return DXamlCore.Current.GetLocalizedResourceString(UIA_SCROLLBAR_VERTICAL);
}
}

return returnValue;
}
}

0 comments on commit c1707ef

Please sign in to comment.