From 01fb2a26d2649666d3879a223a2cf2b779898cfd Mon Sep 17 00:00:00 2001 From: Connor McAdams Date: Tue, 29 Nov 2022 12:34:28 -0500 Subject: [PATCH] uiautomationcore: Implement UiaLookupId for AutomationIdentifierType_Event GUIDs. Signed-off-by: Connor McAdams --- dlls/uiautomationcore/tests/uiautomation.c | 73 ++++++++++++-- dlls/uiautomationcore/uia_classes.idl | 6 ++ dlls/uiautomationcore/uia_ids.c | 107 ++++++++++++++++++++- include/uiautomationclient.idl | 2 + include/uiautomationcoreapi.h | 39 ++++++++ 5 files changed, 216 insertions(+), 11 deletions(-) diff --git a/dlls/uiautomationcore/tests/uiautomation.c b/dlls/uiautomationcore/tests/uiautomation.c index 3756b5cbf1a..a6239b4f300 100644 --- a/dlls/uiautomationcore/tests/uiautomation.c +++ b/dlls/uiautomationcore/tests/uiautomation.c @@ -4022,22 +4022,75 @@ static const struct uia_lookup_id uia_property_lookup_ids[] = { { &IsDialog_Property_GUID, UIA_IsDialogPropertyId }, }; +static const struct uia_lookup_id uia_event_lookup_ids[] = { + { &ToolTipOpened_Event_GUID, UIA_ToolTipOpenedEventId }, + { &ToolTipClosed_Event_GUID, UIA_ToolTipClosedEventId }, + { &StructureChanged_Event_GUID, UIA_StructureChangedEventId }, + { &MenuOpened_Event_GUID, UIA_MenuOpenedEventId }, + { &AutomationPropertyChanged_Event_GUID, UIA_AutomationPropertyChangedEventId }, + { &AutomationFocusChanged_Event_GUID, UIA_AutomationFocusChangedEventId }, + { &AsyncContentLoaded_Event_GUID, UIA_AsyncContentLoadedEventId }, + { &MenuClosed_Event_GUID, UIA_MenuClosedEventId }, + { &LayoutInvalidated_Event_GUID, UIA_LayoutInvalidatedEventId }, + { &Invoke_Invoked_Event_GUID, UIA_Invoke_InvokedEventId }, + { &SelectionItem_ElementAddedToSelectionEvent_Event_GUID, UIA_SelectionItem_ElementAddedToSelectionEventId }, + { &SelectionItem_ElementRemovedFromSelectionEvent_Event_GUID, UIA_SelectionItem_ElementRemovedFromSelectionEventId }, + { &SelectionItem_ElementSelectedEvent_Event_GUID, UIA_SelectionItem_ElementSelectedEventId }, + { &Selection_InvalidatedEvent_Event_GUID, UIA_Selection_InvalidatedEventId }, + { &Text_TextSelectionChangedEvent_Event_GUID, UIA_Text_TextSelectionChangedEventId }, + { &Text_TextChangedEvent_Event_GUID, UIA_Text_TextChangedEventId }, + { &Window_WindowOpened_Event_GUID, UIA_Window_WindowOpenedEventId }, + { &Window_WindowClosed_Event_GUID, UIA_Window_WindowClosedEventId }, + { &MenuModeStart_Event_GUID, UIA_MenuModeStartEventId }, + { &MenuModeEnd_Event_GUID, UIA_MenuModeEndEventId }, + { &InputReachedTarget_Event_GUID, UIA_InputReachedTargetEventId }, + { &InputReachedOtherElement_Event_GUID, UIA_InputReachedOtherElementEventId }, + { &InputDiscarded_Event_GUID, UIA_InputDiscardedEventId }, + /* Implemented on Win8+ */ + { &SystemAlert_Event_GUID, UIA_SystemAlertEventId }, + { &LiveRegionChanged_Event_GUID, UIA_LiveRegionChangedEventId }, + { &HostedFragmentRootsInvalidated_Event_GUID, UIA_HostedFragmentRootsInvalidatedEventId }, + { &Drag_DragStart_Event_GUID, UIA_Drag_DragStartEventId }, + { &Drag_DragCancel_Event_GUID, UIA_Drag_DragCancelEventId }, + { &Drag_DragComplete_Event_GUID, UIA_Drag_DragCompleteEventId }, + { &DropTarget_DragEnter_Event_GUID, UIA_DropTarget_DragEnterEventId }, + { &DropTarget_DragLeave_Event_GUID, UIA_DropTarget_DragLeaveEventId }, + { &DropTarget_Dropped_Event_GUID, UIA_DropTarget_DroppedEventId }, + { &TextEdit_TextChanged_Event_GUID, UIA_TextEdit_TextChangedEventId }, + { &TextEdit_ConversionTargetChanged_Event_GUID, UIA_TextEdit_ConversionTargetChangedEventId }, + /* Implemented on Win10v1809+. */ + { &Changes_Event_GUID, UIA_ChangesEventId }, + { &Notification_Event_GUID, UIA_NotificationEventId }, +}; + static void test_UiaLookupId(void) { - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(uia_property_lookup_ids); i++) + static const struct { + const char *id_type_name; + int id_type; + const struct uia_lookup_id *ids; + int ids_count; + } tests[] = { - int prop_id = UiaLookupId(AutomationIdentifierType_Property, uia_property_lookup_ids[i].guid); + { "property", AutomationIdentifierType_Property, uia_property_lookup_ids, ARRAY_SIZE(uia_property_lookup_ids) }, + { "event", AutomationIdentifierType_Event, uia_event_lookup_ids, ARRAY_SIZE(uia_event_lookup_ids) }, + }; + unsigned int i, y; - if (!prop_id) + for (i = 0; i < ARRAY_SIZE(tests); i++) + { + for (y = 0; y < tests[i].ids_count; y++) { - win_skip("No propertyId for GUID %s, skipping further tests.\n", debugstr_guid(uia_property_lookup_ids[i].guid)); - break; - } + int id = UiaLookupId(tests[i].id_type, tests[i].ids[y].guid); - ok(prop_id == uia_property_lookup_ids[i].id, "Unexpected Property id, expected %d, got %d\n", - uia_property_lookup_ids[i].id, prop_id); + if (!id) + { + win_skip("No %s id for GUID %s, skipping further tests.\n", tests[i].id_type_name, debugstr_guid(tests[i].ids[y].guid)); + break; + } + + ok(id == tests[i].ids[y].id, "Unexpected %s id, expected %d, got %d\n", tests[i].id_type_name, tests[i].ids[y].id, id); + } } } diff --git a/dlls/uiautomationcore/uia_classes.idl b/dlls/uiautomationcore/uia_classes.idl index 2dc7981b702..ace1c12e70c 100644 --- a/dlls/uiautomationcore/uia_classes.idl +++ b/dlls/uiautomationcore/uia_classes.idl @@ -27,6 +27,12 @@ struct uia_prop_info { int type; }; +struct uia_event_info { + const GUID *guid; + int event_id; + int event_arg_type; +}; + [ version(1.0), uuid(8a9ca8eb-856b-43d9-abd7-4a590054064f), diff --git a/dlls/uiautomationcore/uia_ids.c b/dlls/uiautomationcore/uia_ids.c index a3a60c8aec9..c1e51c51ca3 100644 --- a/dlls/uiautomationcore/uia_ids.c +++ b/dlls/uiautomationcore/uia_ids.c @@ -30,6 +30,13 @@ static int __cdecl uia_property_guid_compare(const void *a, const void *b) return memcmp(guid, property->guid, sizeof(*guid)); } +static int __cdecl uia_event_guid_compare(const void *a, const void *b) +{ + const GUID *guid = a; + const struct uia_event_info *event = b; + return memcmp(guid, event->guid, sizeof(*guid)); +} + /* Sorted by GUID. */ static const struct uia_prop_info default_uia_properties[] = { { &AutomationId_Property_GUID, UIA_AutomationIdPropertyId, @@ -308,6 +315,93 @@ const struct uia_prop_info *uia_prop_info_from_id(PROPERTYID prop_id) return &default_uia_properties[prop_id_idx[prop_id - PROP_ID_MIN]]; } +/* Sorted by GUID. */ +static const struct uia_event_info default_uia_events[] = { + { &Selection_InvalidatedEvent_Event_GUID, UIA_Selection_InvalidatedEventId, + EventArgsType_Simple, }, + { &Window_WindowOpened_Event_GUID, UIA_Window_WindowOpenedEventId, + EventArgsType_Simple, }, + { &TextEdit_TextChanged_Event_GUID, UIA_TextEdit_TextChangedEventId, + EventArgsType_TextEditTextChanged, }, + { &Drag_DragStart_Event_GUID, UIA_Drag_DragStartEventId, + EventArgsType_Simple, }, + { &Changes_Event_GUID, UIA_ChangesEventId, + EventArgsType_Changes, }, + { &DropTarget_DragLeave_Event_GUID, UIA_DropTarget_DragLeaveEventId, + EventArgsType_Simple, }, + { &AutomationFocusChanged_Event_GUID, UIA_AutomationFocusChangedEventId, + EventArgsType_Simple, }, + { &AsyncContentLoaded_Event_GUID, UIA_AsyncContentLoadedEventId, + EventArgsType_AsyncContentLoaded, }, + { &MenuModeStart_Event_GUID, UIA_MenuModeStartEventId, + EventArgsType_Simple, }, + { &HostedFragmentRootsInvalidated_Event_GUID, UIA_HostedFragmentRootsInvalidatedEventId, + EventArgsType_Simple, }, + { &LayoutInvalidated_Event_GUID, UIA_LayoutInvalidatedEventId, + EventArgsType_Simple, }, + { &MenuOpened_Event_GUID, UIA_MenuOpenedEventId, + EventArgsType_Simple, }, + { &SystemAlert_Event_GUID, UIA_SystemAlertEventId, + EventArgsType_Simple, }, + { &StructureChanged_Event_GUID, UIA_StructureChangedEventId, + EventArgsType_StructureChanged, }, + { &InputDiscarded_Event_GUID, UIA_InputDiscardedEventId, + EventArgsType_Simple, }, + { &MenuClosed_Event_GUID, UIA_MenuClosedEventId, + EventArgsType_Simple, }, + { &Text_TextChangedEvent_Event_GUID, UIA_Text_TextChangedEventId, + EventArgsType_Simple, }, + { &TextEdit_ConversionTargetChanged_Event_GUID, UIA_TextEdit_ConversionTargetChangedEventId, + EventArgsType_Simple, }, + { &Drag_DragComplete_Event_GUID, UIA_Drag_DragCompleteEventId, + EventArgsType_Simple, }, + { &InputReachedOtherElement_Event_GUID, UIA_InputReachedOtherElementEventId, + EventArgsType_Simple, }, + { &LiveRegionChanged_Event_GUID, UIA_LiveRegionChangedEventId, + EventArgsType_Simple, }, + { &InputReachedTarget_Event_GUID, UIA_InputReachedTargetEventId, + EventArgsType_Simple, }, + { &DropTarget_DragEnter_Event_GUID, UIA_DropTarget_DragEnterEventId, + EventArgsType_Simple, }, + { &MenuModeEnd_Event_GUID, UIA_MenuModeEndEventId, + EventArgsType_Simple, }, + { &Text_TextSelectionChangedEvent_Event_GUID, UIA_Text_TextSelectionChangedEventId, + EventArgsType_Simple, }, + { &AutomationPropertyChanged_Event_GUID, UIA_AutomationPropertyChangedEventId, + EventArgsType_PropertyChanged, }, + { &SelectionItem_ElementRemovedFromSelectionEvent_Event_GUID, UIA_SelectionItem_ElementRemovedFromSelectionEventId, + EventArgsType_Simple, }, + { &SelectionItem_ElementAddedToSelectionEvent_Event_GUID, UIA_SelectionItem_ElementAddedToSelectionEventId, + EventArgsType_Simple, }, + { &DropTarget_Dropped_Event_GUID, UIA_DropTarget_DroppedEventId, + EventArgsType_Simple, }, + { &ToolTipClosed_Event_GUID, UIA_ToolTipClosedEventId, + EventArgsType_Simple, }, + { &Invoke_Invoked_Event_GUID, UIA_Invoke_InvokedEventId, + EventArgsType_Simple, }, + { &Notification_Event_GUID, UIA_NotificationEventId, + EventArgsType_Notification, }, + { &Window_WindowClosed_Event_GUID, UIA_Window_WindowClosedEventId, + EventArgsType_WindowClosed, }, + { &Drag_DragCancel_Event_GUID, UIA_Drag_DragCancelEventId, + EventArgsType_Simple, }, + { &SelectionItem_ElementSelectedEvent_Event_GUID, UIA_SelectionItem_ElementSelectedEventId, + EventArgsType_Simple, }, + { &ToolTipOpened_Event_GUID, UIA_ToolTipOpenedEventId, + EventArgsType_Simple, }, +}; + +static const struct uia_event_info *uia_event_info_from_guid(const GUID *guid) +{ + struct uia_event_info *event; + + if ((event = bsearch(guid, default_uia_events, ARRAY_SIZE(default_uia_events), sizeof(*event), + uia_event_guid_compare))) + return event; + + return NULL; +} + /*********************************************************************** * UiaLookupId (uiautomationcore.@) */ @@ -331,8 +425,19 @@ int WINAPI UiaLookupId(enum AutomationIdentifierType type, const GUID *guid) break; } - case AutomationIdentifierType_Pattern: case AutomationIdentifierType_Event: + { + const struct uia_event_info *event = uia_event_info_from_guid(guid); + + if (event) + ret_id = event->event_id; + else + FIXME("Failed to find eventId for GUID %s\n", debugstr_guid(guid)); + + break; + } + + case AutomationIdentifierType_Pattern: case AutomationIdentifierType_ControlType: case AutomationIdentifierType_TextAttribute: case AutomationIdentifierType_LandmarkType: diff --git a/include/uiautomationclient.idl b/include/uiautomationclient.idl index 4579e4db652..ce0402a5d33 100644 --- a/include/uiautomationclient.idl +++ b/include/uiautomationclient.idl @@ -156,6 +156,8 @@ library UIAutomationClient { const long UIA_DropTarget_DroppedEventId = 20031; const long UIA_TextEdit_TextChangedEventId = 20032; const long UIA_TextEdit_ConversionTargetChangedEventId = 20033; + const long UIA_ChangesEventId = 20034; + const long UIA_NotificationEventId = 20035; /* }; */ diff --git a/include/uiautomationcoreapi.h b/include/uiautomationcoreapi.h index ef94c72d162..52a8e596325 100644 --- a/include/uiautomationcoreapi.h +++ b/include/uiautomationcoreapi.h @@ -221,6 +221,45 @@ DEFINE_GUID(Selection2_ItemCount_Property_GUID, 0xbb49eb9f,0x456d DEFINE_GUID(HeadingLevel_Property_GUID, 0x29084272,0xaaaf,0x4a30,0x87,0x96,0x3c,0x12,0xf6,0x2b,0x6b,0xbb); DEFINE_GUID(IsDialog_Property_GUID, 0x9d0dfb9b,0x8436,0x4501,0xbb,0xbb,0xe5,0x34,0xa4,0xfb,0x3b,0x3f); +/* + * AutomationIdentifierType_Event GUIDs. + */ +DEFINE_GUID(ToolTipOpened_Event_GUID, 0x3f4b97ff,0x2edc,0x451d,0xbc,0xa4,0x95,0xa3,0x18,0x8d,0x5b,0x03); +DEFINE_GUID(ToolTipClosed_Event_GUID, 0x276d71ef,0x24a9,0x49b6,0x8e,0x97,0xda,0x98,0xb4,0x01,0xbb,0xcd); +DEFINE_GUID(StructureChanged_Event_GUID, 0x59977961,0x3edd,0x4b11,0xb1,0x3b,0x67,0x6b,0x2a,0x2a,0x6c,0xa9); +DEFINE_GUID(MenuOpened_Event_GUID, 0xebe2e945,0x66ca,0x4ed1,0x9f,0xf8,0x2a,0xd7,0xdf,0x0a,0x1b,0x08); +DEFINE_GUID(AutomationPropertyChanged_Event_GUID, 0x2527fba1,0x8d7a,0x4630,0xa4,0xcc,0xe6,0x63,0x15,0x94,0x2f,0x52); +DEFINE_GUID(AutomationFocusChanged_Event_GUID, 0xb68a1f17,0xf60d,0x41a7,0xa3,0xcc,0xb0,0x52,0x92,0x15,0x5f,0xe0); +DEFINE_GUID(AsyncContentLoaded_Event_GUID, 0x5fdee11c,0xd2fa,0x4fb9,0x90,0x4e,0x5c,0xbe,0xe8,0x94,0xd5,0xef); +DEFINE_GUID(MenuClosed_Event_GUID, 0x3cf1266e,0x1582,0x4041,0xac,0xd7,0x88,0xa3,0x5a,0x96,0x52,0x97); +DEFINE_GUID(LayoutInvalidated_Event_GUID, 0xed7d6544,0xa6bd,0x4595,0x9b,0xae,0x3d,0x28,0x94,0x6c,0xc7,0x15); +DEFINE_GUID(Invoke_Invoked_Event_GUID, 0xdfd699f0,0xc915,0x49dd,0xb4,0x22,0xdd,0xe7,0x85,0xc3,0xd2,0x4b); +DEFINE_GUID(SelectionItem_ElementAddedToSelectionEvent_Event_GUID, 0x3c822dd1,0xc407,0x4dba,0x91,0xdd,0x79,0xd4,0xae,0xd0,0xae,0xc6); +DEFINE_GUID(SelectionItem_ElementRemovedFromSelectionEvent_Event_GUID, 0x097fa8a9,0x7079,0x41af,0x8b,0x9c,0x09,0x34,0xd8,0x30,0x5e,0x5c); +DEFINE_GUID(SelectionItem_ElementSelectedEvent_Event_GUID, 0xb9c7dbfb,0x4ebe,0x4532,0xaa,0xf4,0x00,0x8c,0xf6,0x47,0x23,0x3c); +DEFINE_GUID(Selection_InvalidatedEvent_Event_GUID, 0xcac14904,0x16b4,0x4b53,0x8e,0x47,0x4c,0xb1,0xdf,0x26,0x7b,0xb7); +DEFINE_GUID(Text_TextSelectionChangedEvent_Event_GUID, 0x918edaa1,0x71b3,0x49ae,0x97,0x41,0x79,0xbe,0xb8,0xd3,0x58,0xf3); +DEFINE_GUID(Text_TextChangedEvent_Event_GUID, 0x4a342082,0xf483,0x48c4,0xac,0x11,0xa8,0x4b,0x43,0x5e,0x2a,0x84); +DEFINE_GUID(Window_WindowOpened_Event_GUID, 0xd3e81d06,0xde45,0x4f2f,0x96,0x33,0xde,0x9e,0x02,0xfb,0x65,0xaf); +DEFINE_GUID(Window_WindowClosed_Event_GUID, 0xedf141f8,0xfa67,0x4e22,0xbb,0xf7,0x94,0x4e,0x05,0x73,0x5e,0xe2); +DEFINE_GUID(MenuModeStart_Event_GUID, 0x18d7c631,0x166a,0x4ac9,0xae,0x3b,0xef,0x4b,0x54,0x20,0xe6,0x81); +DEFINE_GUID(MenuModeEnd_Event_GUID, 0x9ecd4c9f,0x80dd,0x47b8,0x82,0x67,0x5a,0xec,0x06,0xbb,0x2c,0xff); +DEFINE_GUID(InputReachedTarget_Event_GUID, 0x93ed549a,0x0549,0x40f0,0xbe,0xdb,0x28,0xe4,0x4f,0x7d,0xe2,0xa3); +DEFINE_GUID(InputReachedOtherElement_Event_GUID, 0xed201d8a,0x4e6c,0x415e,0xa8,0x74,0x24,0x60,0xc9,0xb6,0x6b,0xa8); +DEFINE_GUID(InputDiscarded_Event_GUID, 0x7f36c367,0x7b18,0x417c,0x97,0xe3,0x9d,0x58,0xdd,0xc9,0x44,0xab); +DEFINE_GUID(SystemAlert_Event_GUID, 0xd271545d,0x7a3a,0x47a7,0x84,0x74,0x81,0xd2,0x9a,0x24,0x51,0xc9); +DEFINE_GUID(LiveRegionChanged_Event_GUID, 0x102d5e90,0xe6a9,0x41b6,0xb1,0xc5,0xa9,0xb1,0x92,0x9d,0x95,0x10); +DEFINE_GUID(HostedFragmentRootsInvalidated_Event_GUID, 0xe6bdb03e,0x0921,0x4ec5,0x8d,0xcf,0xea,0xe8,0x77,0xb0,0x42,0x6b); +DEFINE_GUID(Drag_DragStart_Event_GUID, 0x883a480b,0x3aa9,0x429d,0x95,0xe4,0xd9,0xc8,0xd0,0x11,0xf0,0xdd); +DEFINE_GUID(Drag_DragCancel_Event_GUID, 0xc3ede6fa,0x3451,0x4e0f,0x9e,0x71,0xdf,0x9c,0x28,0x0a,0x46,0x57); +DEFINE_GUID(Drag_DragComplete_Event_GUID, 0x38e96188,0xef1f,0x463e,0x91,0xca,0x3a,0x77,0x92,0xc2,0x9c,0xaf); +DEFINE_GUID(DropTarget_DragEnter_Event_GUID, 0xaad9319b,0x032c,0x4a88,0x96,0x1d,0x1c,0xf5,0x79,0x58,0x1e,0x34); +DEFINE_GUID(DropTarget_DragLeave_Event_GUID, 0x0f82eb15,0x24a2,0x4988,0x92,0x17,0xde,0x16,0x2a,0xee,0x27,0x2b); +DEFINE_GUID(DropTarget_Dropped_Event_GUID, 0x622cead8,0x1edb,0x4a3d,0xab,0xbc,0xbe,0x22,0x11,0xff,0x68,0xb5); +DEFINE_GUID(TextEdit_TextChanged_Event_GUID, 0x120b0308,0xec22,0x4eb8,0x9c,0x98,0x98,0x67,0xcd,0xa1,0xb1,0x65); +DEFINE_GUID(TextEdit_ConversionTargetChanged_Event_GUID, 0x3388c183,0xed4f,0x4c8b,0x9b,0xaa,0x36,0x4d,0x51,0xd8,0x84,0x7f); +DEFINE_GUID(Changes_Event_GUID, 0x7df26714,0x614f,0x4e05,0x94,0x88,0x71,0x6c,0x5b,0xa1,0x94,0x36); +DEFINE_GUID(Notification_Event_GUID, 0x72c5a2f7,0x9788,0x480f,0xb8,0xeb,0x4d,0xee,0x00,0xf6,0x18,0x6f); enum AutomationIdentifierType {