选中行/焦点行语法、列表信息键、拾取层级框、控件属性补全

1) 新增「选中行/焦点行」语法,控件监控新增列表信息
   - XPath 快照新增状态属性:@IsSelected / @IsFocused / @IsOffscreen / @IsEnabled
     例如 /Window[1]//DataGrid[@AutomationId='x']/DataItem[@IsSelected='true']
   - IsSelected 随控件树一起从缓存读(SelectionItemPattern);对只在容器上暴露
     SelectionPattern 的提供者(实测 WinForms ListView/DataGridView),树读完后
     由容器反推每个子项的选中状态,@IsSelected 与「选中状态」取值因此可用
   - 新增取值键:列表行数 / 列表列数 / 列表选中项数(Grid → Table → Selection)
   - 控件属性新增「列表概况」(行×列 + 选中项数 + 首项文本)

2) 拾取时显示层级:蓝框=光标所在窗口,黄框=向上遍历的控件链
   - PointPickResult 增加 HierarchyFrames;TargetProbeService 填蓝色窗口层 +
     UiAutomationService.DescribeAncestorFrames 产出的黄色控件链(最多 6 层)
   - 新增 UI/PickHierarchyOverlayForm:跟随锚点窗口、只读 GetWindowRect、
     最小化/关闭即收起、置顶不抢焦点、点击穿透
   - CrosshairPicker 预览改用层级框;只有 Win32/MSAA 信息时退回原来的单框高亮

3) 控件属性按 UIA/Win32 分类补全(没有的就新增)
   - UIA:父元素、RawView/ControlView/ContentView 子元素数、RangeValue、
     Toggle 状态、选中情况、列表概况(全部按需读取,选中节点时才跨进程)
   - Win32:样式 GWL_STYLE、扩展样式 GWL_EXSTYLE、启用、最大化、层级关系
     (父窗口 / 直接子窗口数 / 同类序号)
   - GetWindowStyle 原本读的其实是 GWL_EXSTYLE,已正名为 GetWindowExStyle,
     GWL_STYLE 用新方法读取

实测(跨进程,目标为夹具/记事本):
- 夹具列表选中第 2 行:DataItem[2] IsSelected=True;@IsSelected='true' 唯一命中并
  取到「项目 2」;列表行数=3、列表列数=2、列表选中项数=1
- 拾取夹具列表行:7 层框(1 蓝窗口 + 6 黄控件链),覆盖层实际绘制并截图确认
- 记事本文档:控件属性显示 文本内容="agfa\r\raaaaa"(Name 是「文本编辑器」)

回归 29/29 通过
This commit is contained in:
zimoyin
2026-10-13 19:19:16 +08:00
parent d7e50675f0
commit ebbf9e1335
19 changed files with 1216 additions and 6 deletions
+62
View File
@@ -30,6 +30,68 @@ namespace PacsWinUia.RegressionTests
tests.Add(new KeyValuePair<string, Action>("Text content falls back to the snapshot Name", TextContentFallsBackToName));
// 防:新增控件默认 ValueKey 回到 Name;富文本这类控件会读到 "RichEdit Control"。
tests.Add(new KeyValuePair<string, Action>("New monitor entries default to the text content key", BuilderDefaultsToTextContent));
// 防:XPath 状态属性(选中行/焦点行)消失或写错,导致 @IsSelected/@IsFocused 语法失效。
tests.Add(new KeyValuePair<string, Action>("XPath can select the selected and focused row", RowStateAttributes));
// 防:列表信息键被移除,监控里没法盯住"这张表几行、选中几行"。
tests.Add(new KeyValuePair<string, Action>("List information keys are offered for UIA", ListKeysOffered));
}
// XPath 属性 @IsSelected / @IsFocused / @IsOffscreen / @IsEnabled:
// 源图是"选中第 2 行"的列表,应当能唯一命中它。
private static void RowStateAttributes()
{
ControlTreeNode root = Row("Window", "列表窗口");
ControlTreeNode grid = Row("DataGrid", "列表", "FixtureListView");
root.Children.Add(grid);
grid.Children.Add(Row("DataItem", "项目 1", null, selected: false, focused: false));
grid.Children.Add(Row("DataItem", "项目 2", null, selected: true, focused: true));
grid.Children.Add(Row("DataItem", "项目 3", null, selected: false, focused: false));
ControlPath.PreparePaths(root);
Check.Matches(root, "//DataItem[@IsSelected='true']", grid.Children[1]);
Check.Matches(root, "//DataItem[@IsFocused='true']", grid.Children[1]);
Check.Matches(root, "//DataItem[@IsSelected='false']", grid.Children[0], grid.Children[2]);
Check.Matches(root, "//DataItem[@IsEnabled='true' and @IsOffscreen='false']",
grid.Children[0], grid.Children[1], grid.Children[2]);
Check.True(ControlValueReader.TryRead(grid.Children[1], ControlValueKeys.TextContent,
new ListReadOptions(), null, out string value, out string error) == false || value != null,
"选中行取值不应抛异常");
}
private static ControlTreeNode Row(string type, string name, string automationId = null,
bool? selected = null, bool? focused = null)
{
return new ControlTreeNode
{
Source = ControlTreeSource.Uia,
Uia = new UiaElementInfo
{
ControlType = "ControlType." + type,
Name = name,
AutomationId = automationId,
IsAvailable = true,
IsSelected = selected ?? (bool?)null,
HasKeyboardFocus = focused ?? (bool?)null,
IsOffscreen = false,
IsEnabled = true
}
};
}
private static void ListKeysOffered()
{
foreach (string key in new[]
{
ControlValueKeys.ListRowCount, ControlValueKeys.ListColumnCount, ControlValueKeys.ListSelectedCount
})
{
Check.True(ControlValueKeys.For(ControlSourcePreference.Uia).Contains(key),
"UIA keys missing " + key);
}
Check.Equal("列表行数", ControlValueKeys.ListRowCount, "Row count key name");
Check.Equal("列表选中项数", ControlValueKeys.ListSelectedCount, "Selected count key name");
}
private static void TextContentKeyOffered()