Android: Fix cursorHandle and EditPopup positions

After the commit 28df9a49776a88cb1a8e69348ae19a59b16a5b7e, a regression
occurred in the positioning of cursorHandle and EditPopup.

Previously, these positions were calculated using QtEditText
coordinates, which worked correctly because the QtEditText size matched
the QtWindow size. However, after the mentioned commit, the QtEditText
size no longer reflects the window size. In this case, we need to use
the parent View for calculations.

This adjustment was already made for the single cursorHandle.

This commit also updates the positioning of selection handles and the EditPopup.

Fixes: QTBUG-132589
Pick-to: 6.8
Change-Id: I861292e363452d487284e3f603fe03a21a334aa4
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 5bd26fda7a3f0a509a64847b58b916830ebc2d0c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Bartlomiej Moskal 2025-02-05 12:20:46 +01:00 committed by Qt Cherry-pick Bot
parent 6869341dce
commit 941434e81f
3 changed files with 22 additions and 7 deletions

View File

@ -135,7 +135,15 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener
initOverlay();
final int[] layoutLocation = new int[2];
m_layout.getLocationOnScreen(layoutLocation);
// m_layout is QtEditText. Since it doesn't match the QtWindow size, we should use its
// parent for cursorHandle positioning. However, there may be cases where the parent is
// not set. In such cases, we need to use QtEditText instead.
View positioningView = (View) m_layout.getParent();
if (positioningView == null)
positioningView = m_layout;
positioningView.getLocationOnScreen(layoutLocation);
// These values are used for handling split screen case
final int[] activityLocation = new int[2];
@ -158,7 +166,7 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener
m_popup.update(x2, y2, -1, -1);
m_cursorView.adjusted(x - m_posX, y - m_posY);
} else {
m_popup.showAtLocation(m_layout, 0, x2, y2);
m_popup.showAtLocation(positioningView, 0, x2, y2);
}
m_posX = x;

View File

@ -57,7 +57,14 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout
Point viewSize = m_view.getCalculatedSize();
final int[] layoutLocation = new int[2];
m_editText.getLocationOnScreen(layoutLocation);
// Since QtEditText doesn't match the QtWindow size, we should use its parent for
// EditPopupMenu positioning. However, there may be cases where the parent is
// not set. In such cases, we need to use QtEditText instead.
View positioningView = (View) m_editText.getParent();
if (positioningView == null)
positioningView = m_editText;
positioningView.getLocationOnScreen(layoutLocation);
// These values are used for handling split screen case
final int[] activityLocation = new int[2];
@ -87,8 +94,8 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout
}
}
if (m_editText.getWidth() < x + viewSize.x / 2)
x2 = m_editText.getWidth() - viewSize.x;
if (positioningView.getWidth() < x + viewSize.x / 2)
x2 = positioningView.getWidth() - viewSize.x;
if (x2 < 0)
x2 = 0;
@ -96,7 +103,7 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout
if (m_popup.isShowing())
m_popup.update(x2, y2, -1, -1);
else
m_popup.showAtLocation(m_editText, 0, x2, y2);
m_popup.showAtLocation(positioningView, 0, x2, y2);
m_posX = x;
m_posY = y;

View File

@ -269,7 +269,7 @@ class QtEditText extends View
break;
case CursorHandleShowNormal:
if (m_cursorHandle == null) {
m_cursorHandle = new CursorHandle((Activity) getContext(), (View) getParent(),
m_cursorHandle = new CursorHandle((Activity) getContext(), this,
CursorHandle.IdCursorHandle,
android.R.attr.textSelectHandle, false);
}