Handle more action triggers (widget annotation actions) in PDF forms
Open, WishlistPublic

Description

In PDF's there can be action annotations to form fields and to additional actions of widget annotations.

Okular currently only parses the additional actions of "FormField::AdditionalActionType" these are: CalculateField, ValidateField, FormatField and FieldModified.

For Bug 307304 we need support for Focus In / Focus Out actions.
For Bug 306818 we need support for MousePressed actions.

The actions are:

actionCursorEntering, ///< Performed when the cursor enters the annotation's active area
actionCursorLeaving,  ///< Performed when the cursor exists the annotation's active area
actionMousePressed,   ///< Performed when the mouse button is pressed inside the annotation's active area
actionMouseReleased,  ///< Performed when the mouse button is released inside the annotation's active area
actionFocusIn,        ///< Performed when the annotation receives the input focus
actionFocusOut,       ///< Performed when the annotation loses the input focus

These actions are actions of the widget annotation. In Qt5 API "Annotation::AdditionalActionType".

Currently I don't see a way to get those actions in the Qt API in connection to their corresponding FormFields. We see the annotation widget in PDFGenerator::addAnnotations but only do something with PageOpeningAction and PageClosingAction and there is no link between the FormField and the widget annotation.

In internal poppler API this should be something like FormWidget::getWidgetAnnotation() then we could call getAdditionalAction on that annotation.

So I think what we need here would be a link between a FormField and the annotation additional actions. As the Qt API already combines annoation widget properties with the field (isVisible) I think it would be least confusing to also expose the WidgetAnnoation actions through the form actions interface.

I have a working prototype that executes the focusOut actions from Bug 307304. I hope to finish this up for review later today or tomorrow.

aheinecke triaged this task as Wishlist priority.

As both Bugs mentioned here have multiple issues (Bug 307304 needs the display java script object, Bug 306818 needs visible read only fields) and I want to avoid muddying the waters, I've built a test PDF that can be used as a basis for a unit test:

For each kind of field the corresponding Focus / Cursor / Mouse buttons change visibility.
Focus: Hidden when the field has focus.
Cursor: Hidden when the cursor is in the field.
Mouse: Hidden when the mouse is pressed. Visible when it's released.

Here is how it looks in Acrobat:

The mouse pressed does not appear to work properly in Acrobat for list fields.

Turned out that this actually does not need much code (with some preprocessor macros).

Here is the necessary poppler patch:


I'll post it in popplers bugzilla now.

The Okular patch I'll attach as a differential. Still needs a unit test, but you can already comment / review the current state. I would be interested in some C++ magic to replace the preprocessor stuff with, I've tried to mixin another template class that contains the qt event overrides but I failed to get this right so I defaulted to preprocessing :-)

Also, the mouse Release action does not work properly. I think this is because mouse release is parsed in poppler as the "activation action" so there is some weirdness related to that. See:

aheinecke updated the task description. (Show Details)May 2 2018, 3:07 PM