Skip to content

Commit

Permalink
fix: resolve browser crash on translation pane click (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bush2021 committed Apr 6, 2024
1 parent fca217b commit 6cbe30d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/IAccessibleUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void TraversalAccessible(NodePtr node, Function f) {
continue;
}
if (bDone) {
arrChildren[j].pdispVal->Release(); // 立刻释放,避免内存泄漏
arrChildren[j].pdispVal->Release(); // 立刻释放,避免内存泄漏
continue;
}

Expand Down Expand Up @@ -197,6 +197,23 @@ NodePtr FindElementWithRole(NodePtr node, long role) {
return element;
}

NodePtr FindPageTabList(NodePtr node) {
NodePtr PageTabList = nullptr;
if (node) {
TraversalAccessible(node, [&](NodePtr child) {
if (auto role = GetAccessibleRole(child);
role == ROLE_SYSTEM_PAGETABLIST) {
PageTabList = child;
} else if (role == ROLE_SYSTEM_PANE || role == ROLE_SYSTEM_TOOLBAR) {
// 必须保留这两个判断,否则会闪退 (#51)
PageTabList = FindPageTabList(child);
}
return PageTabList;
});
}
return PageTabList;
}

NodePtr GetParentElement(NodePtr child) {
NodePtr element = nullptr;
Microsoft::WRL::ComPtr<IDispatch> dispatch = nullptr;
Expand All @@ -217,8 +234,7 @@ NodePtr GetTopContainerView(HWND hwnd) {
NodePtr paccMainWindow = nullptr;
if (S_OK == AccessibleObjectFromWindow(hwnd, OBJID_WINDOW,
IID_PPV_ARGS(&paccMainWindow))) {
NodePtr PageTabList =
FindElementWithRole(paccMainWindow, ROLE_SYSTEM_PAGETABLIST);
NodePtr PageTabList = FindPageTabList(paccMainWindow);
if (PageTabList) {
TopContainerView = GetParentElement(PageTabList);
}
Expand Down

0 comments on commit 6cbe30d

Please sign in to comment.