From 39869b641511c882d78e17548293cdb458c36f38 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 20 Oct 2015 14:57:56 -0400 Subject: Revert "Revert "Add type cast definitions for CPDF_Dictionary."" This reverts commit 937840e1722d1f2b77d80575d6e710d760662c9c. Add type cast definitions for CPDF_Dictionary. This CL adds ToCPDFDictionary type definitions and updates one file to use instead of straight casts. I had to fix two places where we'd casted off the constness of the original pointer. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1420583003 . --- core/src/fpdfdoc/doc_action.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'core/src/fpdfdoc/doc_action.cpp') diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp index 759a06c656..409d050484 100644 --- a/core/src/fpdfdoc/doc_action.cpp +++ b/core/src/fpdfdoc/doc_action.cpp @@ -251,13 +251,10 @@ CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { 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) { + if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { + if (iIndex == 0) return CPDF_Action(pDict); - } - } else if (iObjType == PDFOBJ_ARRAY) { + } else if (pNext->GetType() == PDFOBJ_ARRAY) { CPDF_Array* pArray = static_cast(pNext); return CPDF_Action(pArray->GetDict(iIndex)); } @@ -295,9 +292,10 @@ CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, return CPDF_Action(); } CPDF_Object* pDirect = pObj->GetDirect(); - if (!pDirect || pDirect->GetType() != PDFOBJ_DICTIONARY) { + CPDF_Dictionary* pDict = ToDictionary(pDirect); + if (!pDict) return CPDF_Action(); - } + int i = 0; while (g_sAATypes[i][0] != '\0') { if (csKey == g_sAATypes[i]) { @@ -306,7 +304,7 @@ CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, i++; } eType = (AActionType)i; - return CPDF_Action(static_cast(pDirect)); + return CPDF_Action(pDict); } CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) { m_pDocument = pDoc; @@ -321,7 +319,7 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(int index, ASSERT(m_pDocument != NULL); CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); CPDF_Object* pAction = name_tree.LookupValue(index, csName); - if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { + if (!ToDictionary(pAction)) { return CPDF_Action(); } return CPDF_Action(pAction->GetDict()); @@ -330,7 +328,7 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { ASSERT(m_pDocument != NULL); CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); CPDF_Object* pAction = name_tree.LookupValue(csName); - if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { + if (!ToDictionary(pAction)) { return CPDF_Action(); } return CPDF_Action(pAction->GetDict()); -- cgit v1.2.3