From ac8d1e75645d783cc72d2cfd57554e48e3ed2999 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 6 Mar 2015 10:52:05 -0800 Subject: Merge to XFA: Make conversion between CPDF_Dest and its object explicit. Original Review URL: https://codereview.chromium.org/984703004 TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/984143002 --- core/include/fpdfdoc/fpdf_doc.h | 19 +++++-------------- core/src/fpdfdoc/doc_action.cpp | 19 ++++++++++--------- core/src/fpdfdoc/doc_bookmark.cpp | 13 +++++++------ core/src/fpdfdoc/doc_link.cpp | 11 ++++++----- 4 files changed, 28 insertions(+), 34 deletions(-) (limited to 'core') diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index a21063fedd..5e3e11acab 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -124,28 +124,19 @@ public: class CPDF_Dest : public CFX_Object { public: + CPDF_Dest() : m_pObj(nullptr) { } + explicit CPDF_Dest(CPDF_Object* pObj) : m_pObj(pObj) { } - CPDF_Dest(CPDF_Object* pObj = NULL) - { - m_pObj = pObj; - } - - operator CPDF_Object* () const - { - return m_pObj; - } + operator bool () const { return m_pObj != NULL; } + CPDF_Object* GetObject() const { return m_pObj; } CFX_ByteString GetRemoteName(); - int GetPageIndex(CPDF_Document* pDoc); - FX_DWORD GetPageObjNum(); - int GetZoomMode(); - FX_FLOAT GetParam(int index); - +protected: CPDF_Object* m_pObj; }; class CPDF_OCContext : public CFX_Object, public IPDF_OCContext diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp index 324153563a..ac40335a4c 100644 --- a/core/src/fpdfdoc/doc_action.cpp +++ b/core/src/fpdfdoc/doc_action.cpp @@ -7,25 +7,26 @@ #include "../../include/fpdfdoc/fpdf_doc.h" CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { - if (m_pDict == NULL) { - return NULL; + if (!m_pDict) { + return CPDF_Dest(); } CFX_ByteString type = m_pDict->GetString("S"); if (type != "GoTo" && type != "GoToR") { - return NULL; + return CPDF_Dest(); } CPDF_Object* pDest = m_pDict->GetElementValue("D"); - if (pDest == NULL) { - return NULL; + if (!pDest) { + return CPDF_Dest(); } if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); CFX_ByteStringC name = pDest->GetString(); - return name_tree.LookupNamedDest(pDoc, name); - } else if (pDest->GetType() == PDFOBJ_ARRAY) { - return (CPDF_Array*)pDest; + return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); } - return NULL; + if (pDest->GetType() == PDFOBJ_ARRAY) { + return CPDF_Dest((CPDF_Array*)pDest); + } + return CPDF_Dest(); } const FX_CHAR* g_sATypes[] = {"Unknown", "GoTo", "GoToR", "GoToE", "Launch", "Thread", "URI", "Sound", "Movie", "Hide", "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript", "SetOCGState", diff --git a/core/src/fpdfdoc/doc_bookmark.cpp b/core/src/fpdfdoc/doc_bookmark.cpp index a3a194337e..9814de61bf 100644 --- a/core/src/fpdfdoc/doc_bookmark.cpp +++ b/core/src/fpdfdoc/doc_bookmark.cpp @@ -68,20 +68,21 @@ CFX_WideString CPDF_Bookmark::GetTitle() const CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { if (!m_pDict) { - return NULL; + return CPDF_Dest(); } CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); if (!pDest) { - return NULL; + return CPDF_Dest(); } if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); CFX_ByteStringC name = pDest->GetString(); - return name_tree.LookupNamedDest(pDocument, name); - } else if (pDest->GetType() == PDFOBJ_ARRAY) { - return (CPDF_Array*)pDest; + return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name)); } - return NULL; + if (pDest->GetType() == PDFOBJ_ARRAY) { + return CPDF_Dest((CPDF_Array*)pDest); + } + return CPDF_Dest(); } CPDF_Action CPDF_Bookmark::GetAction() const { diff --git a/core/src/fpdfdoc/doc_link.cpp b/core/src/fpdfdoc/doc_link.cpp index e7b6be5ca4..b7c640af5e 100644 --- a/core/src/fpdfdoc/doc_link.cpp +++ b/core/src/fpdfdoc/doc_link.cpp @@ -90,16 +90,17 @@ CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) { CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); if (pDest == NULL) { - return NULL; + return CPDF_Dest(); } if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); CFX_ByteStringC name = pDest->GetString(); - return name_tree.LookupNamedDest(pDoc, name); - } else if (pDest->GetType() == PDFOBJ_ARRAY) { - return (CPDF_Array*)pDest; + return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); } - return NULL; + if (pDest->GetType() == PDFOBJ_ARRAY) { + return CPDF_Dest((CPDF_Array*)pDest); + } + return CPDF_Dest(); } CPDF_Action CPDF_Link::GetAction() { -- cgit v1.2.3