UITest: Add a method to get the currently focused window

I think this will be useful when you want to manipulate a window that
doesn’t have a unique ID and is difficult to get access to but you can
make it get the keyboard focus via UNO commands or keyboard shortcuts.

Change-Id: Iafc41dda7c3fdc1b15a62875fe3aa7efc88dcbe5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193172
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Neil Roberts
2025-10-30 11:30:43 +01:00
committed by Xisco Fauli
parent 68822e1bfe
commit d2d1e8221f
4 changed files with 31 additions and 0 deletions
+2
View File
@@ -30,6 +30,8 @@ namespace UITest
std::unique_ptr<UIObject> getFocusTopWindow();
std::unique_ptr<UIObject> getFocusWindow();
std::unique_ptr<UIObject> getFloatWindow();
};
+6
View File
@@ -27,6 +27,12 @@ interface XUITest
@since LibreOffice 25.8
*/
XUIObject getWindow([in] ::com::sun::star::awt::XWindow xWindow);
/** Get the XUIObject for the window that currently has focus.
@since LibreOffice 26.2
*/
XUIObject getFocusWindow();
};
}; }; }; }; };
+12
View File
@@ -65,6 +65,18 @@ std::unique_ptr<UIObject> UITest::getFocusTopWindow()
return pSVData->maFrameData.mpFirstFrame->GetUITestFactory()(pSVData->maFrameData.mpFirstFrame);
}
std::unique_ptr<UIObject> UITest::getFocusWindow()
{
ImplSVData* pSVData = ImplGetSVData();
ImplSVWinData& rWinData = *pSVData->mpWinData;
VclPtr<vcl::Window> pFocusWin = rWinData.mpFocusWin;
if (pFocusWin)
return pFocusWin->GetUITestFactory()(pFocusWin);
return nullptr;
}
std::unique_ptr<UIObject> UITest::getFloatWindow()
{
ImplSVData* pSVData = ImplGetSVData();
+11
View File
@@ -43,6 +43,8 @@ public:
css::uno::Reference<css::ui::test::XUIObject> SAL_CALL getTopFocusWindow() override;
css::uno::Reference<css::ui::test::XUIObject> SAL_CALL getFocusWindow() override;
css::uno::Reference<css::ui::test::XUIObject> SAL_CALL getFloatWindow() override;
css::uno::Reference<css::ui::test::XUIObject>
@@ -89,6 +91,15 @@ css::uno::Reference<css::ui::test::XUIObject> SAL_CALL UITestUnoObj::getTopFocus
return new UIObjectUnoObj(std::move(pObj));
}
css::uno::Reference<css::ui::test::XUIObject> SAL_CALL UITestUnoObj::getFocusWindow()
{
SolarMutexGuard aGuard;
std::unique_ptr<UIObject> pObj = UITest::getFocusWindow();
if (!pObj)
throw css::uno::RuntimeException(u"UITest::getFocusWindow did not find a window"_ustr);
return new UIObjectUnoObj(std::move(pObj));
}
css::uno::Reference<css::ui::test::XUIObject> SAL_CALL UITestUnoObj::getFloatWindow()
{
SolarMutexGuard aGuard;