From 624b6c1e0fc6a5b0467061ef37b6db6856681afb Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 5 Mar 2015 16:30:09 -0800 Subject: Make conversion between CPDF_Action and its dictionary explicit. Precursor to taking a second shot at cleaning up the FPDF_* APIs. A FPDF_Action is a CPDF_Dictionary, and a CPDF_Action is a structure holding a FPDF_Action. This goes against the convention that FPDF_ types get cast to CPDF_* types, so we want to make it clear where objects are getting constructed, etc. Also tidy fpdf_actionhandler.cpp because it bugs me. R=thestig@chromium.org Review URL: https://codereview.chromium.org/984773002 --- core/include/fpdfdoc/fpdf_doc.h | 20 ++-- core/src/fpdfdoc/doc_action.cpp | 62 +++++----- core/src/fpdfdoc/doc_bookmark.cpp | 4 +- core/src/fpdfdoc/doc_formcontrol.cpp | 17 ++- core/src/fpdfdoc/doc_link.cpp | 2 +- fpdfsdk/src/fpdfdoc.cpp | 10 +- fpdfsdk/src/fsdk_actionhandler.cpp | 215 ++++++++++++++++------------------- fpdfsdk/src/fsdk_baseannot.cpp | 42 +++---- fpdfsdk/src/fsdk_baseform.cpp | 34 +++--- fpdfsdk/src/fsdk_mgr.cpp | 46 ++++---- 10 files changed, 207 insertions(+), 245 deletions(-) diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index 60f41a5554..dbcc7f433e 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -264,17 +264,6 @@ public: class CPDF_Action : public CFX_Object { public: - - CPDF_Action(CPDF_Dictionary* pDict = NULL) - { - m_pDict = pDict; - } - - operator CPDF_Dictionary* () const - { - return m_pDict; - } - enum ActionType { Unknown = 0, GoTo, @@ -297,6 +286,13 @@ public: GoTo3DView }; + CPDF_Action() : m_pDict(nullptr) { } + explicit CPDF_Action(CPDF_Dictionary* pDict) : m_pDict(pDict) { } + + operator bool () const { return m_pDict != NULL; } + + CPDF_Dictionary* GetDict() const { return m_pDict; } + CFX_ByteString GetTypeName() const { return m_pDict->GetString("S"); @@ -422,7 +418,7 @@ public: CPDF_Action GetSubAction(FX_DWORD iIndex) const; - +protected: CPDF_Dictionary* m_pDict; }; class CPDF_AAction : public CFX_Object diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp index 801c69fbb7..324153563a 100644 --- a/core/src/fpdfdoc/doc_action.cpp +++ b/core/src/fpdfdoc/doc_action.cpp @@ -94,7 +94,7 @@ FX_DWORD CPDF_ActionFields::GetFieldsCount() const if (m_pAction == NULL) { return 0; } - CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction); + CPDF_Dictionary* pDict = m_pAction->GetDict(); if (pDict == NULL) { return 0; } @@ -124,7 +124,7 @@ void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const if (m_pAction == NULL) { return; } - CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction); + CPDF_Dictionary* pDict = m_pAction->GetDict(); if (pDict == NULL) { return; } @@ -157,7 +157,7 @@ CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const if (m_pAction == NULL) { return NULL; } - CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction); + CPDF_Dictionary* pDict = m_pAction->GetDict(); if (pDict == NULL) { return NULL; } @@ -260,19 +260,20 @@ FX_DWORD CPDF_Action::GetSubActionsCount() const CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { - return NULL; + return CPDF_Action(); } CPDF_Object* pNext = m_pDict->GetElementValue("Next"); int iObjType = pNext->GetType(); if (iObjType == PDFOBJ_DICTIONARY) { + CPDF_Dictionary *pDict = static_cast(pNext); if (iIndex == 0) { - return (CPDF_Dictionary*)pNext; + return CPDF_Action(pDict); } + } else if (iObjType == PDFOBJ_ARRAY) { + CPDF_Array* pArray = static_cast(pNext); + return CPDF_Action(pArray->GetDict(iIndex)); } - if (iObjType == PDFOBJ_ARRAY) { - return ((CPDF_Array*)pNext)->GetDict(iIndex); - } - return NULL; + return CPDF_Action(); } const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", "PV", "PI", "O", "C", @@ -289,10 +290,10 @@ FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const } CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { - if (m_pDict == NULL) { - return NULL; + if (!m_pDict) { + return CPDF_Action(); } - return m_pDict->GetDict(g_sAATypes[(int)eType]); + return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType])); } FX_POSITION CPDF_AAction::GetStartPos() const { @@ -304,25 +305,26 @@ FX_POSITION CPDF_AAction::GetStartPos() const CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, AActionType& eType) const { if (m_pDict == NULL) { - return NULL; + return CPDF_Action(); } CFX_ByteString csKey; CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); - if (pObj != NULL) { - CPDF_Object* pDirect = pObj->GetDirect(); - if (pDirect != NULL && pDirect->GetType() == PDFOBJ_DICTIONARY) { - int i = 0; - while (g_sAATypes[i][0] != '\0') { - if (csKey == g_sAATypes[i]) { - break; - } - i ++; - } - eType = (AActionType)i; - return (CPDF_Dictionary*)pDirect; + if (!pObj) { + return CPDF_Action(); + } + CPDF_Object* pDirect = pObj->GetDirect(); + if (!pDirect || pDirect->GetType() != PDFOBJ_DICTIONARY) { + return CPDF_Action(); + } + int i = 0; + while (g_sAATypes[i][0] != '\0') { + if (csKey == g_sAATypes[i]) { + break; } + i++; } - return NULL; + eType = (AActionType)i; + return CPDF_Action(static_cast(pDirect)); } CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) { @@ -340,9 +342,9 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(int index, CFX_ByteString& csName) co CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); CPDF_Object *pAction = name_tree.LookupValue(index, csName); if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { - return NULL; + return CPDF_Action(); } - return pAction->GetDict(); + return CPDF_Action(pAction->GetDict()); } CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { @@ -350,9 +352,9 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); CPDF_Object *pAction = name_tree.LookupValue(csName); if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { - return NULL; + return CPDF_Action(); } - return pAction->GetDict(); + return CPDF_Action(pAction->GetDict()); } int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { diff --git a/core/src/fpdfdoc/doc_bookmark.cpp b/core/src/fpdfdoc/doc_bookmark.cpp index e7b383eced..a3a194337e 100644 --- a/core/src/fpdfdoc/doc_bookmark.cpp +++ b/core/src/fpdfdoc/doc_bookmark.cpp @@ -86,7 +86,7 @@ CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const CPDF_Action CPDF_Bookmark::GetAction() const { if (!m_pDict) { - return NULL; + return CPDF_Action(); } - return m_pDict->GetDict("A"); + return CPDF_Action(m_pDict->GetDict("A")); } diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp index 61cd980754..1ab63234d6 100644 --- a/core/src/fpdfdoc/doc_formcontrol.cpp +++ b/core/src/fpdfdoc/doc_formcontrol.cpp @@ -248,18 +248,17 @@ int CPDF_FormControl::GetTextPosition() } CPDF_Action CPDF_FormControl::GetAction() { - if (m_pWidgetDict == NULL) { - return NULL; + if (!m_pWidgetDict) { + return CPDF_Action(); } if (m_pWidgetDict->KeyExist("A")) { - return m_pWidgetDict->GetDict("A"); - } else { - CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A"); - if (pObj == NULL) { - return NULL; - } - return pObj->GetDict(); + return CPDF_Action(m_pWidgetDict->GetDict("A")); + } + CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A"); + if (!pObj) { + return CPDF_Action(); } + return CPDF_Action(pObj->GetDict()); } CPDF_AAction CPDF_FormControl::GetAdditionalAction() { diff --git a/core/src/fpdfdoc/doc_link.cpp b/core/src/fpdfdoc/doc_link.cpp index 964b84e549..e7b6be5ca4 100644 --- a/core/src/fpdfdoc/doc_link.cpp +++ b/core/src/fpdfdoc/doc_link.cpp @@ -103,5 +103,5 @@ CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) } CPDF_Action CPDF_Link::GetAction() { - return m_pDict->GetDict("A"); + return CPDF_Action(m_pDict->GetDict("A")); } diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp index e1ed3bcbfa..f21d5cf938 100644 --- a/fpdfsdk/src/fpdfdoc.cpp +++ b/fpdfsdk/src/fpdfdoc.cpp @@ -97,14 +97,14 @@ DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) if (!pDict) return NULL; CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); - return bookmark.GetAction(); + return bookmark.GetAction().GetDict(); } DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) { if (!pDict) return 0; - CPDF_Action action = (CPDF_Dictionary*)pDict; + CPDF_Action action((CPDF_Dictionary*)pDict); CPDF_Action::ActionType type = action.GetType(); switch (type) { case CPDF_Action::GoTo: @@ -128,7 +128,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTI if (!pDict) return NULL; CPDF_Document* pDoc = (CPDF_Document*)document; - CPDF_Action action = (CPDF_Dictionary*)pDict; + CPDF_Action action((CPDF_Dictionary*)pDict); return action.GetDest(pDoc); } @@ -140,7 +140,7 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FP if (!pDict) return 0; CPDF_Document* pDoc = (CPDF_Document*)document; - CPDF_Action action = (CPDF_Dictionary*)pDict; + CPDF_Action action((CPDF_Dictionary*)pDict); CFX_ByteString path = action.GetURI(pDoc); unsigned long len = path.GetLength() + 1; if (buffer != NULL && buflen >= len) @@ -203,7 +203,7 @@ DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) if (!pDict) return NULL; CPDF_Link link = (CPDF_Dictionary*)pDict; - return link.GetAction(); + return link.GetAction().GetDict(); } DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FPDF_LINK* linkAnnot) diff --git a/fpdfsdk/src/fsdk_actionhandler.cpp b/fpdfsdk/src/fsdk_actionhandler.cpp index 518abd21f0..e3fdad393d 100644 --- a/fpdfsdk/src/fsdk_actionhandler.cpp +++ b/fpdfsdk/src/fsdk_actionhandler.cpp @@ -1,7 +1,7 @@ // 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 "../include/fsdk_define.h" @@ -11,7 +11,7 @@ /* -------------------------- CBA_ActionHandler -------------------------- */ -CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) : +CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) : m_pFormActionHandler(NULL), m_pMediaActionHandler(NULL) { @@ -47,16 +47,15 @@ void CPDFSDK_ActionHandler::Destroy() } //document open -FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument - /*CReader_Document* pDocument, CReader_DocView *pDocView*/) +FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument) { CFX_PtrList list; - return ExecuteDocumentOpenAction(action, pDocument, /*pDocView, */list); + return ExecuteDocumentOpenAction(action, pDocument, list); } //document open FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,CFX_WideString csJSName, - CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) + CPDFSDK_Document* pDocument) { if (JsAction.GetType() == CPDF_Action::JavaScript) { @@ -71,8 +70,8 @@ FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,C return FALSE; } -FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type, - CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, +FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type, + CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, PDFSDK_FieldAction& data) { CPDFDoc_Environment* pEnv = pDocument->GetEnv(); @@ -90,56 +89,56 @@ FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAct } FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(const CPDF_Action& action, enum CPDF_AAction::AActionType eType, - CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) + CPDFSDK_Document* pDocument) { CFX_PtrList list; - return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list); + return ExecuteDocumentPageAction(action, eType, pDocument, list); } FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(const CPDF_Action& action, enum CPDF_AAction::AActionType eType, - CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) + CPDFSDK_Document* pDocument) { CFX_PtrList list; - return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list); + return ExecuteDocumentPageAction(action, eType, pDocument, list); } -FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type, - CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) +FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type, + CPDFSDK_Document* pDocument) { CFX_PtrList list; - return this->ExecuteBookMark(action, pDocument,/* pDocView,*/ pBookMark, list); + return this->ExecuteBookMark(action, pDocument, pBookMark, list); } -FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type, - CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/ CPDFSDK_Annot* pScreen) +FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type, + CPDFSDK_Document* pDocument, CPDFSDK_Annot* pScreen) { CFX_PtrList list; - return this->ExecuteScreenAction(action, type, pDocument,/* pDocView,*/ pScreen, list); + return this->ExecuteScreenAction(action, type, pDocument, pScreen, list); } -FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action, - CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) +FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action, + CPDFSDK_Document* pDocument) { CFX_PtrList list; - return ExecuteLinkAction(action, pDocument,/* pDocView,*/ list); + return ExecuteLinkAction(action, pDocument, list); } -FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type, - CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/ +FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type, + CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, PDFSDK_FieldAction& data) { CFX_PtrList list; - return ExecuteFieldAction(action, type, pDocument,/* pDocView,*/ pFormField, data, list); + return ExecuteFieldAction(action, type, pDocument, pFormField, data, list); } FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& action, CPDFSDK_Document* pDocument, - /*CReader_DocView *pDocView,*/ CFX_PtrList& list) + CFX_PtrList& list) { - ASSERT(pDocument != NULL); - - if (list.Find((CPDF_Dictionary*)action)) + CPDF_Dictionary* pDict = action.GetDict(); + if (list.Find(pDict)) return FALSE; - list.AddTail((CPDF_Dictionary*)action); + + list.AddTail(pDict); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); ASSERT(pEnv); @@ -156,29 +155,28 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& acti } else { - DoAction_NoJs(action, pDocument/*, pDocView*/); + DoAction_NoJs(action, pDocument); } -// if (!IsValidDocView(pDocument, pDocView)) -// return FALSE; - for (FX_INT32 i=0,sz=action.GetSubActionsCount(); iGetEnv(); ASSERT(pEnv); @@ -203,7 +201,7 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action, CPDF FX_BOOL bRet = pContext->RunScript(swJS, csInfo); if (!bRet) { - //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); + // FIXME: return error. } pRuntime->ReleaseContext(pContext); @@ -212,29 +210,28 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action, CPDF } else { - DoAction_NoJs(action, pDocument/*, pDocView*/); + DoAction_NoJs(action, pDocument); } -// if (!IsValidDocView(pDocument, pDocView)) -// return FALSE; - for (FX_INT32 i=0,sz=action.GetSubActionsCount(); iGetEnv(); ASSERT(pEnv); @@ -251,16 +248,16 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(const CPDF_Action& acti } else { - DoAction_NoJs(action, pDocument/*, pDocView*/); + DoAction_NoJs(action, pDocument); } - if (!IsValidDocView(pDocument/*, pDocView*/)) + if (!IsValidDocView(pDocument)) return FALSE; for (FX_INT32 i=0,sz=action.GetSubActionsCount(); iGetFieldByDict(pFieldDict) != NULL; } -FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type, - CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDF_FormField* pFormField, +FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type, + CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, PDFSDK_FieldAction& data, CFX_PtrList& list) { ASSERT(pDocument != NULL); - if (list.Find((CPDF_Dictionary*)action)) + CPDF_Dictionary* pDict = action.GetDict(); + if (list.Find(pDict)) return FALSE; - list.AddTail((CPDF_Dictionary*)action); + + list.AddTail(pDict); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); ASSERT(pEnv); @@ -307,28 +306,28 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPD } else { - DoAction_NoJs(action, pDocument/*, pDocView*/); -// if (!IsValidDocView(pDocument, pDocView)) -// return FALSE; + DoAction_NoJs(action, pDocument); } for (FX_INT32 i=0,sz=action.GetSubActionsCount(); iGetEnv(); ASSERT(pEnv); @@ -397,29 +396,28 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CP } else { - DoAction_NoJs(action, pDocument/*, pDocView*/); + DoAction_NoJs(action, pDocument); } -// if (!IsValidDocView(pDocument, pDocView)) -// return FALSE; - for (FX_INT32 i=0,sz=action.GetSubActionsCount(); iGetEnv(); ASSERT(pEnv); @@ -453,29 +451,26 @@ FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSD } else { - DoAction_NoJs(action, pDocument/*, pDocView*/); + DoAction_NoJs(action, pDocument); } -// if (!IsValidDocView(pDocument, pDocView)) -// return FALSE; - for (FX_INT32 i=0,sz=action.GetSubActionsCount(); iDoAction_Sound(action, pDocument/*, pDocView*/); + m_pMediaActionHandler->DoAction_Sound(action, pDocument); } break; case CPDF_Action::Movie: if (m_pMediaActionHandler) { - m_pMediaActionHandler->DoAction_Movie(action, pDocument/*, pDocView*/); + m_pMediaActionHandler->DoAction_Movie(action, pDocument); } break; case CPDF_Action::Hide: @@ -514,7 +509,7 @@ void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Doc case CPDF_Action::SubmitForm: if (m_pFormActionHandler) { - m_pFormActionHandler->DoAction_SubmitForm(action, pDocument/*, pDocView*/); + m_pFormActionHandler->DoAction_SubmitForm(action, pDocument); } break; case CPDF_Action::ResetForm: @@ -526,19 +521,19 @@ void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Doc case CPDF_Action::ImportData: if (m_pFormActionHandler) { - m_pFormActionHandler->DoAction_ImportData(action, pDocument/*, pDocView*/); + m_pFormActionHandler->DoAction_ImportData(action, pDocument); } break; case CPDF_Action::JavaScript: ASSERT(FALSE); break; case CPDF_Action::SetOCGState: - DoAction_SetOCGState(pDocument, /*pDocView,*/ action); + DoAction_SetOCGState(pDocument, action); break; case CPDF_Action::Rendition: if (m_pMediaActionHandler) { - m_pMediaActionHandler->DoAction_Rendition(action, pDocument/*, pDocView*/); + m_pMediaActionHandler->DoAction_Rendition(action, pDocument); } break; case CPDF_Action::Trans: @@ -550,21 +545,16 @@ void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Doc } } -FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/) +FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) { ASSERT(pDocument != NULL); - //ASSERT(pDocView != NULL); - - //return pDocument->IsValidDocView(pDocView); return TRUE; } -void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, /*CReader_DocView* pDocView,*/ +void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, const CPDF_Action& action) { - ASSERT(pDocument != NULL); -// ASSERT(pDocView != NULL); - ASSERT(action != NULL); + ASSERT(action); CPDF_Document* pPDFDocument = pDocument->GetDocument(); ASSERT(pPDFDocument != NULL); @@ -604,27 +594,25 @@ void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const C void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action) { - ASSERT(pDocument != NULL); - ASSERT(action != NULL); + ASSERT(action); CPDFDoc_Environment* pApp = pDocument->GetEnv(); ASSERT(pApp != NULL); - + CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()); pApp->FFI_DoURIAction(FX_LPCSTR(sURI)); } void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action) { - ASSERT(pDocument != NULL); - ASSERT(action != NULL); - + ASSERT(action); + CFX_ByteString csName = action.GetNamedAction(); pDocument->GetEnv()->FFI_ExecuteNamedAction(csName); } -void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ const CPDF_Action& action) +void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument, const CPDF_Action& action) { } @@ -665,7 +653,7 @@ void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue); break; case CPDF_AAction::KeyStroke: - pContext->OnField_Keystroke(data.nCommitKey, data.sChange, data.sChangeEx, data.bKeyDown, + pContext->OnField_Keystroke(data.nCommitKey, data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue, data.bWillCommit, data.bFieldFull, data.bRC); break; @@ -725,7 +713,7 @@ void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocumen ASSERT(pContext != NULL); switch (type) - { + { case CPDF_AAction::OpenPage: pContext->OnPage_Open(pDocument); break; @@ -772,57 +760,57 @@ void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocumen FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument) { ASSERT(pDocument != NULL); - + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - + if (pInterForm->DoAction_Hide(action)) { pDocument->SetChangeMark(); return TRUE; } - + return FALSE; } FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument) { ASSERT(pDocument != NULL); - + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - + return pInterForm->DoAction_SubmitForm(action); } FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument) { ASSERT(pDocument != NULL); - + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - + if (pInterForm->DoAction_ResetForm(action)) - { + { return TRUE; } - + return FALSE; } FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument) { ASSERT(pDocument != NULL); - + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - + if (pInterForm->DoAction_ImportData(action)) { - pDocument->SetChangeMark(); + pDocument->SetChangeMark(); return TRUE; } - + return FALSE; } @@ -840,4 +828,3 @@ FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CP { return FALSE; } - diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp index 2b8cee9035..8265662be3 100644 --- a/fpdfsdk/src/fsdk_baseannot.cpp +++ b/fpdfsdk/src/fsdk_baseannot.cpp @@ -1090,43 +1090,30 @@ FX_BOOL CPDFSDK_Annot::IsVisible() const CPDF_Action CPDFSDK_Annot::GetAction() const { - ASSERT(m_pAnnot != NULL); - ASSERT(m_pAnnot->m_pAnnotDict != NULL); - - return m_pAnnot->m_pAnnotDict->GetDict("A"); + return CPDF_Action(m_pAnnot->m_pAnnotDict->GetDict("A")); } void CPDFSDK_Annot::SetAction(const CPDF_Action& action) { - ASSERT(m_pAnnot != NULL); - ASSERT(m_pAnnot->m_pAnnotDict != NULL); - - ASSERT(action != NULL); - - if ((CPDF_Action&)action != m_pAnnot->m_pAnnotDict->GetDict("A")) + ASSERT(action); + if ((CPDF_Action&)action != CPDF_Action(m_pAnnot->m_pAnnotDict->GetDict("A"))) { CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); - ASSERT(pDoc != NULL); - - if (action.m_pDict && (action.m_pDict->GetObjNum() == 0)) - pDoc->AddIndirectObject(action.m_pDict); - m_pAnnot->m_pAnnotDict->SetAtReference("A", pDoc, action.m_pDict->GetObjNum()); + CPDF_Dictionary* pDict = action.GetDict(); + if (pDict && pDict->GetObjNum() == 0) { + pDoc->AddIndirectObject(pDict); + } + m_pAnnot->m_pAnnotDict->SetAtReference("A", pDoc, pDict->GetObjNum()); } } void CPDFSDK_Annot::RemoveAction() { - ASSERT(m_pAnnot != NULL); - ASSERT(m_pAnnot->m_pAnnotDict != NULL); - m_pAnnot->m_pAnnotDict->RemoveAt("A"); } CPDF_AAction CPDFSDK_Annot::GetAAction() const { - ASSERT(m_pAnnot != NULL); - ASSERT(m_pAnnot->m_pAnnotDict != NULL); - return m_pAnnot->m_pAnnotDict->GetDict("AA"); } @@ -1151,17 +1138,14 @@ void CPDFSDK_Annot::RemoveAAction() CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT) { CPDF_AAction AAction = GetAAction(); - + if (AAction.ActionExist(eAAT)) - { return AAction.GetAction(eAAT); - } - else if (eAAT == CPDF_AAction::ButtonUp) - { + + if (eAAT == CPDF_AAction::ButtonUp) return GetAction(); - } - - return NULL; + + return CPDF_Action(); } void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions) diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index 6203f85662..a53e914b5c 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -1623,24 +1623,23 @@ CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) case CPDF_AAction::PageVisible: case CPDF_AAction::PageInvisible: return CPDFSDK_Annot::GetAAction(eAAT); + case CPDF_AAction::KeyStroke: case CPDF_AAction::Format: case CPDF_AAction::Validate: case CPDF_AAction::Calculate: { CPDF_FormField* pField = this->GetFormField(); - ASSERT(pField != NULL); - if (CPDF_AAction aa = pField->GetAdditionalAction()) return aa.GetAction(eAAT); - else - return CPDFSDK_Annot::GetAAction(eAAT); + + return CPDFSDK_Annot::GetAAction(eAAT); } default: - return NULL; + break; } - return NULL; + return CPDF_Action(); } @@ -2161,7 +2160,7 @@ void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, CFX_WideString& c FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { - ASSERT(action != NULL); + ASSERT(action); CPDF_ActionFields af = action.GetWidgets(); CFX_PtrArray fieldObjects; @@ -2217,13 +2216,13 @@ FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { - ASSERT(action != NULL); + ASSERT(action); ASSERT(m_pInterForm != NULL); CFX_WideString sDestination = action.GetFilePath(); if (sDestination.IsEmpty()) return FALSE; - CPDF_Dictionary* pActionDict = action; + CPDF_Dictionary* pActionDict = action.GetDict(); if (pActionDict->KeyExist("Fields")) { CPDF_ActionFields af = action.GetWidgets(); @@ -2448,29 +2447,22 @@ FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { - ASSERT(action != NULL); - - CPDF_Dictionary* pActionDict = action; + ASSERT(action); + CPDF_Dictionary* pActionDict = action.GetDict(); if (pActionDict->KeyExist("Fields")) { CPDF_ActionFields af = action.GetWidgets(); FX_DWORD dwFlags = action.GetFlags(); - + CFX_PtrArray fieldObjects; af.GetAllFields(fieldObjects); CFX_PtrArray fields; GetFieldFromObjects(fieldObjects, fields); - - ASSERT(m_pInterForm != NULL); - return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE); } - else - { - ASSERT(m_pInterForm != NULL); - return m_pInterForm->ResetForm(TRUE); - } + + return m_pInterForm->ResetForm(TRUE); } FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index efb21a7efc..9e0b230439 100644 --- a/fpdfsdk/src/fsdk_mgr.cpp +++ b/fpdfsdk/src/fsdk_mgr.cpp @@ -424,30 +424,32 @@ void CPDFSDK_Document:: ProcJavascriptFun() FX_BOOL CPDFSDK_Document::ProcOpenAction() { - if(!m_pDoc) return FALSE; - - CPDF_Dictionary* pRoot = m_pDoc->GetRoot(); - if (!pRoot) return FALSE; - CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");// - if(!pOpenAction) pOpenAction = pRoot->GetArray("OpenAction");// - if(!pOpenAction) return FALSE; - + if(!m_pDoc) + return FALSE; + + CPDF_Dictionary* pRoot = m_pDoc->GetRoot(); + if (!pRoot) + return FALSE; + + CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction"); + if(!pOpenAction) + pOpenAction = pRoot->GetArray("OpenAction"); + + if(!pOpenAction) + return FALSE; + if(pOpenAction->GetType()==PDFOBJ_ARRAY) - { - } - else if(pOpenAction->GetType()==PDFOBJ_DICTIONARY) - { - CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction; - CPDF_Action Action = pDict; - - if(m_pEnv->GetActionHander()) - m_pEnv->GetActionHander()->DoAction_DocOpen(Action,this); - } - else + return TRUE; + + if(pOpenAction->GetType()==PDFOBJ_DICTIONARY) { - return FALSE; - } - return TRUE; + CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction; + CPDF_Action action(pDict); + if(m_pEnv->GetActionHander()) + m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); + return TRUE; + } + return FALSE; } CPDF_OCContext* CPDFSDK_Document::GetOCContext() -- cgit v1.2.3