Commit eeb098e7 authored by Connor McAdams's avatar Connor McAdams Committed by Alexandre Julliard

uiautomationcore: Implement IUIAutomationElement::FindFirst{BuildCache}.

parent fdb3c9f9
......@@ -11418,10 +11418,9 @@ static void test_Element_Find(IUIAutomation *uia_iface)
* root is TRUE. element2 now represents Provider_child.
*/
hr = IUIAutomationElement_FindFirstBuildCache(element, TreeScope_Children, condition, cache_req, &element2);
todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
todo_wine ok(Provider_child.ref == 2, "Unexpected refcnt %ld\n", Provider_child.ref);
if (SUCCEEDED(hr))
{
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
ok(Provider_child.ref == 2, "Unexpected refcnt %ld\n", Provider_child.ref);
hr = IUIAutomationElement_GetCurrentPropertyValueEx(element2, UIA_ProviderDescriptionPropertyId, TRUE, &v);
todo_wine ok(hr == S_OK, "Unexpected hr %#lx\n", hr);
if (SUCCEEDED(hr))
......@@ -11432,10 +11431,7 @@ static void test_Element_Find(IUIAutomation *uia_iface)
}
ok_method_sequence(find_seq4, "find_seq4");
}
if (element2)
{
/*
* Equivalent to: Maximum find depth of 0, find first is FALSE, exclude
* root is FALSE. Provider_child doesn't have a runtime id for UI
......@@ -11443,9 +11439,8 @@ static void test_Element_Find(IUIAutomation *uia_iface)
* node that began the search, so it will get siblings.
*/
hr = IUIAutomationElement_FindAllBuildCache(element2, TreeScope_Element, condition, cache_req, &element_arr);
todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
if (SUCCEEDED(hr))
{
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
set_elem_desc(&exp_elems[0], &Provider_child, NULL, GetCurrentProcessId(), 2, 2);
add_provider_desc(&exp_elems[0].prov_desc, L"Main", L"Provider_child", TRUE);
set_elem_desc(&exp_elems[1], &Provider_child2, NULL, GetCurrentProcessId(), 2, 1);
......@@ -11453,7 +11448,6 @@ static void test_Element_Find(IUIAutomation *uia_iface)
test_uia_element_arr(element_arr, exp_elems, 2);
ok_method_sequence(find_seq5, "find_seq5");
}
/*
* Equivalent to: Maximum find depth of 0, find first is FALSE, exclude
......@@ -11463,17 +11457,14 @@ static void test_Element_Find(IUIAutomation *uia_iface)
Provider_child.runtime_id[0] = Provider_child.runtime_id[1] = 0xdeadbeef;
hr = IUIAutomationElement_FindAllBuildCache(element2, TreeScope_Element, condition, cache_req, &element_arr);
IUIAutomationElement_Release(element2);
todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
if (SUCCEEDED(hr))
{
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
set_elem_desc(&exp_elems[0], &Provider_child, NULL, GetCurrentProcessId(), 2, 1);
add_provider_desc(&exp_elems[0].prov_desc, L"Main", L"Provider_child", TRUE);
test_uia_element_arr(element_arr, exp_elems, 1);
ok_method_sequence(find_seq6, "find_seq6");
}
initialize_provider_tree(FALSE);
}
IUIAutomationCondition_Release(condition);
......@@ -11618,10 +11609,9 @@ static void test_Element_Find(IUIAutomation *uia_iface)
* to match our condition.
*/
hr = IUIAutomationElement_FindFirstBuildCache(element, TreeScope_SubTree, condition, cache_req, &element2);
todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
todo_wine ok(Provider_child_child2.ref == 2, "Unexpected refcnt %ld\n", Provider_child_child2.ref);
if (SUCCEEDED(hr))
{
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
ok(Provider_child_child2.ref == 2, "Unexpected refcnt %ld\n", Provider_child_child2.ref);
hr = IUIAutomationElement_GetCurrentPropertyValueEx(element2, UIA_ProviderDescriptionPropertyId, TRUE, &v);
todo_wine ok(hr == S_OK, "Unexpected hr %#lx\n", hr);
if (SUCCEEDED(hr))
......@@ -11633,7 +11623,6 @@ static void test_Element_Find(IUIAutomation *uia_iface)
IUIAutomationElement_Release(element2);
ok_method_sequence(find_seq11, "find_seq11");
}
initialize_provider_tree(FALSE);
IUIAutomationCondition_Release(condition);
......@@ -11688,10 +11677,9 @@ static void test_Element_Find(IUIAutomation *uia_iface)
set_provider_prop_override(&Provider_child_child, &prop_override, 1);
hr = IUIAutomationElement_FindFirst(element, TreeScope_SubTree, condition, &element2);
todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
todo_wine ok(Provider_child_child2.ref == 2, "Unexpected refcnt %ld\n", Provider_child_child2.ref);
if (SUCCEEDED(hr))
{
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
ok(Provider_child_child2.ref == 2, "Unexpected refcnt %ld\n", Provider_child_child2.ref);
hr = IUIAutomationElement_GetCurrentPropertyValueEx(element2, UIA_ProviderDescriptionPropertyId, TRUE, &v);
todo_wine ok(hr == S_OK, "Unexpected hr %#lx\n", hr);
if (SUCCEEDED(hr))
......@@ -11703,8 +11691,6 @@ static void test_Element_Find(IUIAutomation *uia_iface)
IUIAutomationElement_Release(element2);
ok_method_sequence(element_find_seq2, "element_find_seq2");
}
initialize_provider_tree(TRUE);
IUIAutomationCondition_Release(condition);
......
......@@ -1110,8 +1110,23 @@ static HRESULT WINAPI uia_element_GetRuntimeId(IUIAutomationElement9 *iface, SAF
static HRESULT WINAPI uia_element_FindFirst(IUIAutomationElement9 *iface, enum TreeScope scope,
IUIAutomationCondition *condition, IUIAutomationElement **found)
{
FIXME("%p: stub\n", iface);
return E_NOTIMPL;
IUIAutomationCacheRequest *cache_req;
HRESULT hr;
TRACE("%p, %#x, %p, %p\n", iface, scope, condition, found);
if (!found)
return E_POINTER;
*found = NULL;
hr = create_uia_cache_request_iface(&cache_req);
if (FAILED(hr))
return hr;
hr = IUIAutomationElement9_FindFirstBuildCache(iface, scope, condition, cache_req, found);
IUIAutomationCacheRequest_Release(cache_req);
return hr;
}
static HRESULT WINAPI uia_element_FindAll(IUIAutomationElement9 *iface, enum TreeScope scope,
......@@ -1136,13 +1151,93 @@ static HRESULT WINAPI uia_element_FindAll(IUIAutomationElement9 *iface, enum Tre
return hr;
}
static HRESULT set_find_params_struct(struct UiaFindParams *params, IUIAutomationCondition *cond, int scope,
BOOL find_first)
{
HRESULT hr;
hr = get_uia_condition_struct_from_iface(cond, &params->pFindCondition);
if (FAILED(hr))
return hr;
if (!scope || (scope & (~TreeScope_SubTree)))
return E_INVALIDARG;
params->FindFirst = find_first;
if (scope & TreeScope_Element)
params->ExcludeRoot = FALSE;
else
params->ExcludeRoot = TRUE;
if (scope & TreeScope_Descendants)
params->MaxDepth = -1;
else if (scope & TreeScope_Children)
params->MaxDepth = 1;
else
params->MaxDepth = 0;
return S_OK;
}
static HRESULT create_uia_element_from_cache_req(IUIAutomationElement **iface, BOOL from_cui8,
struct UiaCacheRequest *cache_req, LONG start_idx, SAFEARRAY *req_data, BSTR tree_struct);
static HRESULT WINAPI uia_element_FindFirstBuildCache(IUIAutomationElement9 *iface, enum TreeScope scope,
IUIAutomationCondition *condition, IUIAutomationCacheRequest *cache_req, IUIAutomationElement **found)
{
FIXME("%p: stub\n", iface);
return E_NOTIMPL;
struct uia_element *element = impl_from_IUIAutomationElement9(iface);
LONG lbound_offsets, lbound_tree_structs, elems_count, offset_idx;
struct UiaFindParams find_params = { 0 };
struct UiaCacheRequest *cache_req_struct;
SAFEARRAY *sa, *tree_structs, *offsets;
IUIAutomationElement *elem;
BSTR tree_struct_str;
HRESULT hr;
TRACE("%p, %#x, %p, %p, %p\n", iface, scope, condition, cache_req, found);
if (!found)
return E_POINTER;
*found = elem = NULL;
hr = get_uia_cache_request_struct_from_iface(cache_req, &cache_req_struct);
if (FAILED(hr))
return hr;
hr = set_find_params_struct(&find_params, condition, scope, TRUE);
if (FAILED(hr))
return hr;
sa = offsets = tree_structs = NULL;
hr = UiaFind(element->node, &find_params, cache_req_struct, &sa, &offsets, &tree_structs);
if (FAILED(hr) || !sa)
goto exit;
hr = get_safearray_bounds(tree_structs, &lbound_tree_structs, &elems_count);
if (FAILED(hr))
goto exit;
hr = SafeArrayGetElement(tree_structs, &lbound_tree_structs, &tree_struct_str);
if (FAILED(hr))
goto exit;
hr = get_safearray_bounds(offsets, &lbound_offsets, &elems_count);
if (FAILED(hr))
goto exit;
hr = SafeArrayGetElement(offsets, &lbound_offsets, &offset_idx);
if (FAILED(hr))
goto exit;
hr = create_uia_element_from_cache_req(&elem, element->from_cui8, cache_req_struct, offset_idx, sa, tree_struct_str);
if (SUCCEEDED(hr))
*found = elem;
exit:
SafeArrayDestroy(tree_structs);
SafeArrayDestroy(offsets);
SafeArrayDestroy(sa);
return hr;
}
static HRESULT WINAPI uia_element_FindAllBuildCache(IUIAutomationElement9 *iface, enum TreeScope scope,
......@@ -1168,25 +1263,10 @@ static HRESULT WINAPI uia_element_FindAllBuildCache(IUIAutomationElement9 *iface
if (FAILED(hr))
return hr;
hr = get_uia_condition_struct_from_iface(condition, &find_params.pFindCondition);
hr = set_find_params_struct(&find_params, condition, scope, FALSE);
if (FAILED(hr))
return hr;
if (!scope || (scope & (~TreeScope_SubTree)))
return E_INVALIDARG;
if (scope & TreeScope_Element)
find_params.ExcludeRoot = FALSE;
else
find_params.ExcludeRoot = TRUE;
if (scope & TreeScope_Descendants)
find_params.MaxDepth = -1;
else if (scope & TreeScope_Children)
find_params.MaxDepth = 1;
else
find_params.MaxDepth = 0;
sa = offsets = tree_structs = NULL;
hr = UiaFind(element->node, &find_params, cache_req_struct, &sa, &offsets, &tree_structs);
if (FAILED(hr) || !sa)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment