From 7d12532362545273e0ceac93fae2154661323fd1 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 28 Mar 2018 18:49:34 +0000 Subject: More fpdfsdk filename cleanup This CL moves more of the fpdfsdk/ code around to better match the naming of other files. Change-Id: I203d91e3e345b2b4767df7a69dd5bd981d61f1d2 Reviewed-on: https://pdfium-review.googlesource.com/29372 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- fpdfsdk/cba_annotiterator_embeddertest.cpp | 126 +++++ fpdfsdk/cpdfsdk_actionhandler.cpp | 551 ++++++++++++++++++++++ fpdfsdk/cpdfsdk_actionhandler.h | 129 +++++ fpdfsdk/cpdfsdk_fieldaction.cpp | 17 + fpdfsdk/cpdfsdk_fieldaction.h | 38 ++ fpdfsdk/cpdfsdk_filewriteadapter.cpp | 23 + fpdfsdk/cpdfsdk_filewriteadapter.h | 29 ++ fpdfsdk/cpdfsdk_formfillenvironment.cpp | 2 +- fpdfsdk/cpdfsdk_helpers.h | 4 +- fpdfsdk/cpdfsdk_interform.cpp | 6 +- fpdfsdk/cpdfsdk_widget.cpp | 6 +- fpdfsdk/cpdfsdk_widget.h | 6 +- fpdfsdk/formfiller/cffl_combobox.cpp | 8 +- fpdfsdk/formfiller/cffl_combobox.h | 8 +- fpdfsdk/formfiller/cffl_formfiller.cpp | 8 +- fpdfsdk/formfiller/cffl_formfiller.h | 10 +- fpdfsdk/formfiller/cffl_interactiveformfiller.cpp | 26 +- fpdfsdk/formfiller/cffl_listbox.cpp | 2 +- fpdfsdk/formfiller/cffl_listbox.h | 2 +- fpdfsdk/formfiller/cffl_textfield.cpp | 8 +- fpdfsdk/formfiller/cffl_textfield.h | 8 +- fpdfsdk/fpdf_progressive.cpp | 6 +- fpdfsdk/fpdfformfill.cpp | 2 +- fpdfsdk/fpdfsave.cpp | 6 +- fpdfsdk/fpdfview.cpp | 6 +- fpdfsdk/fsdk_actionhandler.cpp | 551 ---------------------- fpdfsdk/fsdk_actionhandler.h | 129 ----- fpdfsdk/fsdk_baseform_embeddertest.cpp | 126 ----- fpdfsdk/fsdk_filewriteadapter.cpp | 22 - fpdfsdk/fsdk_filewriteadapter.h | 29 -- fpdfsdk/fsdk_pauseadapter.cpp | 16 - fpdfsdk/fsdk_pauseadapter.h | 26 - fpdfsdk/ipdfsdk_pauseadapter.cpp | 16 + fpdfsdk/ipdfsdk_pauseadapter.h | 26 + fpdfsdk/pdfsdk_fieldaction.cpp | 17 - fpdfsdk/pdfsdk_fieldaction.h | 38 -- 36 files changed, 1017 insertions(+), 1016 deletions(-) create mode 100644 fpdfsdk/cba_annotiterator_embeddertest.cpp create mode 100644 fpdfsdk/cpdfsdk_actionhandler.cpp create mode 100644 fpdfsdk/cpdfsdk_actionhandler.h create mode 100644 fpdfsdk/cpdfsdk_fieldaction.cpp create mode 100644 fpdfsdk/cpdfsdk_fieldaction.h create mode 100644 fpdfsdk/cpdfsdk_filewriteadapter.cpp create mode 100644 fpdfsdk/cpdfsdk_filewriteadapter.h delete mode 100644 fpdfsdk/fsdk_actionhandler.cpp delete mode 100644 fpdfsdk/fsdk_actionhandler.h delete mode 100644 fpdfsdk/fsdk_baseform_embeddertest.cpp delete mode 100644 fpdfsdk/fsdk_filewriteadapter.cpp delete mode 100644 fpdfsdk/fsdk_filewriteadapter.h delete mode 100644 fpdfsdk/fsdk_pauseadapter.cpp delete mode 100644 fpdfsdk/fsdk_pauseadapter.h create mode 100644 fpdfsdk/ipdfsdk_pauseadapter.cpp create mode 100644 fpdfsdk/ipdfsdk_pauseadapter.h delete mode 100644 fpdfsdk/pdfsdk_fieldaction.cpp delete mode 100644 fpdfsdk/pdfsdk_fieldaction.h (limited to 'fpdfsdk') diff --git a/fpdfsdk/cba_annotiterator_embeddertest.cpp b/fpdfsdk/cba_annotiterator_embeddertest.cpp new file mode 100644 index 0000000000..6198ee1eb4 --- /dev/null +++ b/fpdfsdk/cba_annotiterator_embeddertest.cpp @@ -0,0 +1,126 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "fpdfsdk/cba_annotiterator.h" +#include "fpdfsdk/cpdfsdk_annot.h" +#include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_helpers.h" +#include "testing/embedder_test.h" +#include "testing/embedder_test_mock_delegate.h" +#include "testing/embedder_test_timer_handling_delegate.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +void CheckRect(const CFX_FloatRect& actual, const CFX_FloatRect& expected) { + EXPECT_EQ(expected.left, actual.left); + EXPECT_EQ(expected.bottom, actual.bottom); + EXPECT_EQ(expected.right, actual.right); + EXPECT_EQ(expected.top, actual.top); +} + +} // namespace + +class CBA_AnnotIteratorTest : public EmbedderTest {}; + +TEST_F(CBA_AnnotIteratorTest, CBA_AnnotIterator) { + EXPECT_TRUE(OpenDocument("annotiter.pdf")); + FPDF_PAGE page0 = LoadPage(0); + FPDF_PAGE page1 = LoadPage(1); + FPDF_PAGE page2 = LoadPage(2); + ASSERT_TRUE(page0); + ASSERT_TRUE(page1); + ASSERT_TRUE(page2); + + CFX_FloatRect LeftBottom(200, 200, 220, 220); + CFX_FloatRect RightBottom(400, 201, 420, 221); + CFX_FloatRect LeftTop(201, 400, 221, 420); + CFX_FloatRect RightTop(401, 401, 421, 421); + + CPDFSDK_FormFillEnvironment* pFormFillEnv = + static_cast(form_handle()); + + { + // Page 0 specifies "row order". + CBA_AnnotIterator iter(pFormFillEnv->GetPageView(0), + CPDF_Annot::Subtype::WIDGET); + CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); + CheckRect(pAnnot->GetRect(), RightTop); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftTop); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightBottom); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftBottom); + pAnnot = iter.GetNextAnnot(pAnnot); + EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); + + pAnnot = iter.GetLastAnnot(); + CheckRect(pAnnot->GetRect(), LeftBottom); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightBottom); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftTop); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightTop); + pAnnot = iter.GetPrevAnnot(pAnnot); + EXPECT_EQ(iter.GetLastAnnot(), pAnnot); + } + { + // Page 1 specifies "column order" + CBA_AnnotIterator iter(pFormFillEnv->GetPageView(1), + CPDF_Annot::Subtype::WIDGET); + CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); + CheckRect(pAnnot->GetRect(), RightTop); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightBottom); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftTop); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftBottom); + pAnnot = iter.GetNextAnnot(pAnnot); + EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); + + pAnnot = iter.GetLastAnnot(); + CheckRect(pAnnot->GetRect(), LeftBottom); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftTop); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightBottom); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightTop); + pAnnot = iter.GetPrevAnnot(pAnnot); + EXPECT_EQ(iter.GetLastAnnot(), pAnnot); + } + { + // Page 2 specifies "struct order" + CBA_AnnotIterator iter(pFormFillEnv->GetPageView(2), + CPDF_Annot::Subtype::WIDGET); + CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); + CheckRect(pAnnot->GetRect(), LeftBottom); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightTop); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftTop); + pAnnot = iter.GetNextAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightBottom); + pAnnot = iter.GetNextAnnot(pAnnot); + EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); + + pAnnot = iter.GetLastAnnot(); + CheckRect(pAnnot->GetRect(), RightBottom); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftTop); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), RightTop); + pAnnot = iter.GetPrevAnnot(pAnnot); + CheckRect(pAnnot->GetRect(), LeftBottom); + pAnnot = iter.GetPrevAnnot(pAnnot); + EXPECT_EQ(iter.GetLastAnnot(), pAnnot); + } + UnloadPage(page2); + UnloadPage(page1); + UnloadPage(page0); +} diff --git a/fpdfsdk/cpdfsdk_actionhandler.cpp b/fpdfsdk/cpdfsdk_actionhandler.cpp new file mode 100644 index 0000000000..98c01240b2 --- /dev/null +++ b/fpdfsdk/cpdfsdk_actionhandler.cpp @@ -0,0 +1,551 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/cpdfsdk_actionhandler.h" + +#include +#include + +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfdoc/cpdf_formfield.h" +#include "core/fpdfdoc/cpdf_interform.h" +#include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_helpers.h" +#include "fpdfsdk/cpdfsdk_interform.h" +#include "fxjs/ijs_event_context.h" +#include "fxjs/ijs_runtime.h" +#include "third_party/base/logging.h" +#include "third_party/base/stl_util.h" + +bool CPDFSDK_ActionHandler::DoAction_DocOpen( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + std::set visited; + return ExecuteDocumentOpenAction(action, pFormFillEnv, &visited); +} + +bool CPDFSDK_ActionHandler::DoAction_JavaScript( + const CPDF_Action& JsAction, + WideString csJSName, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + if (JsAction.GetType() == CPDF_Action::JavaScript) { + WideString swJS = JsAction.GetJavaScript(); + if (!swJS.IsEmpty()) { + RunDocumentOpenJavaScript(pFormFillEnv, csJSName, swJS); + return true; + } + } + + return false; +} + +bool CPDFSDK_ActionHandler::DoAction_FieldJavaScript( + const CPDF_Action& JsAction, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_FormField* pFormField, + CPDFSDK_FieldAction* data) { + ASSERT(pFormFillEnv); + if (pFormFillEnv->IsJSPlatformPresent() && + JsAction.GetType() == CPDF_Action::JavaScript) { + WideString swJS = JsAction.GetJavaScript(); + if (!swJS.IsEmpty()) { + RunFieldJavaScript(pFormFillEnv, pFormField, type, data, swJS); + return true; + } + } + return false; +} + +bool CPDFSDK_ActionHandler::DoAction_Page( + const CPDF_Action& action, + enum CPDF_AAction::AActionType eType, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + std::set visited; + return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited); +} + +bool CPDFSDK_ActionHandler::DoAction_Document( + const CPDF_Action& action, + enum CPDF_AAction::AActionType eType, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + std::set visited; + return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited); +} + +bool CPDFSDK_ActionHandler::DoAction_BookMark( + CPDF_Bookmark* pBookMark, + const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + std::set visited; + return ExecuteBookMark(action, pFormFillEnv, pBookMark, &visited); +} + +bool CPDFSDK_ActionHandler::DoAction_Screen( + const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDFSDK_Annot* pScreen) { + std::set visited; + return ExecuteScreenAction(action, type, pFormFillEnv, pScreen, &visited); +} + +bool CPDFSDK_ActionHandler::DoAction_Link( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + std::set visited; + return ExecuteLinkAction(action, pFormFillEnv, &visited); +} + +bool CPDFSDK_ActionHandler::DoAction_Field( + const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_FormField* pFormField, + CPDFSDK_FieldAction* data) { + std::set visited; + return ExecuteFieldAction(action, type, pFormFillEnv, pFormField, data, + &visited); +} + +bool CPDFSDK_ActionHandler::ExecuteDocumentOpenAction( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + std::set* visited) { + CPDF_Dictionary* pDict = action.GetDict(); + if (pdfium::ContainsKey(*visited, pDict)) + return false; + + visited->insert(pDict); + + ASSERT(pFormFillEnv); + if (action.GetType() == CPDF_Action::JavaScript) { + if (pFormFillEnv->IsJSPlatformPresent()) { + WideString swJS = action.GetJavaScript(); + if (!swJS.IsEmpty()) + RunDocumentOpenJavaScript(pFormFillEnv, L"", swJS); + } + } else { + DoAction_NoJs(action, pFormFillEnv); + } + + for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { + CPDF_Action subaction = action.GetSubAction(i); + if (!ExecuteDocumentOpenAction(subaction, pFormFillEnv, visited)) + return false; + } + + return true; +} + +bool CPDFSDK_ActionHandler::ExecuteLinkAction( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + std::set* visited) { + CPDF_Dictionary* pDict = action.GetDict(); + if (pdfium::ContainsKey(*visited, pDict)) + return false; + + visited->insert(pDict); + + ASSERT(pFormFillEnv); + if (action.GetType() == CPDF_Action::JavaScript) { + RunScriptForAction(action, pFormFillEnv, + [pFormFillEnv](IJS_EventContext* context) { + context->OnLink_MouseUp(pFormFillEnv); + }); + } else { + DoAction_NoJs(action, pFormFillEnv); + } + + for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { + CPDF_Action subaction = action.GetSubAction(i); + if (!ExecuteLinkAction(subaction, pFormFillEnv, visited)) + return false; + } + + return true; +} + +bool CPDFSDK_ActionHandler::ExecuteDocumentPageAction( + const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + std::set* visited) { + CPDF_Dictionary* pDict = action.GetDict(); + if (pdfium::ContainsKey(*visited, pDict)) + return false; + + visited->insert(pDict); + + ASSERT(pFormFillEnv); + if (action.GetType() == CPDF_Action::JavaScript) { + if (pFormFillEnv->IsJSPlatformPresent()) { + WideString swJS = action.GetJavaScript(); + if (!swJS.IsEmpty()) + RunDocumentPageJavaScript(pFormFillEnv, type, swJS); + } + } else { + DoAction_NoJs(action, pFormFillEnv); + } + + ASSERT(pFormFillEnv); + + for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { + CPDF_Action subaction = action.GetSubAction(i); + if (!ExecuteDocumentPageAction(subaction, type, pFormFillEnv, visited)) + return false; + } + + return true; +} + +bool CPDFSDK_ActionHandler::IsValidField( + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_Dictionary* pFieldDict) { + ASSERT(pFieldDict); + + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); + CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); + return !!pPDFInterForm->GetFieldByDict(pFieldDict); +} + +bool CPDFSDK_ActionHandler::ExecuteFieldAction( + const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_FormField* pFormField, + CPDFSDK_FieldAction* data, + std::set* visited) { + CPDF_Dictionary* pDict = action.GetDict(); + if (pdfium::ContainsKey(*visited, pDict)) + return false; + + visited->insert(pDict); + + ASSERT(pFormFillEnv); + if (action.GetType() == CPDF_Action::JavaScript) { + if (pFormFillEnv->IsJSPlatformPresent()) { + WideString swJS = action.GetJavaScript(); + if (!swJS.IsEmpty()) { + RunFieldJavaScript(pFormFillEnv, pFormField, type, data, swJS); + if (!IsValidField(pFormFillEnv, pFormField->GetFieldDict())) + return false; + } + } + } else { + DoAction_NoJs(action, pFormFillEnv); + } + + for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { + CPDF_Action subaction = action.GetSubAction(i); + if (!ExecuteFieldAction(subaction, type, pFormFillEnv, pFormField, data, + visited)) + return false; + } + + return true; +} + +bool CPDFSDK_ActionHandler::ExecuteScreenAction( + const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDFSDK_Annot* pScreen, + std::set* visited) { + CPDF_Dictionary* pDict = action.GetDict(); + if (pdfium::ContainsKey(*visited, pDict)) + return false; + + visited->insert(pDict); + + ASSERT(pFormFillEnv); + if (action.GetType() == CPDF_Action::JavaScript) + RunScriptForAction(action, pFormFillEnv, [](IJS_EventContext*) {}); + else + DoAction_NoJs(action, pFormFillEnv); + + for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { + CPDF_Action subaction = action.GetSubAction(i); + if (!ExecuteScreenAction(subaction, type, pFormFillEnv, pScreen, visited)) + return false; + } + + return true; +} + +bool CPDFSDK_ActionHandler::ExecuteBookMark( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_Bookmark* pBookmark, + std::set* visited) { + CPDF_Dictionary* pDict = action.GetDict(); + if (pdfium::ContainsKey(*visited, pDict)) + return false; + + visited->insert(pDict); + + ASSERT(pFormFillEnv); + if (action.GetType() == CPDF_Action::JavaScript) { + RunScriptForAction(action, pFormFillEnv, + [pFormFillEnv, pBookmark](IJS_EventContext* context) { + context->OnBookmark_MouseUp(pBookmark); + }); + } else { + DoAction_NoJs(action, pFormFillEnv); + } + + for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { + CPDF_Action subaction = action.GetSubAction(i); + if (!ExecuteBookMark(subaction, pFormFillEnv, pBookmark, visited)) + return false; + } + + return true; +} + +void CPDFSDK_ActionHandler::DoAction_NoJs( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + ASSERT(pFormFillEnv); + + switch (action.GetType()) { + case CPDF_Action::GoTo: + DoAction_GoTo(pFormFillEnv, action); + break; + case CPDF_Action::URI: + DoAction_URI(pFormFillEnv, action); + break; + case CPDF_Action::Hide: + DoAction_Hide(action, pFormFillEnv); + break; + case CPDF_Action::Named: + DoAction_Named(pFormFillEnv, action); + break; + case CPDF_Action::SubmitForm: + DoAction_SubmitForm(action, pFormFillEnv); + break; + case CPDF_Action::ResetForm: + DoAction_ResetForm(action, pFormFillEnv); + break; + case CPDF_Action::JavaScript: + NOTREACHED(); + break; + case CPDF_Action::SetOCGState: + case CPDF_Action::Thread: + case CPDF_Action::Sound: + case CPDF_Action::Movie: + case CPDF_Action::Rendition: + case CPDF_Action::Trans: + case CPDF_Action::GoTo3DView: + case CPDF_Action::GoToR: + case CPDF_Action::GoToE: + case CPDF_Action::Launch: + case CPDF_Action::ImportData: + // Unimplemented + break; + default: + break; + } +} + +void CPDFSDK_ActionHandler::DoAction_GoTo( + CPDFSDK_FormFillEnvironment* pFormFillEnv, + const CPDF_Action& action) { + ASSERT(action.GetDict()); + + CPDF_Document* pPDFDocument = pFormFillEnv->GetPDFDocument(); + ASSERT(pPDFDocument); + + CPDF_Dest MyDest = action.GetDest(pPDFDocument); + int nPageIndex = MyDest.GetDestPageIndex(pPDFDocument); + int nFitType = MyDest.GetZoomMode(); + const CPDF_Array* pMyArray = ToArray(MyDest.GetObject()); + std::vector posArray; + if (pMyArray) { + for (size_t i = 2; i < pMyArray->GetCount(); i++) + posArray.push_back(pMyArray->GetFloatAt(i)); + } + pFormFillEnv->DoGoToAction(nPageIndex, nFitType, posArray.data(), + posArray.size()); +} + +void CPDFSDK_ActionHandler::DoAction_URI( + CPDFSDK_FormFillEnvironment* pFormFillEnv, + const CPDF_Action& action) { + ASSERT(action.GetDict()); + + ByteString sURI = action.GetURI(pFormFillEnv->GetPDFDocument()); + pFormFillEnv->DoURIAction(sURI.c_str()); +} + +void CPDFSDK_ActionHandler::DoAction_Named( + CPDFSDK_FormFillEnvironment* pFormFillEnv, + const CPDF_Action& action) { + ASSERT(action.GetDict()); + + ByteString csName = action.GetNamedAction(); + pFormFillEnv->ExecuteNamedAction(csName.c_str()); +} + +void CPDFSDK_ActionHandler::RunFieldJavaScript( + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_FormField* pFormField, + CPDF_AAction::AActionType type, + CPDFSDK_FieldAction* data, + const WideString& script) { + ASSERT(type != CPDF_AAction::Calculate); + ASSERT(type != CPDF_AAction::Format); + + RunScript( + pFormFillEnv, script, + [type, data, pFormField](IJS_EventContext* context) { + switch (type) { + case CPDF_AAction::CursorEnter: + context->OnField_MouseEnter(data->bModifier, data->bShift, + pFormField); + break; + case CPDF_AAction::CursorExit: + context->OnField_MouseExit(data->bModifier, data->bShift, + pFormField); + break; + case CPDF_AAction::ButtonDown: + context->OnField_MouseDown(data->bModifier, data->bShift, + pFormField); + break; + case CPDF_AAction::ButtonUp: + context->OnField_MouseUp(data->bModifier, data->bShift, pFormField); + break; + case CPDF_AAction::GetFocus: + context->OnField_Focus(data->bModifier, data->bShift, pFormField, + data->sValue); + break; + case CPDF_AAction::LoseFocus: + context->OnField_Blur(data->bModifier, data->bShift, pFormField, + data->sValue); + break; + case CPDF_AAction::KeyStroke: + context->OnField_Keystroke( + data->sChange, data->sChangeEx, data->bKeyDown, data->bModifier, + data->nSelEnd, data->nSelStart, data->bShift, pFormField, + data->sValue, data->bWillCommit, data->bFieldFull, data->bRC); + break; + case CPDF_AAction::Validate: + context->OnField_Validate( + data->sChange, data->sChangeEx, data->bKeyDown, data->bModifier, + data->bShift, pFormField, data->sValue, data->bRC); + break; + default: + NOTREACHED(); + break; + } + }); +} + +void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript( + CPDFSDK_FormFillEnvironment* pFormFillEnv, + const WideString& sScriptName, + const WideString& script) { + RunScript(pFormFillEnv, script, + [pFormFillEnv, sScriptName](IJS_EventContext* context) { + context->OnDoc_Open(pFormFillEnv, sScriptName); + }); +} + +void CPDFSDK_ActionHandler::RunDocumentPageJavaScript( + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_AAction::AActionType type, + const WideString& script) { + RunScript(pFormFillEnv, script, + [type, pFormFillEnv](IJS_EventContext* context) { + switch (type) { + case CPDF_AAction::OpenPage: + context->OnPage_Open(pFormFillEnv); + break; + case CPDF_AAction::ClosePage: + context->OnPage_Close(pFormFillEnv); + break; + case CPDF_AAction::CloseDocument: + context->OnDoc_WillClose(pFormFillEnv); + break; + case CPDF_AAction::SaveDocument: + context->OnDoc_WillSave(pFormFillEnv); + break; + case CPDF_AAction::DocumentSaved: + context->OnDoc_DidSave(pFormFillEnv); + break; + case CPDF_AAction::PrintDocument: + context->OnDoc_WillPrint(pFormFillEnv); + break; + case CPDF_AAction::DocumentPrinted: + context->OnDoc_DidPrint(pFormFillEnv); + break; + case CPDF_AAction::PageVisible: + context->OnPage_InView(pFormFillEnv); + break; + case CPDF_AAction::PageInvisible: + context->OnPage_OutView(pFormFillEnv); + break; + default: + NOTREACHED(); + break; + } + }); +} + +bool CPDFSDK_ActionHandler::DoAction_Hide( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); + if (pInterForm->DoAction_Hide(action)) { + pFormFillEnv->SetChangeMark(); + return true; + } + return false; +} + +bool CPDFSDK_ActionHandler::DoAction_SubmitForm( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); + return pInterForm->DoAction_SubmitForm(action); +} + +void CPDFSDK_ActionHandler::DoAction_ResetForm( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv) { + CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); + pInterForm->DoAction_ResetForm(action); +} + +void CPDFSDK_ActionHandler::RunScriptForAction( + const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + const RunScriptCallback& cb) { + if (!pFormFillEnv->IsJSPlatformPresent()) + return; + + WideString swJS = action.GetJavaScript(); + if (swJS.IsEmpty()) + return; + + RunScript(pFormFillEnv, swJS, cb); +} + +void CPDFSDK_ActionHandler::RunScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const WideString& script, + const RunScriptCallback& cb) { + IJS_Runtime* pRuntime = pFormFillEnv->GetIJSRuntime(); + IJS_EventContext* pContext = pRuntime->NewEventContext(); + + cb(pContext); + + WideString csInfo; + pContext->RunScript(script, &csInfo); + pRuntime->ReleaseEventContext(pContext); + // TODO(dsinclair): Return error if RunScript returns false. +} diff --git a/fpdfsdk/cpdfsdk_actionhandler.h b/fpdfsdk/cpdfsdk_actionhandler.h new file mode 100644 index 0000000000..78d3e22e4f --- /dev/null +++ b/fpdfsdk/cpdfsdk_actionhandler.h @@ -0,0 +1,129 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_CPDFSDK_ACTIONHANDLER_H_ +#define FPDFSDK_CPDFSDK_ACTIONHANDLER_H_ + +#include +#include + +#include "core/fpdfdoc/cpdf_aaction.h" +#include "core/fpdfdoc/cpdf_action.h" +#include "core/fxcrt/fx_string.h" +#include "fpdfsdk/cpdfsdk_fieldaction.h" + +class CPDFSDK_Annot; +class CPDFSDK_FormFillEnvironment; +class CPDF_Bookmark; +class CPDF_Dictionary; +class CPDF_FormField; +class IJS_EventContext; + +class CPDFSDK_ActionHandler { + public: + bool DoAction_DocOpen(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + bool DoAction_JavaScript(const CPDF_Action& JsAction, + WideString csJSName, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + bool DoAction_Page(const CPDF_Action& action, + enum CPDF_AAction::AActionType eType, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + bool DoAction_Document(const CPDF_Action& action, + enum CPDF_AAction::AActionType eType, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + bool DoAction_BookMark(CPDF_Bookmark* pBookMark, + const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + bool DoAction_Screen(const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDFSDK_Annot* pScreen); + bool DoAction_Link(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + bool DoAction_Field(const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_FormField* pFormField, + CPDFSDK_FieldAction* data); + bool DoAction_FieldJavaScript(const CPDF_Action& JsAction, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_FormField* pFormField, + CPDFSDK_FieldAction* data); + + private: + using RunScriptCallback = std::function; + + void RunScriptForAction(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + const RunScriptCallback& cb); + void RunScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const WideString& script, + const RunScriptCallback& cb); + + bool ExecuteDocumentOpenAction(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + std::set* visited); + bool ExecuteDocumentPageAction(const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + std::set* visited); + bool ExecuteFieldAction(const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_FormField* pFormField, + CPDFSDK_FieldAction* data, + std::set* visited); + bool ExecuteScreenAction(const CPDF_Action& action, + CPDF_AAction::AActionType type, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDFSDK_Annot* pScreen, + std::set* visited); + bool ExecuteBookMark(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_Bookmark* pBookmark, + std::set* visited); + bool ExecuteLinkAction(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + std::set* visited); + + void DoAction_NoJs(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + void RunDocumentPageJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_AAction::AActionType type, + const WideString& script); + void RunDocumentOpenJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const WideString& sScriptName, + const WideString& script); + void RunFieldJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_FormField* pFormField, + CPDF_AAction::AActionType type, + CPDFSDK_FieldAction* data, + const WideString& script); + + bool IsValidField(CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDF_Dictionary* pFieldDict); + + void DoAction_GoTo(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const CPDF_Action& action); + void DoAction_Launch(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const CPDF_Action& action); + void DoAction_URI(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const CPDF_Action& action); + void DoAction_Named(CPDFSDK_FormFillEnvironment* pFormFillEnv, + const CPDF_Action& action); + + bool DoAction_Hide(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + bool DoAction_SubmitForm(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv); + void DoAction_ResetForm(const CPDF_Action& action, + CPDFSDK_FormFillEnvironment* pFormFillEnv); +}; + +#endif // FPDFSDK_CPDFSDK_ACTIONHANDLER_H_ diff --git a/fpdfsdk/cpdfsdk_fieldaction.cpp b/fpdfsdk/cpdfsdk_fieldaction.cpp new file mode 100644 index 0000000000..352da391df --- /dev/null +++ b/fpdfsdk/cpdfsdk_fieldaction.cpp @@ -0,0 +1,17 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/cpdfsdk_fieldaction.h" + +CPDFSDK_FieldAction::CPDFSDK_FieldAction() + : bModifier(false), + bShift(false), + bKeyDown(false), + nSelEnd(0), + nSelStart(0), + bWillCommit(false), + bFieldFull(false), + bRC(true) {} diff --git a/fpdfsdk/cpdfsdk_fieldaction.h b/fpdfsdk/cpdfsdk_fieldaction.h new file mode 100644 index 0000000000..36a57e55d2 --- /dev/null +++ b/fpdfsdk/cpdfsdk_fieldaction.h @@ -0,0 +1,38 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_CPDFSDK_FIELDACTION_H_ +#define FPDFSDK_CPDFSDK_FIELDACTION_H_ + +#include "core/fxcrt/fx_string.h" + +#ifdef PDF_ENABLE_XFA +typedef enum { + PDFSDK_XFA_Click = 0, + PDFSDK_XFA_Full, + PDFSDK_XFA_PreOpen, + PDFSDK_XFA_PostOpen +} PDFSDK_XFAAActionType; +#endif // PDF_ENABLE_XFA + +struct CPDFSDK_FieldAction { + CPDFSDK_FieldAction(); + CPDFSDK_FieldAction(const CPDFSDK_FieldAction& other) = delete; + + bool bModifier; + bool bShift; + WideString sChange; + WideString sChangeEx; + bool bKeyDown; + int nSelEnd; + int nSelStart; + WideString sValue; + bool bWillCommit; + bool bFieldFull; + bool bRC; +}; + +#endif // FPDFSDK_CPDFSDK_FIELDACTION_H_ diff --git a/fpdfsdk/cpdfsdk_filewriteadapter.cpp b/fpdfsdk/cpdfsdk_filewriteadapter.cpp new file mode 100644 index 0000000000..8fc269402b --- /dev/null +++ b/fpdfsdk/cpdfsdk_filewriteadapter.cpp @@ -0,0 +1,23 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/cpdfsdk_filewriteadapter.h" + +CPDFSDK_FileWriteAdapter::CPDFSDK_FileWriteAdapter( + FPDF_FILEWRITE* fileWriteStruct) + : fileWriteStruct_(fileWriteStruct) { + ASSERT(fileWriteStruct_); +} + +CPDFSDK_FileWriteAdapter::~CPDFSDK_FileWriteAdapter() {} + +bool CPDFSDK_FileWriteAdapter::WriteBlock(const void* data, size_t size) { + return fileWriteStruct_->WriteBlock(fileWriteStruct_, data, size) != 0; +} + +bool CPDFSDK_FileWriteAdapter::WriteString(const ByteStringView& str) { + return WriteBlock(str.unterminated_c_str(), str.GetLength()); +} diff --git a/fpdfsdk/cpdfsdk_filewriteadapter.h b/fpdfsdk/cpdfsdk_filewriteadapter.h new file mode 100644 index 0000000000..a5b4dc89f9 --- /dev/null +++ b/fpdfsdk/cpdfsdk_filewriteadapter.h @@ -0,0 +1,29 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_CPDFSDK_FILEWRITEADAPTER_H_ +#define FPDFSDK_CPDFSDK_FILEWRITEADAPTER_H_ + +#include "core/fxcrt/fx_stream.h" +#include "core/fxcrt/retain_ptr.h" +#include "public/fpdf_save.h" + +class CPDFSDK_FileWriteAdapter : public IFX_WriteStream { + public: + template + friend RetainPtr pdfium::MakeRetain(Args&&... args); + + bool WriteBlock(const void* data, size_t size) override; + bool WriteString(const ByteStringView& str) override; + + private: + explicit CPDFSDK_FileWriteAdapter(FPDF_FILEWRITE* fileWriteStruct); + ~CPDFSDK_FileWriteAdapter() override; + + FPDF_FILEWRITE* fileWriteStruct_; +}; + +#endif // FPDFSDK_CPDFSDK_FILEWRITEADAPTER_H_ diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 156314fd5a..dd7d082312 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -11,12 +11,12 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfdoc/cpdf_docjsactions.h" +#include "fpdfsdk/cpdfsdk_actionhandler.h" #include "fpdfsdk/cpdfsdk_annothandlermgr.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" -#include "fpdfsdk/fsdk_actionhandler.h" #include "fxjs/ijs_runtime.h" #include "third_party/base/ptr_util.h" diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h index c2f6515cf9..dcd0cc9558 100644 --- a/fpdfsdk/cpdfsdk_helpers.h +++ b/fpdfsdk/cpdfsdk_helpers.h @@ -28,7 +28,7 @@ class CPDF_PageObject; class CPDF_PageRenderContext; class CPDF_PathObject; class CPDF_Stream; -class IFSDK_PAUSE_Adapter; +class IPDFSDK_PauseAdapter; class FX_PATHPOINT; // Object types for public FPDF_ types; these correspond to next layer down @@ -91,7 +91,7 @@ void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, int rotate, int flags, bool bNeedToRestore, - IFSDK_PAUSE_Adapter* pause); + IPDFSDK_PauseAdapter* pause); void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code); void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot); diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 9b1dbb75ef..22d1a47e33 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -22,13 +22,13 @@ #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "fpdfsdk/cba_annotiterator.h" +#include "fpdfsdk/cpdfsdk_actionhandler.h" #include "fpdfsdk/cpdfsdk_annot.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/fsdk_actionhandler.h" #include "fpdfsdk/ipdfsdk_annothandler.h" #include "fxjs/ijs_event_context.h" #include "fxjs/ijs_runtime.h" @@ -380,7 +380,7 @@ bool CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, return true; CPDFSDK_ActionHandler* pActionHandler = m_pFormFillEnv->GetActionHandler(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = false; fa.bShift = false; fa.sValue = csValue; @@ -400,7 +400,7 @@ bool CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, return true; CPDFSDK_ActionHandler* pActionHandler = m_pFormFillEnv->GetActionHandler(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = false; fa.bShift = false; fa.sValue = csValue; diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 23241953e4..3a49f9c6a0 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -23,12 +23,12 @@ #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/cpdfsdk_actionhandler.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/formfiller/cba_fontmap.h" -#include "fpdfsdk/fsdk_actionhandler.h" #include "fpdfsdk/pwl/cpwl_appstream.h" #include "fpdfsdk/pwl/cpwl_edit.h" @@ -210,7 +210,7 @@ bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { } bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, - PDFSDK_FieldAction* data, + CPDFSDK_FieldAction* data, CPDFSDK_PageView* pPageView) { CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); @@ -816,7 +816,7 @@ CFX_Color CPDFSDK_Widget::GetFillPWLColor() const { } bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, - PDFSDK_FieldAction* data, + CPDFSDK_FieldAction* data, CPDFSDK_PageView* pPageView) { CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h index c3257325e7..81d87376f9 100644 --- a/fpdfsdk/cpdfsdk_widget.h +++ b/fpdfsdk/cpdfsdk_widget.h @@ -17,7 +17,7 @@ #include "core/fxcrt/unowned_ptr.h" #include "core/fxge/cfx_color.h" #include "fpdfsdk/cpdfsdk_baannot.h" -#include "fpdfsdk/pdfsdk_fieldaction.h" +#include "fpdfsdk/cpdfsdk_fieldaction.h" class CFX_RenderDevice; class CPDF_Annot; @@ -42,7 +42,7 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT); bool OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, - PDFSDK_FieldAction* data, + CPDFSDK_FieldAction* data, CPDFSDK_PageView* pPageView); void Synchronize(bool bSynchronizeElse); @@ -100,7 +100,7 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { WideString OnFormat(bool& bFormatted); bool OnAAction(CPDF_AAction::AActionType type, - PDFSDK_FieldAction* data, + CPDFSDK_FieldAction* data, CPDFSDK_PageView* pPageView); CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm.Get(); } diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index 92dc8d621a..055b697669 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -123,7 +123,7 @@ void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) { void CFFL_ComboBox::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) { + CPDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::KeyStroke: if (CPWL_ComboBox* pComboBox = @@ -164,7 +164,7 @@ void CFFL_ComboBox::GetActionData(CPDFSDK_PageView* pPageView, void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) { + const CPDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::KeyStroke: if (CPWL_ComboBox* pComboBox = @@ -181,8 +181,8 @@ void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, } bool CFFL_ComboBox::IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) { + const CPDFSDK_FieldAction& faOld, + const CPDFSDK_FieldAction& faNew) { switch (type) { case CPDF_AAction::KeyStroke: return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || diff --git a/fpdfsdk/formfiller/cffl_combobox.h b/fpdfsdk/formfiller/cffl_combobox.h index bdc0934862..7a6390e491 100644 --- a/fpdfsdk/formfiller/cffl_combobox.h +++ b/fpdfsdk/formfiller/cffl_combobox.h @@ -33,13 +33,13 @@ class CFFL_ComboBox : public CFFL_TextObject, void SaveData(CPDFSDK_PageView* pPageView) override; void GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) override; + CPDFSDK_FieldAction& fa) override; void SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) override; + const CPDFSDK_FieldAction& fa) override; bool IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) override; + const CPDFSDK_FieldAction& faOld, + const CPDFSDK_FieldAction& faNew) override; void SaveState(CPDFSDK_PageView* pPageView) override; void RestoreState(CPDFSDK_PageView* pPageView) override; #ifdef PDF_ENABLE_XFA diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index 6ec7e266e3..dcbe0181f3 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -524,17 +524,17 @@ void CFFL_FormFiller::SetChangeMark() { void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) { + CPDFSDK_FieldAction& fa) { fa.sValue = m_pWidget->GetValue(); } void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) {} + const CPDFSDK_FieldAction& fa) {} bool CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) { + const CPDFSDK_FieldAction& faOld, + const CPDFSDK_FieldAction& faNew) { return false; } diff --git a/fpdfsdk/formfiller/cffl_formfiller.h b/fpdfsdk/formfiller/cffl_formfiller.h index 11a2f8c935..0dfb0bb177 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.h +++ b/fpdfsdk/formfiller/cffl_formfiller.h @@ -10,9 +10,9 @@ #include #include "core/fxcrt/unowned_ptr.h" +#include "fpdfsdk/cpdfsdk_fieldaction.h" #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" -#include "fpdfsdk/pdfsdk_fieldaction.h" class CPDFSDK_Annot; class CPDFSDK_FormFillEnvironment; @@ -90,13 +90,13 @@ class CFFL_FormFiller : public CPWL_Wnd::ProviderIface, virtual void GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa); + CPDFSDK_FieldAction& fa); virtual void SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa); + const CPDFSDK_FieldAction& fa); virtual bool IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew); + const CPDFSDK_FieldAction& faOld, + const CPDFSDK_FieldAction& faNew); virtual void SaveState(CPDFSDK_PageView* pPageView); virtual void RestoreState(CPDFSDK_PageView* pPageView); diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index f33bde68cc..83b425725a 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -126,7 +126,7 @@ void CFFL_InteractiveFormFiller::OnMouseEnter( pWidget->ClearAppModified(); ASSERT(pPageView); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); pWidget->OnAAction(CPDF_AAction::CursorEnter, &fa, pPageView); @@ -159,7 +159,7 @@ void CFFL_InteractiveFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, pWidget->ClearAppModified(); ASSERT(pPageView); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); pWidget->OnAAction(CPDF_AAction::CursorExit, &fa, pPageView); @@ -195,7 +195,7 @@ bool CFFL_InteractiveFormFiller::OnLButtonDown( pWidget->ClearAppModified(); ASSERT(pPageView); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlags); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlags); pWidget->OnAAction(CPDF_AAction::ButtonDown, &fa, pPageView); @@ -273,7 +273,7 @@ bool CFFL_InteractiveFormFiller::OnButtonUp(CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nValueAge = pWidget->GetValueAge(); ASSERT(pPageView); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); pWidget->OnAAction(CPDF_AAction::ButtonUp, &fa, pPageView); @@ -385,7 +385,7 @@ bool CFFL_InteractiveFormFiller::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView(); ASSERT(pPageView); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); pFormFiller->GetActionData(pPageView, CPDF_AAction::GetFocus, fa); @@ -436,7 +436,7 @@ bool CFFL_InteractiveFormFiller::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView = pWidget->GetPageView(); ASSERT(pPageView); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa); @@ -611,7 +611,7 @@ bool CFFL_InteractiveFormFiller::OnKeyStrokeCommit( m_bNotifying = true; pWidget->ClearAppModified(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); fa.bWillCommit = true; @@ -643,7 +643,7 @@ bool CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot, m_bNotifying = true; pWidget->ClearAppModified(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); fa.bKeyDown = true; @@ -712,7 +712,7 @@ bool CFFL_InteractiveFormFiller::OnClick(CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); @@ -742,7 +742,7 @@ bool CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); @@ -795,7 +795,7 @@ bool CFFL_InteractiveFormFiller::OnPreOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); @@ -826,7 +826,7 @@ bool CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); @@ -884,7 +884,7 @@ std::pair CFFL_InteractiveFormFiller::OnBeforeKeyStroke( CPDFSDK_FormFillEnvironment* pFormFillEnv = privateData.pPageView->GetFormFillEnv(); - PDFSDK_FieldAction fa; + CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); fa.sChange = strChange; diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index 41e4774218..943412d509 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -134,7 +134,7 @@ void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) { void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) { + CPDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::Validate: if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { diff --git a/fpdfsdk/formfiller/cffl_listbox.h b/fpdfsdk/formfiller/cffl_listbox.h index 014865d567..9db3c5da1d 100644 --- a/fpdfsdk/formfiller/cffl_listbox.h +++ b/fpdfsdk/formfiller/cffl_listbox.h @@ -27,7 +27,7 @@ class CFFL_ListBox : public CFFL_TextObject { void SaveData(CPDFSDK_PageView* pPageView) override; void GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) override; + CPDFSDK_FieldAction& fa) override; void SaveState(CPDFSDK_PageView* pPageView) override; void RestoreState(CPDFSDK_PageView* pPageView) override; diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index 6d7277c8fa..eeed266235 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -156,7 +156,7 @@ void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) { + CPDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::KeyStroke: if (CPWL_Edit* pWnd = GetEdit(pPageView, false)) { @@ -186,7 +186,7 @@ void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) { + const CPDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::KeyStroke: if (CPWL_Edit* pEdit = GetEdit(pPageView, false)) { @@ -201,8 +201,8 @@ void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, } bool CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) { + const CPDFSDK_FieldAction& faOld, + const CPDFSDK_FieldAction& faNew) { switch (type) { case CPDF_AAction::KeyStroke: return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || diff --git a/fpdfsdk/formfiller/cffl_textfield.h b/fpdfsdk/formfiller/cffl_textfield.h index 49ffc0fc33..4d34d055a5 100644 --- a/fpdfsdk/formfiller/cffl_textfield.h +++ b/fpdfsdk/formfiller/cffl_textfield.h @@ -38,13 +38,13 @@ class CFFL_TextField : public CFFL_TextObject, void SaveData(CPDFSDK_PageView* pPageView) override; void GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) override; + CPDFSDK_FieldAction& fa) override; void SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) override; + const CPDFSDK_FieldAction& fa) override; bool IsActionDataChanged(CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) override; + const CPDFSDK_FieldAction& faOld, + const CPDFSDK_FieldAction& faNew) override; void SaveState(CPDFSDK_PageView* pPageView) override; void RestoreState(CPDFSDK_PageView* pPageView) override; #ifdef PDF_ENABLE_XFA diff --git a/fpdfsdk/fpdf_progressive.cpp b/fpdfsdk/fpdf_progressive.cpp index d53ab15d0e..6ac6686ac8 100644 --- a/fpdfsdk/fpdf_progressive.cpp +++ b/fpdfsdk/fpdf_progressive.cpp @@ -15,7 +15,7 @@ #include "core/fxge/cfx_defaultrenderdevice.h" #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "fpdfsdk/fsdk_pauseadapter.h" +#include "fpdfsdk/ipdfsdk_pauseadapter.h" #include "public/fpdfview.h" #include "third_party/base/ptr_util.h" @@ -56,7 +56,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, pContext->m_pDevice = std::move(pOwnedDevice); pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); - IFSDK_PAUSE_Adapter IPauseAdapter(pause); + IPDFSDK_PauseAdapter IPauseAdapter(pause); FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, rotate, flags, false, &IPauseAdapter); @@ -82,7 +82,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPage_Continue(FPDF_PAGE page, CPDF_PageRenderContext* pContext = pPage->GetRenderContext(); if (pContext && pContext->m_pRenderer) { - IFSDK_PAUSE_Adapter IPauseAdapter(pause); + IPDFSDK_PauseAdapter IPauseAdapter(pause); pContext->m_pRenderer->Continue(&IPauseAdapter); #ifdef _SKIA_SUPPORT_PATHS_ CFX_RenderDevice* pDevice = pContext->m_pDevice.get(); diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 6cf587c7ac..ddd460da05 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -17,11 +17,11 @@ #include "core/fpdfdoc/cpdf_interform.h" #include "core/fpdfdoc/cpdf_occontext.h" #include "core/fxge/cfx_defaultrenderdevice.h" +#include "fpdfsdk/cpdfsdk_actionhandler.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/fsdk_actionhandler.h" #include "public/fpdfview.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index 2c615f434c..da3e12fc9c 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -18,8 +18,8 @@ #include "core/fpdfapi/parser/cpdf_string.h" #include "core/fxcrt/cfx_memorystream.h" #include "core/fxcrt/fx_extension.h" +#include "fpdfsdk/cpdfsdk_filewriteadapter.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "fpdfsdk/fsdk_filewriteadapter.h" #include "public/fpdf_edit.h" #ifdef PDF_ENABLE_XFA @@ -254,8 +254,8 @@ bool FPDF_Doc_Save(FPDF_DOCUMENT document, if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) flags = 0; - CPDF_Creator fileMaker(pPDFDoc, - pdfium::MakeRetain(pFileWrite)); + CPDF_Creator fileMaker( + pPDFDoc, pdfium::MakeRetain(pFileWrite)); if (bSetVersion) fileMaker.SetFileVersion(fileVerion); if (flags == FPDF_REMOVE_SECURITY) { diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index ff2a4633f1..187db9b126 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -35,7 +35,7 @@ #include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_memoryaccess.h" #include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/fsdk_pauseadapter.h" +#include "fpdfsdk/ipdfsdk_pauseadapter.h" #include "fxjs/ijs_runtime.h" #include "public/fpdf_formfill.h" #include "third_party/base/ptr_util.h" @@ -71,7 +71,7 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext, const FX_RECT& clipping_rect, int flags, bool bNeedToRestore, - IFSDK_PAUSE_Adapter* pause) { + IPDFSDK_PauseAdapter* pause) { if (!pContext->m_pOptions) pContext->m_pOptions = pdfium::MakeUnique(); @@ -899,7 +899,7 @@ void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, int rotate, int flags, bool bNeedToRestore, - IFSDK_PAUSE_Adapter* pause) { + IPDFSDK_PauseAdapter* pause) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return; diff --git a/fpdfsdk/fsdk_actionhandler.cpp b/fpdfsdk/fsdk_actionhandler.cpp deleted file mode 100644 index 73c7d84f69..0000000000 --- a/fpdfsdk/fsdk_actionhandler.cpp +++ /dev/null @@ -1,551 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/fsdk_actionhandler.h" - -#include -#include - -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfdoc/cpdf_formfield.h" -#include "core/fpdfdoc/cpdf_interform.h" -#include "fpdfsdk/cpdfsdk_formfillenvironment.h" -#include "fpdfsdk/cpdfsdk_helpers.h" -#include "fpdfsdk/cpdfsdk_interform.h" -#include "fxjs/ijs_event_context.h" -#include "fxjs/ijs_runtime.h" -#include "third_party/base/logging.h" -#include "third_party/base/stl_util.h" - -bool CPDFSDK_ActionHandler::DoAction_DocOpen( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - std::set visited; - return ExecuteDocumentOpenAction(action, pFormFillEnv, &visited); -} - -bool CPDFSDK_ActionHandler::DoAction_JavaScript( - const CPDF_Action& JsAction, - WideString csJSName, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - if (JsAction.GetType() == CPDF_Action::JavaScript) { - WideString swJS = JsAction.GetJavaScript(); - if (!swJS.IsEmpty()) { - RunDocumentOpenJavaScript(pFormFillEnv, csJSName, swJS); - return true; - } - } - - return false; -} - -bool CPDFSDK_ActionHandler::DoAction_FieldJavaScript( - const CPDF_Action& JsAction, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_FormField* pFormField, - PDFSDK_FieldAction* data) { - ASSERT(pFormFillEnv); - if (pFormFillEnv->IsJSPlatformPresent() && - JsAction.GetType() == CPDF_Action::JavaScript) { - WideString swJS = JsAction.GetJavaScript(); - if (!swJS.IsEmpty()) { - RunFieldJavaScript(pFormFillEnv, pFormField, type, data, swJS); - return true; - } - } - return false; -} - -bool CPDFSDK_ActionHandler::DoAction_Page( - const CPDF_Action& action, - enum CPDF_AAction::AActionType eType, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - std::set visited; - return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited); -} - -bool CPDFSDK_ActionHandler::DoAction_Document( - const CPDF_Action& action, - enum CPDF_AAction::AActionType eType, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - std::set visited; - return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited); -} - -bool CPDFSDK_ActionHandler::DoAction_BookMark( - CPDF_Bookmark* pBookMark, - const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - std::set visited; - return ExecuteBookMark(action, pFormFillEnv, pBookMark, &visited); -} - -bool CPDFSDK_ActionHandler::DoAction_Screen( - const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDFSDK_Annot* pScreen) { - std::set visited; - return ExecuteScreenAction(action, type, pFormFillEnv, pScreen, &visited); -} - -bool CPDFSDK_ActionHandler::DoAction_Link( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - std::set visited; - return ExecuteLinkAction(action, pFormFillEnv, &visited); -} - -bool CPDFSDK_ActionHandler::DoAction_Field( - const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_FormField* pFormField, - PDFSDK_FieldAction* data) { - std::set visited; - return ExecuteFieldAction(action, type, pFormFillEnv, pFormField, data, - &visited); -} - -bool CPDFSDK_ActionHandler::ExecuteDocumentOpenAction( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - std::set* visited) { - CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) - return false; - - visited->insert(pDict); - - ASSERT(pFormFillEnv); - if (action.GetType() == CPDF_Action::JavaScript) { - if (pFormFillEnv->IsJSPlatformPresent()) { - WideString swJS = action.GetJavaScript(); - if (!swJS.IsEmpty()) - RunDocumentOpenJavaScript(pFormFillEnv, L"", swJS); - } - } else { - DoAction_NoJs(action, pFormFillEnv); - } - - for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { - CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteDocumentOpenAction(subaction, pFormFillEnv, visited)) - return false; - } - - return true; -} - -bool CPDFSDK_ActionHandler::ExecuteLinkAction( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - std::set* visited) { - CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) - return false; - - visited->insert(pDict); - - ASSERT(pFormFillEnv); - if (action.GetType() == CPDF_Action::JavaScript) { - RunScriptForAction(action, pFormFillEnv, - [pFormFillEnv](IJS_EventContext* context) { - context->OnLink_MouseUp(pFormFillEnv); - }); - } else { - DoAction_NoJs(action, pFormFillEnv); - } - - for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { - CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteLinkAction(subaction, pFormFillEnv, visited)) - return false; - } - - return true; -} - -bool CPDFSDK_ActionHandler::ExecuteDocumentPageAction( - const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - std::set* visited) { - CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) - return false; - - visited->insert(pDict); - - ASSERT(pFormFillEnv); - if (action.GetType() == CPDF_Action::JavaScript) { - if (pFormFillEnv->IsJSPlatformPresent()) { - WideString swJS = action.GetJavaScript(); - if (!swJS.IsEmpty()) - RunDocumentPageJavaScript(pFormFillEnv, type, swJS); - } - } else { - DoAction_NoJs(action, pFormFillEnv); - } - - ASSERT(pFormFillEnv); - - for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { - CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteDocumentPageAction(subaction, type, pFormFillEnv, visited)) - return false; - } - - return true; -} - -bool CPDFSDK_ActionHandler::IsValidField( - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_Dictionary* pFieldDict) { - ASSERT(pFieldDict); - - CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); - CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); - return !!pPDFInterForm->GetFieldByDict(pFieldDict); -} - -bool CPDFSDK_ActionHandler::ExecuteFieldAction( - const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_FormField* pFormField, - PDFSDK_FieldAction* data, - std::set* visited) { - CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) - return false; - - visited->insert(pDict); - - ASSERT(pFormFillEnv); - if (action.GetType() == CPDF_Action::JavaScript) { - if (pFormFillEnv->IsJSPlatformPresent()) { - WideString swJS = action.GetJavaScript(); - if (!swJS.IsEmpty()) { - RunFieldJavaScript(pFormFillEnv, pFormField, type, data, swJS); - if (!IsValidField(pFormFillEnv, pFormField->GetFieldDict())) - return false; - } - } - } else { - DoAction_NoJs(action, pFormFillEnv); - } - - for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { - CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteFieldAction(subaction, type, pFormFillEnv, pFormField, data, - visited)) - return false; - } - - return true; -} - -bool CPDFSDK_ActionHandler::ExecuteScreenAction( - const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDFSDK_Annot* pScreen, - std::set* visited) { - CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) - return false; - - visited->insert(pDict); - - ASSERT(pFormFillEnv); - if (action.GetType() == CPDF_Action::JavaScript) - RunScriptForAction(action, pFormFillEnv, [](IJS_EventContext*) {}); - else - DoAction_NoJs(action, pFormFillEnv); - - for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { - CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteScreenAction(subaction, type, pFormFillEnv, pScreen, visited)) - return false; - } - - return true; -} - -bool CPDFSDK_ActionHandler::ExecuteBookMark( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_Bookmark* pBookmark, - std::set* visited) { - CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) - return false; - - visited->insert(pDict); - - ASSERT(pFormFillEnv); - if (action.GetType() == CPDF_Action::JavaScript) { - RunScriptForAction(action, pFormFillEnv, - [pFormFillEnv, pBookmark](IJS_EventContext* context) { - context->OnBookmark_MouseUp(pBookmark); - }); - } else { - DoAction_NoJs(action, pFormFillEnv); - } - - for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { - CPDF_Action subaction = action.GetSubAction(i); - if (!ExecuteBookMark(subaction, pFormFillEnv, pBookmark, visited)) - return false; - } - - return true; -} - -void CPDFSDK_ActionHandler::DoAction_NoJs( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - ASSERT(pFormFillEnv); - - switch (action.GetType()) { - case CPDF_Action::GoTo: - DoAction_GoTo(pFormFillEnv, action); - break; - case CPDF_Action::URI: - DoAction_URI(pFormFillEnv, action); - break; - case CPDF_Action::Hide: - DoAction_Hide(action, pFormFillEnv); - break; - case CPDF_Action::Named: - DoAction_Named(pFormFillEnv, action); - break; - case CPDF_Action::SubmitForm: - DoAction_SubmitForm(action, pFormFillEnv); - break; - case CPDF_Action::ResetForm: - DoAction_ResetForm(action, pFormFillEnv); - break; - case CPDF_Action::JavaScript: - NOTREACHED(); - break; - case CPDF_Action::SetOCGState: - case CPDF_Action::Thread: - case CPDF_Action::Sound: - case CPDF_Action::Movie: - case CPDF_Action::Rendition: - case CPDF_Action::Trans: - case CPDF_Action::GoTo3DView: - case CPDF_Action::GoToR: - case CPDF_Action::GoToE: - case CPDF_Action::Launch: - case CPDF_Action::ImportData: - // Unimplemented - break; - default: - break; - } -} - -void CPDFSDK_ActionHandler::DoAction_GoTo( - CPDFSDK_FormFillEnvironment* pFormFillEnv, - const CPDF_Action& action) { - ASSERT(action.GetDict()); - - CPDF_Document* pPDFDocument = pFormFillEnv->GetPDFDocument(); - ASSERT(pPDFDocument); - - CPDF_Dest MyDest = action.GetDest(pPDFDocument); - int nPageIndex = MyDest.GetDestPageIndex(pPDFDocument); - int nFitType = MyDest.GetZoomMode(); - const CPDF_Array* pMyArray = ToArray(MyDest.GetObject()); - std::vector posArray; - if (pMyArray) { - for (size_t i = 2; i < pMyArray->GetCount(); i++) - posArray.push_back(pMyArray->GetFloatAt(i)); - } - pFormFillEnv->DoGoToAction(nPageIndex, nFitType, posArray.data(), - posArray.size()); -} - -void CPDFSDK_ActionHandler::DoAction_URI( - CPDFSDK_FormFillEnvironment* pFormFillEnv, - const CPDF_Action& action) { - ASSERT(action.GetDict()); - - ByteString sURI = action.GetURI(pFormFillEnv->GetPDFDocument()); - pFormFillEnv->DoURIAction(sURI.c_str()); -} - -void CPDFSDK_ActionHandler::DoAction_Named( - CPDFSDK_FormFillEnvironment* pFormFillEnv, - const CPDF_Action& action) { - ASSERT(action.GetDict()); - - ByteString csName = action.GetNamedAction(); - pFormFillEnv->ExecuteNamedAction(csName.c_str()); -} - -void CPDFSDK_ActionHandler::RunFieldJavaScript( - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_FormField* pFormField, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction* data, - const WideString& script) { - ASSERT(type != CPDF_AAction::Calculate); - ASSERT(type != CPDF_AAction::Format); - - RunScript( - pFormFillEnv, script, - [type, data, pFormField](IJS_EventContext* context) { - switch (type) { - case CPDF_AAction::CursorEnter: - context->OnField_MouseEnter(data->bModifier, data->bShift, - pFormField); - break; - case CPDF_AAction::CursorExit: - context->OnField_MouseExit(data->bModifier, data->bShift, - pFormField); - break; - case CPDF_AAction::ButtonDown: - context->OnField_MouseDown(data->bModifier, data->bShift, - pFormField); - break; - case CPDF_AAction::ButtonUp: - context->OnField_MouseUp(data->bModifier, data->bShift, pFormField); - break; - case CPDF_AAction::GetFocus: - context->OnField_Focus(data->bModifier, data->bShift, pFormField, - data->sValue); - break; - case CPDF_AAction::LoseFocus: - context->OnField_Blur(data->bModifier, data->bShift, pFormField, - data->sValue); - break; - case CPDF_AAction::KeyStroke: - context->OnField_Keystroke( - data->sChange, data->sChangeEx, data->bKeyDown, data->bModifier, - data->nSelEnd, data->nSelStart, data->bShift, pFormField, - data->sValue, data->bWillCommit, data->bFieldFull, data->bRC); - break; - case CPDF_AAction::Validate: - context->OnField_Validate( - data->sChange, data->sChangeEx, data->bKeyDown, data->bModifier, - data->bShift, pFormField, data->sValue, data->bRC); - break; - default: - NOTREACHED(); - break; - } - }); -} - -void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript( - CPDFSDK_FormFillEnvironment* pFormFillEnv, - const WideString& sScriptName, - const WideString& script) { - RunScript(pFormFillEnv, script, - [pFormFillEnv, sScriptName](IJS_EventContext* context) { - context->OnDoc_Open(pFormFillEnv, sScriptName); - }); -} - -void CPDFSDK_ActionHandler::RunDocumentPageJavaScript( - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_AAction::AActionType type, - const WideString& script) { - RunScript(pFormFillEnv, script, - [type, pFormFillEnv](IJS_EventContext* context) { - switch (type) { - case CPDF_AAction::OpenPage: - context->OnPage_Open(pFormFillEnv); - break; - case CPDF_AAction::ClosePage: - context->OnPage_Close(pFormFillEnv); - break; - case CPDF_AAction::CloseDocument: - context->OnDoc_WillClose(pFormFillEnv); - break; - case CPDF_AAction::SaveDocument: - context->OnDoc_WillSave(pFormFillEnv); - break; - case CPDF_AAction::DocumentSaved: - context->OnDoc_DidSave(pFormFillEnv); - break; - case CPDF_AAction::PrintDocument: - context->OnDoc_WillPrint(pFormFillEnv); - break; - case CPDF_AAction::DocumentPrinted: - context->OnDoc_DidPrint(pFormFillEnv); - break; - case CPDF_AAction::PageVisible: - context->OnPage_InView(pFormFillEnv); - break; - case CPDF_AAction::PageInvisible: - context->OnPage_OutView(pFormFillEnv); - break; - default: - NOTREACHED(); - break; - } - }); -} - -bool CPDFSDK_ActionHandler::DoAction_Hide( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); - if (pInterForm->DoAction_Hide(action)) { - pFormFillEnv->SetChangeMark(); - return true; - } - return false; -} - -bool CPDFSDK_ActionHandler::DoAction_SubmitForm( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); - return pInterForm->DoAction_SubmitForm(action); -} - -void CPDFSDK_ActionHandler::DoAction_ResetForm( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); - pInterForm->DoAction_ResetForm(action); -} - -void CPDFSDK_ActionHandler::RunScriptForAction( - const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - const RunScriptCallback& cb) { - if (!pFormFillEnv->IsJSPlatformPresent()) - return; - - WideString swJS = action.GetJavaScript(); - if (swJS.IsEmpty()) - return; - - RunScript(pFormFillEnv, swJS, cb); -} - -void CPDFSDK_ActionHandler::RunScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const WideString& script, - const RunScriptCallback& cb) { - IJS_Runtime* pRuntime = pFormFillEnv->GetIJSRuntime(); - IJS_EventContext* pContext = pRuntime->NewEventContext(); - - cb(pContext); - - WideString csInfo; - pContext->RunScript(script, &csInfo); - pRuntime->ReleaseEventContext(pContext); - // TODO(dsinclair): Return error if RunScript returns false. -} diff --git a/fpdfsdk/fsdk_actionhandler.h b/fpdfsdk/fsdk_actionhandler.h deleted file mode 100644 index 0e5af1a41a..0000000000 --- a/fpdfsdk/fsdk_actionhandler.h +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_FSDK_ACTIONHANDLER_H_ -#define FPDFSDK_FSDK_ACTIONHANDLER_H_ - -#include -#include - -#include "core/fpdfdoc/cpdf_aaction.h" -#include "core/fpdfdoc/cpdf_action.h" -#include "core/fxcrt/fx_string.h" -#include "fpdfsdk/pdfsdk_fieldaction.h" - -class CPDFSDK_Annot; -class CPDFSDK_FormFillEnvironment; -class CPDF_Bookmark; -class CPDF_Dictionary; -class CPDF_FormField; -class IJS_EventContext; - -class CPDFSDK_ActionHandler { - public: - bool DoAction_DocOpen(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - bool DoAction_JavaScript(const CPDF_Action& JsAction, - WideString csJSName, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - bool DoAction_Page(const CPDF_Action& action, - enum CPDF_AAction::AActionType eType, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - bool DoAction_Document(const CPDF_Action& action, - enum CPDF_AAction::AActionType eType, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - bool DoAction_BookMark(CPDF_Bookmark* pBookMark, - const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - bool DoAction_Screen(const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDFSDK_Annot* pScreen); - bool DoAction_Link(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - bool DoAction_Field(const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_FormField* pFormField, - PDFSDK_FieldAction* data); - bool DoAction_FieldJavaScript(const CPDF_Action& JsAction, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_FormField* pFormField, - PDFSDK_FieldAction* data); - - private: - using RunScriptCallback = std::function; - - void RunScriptForAction(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - const RunScriptCallback& cb); - void RunScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const WideString& script, - const RunScriptCallback& cb); - - bool ExecuteDocumentOpenAction(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - std::set* visited); - bool ExecuteDocumentPageAction(const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - std::set* visited); - bool ExecuteFieldAction(const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_FormField* pFormField, - PDFSDK_FieldAction* data, - std::set* visited); - bool ExecuteScreenAction(const CPDF_Action& action, - CPDF_AAction::AActionType type, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDFSDK_Annot* pScreen, - std::set* visited); - bool ExecuteBookMark(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_Bookmark* pBookmark, - std::set* visited); - bool ExecuteLinkAction(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - std::set* visited); - - void DoAction_NoJs(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - void RunDocumentPageJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_AAction::AActionType type, - const WideString& script); - void RunDocumentOpenJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const WideString& sScriptName, - const WideString& script); - void RunFieldJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_FormField* pFormField, - CPDF_AAction::AActionType type, - PDFSDK_FieldAction* data, - const WideString& script); - - bool IsValidField(CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDF_Dictionary* pFieldDict); - - void DoAction_GoTo(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const CPDF_Action& action); - void DoAction_Launch(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const CPDF_Action& action); - void DoAction_URI(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const CPDF_Action& action); - void DoAction_Named(CPDFSDK_FormFillEnvironment* pFormFillEnv, - const CPDF_Action& action); - - bool DoAction_Hide(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - bool DoAction_SubmitForm(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv); - void DoAction_ResetForm(const CPDF_Action& action, - CPDFSDK_FormFillEnvironment* pFormFillEnv); -}; - -#endif // FPDFSDK_FSDK_ACTIONHANDLER_H_ diff --git a/fpdfsdk/fsdk_baseform_embeddertest.cpp b/fpdfsdk/fsdk_baseform_embeddertest.cpp deleted file mode 100644 index 9f2c606309..0000000000 --- a/fpdfsdk/fsdk_baseform_embeddertest.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "fpdfsdk/cba_annotiterator.h" -#include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/cpdfsdk_formfillenvironment.h" -#include "fpdfsdk/cpdfsdk_helpers.h" -#include "testing/embedder_test.h" -#include "testing/embedder_test_mock_delegate.h" -#include "testing/embedder_test_timer_handling_delegate.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -void CheckRect(const CFX_FloatRect& actual, const CFX_FloatRect& expected) { - EXPECT_EQ(expected.left, actual.left); - EXPECT_EQ(expected.bottom, actual.bottom); - EXPECT_EQ(expected.right, actual.right); - EXPECT_EQ(expected.top, actual.top); -} - -} // namespace - -class FSDKBaseFormEmbeddertest : public EmbedderTest {}; - -TEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) { - EXPECT_TRUE(OpenDocument("annotiter.pdf")); - FPDF_PAGE page0 = LoadPage(0); - FPDF_PAGE page1 = LoadPage(1); - FPDF_PAGE page2 = LoadPage(2); - EXPECT_TRUE(page0); - EXPECT_TRUE(page1); - EXPECT_TRUE(page2); - - CFX_FloatRect LeftBottom(200, 200, 220, 220); - CFX_FloatRect RightBottom(400, 201, 420, 221); - CFX_FloatRect LeftTop(201, 400, 221, 420); - CFX_FloatRect RightTop(401, 401, 421, 421); - - CPDFSDK_FormFillEnvironment* pFormFillEnv = - static_cast(form_handle()); - - { - // Page 0 specifies "row order". - CBA_AnnotIterator iter(pFormFillEnv->GetPageView(0), - CPDF_Annot::Subtype::WIDGET); - CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); - CheckRect(pAnnot->GetRect(), RightTop); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftTop); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightBottom); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftBottom); - pAnnot = iter.GetNextAnnot(pAnnot); - EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); - - pAnnot = iter.GetLastAnnot(); - CheckRect(pAnnot->GetRect(), LeftBottom); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightBottom); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftTop); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightTop); - pAnnot = iter.GetPrevAnnot(pAnnot); - EXPECT_EQ(iter.GetLastAnnot(), pAnnot); - } - { - // Page 1 specifies "column order" - CBA_AnnotIterator iter(pFormFillEnv->GetPageView(1), - CPDF_Annot::Subtype::WIDGET); - CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); - CheckRect(pAnnot->GetRect(), RightTop); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightBottom); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftTop); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftBottom); - pAnnot = iter.GetNextAnnot(pAnnot); - EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); - - pAnnot = iter.GetLastAnnot(); - CheckRect(pAnnot->GetRect(), LeftBottom); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftTop); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightBottom); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightTop); - pAnnot = iter.GetPrevAnnot(pAnnot); - EXPECT_EQ(iter.GetLastAnnot(), pAnnot); - } - { - // Page 2 specifies "struct order" - CBA_AnnotIterator iter(pFormFillEnv->GetPageView(2), - CPDF_Annot::Subtype::WIDGET); - CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); - CheckRect(pAnnot->GetRect(), LeftBottom); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightTop); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftTop); - pAnnot = iter.GetNextAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightBottom); - pAnnot = iter.GetNextAnnot(pAnnot); - EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); - - pAnnot = iter.GetLastAnnot(); - CheckRect(pAnnot->GetRect(), RightBottom); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftTop); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), RightTop); - pAnnot = iter.GetPrevAnnot(pAnnot); - CheckRect(pAnnot->GetRect(), LeftBottom); - pAnnot = iter.GetPrevAnnot(pAnnot); - EXPECT_EQ(iter.GetLastAnnot(), pAnnot); - } - UnloadPage(page2); - UnloadPage(page1); - UnloadPage(page0); -} diff --git a/fpdfsdk/fsdk_filewriteadapter.cpp b/fpdfsdk/fsdk_filewriteadapter.cpp deleted file mode 100644 index fad058fb54..0000000000 --- a/fpdfsdk/fsdk_filewriteadapter.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/fsdk_filewriteadapter.h" - -FSDK_FileWriteAdapter::FSDK_FileWriteAdapter(FPDF_FILEWRITE* fileWriteStruct) - : fileWriteStruct_(fileWriteStruct) { - ASSERT(fileWriteStruct_); -} - -FSDK_FileWriteAdapter::~FSDK_FileWriteAdapter() {} - -bool FSDK_FileWriteAdapter::WriteBlock(const void* data, size_t size) { - return fileWriteStruct_->WriteBlock(fileWriteStruct_, data, size) != 0; -} - -bool FSDK_FileWriteAdapter::WriteString(const ByteStringView& str) { - return WriteBlock(str.unterminated_c_str(), str.GetLength()); -} diff --git a/fpdfsdk/fsdk_filewriteadapter.h b/fpdfsdk/fsdk_filewriteadapter.h deleted file mode 100644 index 6bba1da9a7..0000000000 --- a/fpdfsdk/fsdk_filewriteadapter.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_FSDK_FILEWRITEADAPTER_H_ -#define FPDFSDK_FSDK_FILEWRITEADAPTER_H_ - -#include "core/fxcrt/fx_stream.h" -#include "core/fxcrt/retain_ptr.h" -#include "public/fpdf_save.h" - -class FSDK_FileWriteAdapter : public IFX_WriteStream { - public: - template - friend RetainPtr pdfium::MakeRetain(Args&&... args); - - bool WriteBlock(const void* data, size_t size) override; - bool WriteString(const ByteStringView& str) override; - - private: - explicit FSDK_FileWriteAdapter(FPDF_FILEWRITE* fileWriteStruct); - ~FSDK_FileWriteAdapter() override; - - FPDF_FILEWRITE* fileWriteStruct_; -}; - -#endif // FPDFSDK_FSDK_FILEWRITEADAPTER_H_ diff --git a/fpdfsdk/fsdk_pauseadapter.cpp b/fpdfsdk/fsdk_pauseadapter.cpp deleted file mode 100644 index cf99253ff9..0000000000 --- a/fpdfsdk/fsdk_pauseadapter.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/fsdk_pauseadapter.h" - -IFSDK_PAUSE_Adapter::IFSDK_PAUSE_Adapter(IFSDK_PAUSE* IPause) - : m_IPause(IPause) {} - -IFSDK_PAUSE_Adapter::~IFSDK_PAUSE_Adapter() {} - -bool IFSDK_PAUSE_Adapter::NeedToPauseNow() { - return m_IPause->NeedToPauseNow && m_IPause->NeedToPauseNow(m_IPause.Get()); -} diff --git a/fpdfsdk/fsdk_pauseadapter.h b/fpdfsdk/fsdk_pauseadapter.h deleted file mode 100644 index 405f4d94d1..0000000000 --- a/fpdfsdk/fsdk_pauseadapter.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_FSDK_PAUSEADAPTER_H_ -#define FPDFSDK_FSDK_PAUSEADAPTER_H_ - -#include "core/fxcrt/fx_system.h" -#include "core/fxcrt/pauseindicator_iface.h" -#include "core/fxcrt/unowned_ptr.h" -#include "public/fpdf_progressive.h" - -class IFSDK_PAUSE_Adapter : public PauseIndicatorIface { - public: - explicit IFSDK_PAUSE_Adapter(IFSDK_PAUSE* IPause); - ~IFSDK_PAUSE_Adapter() override; - - bool NeedToPauseNow() override; - - private: - UnownedPtr const m_IPause; -}; - -#endif // FPDFSDK_FSDK_PAUSEADAPTER_H_ diff --git a/fpdfsdk/ipdfsdk_pauseadapter.cpp b/fpdfsdk/ipdfsdk_pauseadapter.cpp new file mode 100644 index 0000000000..3cdf1330d8 --- /dev/null +++ b/fpdfsdk/ipdfsdk_pauseadapter.cpp @@ -0,0 +1,16 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/ipdfsdk_pauseadapter.h" + +IPDFSDK_PauseAdapter::IPDFSDK_PauseAdapter(IFSDK_PAUSE* IPause) + : m_IPause(IPause) {} + +IPDFSDK_PauseAdapter::~IPDFSDK_PauseAdapter() {} + +bool IPDFSDK_PauseAdapter::NeedToPauseNow() { + return m_IPause->NeedToPauseNow && m_IPause->NeedToPauseNow(m_IPause.Get()); +} diff --git a/fpdfsdk/ipdfsdk_pauseadapter.h b/fpdfsdk/ipdfsdk_pauseadapter.h new file mode 100644 index 0000000000..7ee01ba53f --- /dev/null +++ b/fpdfsdk/ipdfsdk_pauseadapter.h @@ -0,0 +1,26 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_IPDFSDK_PAUSEADAPTER_H_ +#define FPDFSDK_IPDFSDK_PAUSEADAPTER_H_ + +#include "core/fxcrt/fx_system.h" +#include "core/fxcrt/pauseindicator_iface.h" +#include "core/fxcrt/unowned_ptr.h" +#include "public/fpdf_progressive.h" + +class IPDFSDK_PauseAdapter : public PauseIndicatorIface { + public: + explicit IPDFSDK_PauseAdapter(IFSDK_PAUSE* IPause); + ~IPDFSDK_PauseAdapter() override; + + bool NeedToPauseNow() override; + + private: + UnownedPtr const m_IPause; +}; + +#endif // FPDFSDK_IPDFSDK_PAUSEADAPTER_H_ diff --git a/fpdfsdk/pdfsdk_fieldaction.cpp b/fpdfsdk/pdfsdk_fieldaction.cpp deleted file mode 100644 index ecf01b7488..0000000000 --- a/fpdfsdk/pdfsdk_fieldaction.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/pdfsdk_fieldaction.h" - -PDFSDK_FieldAction::PDFSDK_FieldAction() - : bModifier(false), - bShift(false), - bKeyDown(false), - nSelEnd(0), - nSelStart(0), - bWillCommit(false), - bFieldFull(false), - bRC(true) {} diff --git a/fpdfsdk/pdfsdk_fieldaction.h b/fpdfsdk/pdfsdk_fieldaction.h deleted file mode 100644 index 27049892a3..0000000000 --- a/fpdfsdk/pdfsdk_fieldaction.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_PDFSDK_FIELDACTION_H_ -#define FPDFSDK_PDFSDK_FIELDACTION_H_ - -#include "core/fxcrt/fx_string.h" - -#ifdef PDF_ENABLE_XFA -typedef enum { - PDFSDK_XFA_Click = 0, - PDFSDK_XFA_Full, - PDFSDK_XFA_PreOpen, - PDFSDK_XFA_PostOpen -} PDFSDK_XFAAActionType; -#endif // PDF_ENABLE_XFA - -struct PDFSDK_FieldAction { - PDFSDK_FieldAction(); - PDFSDK_FieldAction(const PDFSDK_FieldAction& other) = delete; - - bool bModifier; - bool bShift; - WideString sChange; - WideString sChangeEx; - bool bKeyDown; - int nSelEnd; - int nSelStart; - WideString sValue; - bool bWillCommit; - bool bFieldFull; - bool bRC; -}; - -#endif // FPDFSDK_PDFSDK_FIELDACTION_H_ -- cgit v1.2.3