diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-07-18 11:18:28 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-07-18 12:27:02 +0200 |
commit | aaebfb9baf53e4ed221a9bb8e1772fcbb7b921ab (patch) | |
tree | 4edfcff49dce27b31aeb6385e168993bf24902c1 /sw/qa/core | |
parent | 28daee8a3252e03a67484dc8d3dd26fd73af4826 (diff) |
sw content control, picture: allow replacing via the keyboard
It was not possible to replace a picture placeholder with an actual
bitmap without using the mouse, which breaks accessibility.
The mouse handling code was added in commit
b213abcb77e19fa5d22af45c7ecd17c8a63af554 (sw content controls, picture:
replace placeholder image on click, 2022-05-18), which already split the
functionality between SwEditWin::MouseButtonUp() and
SwWrtShell::GotoContentControl().
Fix the problem by reusing the shared SwWrtShell::GotoContentControl()
and extending SwEditWin::KeyInput() to allow doing the same with the
keyboard. This way the scenario when Shift-F4 selects the frame and the
user presses Enter now triggers the filepicker.
A possible future improvement would be to also handle Enter similarly
when the text cursor is inside a picture content control, but that's not
implemented here.
Change-Id: I756395d3811e3f4dfdce698751c4de13a0d49729
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137168
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa/core')
-rw-r--r-- | sw/qa/core/txtnode/txtnode.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx index 7791cf82bbc3..15d2188a8cb6 100644 --- a/sw/qa/core/txtnode/txtnode.cxx +++ b/sw/qa/core/txtnode/txtnode.cxx @@ -270,6 +270,33 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDropdownContentControlKeyboard) CPPUNIT_ASSERT(bShouldOpen); } +CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testPicutreContentControlKeyboard) +{ + // Given an already selected picture content control: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::PICTURE); + pWrtShell->GotoObj(/*bNext=*/true, GotoObjFlags::Any); + + // When checking if enter should trigger the file picker: + const SwFrameFormat* pFlyFormat = pWrtShell->GetFlyFrameFormat(); + const SwFormatAnchor& rFormatAnchor = pFlyFormat->GetAnchor(); + const SwPosition* pAnchorPos = rFormatAnchor.GetContentAnchor(); + SwTextNode* pTextNode = pAnchorPos->nNode.GetNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrAt(pAnchorPos->nContent.GetIndex(), + RES_TXTATR_CONTENTCONTROL, SwTextNode::PARENT); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + bool bIsInteracting = pContentControl->IsInteractingCharacter('\r'); + + // Then make sure that the answer is yes for pictures: + // Without the accompanying fix in place, this test would have failed, the picture replacement + // file-picker was mouse-only. + CPPUNIT_ASSERT(bIsInteracting); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |