Add support for dynamic visibility

Summary:
This adds the hidden property to JavaScript fields and
uses it to implement support for HideAction.

Test Plan: Unit test in the next commit.

Reviewers: #okular

Subscribers: aacid

Tags: #okular

Maniphest Tasks: T8274

Differential Revision: https://phabricator.kde.org/D11596
remotes/offline-stg/wilder
Andre Heinecke 8 years ago committed by Albert Astals Cid
parent b3f8b51b39
commit bf90867c13
  1. 4
      core/form.cpp
  2. 7
      core/form.h
  3. 18
      core/script/kjs_field.cpp
  4. 1
      generators/poppler/CMakeLists.txt
  5. 27
      generators/poppler/formfields.cpp
  6. 3
      generators/poppler/formfields.h
  7. 14
      generators/poppler/generator_pdf.cpp

@ -64,6 +64,10 @@ bool FormField::isVisible() const
return true;
}
void FormField::setVisible( bool )
{
}
Action* FormField::activationAction() const
{
Q_D( const FormField );

@ -98,6 +98,13 @@ class OKULARCORE_EXPORT FormField
*/
virtual bool isVisible() const;
/**
* Whether the field is visible.
*
* @since 1.5
*/
virtual void setVisible( bool value );
Action* activationAction() const;
/**

@ -207,6 +207,23 @@ static void fieldSetValue( KJSContext *context, void *object, KJSObject value )
}
}
// Field.hidden (getter)
static KJSObject fieldGetHidden( KJSContext *, void *object )
{
const FormField *field = reinterpret_cast< FormField * >( object );
return KJSBoolean( !field->isVisible() );
}
// Field.hidden (setter)
static void fieldSetHidden( KJSContext *context, void *object, KJSObject value )
{
FormField *field = reinterpret_cast< FormField * >( object );
bool b = value.toBoolean( context );
field->setVisible( !b );
updateField( field );
}
void JSField::initType( KJSContext *ctx )
{
static bool initialized = false;
@ -223,6 +240,7 @@ void JSField::initType( KJSContext *ctx )
fieldGetReadOnly, fieldSetReadOnly );
g_fieldProto->defineProperty( ctx, QStringLiteral("type"), fieldGetType );
g_fieldProto->defineProperty( ctx, QStringLiteral("value"), fieldGetValue, fieldSetValue );
g_fieldProto->defineProperty( ctx, QStringLiteral("hidden"), fieldGetHidden, fieldSetHidden );
}
KJSObject JSField::wrapField( KJSContext *ctx, FormField *field, Page *page )

@ -79,6 +79,7 @@ int main()
{
Poppler::FormField *f;
f->setReadOnly(true);
f->setVisible(true);
}
" HAVE_POPPLER_0_64)

@ -81,6 +81,15 @@ bool PopplerFormFieldButton::isVisible() const
return m_field->isVisible();
}
void PopplerFormFieldButton::setVisible( bool value )
{
#ifdef HAVE_POPPLER_0_64
m_field->setVisible( value );
#else
Q_UNUSED( value );
#endif
}
Okular::FormFieldButton::ButtonType PopplerFormFieldButton::buttonType() const
{
switch ( m_field->buttonType() )
@ -168,6 +177,15 @@ bool PopplerFormFieldText::isVisible() const
return m_field->isVisible();
}
void PopplerFormFieldText::setVisible( bool value )
{
#ifdef HAVE_POPPLER_0_64
m_field->setVisible( value );
#else
Q_UNUSED( value );
#endif
}
Okular::FormFieldText::TextType PopplerFormFieldText::textType() const
{
switch ( m_field->textType() )
@ -270,6 +288,15 @@ bool PopplerFormFieldChoice::isVisible() const
return m_field->isVisible();
}
void PopplerFormFieldChoice::setVisible( bool value )
{
#ifdef HAVE_POPPLER_0_64
m_field->setVisible( value );
#else
Q_UNUSED( value );
#endif
}
Okular::FormFieldChoice::ChoiceType PopplerFormFieldChoice::choiceType() const
{
switch ( m_field->choiceType() )

@ -27,6 +27,7 @@ class PopplerFormFieldButton : public Okular::FormFieldButton
bool isReadOnly() const override;
void setReadOnly( bool value ) override;
bool isVisible() const override;
void setVisible( bool value ) override;
// inherited from Okular::FormFieldButton
ButtonType buttonType() const override;
@ -56,6 +57,7 @@ class PopplerFormFieldText : public Okular::FormFieldText
bool isReadOnly() const override;
void setReadOnly( bool value ) override;
bool isVisible() const override;
void setVisible( bool value ) override;
// inherited from Okular::FormFieldText
Okular::FormFieldText::TextType textType() const override;
@ -88,6 +90,7 @@ class PopplerFormFieldChoice : public Okular::FormFieldChoice
bool isReadOnly() const override;
void setReadOnly( bool value ) override;
bool isVisible() const override;
void setVisible( bool value ) override;
// inherited from Okular::FormFieldChoice
ChoiceType choiceType() const override;

@ -446,6 +446,20 @@ Okular::Action* createLinkFromPopplerLink(const Poppler::Link *popplerLink)
link = movieAction;
}
break;
#ifdef HAVE_POPPLER_0_64
case Poppler::Link::Hide:
{
const Poppler::LinkHide * l = static_cast<const Poppler::LinkHide *>( popplerLink );
QStringList scripts;
for ( const QString &target: l->targets() )
{
scripts << QStringLiteral( "getField(\"%1\").hidden = %2;" ).arg( target ).arg( l->isShowAction() ? QLatin1String( "false" ) : QLatin1String( "true" ) );
}
link = new Okular::ScriptAction( Okular::JavaScript, scripts.join( QLatin1Char( '\n' ) ) );
}
break;
#endif
}
if ( deletePopplerLink )

Loading…
Cancel
Save