[Libreoffice-commits] core.git: sw/qa sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Mar 8 07:34:16 UTC 2019
sw/qa/extras/layout/layout.cxx | 34 ++++++++++++++++++++++++++++++++++
sw/source/core/text/txtfrm.cxx | 15 ++++++++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)
New commits:
commit 404bfc6f78549d16de193794960a9c9ab7604511
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Mar 7 21:39:14 2019 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Mar 8 08:33:47 2019 +0100
sw btlr writing mode shell: left/right cursor travelling, fix vert pos
By implementing BTLR support in
SwTextFrame::SwitchVerticalToHorizontal() (Point version).
Cursor traveling now looks good: all of up/down/left/right direction
have the correct paragraph and character position for all the lrtb, tbrl
and btlr cases.
As a side effect this also fixes mouse click, where clicking above the
paragraph positioned the cursor at the bottom of the paragraph.
Explicitly add a test for the mouse case as well, given that I initially
planned to fix the keyboard part directly in SwCursor::UpDown(), where
the keyboard test would pass, but not the mouse one.
Change-Id: Iabeded3f03a64416cfcaf58e0438c4a1a793e662
Reviewed-on: https://gerrit.libreoffice.org/68886
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 6b54065d9e88..a0cc3dea15a5 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -2840,6 +2840,9 @@ void SwLayoutWriter::testBtlrCell()
CPPUNIT_ASSERT_GREATER(nFirstParaMiddle, rCharRect.Top());
CPPUNIT_ASSERT_LESS(nFirstParaBottom, rCharRect.Top());
+ // Save initial cursor position.
+ SwPosition aCellStart = *pWrtShell->GetCursor()->Start();
+
// Test that pressing "up" at the start of the cell goes to the next character position.
sal_uLong nNodeIndex = pWrtShell->GetCursor()->Start()->nNode.GetIndex();
sal_Int32 nIndex = pWrtShell->GetCursor()->Start()->nContent.GetIndex();
@@ -2852,12 +2855,43 @@ void SwLayoutWriter::testBtlrCell()
CPPUNIT_ASSERT_EQUAL(nIndex + 1, pWrtShell->GetCursor()->Start()->nContent.GetIndex());
// Test that pressing "right" goes to the next paragraph (logical "down").
+ sal_Int32 nContentIndex = pWrtShell->GetCursor()->Start()->nContent.GetIndex();
aKeyEvent = KeyEvent(0, KEY_RIGHT);
rEditWin.KeyInput(aKeyEvent);
Scheduler::ProcessEventsToIdle();
// Without the accompanying fix in place, this test would have failed: the cursor went to the
// paragraph after the table.
CPPUNIT_ASSERT_EQUAL(nNodeIndex + 1, pWrtShell->GetCursor()->Start()->nNode.GetIndex());
+
+ // Test that we have the correct character index after traveling to the next paragraph.
+ // Without the accompanying fix in place, this test would have failed: char position was 5, i.e.
+ // the cursor jumped to the end of the paragraph for no reason.
+ CPPUNIT_ASSERT_EQUAL(nContentIndex, pWrtShell->GetCursor()->Start()->nContent.GetIndex());
+
+ // Test that clicking "below" the second paragraph positions the cursor at the start of the
+ // second paragraph.
+ SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+ SwPosition aPosition(aCellStart);
+ SwTwips nSecondParaLeft
+ = getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds", "left")
+ .toInt32();
+ SwTwips nSecondParaWidth
+ = getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds", "width")
+ .toInt32();
+ SwTwips nSecondParaTop
+ = getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds", "top").toInt32();
+ SwTwips nSecondParaHeight
+ = getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds", "height")
+ .toInt32();
+ Point aPoint;
+ aPoint.setX(nSecondParaLeft + nSecondParaWidth / 2);
+ aPoint.setY(nSecondParaTop + nSecondParaHeight - 100);
+ SwCursorMoveState aState(MV_NONE);
+ pLayout->GetCursorOfst(&aPosition, aPoint, &aState);
+ CPPUNIT_ASSERT_EQUAL(aCellStart.nNode.GetIndex() + 1, aPosition.nNode.GetIndex());
+ // Without the accompanying fix in place, this test would have failed: character position was 5,
+ // i.e. cursor was at the end of the paragraph.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aPosition.nContent.GetIndex());
#endif
}
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 85a179880780..81e71b8176f9 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -614,16 +614,29 @@ void SwTextFrame::SwitchVerticalToHorizontal( Point& rPoint ) const
// calc offset inside frame
if ( IsVertLR() )
+ // X offset is Y - left.
nOfstX = rPoint.X() - getFrameArea().Left();
else
{
+ // X offset is right - X.
if ( mbIsSwapped )
nOfstX = getFrameArea().Left() + getFrameArea().Height() - rPoint.X();
else
nOfstX = getFrameArea().Left() + getFrameArea().Width() - rPoint.X();
}
- const long nOfstY = rPoint.Y() - getFrameArea().Top();
+ long nOfstY;
+ if (IsVertLRBT())
+ {
+ // Y offset is bottom - Y.
+ if (mbIsSwapped)
+ nOfstY = getFrameArea().Top() + getFrameArea().Width() - rPoint.Y();
+ else
+ nOfstY = getFrameArea().Top() + getFrameArea().Height() - rPoint.Y();
+ }
+ else
+ // Y offset is Y - top.
+ nOfstY = rPoint.Y() - getFrameArea().Top();
// calc rotated coords
rPoint.setX( getFrameArea().Left() + nOfstY );
More information about the Libreoffice-commits
mailing list