Android: Fix RTL selection handles directions
Invert the selection handles icons when the selected text is rtl. Task-number: QTBUG-61073 Change-Id: I8339a14d1e4d9e79d218516daf3ac783911f6026 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>bb10
parent
b91d37a600
commit
ea568c310d
|
|
@ -107,13 +107,14 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
|||
private int m_id;
|
||||
private int m_attr;
|
||||
private Activity m_activity;
|
||||
private int m_posX;
|
||||
private int m_posY;
|
||||
private int m_posX = 0;
|
||||
private int m_posY = 0;
|
||||
private int m_lastX;
|
||||
private int m_lastY;
|
||||
int tolerance;
|
||||
private boolean m_rtl;
|
||||
|
||||
public CursorHandle(Activity activity, View layout, int id, int attr) {
|
||||
public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) {
|
||||
m_activity = activity;
|
||||
m_id = id;
|
||||
m_attr = attr;
|
||||
|
|
@ -122,6 +123,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
|||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
tolerance = Math.round(2 * metrics.density);
|
||||
m_lastX = m_lastY = -1 - tolerance;
|
||||
m_rtl = rtl;
|
||||
}
|
||||
|
||||
private boolean initOverlay(){
|
||||
|
|
@ -160,9 +162,9 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
|||
|
||||
if (m_id == QtNative.IdCursorHandle) {
|
||||
x2 -= m_cursorView.getWidth() / 2 ;
|
||||
} else if (m_id == QtNative.IdLeftHandle) {
|
||||
} else if ((m_id == QtNative.IdLeftHandle && !m_rtl) || (m_id == QtNative.IdRightHandle && m_rtl)) {
|
||||
x2 -= m_cursorView.getWidth() * 3 / 4;
|
||||
} else if (m_id == QtNative.IdRightHandle) {
|
||||
} else {
|
||||
x2 -= m_cursorView.getWidth() / 4;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -490,7 +490,7 @@ public class QtActivityDelegate
|
|||
be adjusted.
|
||||
mode is one of QAndroidInputContext::CursorHandleShowMode
|
||||
*/
|
||||
public void updateHandles(int mode, int x1, int y1, int x2, int y2)
|
||||
public void updateHandles(int mode, int x1, int y1, int x2, int y2, boolean rtl)
|
||||
{
|
||||
if (mode == CursorHandleNotShown) {
|
||||
if (m_cursorHandle != null)
|
||||
|
|
@ -498,6 +498,8 @@ public class QtActivityDelegate
|
|||
if (m_rightSelectionHandle != null) {
|
||||
m_rightSelectionHandle.hide();
|
||||
m_leftSelectionHandle.hide();
|
||||
m_rightSelectionHandle = null;
|
||||
m_leftSelectionHandle = null;
|
||||
}
|
||||
if (m_editMenu != null)
|
||||
m_editMenu.hide();
|
||||
|
|
@ -506,19 +508,25 @@ public class QtActivityDelegate
|
|||
} else if (mode == CursorHandleShowNormal || mode == CursorHandleShowPopup) {
|
||||
if (m_cursorHandle == null) {
|
||||
m_cursorHandle = new CursorHandle(m_activity, m_layout, QtNative.IdCursorHandle,
|
||||
android.R.attr.textSelectHandle);
|
||||
android.R.attr.textSelectHandle, false);
|
||||
}
|
||||
m_cursorHandle.setPosition(x1, y1);
|
||||
if (m_rightSelectionHandle != null) {
|
||||
m_rightSelectionHandle.hide();
|
||||
m_leftSelectionHandle.hide();
|
||||
m_rightSelectionHandle = null;
|
||||
m_leftSelectionHandle = null;
|
||||
}
|
||||
} else if (mode == CursorHandleShowSelection) {
|
||||
if (m_rightSelectionHandle == null) {
|
||||
m_leftSelectionHandle = new CursorHandle(m_activity, m_layout, QtNative.IdLeftHandle,
|
||||
android.R.attr.textSelectHandleLeft);
|
||||
!rtl ? android.R.attr.textSelectHandleLeft :
|
||||
android.R.attr.textSelectHandleRight,
|
||||
rtl);
|
||||
m_rightSelectionHandle = new CursorHandle(m_activity, m_layout, QtNative.IdRightHandle,
|
||||
android.R.attr.textSelectHandleRight);
|
||||
!rtl ? android.R.attr.textSelectHandleRight :
|
||||
android.R.attr.textSelectHandleLeft,
|
||||
rtl);
|
||||
}
|
||||
m_leftSelectionHandle.setPosition(x1,y1);
|
||||
m_rightSelectionHandle.setPosition(x2,y2);
|
||||
|
|
|
|||
|
|
@ -516,12 +516,13 @@ public class QtNative
|
|||
final int x1,
|
||||
final int y1,
|
||||
final int x2,
|
||||
final int y2)
|
||||
final int y2,
|
||||
final boolean rtl)
|
||||
{
|
||||
runAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
m_activityDelegate.updateHandles(mode, x1, y1, x2, y2);
|
||||
m_activityDelegate.updateHandles(mode, x1, y1, x2, y2, rtl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,11 +121,11 @@ namespace QtAndroidInput
|
|||
return m_softwareKeyboardRect;
|
||||
}
|
||||
|
||||
void updateHandles(int mode, QPoint cursor, QPoint anchor)
|
||||
void updateHandles(int mode, QPoint cursor, QPoint anchor, bool rtl)
|
||||
{
|
||||
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(), "updateHandles", "(IIIII)V",
|
||||
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(), "updateHandles", "(IIIIIZ)V",
|
||||
mode, cursor.x(), cursor.y(), anchor.x(),
|
||||
anchor.y());
|
||||
anchor.y(), rtl);
|
||||
}
|
||||
|
||||
static void mouseDown(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace QtAndroidInput
|
|||
// Software keyboard support
|
||||
|
||||
// cursor/selection handles
|
||||
void updateHandles(int handleCount, QPoint cursor = QPoint(), QPoint anchor = QPoint());
|
||||
void updateHandles(int handleCount, QPoint cursor = QPoint(), QPoint anchor = QPoint(), bool rtl = false);
|
||||
|
||||
bool registerNatives(JNIEnv *env);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ void QAndroidInputContext::updateSelectionHandles()
|
|||
? QHighDpiScaling::factor(window)
|
||||
: QHighDpiScaling::factor(QtAndroid::androidPlatformIntegration()->screen());
|
||||
|
||||
QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition | Qt::ImEnabled);
|
||||
QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition | Qt::ImEnabled | Qt::ImCurrentSelection);
|
||||
QCoreApplication::sendEvent(m_focusObject, &query);
|
||||
int cpos = query.value(Qt::ImCursorPosition).toInt();
|
||||
int anchor = query.value(Qt::ImAnchorPosition).toInt();
|
||||
|
|
@ -563,7 +563,8 @@ void QAndroidInputContext::updateSelectionHandles()
|
|||
|
||||
QPoint leftPoint(leftRect.bottomLeft().toPoint() * pixelDensity);
|
||||
QPoint righPoint(rightRect.bottomRight().toPoint() * pixelDensity);
|
||||
QtAndroidInput::updateHandles(CursorHandleShowSelection, leftPoint, righPoint);
|
||||
QtAndroidInput::updateHandles(CursorHandleShowSelection, leftPoint, righPoint,
|
||||
query.value(Qt::ImCurrentSelection).toString().isRightToLeft());
|
||||
|
||||
if (m_cursorHandleShown == CursorHandleShowPopup) {
|
||||
// make sure the popup does not reappear when the selection menu closes
|
||||
|
|
|
|||
Loading…
Reference in New Issue