summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc/doc_action.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-03-05 16:30:09 -0800
committerTom Sepez <tsepez@chromium.org>2015-03-05 16:30:09 -0800
commit624b6c1e0fc6a5b0467061ef37b6db6856681afb (patch)
tree8b1083b0b3f167da7fa7747ab530a9b37dab44b7 /core/src/fpdfdoc/doc_action.cpp
parent61c25eebf5a0fcf44dd1a434c88f502a34073eac (diff)
downloadpdfium-624b6c1e0fc6a5b0467061ef37b6db6856681afb.tar.xz
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
Diffstat (limited to 'core/src/fpdfdoc/doc_action.cpp')
-rw-r--r--core/src/fpdfdoc/doc_action.cpp62
1 files changed, 32 insertions, 30 deletions
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<CPDF_Dictionary*>(pNext);
if (iIndex == 0) {
- return (CPDF_Dictionary*)pNext;
+ return CPDF_Action(pDict);
}
+ } else if (iObjType == PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = static_cast<CPDF_Array*>(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<CPDF_Dictionary*>(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
{