diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-03-06 17:59:32 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-04-30 11:06:17 +0200 |
commit | 8d13facbd88d821cc89b21f43708cc1a81ac79f3 (patch) | |
tree | 4732dd861938f974fe77366bdeab63db76e842cb /src/core/web_engine_context.cpp | |
parent | 685430b66ab2830d5e0e5ebafc17294ff1ce1f48 (diff) |
Support text selection handles in PDF views
Testing only on iOS so far; QtPdf doesn't work on Android because of
QTBUG-83459, so we can only hope that this might perhaps be cross-platform,
if only text selection handles actually existed on all platforms.
As usual, text selection begins with a long-press; the iOS platform
plugin intercepts that, and we get QInputMethodEvent::Cursor.
There is no cursor, but we use the opportunity to do hit-testing,
because the Cursor event is the only way that we receive the pixel
location where the user is interacting. Then a popover menu appears,
which contains Select and Select All, and either Copy or Paste depending
on the qt_im_readonly property workaround. You don't get handles until
you choose Select, which will select a word. That makes the popover
menu disappear. You can use the toolbar button to copy to the clipboard.
After that, you can drag either handle. inputMethodQuery(query, argument)
is only ever called with ImCursorPosition regardless which handle is
being dragged, so it doesn't make sense to change the selection there,
even though that would be easy if we were given that information.
Instead, the iOS platform figures out the character range for itself and
sends a QInputMethodEvent::Selection event to tell us which text to
select. And yet it still doesn't move the handles without being told:
QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle | Qt::ImAnchorRectangle)
makes that happen. Then the popover menu will appear again, and now you
can use the Copy function on it as an alternative way to copy text to
the clipboard.
By default, when the user does the initial long-press to start selecting
text, the popover menu has Select, Select All, and Paste. In editable
controls there is a second possible menu that normally has Cut, Copy,
Paste and Delete. We are not able to enter that mode. So as a
workaround, to substitute Copy instead of Paste, we set the
qt_im_readonly property so that QIOSTextResponder::canPerformAction()
can detect it and make the substition. Of course that won't work
without the patch to 5.15; so you still get a useless Paste action on
earlier Qt versions.
Selecting a word via the Select popover menu item happens because iOS sends
QKeySequence::MoveToPreviousWord and then QKeySequence::SelectNextWord.
We spend time calling getSelectionAtIndex() twice because of that.
With an actual keyboard, it should be possible to use keystrokes to
extend the selection, but it doesn't seem to work yet with shift-arrows
on a physical bluetooth keyboard on iOS.
Select All on the popover menu works via inputMethodEvent() with attr
QInputMethodEvent::Selection. Copy sends the standard copy key sequence,
so keyReleaseEvent() handles it.
We must rename the geometryChanged signal to selectedAreaChanged now
that we're inheriting from QQuickItem, to avoid shadowing
QQuickItem::geometryChanged.
For this kind of text selection to work even when the rendering is scaled,
it became necessary to inform PdfSelection of the rendering scale; so
a renderScale property is added. Thus it is sensible (and a nice
simplification in QML code) to use it for the fromPoint and toPoint
properties, such that those are now expressed in pixels rather than points.
Fixes: QTBUG-82441
Task-number: QTBUG-83811
Change-Id: I16ecd2db55c6a834be6139ce4f3aae23446fed54
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/core/web_engine_context.cpp')
0 files changed, 0 insertions, 0 deletions