diff --git a/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Automation.Peers/RichTextBlockOverflowAutomationPeer.cs b/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Automation.Peers/RichTextBlockOverflowAutomationPeer.cs index 69a0baf6ea7c..2c06e219348c 100644 --- a/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Automation.Peers/RichTextBlockOverflowAutomationPeer.cs +++ b/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Automation.Peers/RichTextBlockOverflowAutomationPeer.cs @@ -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 RichTextBlockOverflowAutomationPeer : global::Microsoft.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer { -#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 RichTextBlockOverflowAutomationPeer(global::Microsoft.UI.Xaml.Controls.RichTextBlockOverflow owner) : base(owner) { diff --git a/src/Uno.UI/UI/Xaml/Automation/Peers/RichTextBlockOverflowAutomationPeer.cs b/src/Uno.UI/UI/Xaml/Automation/Peers/RichTextBlockOverflowAutomationPeer.cs new file mode 100644 index 000000000000..dc60fa3465f0 --- /dev/null +++ b/src/Uno.UI/UI/Xaml/Automation/Peers/RichTextBlockOverflowAutomationPeer.cs @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +// MUX Reference RichTextBlockOverflowAutomationPeer_Partial.cpp, tag winui3/release/1.4.2 +using System.Collections.Generic; + +namespace Microsoft.UI.Xaml.Automation.Peers; + +/// +/// Exposes RichTextBlockOverflow types to Microsoft UI Automation. +/// +public partial class RichTextBlockOverflowAutomationPeer : FrameworkElementAutomationPeer +{ + public RichTextBlockOverflowAutomationPeer(Controls.RichTextBlockOverflow owner) : base(owner) + { + } + + protected override object GetPatternCore(PatternInterface patternInterface) + { + if (patternInterface == PatternInterface.Text) + { + //if (m_pTextPattern == nullptr) + //{ + // ctl::ComPtr spOwner; + // ctl::ComPtr spTextAdapter; + // IFC(get_Owner(&spOwner)); + // IFCPTR(spOwner.Get()); + + // // RichTextBlockOverflows that don't have a master RichTextBlock don't have a text pattern, and should return nullptr. + // if (static_cast((static_cast(spOwner.Get())->GetHandle()))->m_pMaster != nullptr) + // { + // IFC(ActivationAPI::ActivateAutomationInstance(KnownTypeIndex::TextAdapter, static_cast(spOwner.Get())->GetHandle(), spTextAdapter.GetAddressOf())); + + // IFCPTR(spTextAdapter.Get()); + + // m_pTextPattern = spTextAdapter.Detach(); + // IFC(m_pTextPattern->put_Owner(spOwner.Get())); + // } + //} + //*ppReturnValue = ctl::as_iinspectable((m_pTextPattern)); + //ctl::addref_interface(m_pTextPattern); + } + else + { + return base.GetPatternCore(patternInterface); + } + } + + protected override string GetClassNameCore() => nameof(Controls.RichTextBlockOverflow); + + protected override AutomationControlType GetAutomationControlTypeCore() + => AutomationControlType.Text; + + // We populate automation peer children from its block collection recursively + // Here we need to eliminate all text elements which are + // are present in the previous RichTextBlock/RichTextBlockOverflow + // overflowing to next RichTextOverflow if any + protected override IList GetChildrenCore() + { + var owner = Owner as Controls.RichTextBlockOverflow; + + var posContentStart = 0; + var posOverflowStart = int.MaxValue; + + var returnValue = base.GetChildrenCore(); + + if (owner.ContentStart is { } contentStart) + { + posContentStart = contentStart.Offset; + + if (owner.HasOverflowContent) + { + if (owner.OverflowContentTarget?.ContentStart is { } spOverflowStart) + { + posOverflowStart = spOverflowStart.Offset; + } + } + } + + var spSourceControl = owner.ContentSource; + var spBlocks = spSourceControl.Blocks; + var count = spBlocks.Count; + + for (var i = 0; i < count; i++) + { + var spBlock = spBlocks[i]; + if (owner.HasOverflowContent) + { + var blockStart = spBlock.ContentStart; + + if (blockStart.Offset >= posOverflowStart) + { + break; + } + } + + //UNO TODO: AppendAutomationPeerChildren + returnValue = spBlock.AppendAutomationPeerChildren(posContentStart, posOverflowStart); + } + + return returnValue; + } +}