forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement
RichTextBlockAutomationPeer
- Loading branch information
1 parent
43db136
commit ca5cdd0
Showing
2 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Uno.UI/UI/Xaml/Automation/Peers/RichTextBlockAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
// MUX Reference RichTextBlockAutomationPeer_Partial.cpp, tag winui3/release/1.4.2 | ||
using System; | ||
using DirectUI; | ||
using Windows.Foundation; | ||
using Microsoft.UI.Xaml.Controls; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.UI.Xaml.Automation.Peers; | ||
|
||
/// <summary> | ||
/// Exposes RichTextBlock types to Microsoft UI Automation. | ||
/// </summary> | ||
public partial class RichTextBlockAutomationPeer : FrameworkElementAutomationPeer | ||
{ | ||
public RichTextBlockAutomationPeer(RichTextBlock owner) : base(owner) | ||
{ | ||
} | ||
|
||
protected override object GetPatternCore(PatternInterface patternInterface) | ||
{ | ||
if (patternInterface == PatternInterface.Text) | ||
{ | ||
//if (!m_pTextPattern) | ||
//{ | ||
// ctl::ComPtr<IUIElement> spOwner; | ||
// ctl::ComPtr<TextAdapter> spTextAdapter; | ||
|
||
// IFC(get_Owner(&spOwner)); | ||
// IFCPTR(spOwner.Get()); | ||
|
||
// IFC(ActivationAPI::ActivateAutomationInstance(KnownTypeIndex::TextAdapter, static_cast<RichTextBlock*>(spOwner.Get())->GetHandle(), spTextAdapter.GetAddressOf())); | ||
|
||
// 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(RichTextBlock); | ||
|
||
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 overflowing to next RichTextBlockOverflow if any | ||
protected override IList<AutomationPeer> 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; | ||
} | ||
} |