summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2021-01-26 12:51:11 +0100
committerMorten Sørvig <morten.sorvig@qt.io>2021-02-01 22:44:51 +0100
commitb23f5621d7e5275dbb3f96f6b46f691c8b19a13d (patch)
tree984b4e100d73dc3c54bec295442f5899a29d533a /src/plugins/platforms/ios
parentdafe9e23638c4fe272044fae91380a225e19193a (diff)
iOS: Use new QPlatformInputContext geometry API
This enables support for QT_SCALE_FACTOR on iOS. Fixes: QTBUG-74978 Change-Id: Ibcf0741c178e44802065e472e096a5f4c7d6f3cf Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qiosinputcontext.mm5
-rw-r--r--src/plugins/platforms/ios/qiostextinputoverlay.mm31
-rw-r--r--src/plugins/platforms/ios/qiostextresponder.mm11
3 files changed, 22 insertions, 25 deletions
diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm
index 0eb12498b4..ca95531292 100644
--- a/src/plugins/platforms/ios/qiosinputcontext.mm
+++ b/src/plugins/platforms/ios/qiosinputcontext.mm
@@ -499,8 +499,9 @@ void QIOSInputContext::scrollToCursor()
return;
}
- QWindow *focusWindow = qApp->focusWindow();
- QRect cursorRect = qApp->inputMethod()->cursorRectangle().translated(focusWindow->geometry().topLeft()).toRect();
+ QPlatformWindow *focusWindow = qApp->focusWindow()->handle();
+ QRect windowCurosorRect = QPlatformInputContext::cursorRectangle().toRect();
+ QRect cursorRect = QRect(focusWindow->mapToGlobal(windowCurosorRect.topLeft()), windowCurosorRect.size());
// We explicitly ask for the geometry of the screen instead of the availableGeometry,
// as we hide the status bar when scrolling the screen, so the available geometry will
diff --git a/src/plugins/platforms/ios/qiostextinputoverlay.mm b/src/plugins/platforms/ios/qiostextinputoverlay.mm
index 15be19c6bc..e7f9e5aa79 100644
--- a/src/plugins/platforms/ios/qiostextinputoverlay.mm
+++ b/src/plugins/platforms/ios/qiostextinputoverlay.mm
@@ -146,8 +146,9 @@ static void executeBlockWithoutAnimation(Block block)
if (visible) {
// Note that the contents of the edit menu is decided by
// first responder, which is normally QIOSTextResponder.
- QRectF cr = qApp->inputMethod()->cursorRectangle();
- QRectF ar = qApp->inputMethod()->anchorRectangle();
+ QRectF cr = QPlatformInputContext::cursorRectangle();
+ QRectF ar = QPlatformInputContext::anchorRectangle();
+
CGRect targetRect = cr.united(ar).toCGRect();
UIView *focusView = reinterpret_cast<UIView *>(qApp->focusWindow()->winId());
[[UIMenuController sharedMenuController] setTargetRect:targetRect inView:focusView];
@@ -627,13 +628,13 @@ static void executeBlockWithoutAnimation(Block block)
- (BOOL)acceptTouchesBegan:(QPointF)touchPoint
{
- QRectF inputRect = QGuiApplication::inputMethod()->inputItemClipRectangle();
+ QRectF inputRect = QPlatformInputContext::inputItemRectangle();
return !hasSelection() && inputRect.contains(touchPoint);
}
- (void)updateFocalPoint:(QPointF)touchPoint
{
- platformInputContext()->setSelectionOnFocusObject(touchPoint, touchPoint);
+ QPlatformInputContext::setSelectionOnFocusObject(touchPoint, touchPoint);
self.focalPoint = touchPoint;
}
@@ -783,8 +784,8 @@ static void executeBlockWithoutAnimation(Block block)
// Accept the touch if it "overlaps" with any of the handles
const int handleRadius = 50;
- QPointF cursorCenter = qApp->inputMethod()->cursorRectangle().center();
- QPointF anchorCenter = qApp->inputMethod()->anchorRectangle().center();
+ QPointF cursorCenter = QPlatformInputContext::cursorRectangle().center();
+ QPointF anchorCenter = QPlatformInputContext::anchorRectangle().center();
QPointF cursorOffset = QPointF(cursorCenter.x() - touchPoint.x(), cursorCenter.y() - touchPoint.y());
QPointF anchorOffset = QPointF(anchorCenter.x() - touchPoint.x(), anchorCenter.y() - touchPoint.y());
double cursorDist = hypot(cursorOffset.x(), cursorOffset.y());
@@ -812,8 +813,7 @@ static void executeBlockWithoutAnimation(Block block)
// Get the text position under the touch
SelectionPair selection = querySelection();
- const QTransform mapToLocal = QGuiApplication::inputMethod()->inputItemTransform().inverted();
- int touchTextPos = QInputMethod::queryFocusObject(Qt::ImCursorPosition, touchPoint * mapToLocal).toInt();
+ int touchTextPos = QPlatformInputContext::queryFocusObject(Qt::ImCursorPosition, touchPoint).toInt();
// Ensure that the handels cannot be dragged past each other
if (_dragOnCursor)
@@ -830,8 +830,8 @@ static void executeBlockWithoutAnimation(Block block)
// Move loupe to new position
QRectF handleRect = _dragOnCursor ?
- qApp->inputMethod()->cursorRectangle() :
- qApp->inputMethod()->anchorRectangle();
+ QPlatformInputContext::cursorRectangle() :
+ QPlatformInputContext::anchorRectangle();
self.focalPoint = QPointF(touchPoint.x(), handleRect.center().y());
}
@@ -858,9 +858,9 @@ static void executeBlockWithoutAnimation(Block block)
}
// Adjust handles and input rect to match the new selection
- QRectF inputRect = QGuiApplication::inputMethod()->inputItemClipRectangle();
- CGRect cursorRect = QGuiApplication::inputMethod()->cursorRectangle().toCGRect();
- CGRect anchorRect = QGuiApplication::inputMethod()->anchorRectangle().toCGRect();
+ QRectF inputRect = QPlatformInputContext::inputItemClipRectangle();
+ CGRect cursorRect = QPlatformInputContext::cursorRectangle().toCGRect();
+ CGRect anchorRect = QPlatformInputContext::anchorRectangle().toCGRect();
if (!_multiLine) {
// Resize the layer a bit bigger to ensure that the handles are
@@ -924,7 +924,7 @@ static void executeBlockWithoutAnimation(Block block)
{
[super touchesBegan:touches withEvent:event];
- QRectF inputRect = QGuiApplication::inputMethod()->inputItemClipRectangle();
+ QRectF inputRect = QPlatformInputContext::inputItemClipRectangle();
QPointF touchPos = QPointF::fromCGPoint([static_cast<UITouch *>([touches anyObject]) locationInView:_focusView]);
const bool touchInsideInputArea = inputRect.contains(touchPos);
@@ -969,8 +969,7 @@ static void executeBlockWithoutAnimation(Block block)
_menuShouldBeVisible = false;
} else {
QPointF touchPos = QPointF::fromCGPoint([static_cast<UITouch *>([touches anyObject]) locationInView:_focusView]);
- const QTransform mapToLocal = QGuiApplication::inputMethod()->inputItemTransform().inverted();
- int cursorPosOnRelease = QInputMethod::queryFocusObject(Qt::ImCursorPosition, touchPos * mapToLocal).toInt();
+ int cursorPosOnRelease = QPlatformInputContext::queryFocusObject(Qt::ImCursorPosition, touchPos).toInt();
if (cursorPosOnRelease == _cursorPosOnPress) {
_menuShouldBeVisible = true;
diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm
index 358ccbf602..e030ec200c 100644
--- a/src/plugins/platforms/ios/qiostextresponder.mm
+++ b/src/plugins/platforms/ios/qiostextresponder.mm
@@ -832,7 +832,7 @@
QInputMethodEvent e(m_markedText, attrs);
[self sendEventToFocusObject:e];
}
- QRectF startRect = qApp->inputMethod()->cursorRectangle();
+ QRectF startRect = QPlatformInputContext::cursorRectangle();;
attrs = QList<QInputMethodEvent::Attribute>();
attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, r.location + r.length, 0, 0);
@@ -840,7 +840,7 @@
QInputMethodEvent e(m_markedText, attrs);
[self sendEventToFocusObject:e];
}
- QRectF endRect = qApp->inputMethod()->cursorRectangle();
+ QRectF endRect = QPlatformInputContext::cursorRectangle();;
if (cursorPos != int(r.location + r.length) || cursorPos != anchorPos) {
attrs = QList<QInputMethodEvent::Attribute>();
@@ -866,8 +866,7 @@
Q_UNUSED(position);
// Assume for now that position is always the same as
// cursor index until a better API is in place:
- QRectF cursorRect = qApp->inputMethod()->cursorRectangle();
- return cursorRect.toCGRect();
+ return QPlatformInputContext::cursorRectangle().toCGRect();
}
- (void)replaceRange:(UITextRange *)range withText:(NSString *)text
@@ -906,9 +905,7 @@
- (UITextPosition *)closestPositionToPoint:(CGPoint)point
{
- QPointF p = QPointF::fromCGPoint(point);
- const QTransform mapToLocal = QGuiApplication::inputMethod()->inputItemTransform().inverted();
- int textPos = QInputMethod::queryFocusObject(Qt::ImCursorPosition, p * mapToLocal).toInt();
+ int textPos = QPlatformInputContext::queryFocusObject(Qt::ImCursorPosition, QPointF::fromCGPoint(point)).toInt();
return [QUITextPosition positionWithIndex:textPos];
}