diff --git a/src/plugins/platforms/ios/qiostextinputoverlay.mm b/src/plugins/platforms/ios/qiostextinputoverlay.mm index 83170c18511..8cdaa48500d 100644 --- a/src/plugins/platforms/ios/qiostextinputoverlay.mm +++ b/src/plugins/platforms/ios/qiostextinputoverlay.mm @@ -14,6 +14,8 @@ #include "qiosglobal.h" #include "qiostextinputoverlay.h" +#include "qioswindow.h" +#include "quiview.h" typedef QPair SelectionPair; typedef void (^Block)(void); @@ -130,6 +132,24 @@ static void executeBlockWithoutAnimation(Block block) @end +void showEditMenu(UIView *focusView, QPoint touchPos) +{ + const bool mouseTriggered = false; + const Qt::KeyboardModifiers keyboardModifiers = Qt::NoModifier; + QWindow *qtWindow = quiview_cast(focusView).platformWindow->window(); + const auto globalTouchPos = qtWindow->mapToGlobal(touchPos); + const bool contextMenuEventAccepted = QWindowSystemInterface::handleContextMenuEvent< + QWindowSystemInterface::SynchronousDelivery>(qtWindow, mouseTriggered, touchPos, + globalTouchPos, keyboardModifiers); + + if (!contextMenuEventAccepted) { + // Fall back to show the default platform menu, like we did + // before we started sending context menu events. This is + // to be backwards compatible with Widgets and Quick items. + QIOSTextInputOverlay::s_editMenu.visible = YES; + } +} + // ------------------------------------------------------------------------- @interface QIOSLoupeLayer : CALayer @@ -469,12 +489,14 @@ static void executeBlockWithoutAnimation(Block block) // Tell the sub class to move the loupe to the correct position [self updateFocalPoint:QPointF::fromCGPoint(_lastTouchPoint)]; break; - case UIGestureRecognizerStateEnded: + case UIGestureRecognizerStateEnded: { // Restore cursor blinking, and hide the loupe QGuiApplication::styleHints()->setCursorFlashTime(_originalCursorFlashTime); - QIOSTextInputOverlay::s_editMenu.visible = YES; + const QPoint touchPos = QPointF::fromCGPoint(_lastTouchPoint).toPoint(); + showEditMenu(_focusView, touchPos); _loupeLayer.visible = NO; break; + } default: _loupeLayer.visible = NO; break; @@ -956,7 +978,10 @@ static void executeBlockWithoutAnimation(Block block) _menuShouldBeVisible = true; self.state = UIGestureRecognizerStateFailed; dispatch_async(dispatch_get_main_queue(), ^{ - QIOSTextInputOverlay::s_editMenu.visible = _menuShouldBeVisible; + if (_menuShouldBeVisible) + showEditMenu(_focusView, touchPos.toPoint()); + else + QIOSTextInputOverlay::s_editMenu.visible = false; }); } else { // The menu is hidden, and the cursor will change position once