Merge to XFA: Make conversions for CPDF_Link explicit.
authorTom Sepez <tsepez@chromium.org>
Fri, 6 Mar 2015 20:37:13 +0000 (12:37 -0800)
committerTom Sepez <tsepez@chromium.org>
Fri, 6 Mar 2015 20:37:13 +0000 (12:37 -0800)
Original Review URL: https://codereview.chromium.org/985503005
TBR=thestig@chromium.org

Review URL: https://codereview.chromium.org/985153002

core/include/fpdfdoc/fpdf_doc.h
core/src/fpdfdoc/doc_link.cpp
fpdfsdk/src/fpdfdoc.cpp

index 5e3e11a..5c73764 100644 (file)
@@ -545,26 +545,16 @@ protected:
 class CPDF_Link : public CFX_Object
 {
 public:
+    CPDF_Link() : m_pDict(nullptr) { }
+    explicit CPDF_Link(CPDF_Dictionary* pDict) : m_pDict(pDict) { }
 
-    CPDF_Link(CPDF_Dictionary* pDict = NULL)
-    {
-        m_pDict = pDict;
-    }
-
-    operator CPDF_Dictionary*() const
-    {
-        return m_pDict;
-    }
+    CPDF_Dictionary* GetDict() const { return m_pDict; }
 
     CFX_FloatRect              GetRect();
-
-
-
     CPDF_Dest                  GetDest(CPDF_Document* pDoc);
-
     CPDF_Action                        GetAction();
 
-
+protected:
     CPDF_Dictionary*   m_pDict;
 };
 #define ANNOTFLAG_INVISIBLE                    1
index b7c640a..4a42e21 100644 (file)
@@ -44,26 +44,26 @@ int CPDF_LinkList::CountLinks(CPDF_Page* pPage)
 CPDF_Link CPDF_LinkList::GetLink(CPDF_Page* pPage, int index)
 {
     CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
-    if (pPageLinkList == NULL) {
-        return NULL;
+    if (!pPageLinkList) {
+        return CPDF_Link();
     }
-    return (CPDF_Dictionary*)pPageLinkList->GetAt(index);
+    return CPDF_Link((CPDF_Dictionary*)pPageLinkList->GetAt(index));
 }
 CPDF_Link CPDF_LinkList::GetLinkAtPoint(CPDF_Page* pPage, FX_FLOAT pdf_x, FX_FLOAT pdf_y)
 {
     CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
-    if (pPageLinkList == NULL) {
-        return NULL;
+    if (!pPageLinkList) {
+        return CPDF_Link();
     }
     int size = pPageLinkList->GetSize();
     for (int i = size - 1; i >= 0; --i) {
-        CPDF_Link Link = (CPDF_Dictionary*)pPageLinkList->GetAt(i);
-        CPDF_Rect rect = Link.GetRect();
+        CPDF_Link link((CPDF_Dictionary*)pPageLinkList->GetAt(i));
+        CPDF_Rect rect = link.GetRect();
         if (rect.Contains(pdf_x, pdf_y)) {
-            return Link;
+            return link;
         }
     }
-    return NULL;
+    return CPDF_Link();
 }
 void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList)
 {
index e89a7aa..1cd7c8b 100644 (file)
@@ -180,18 +180,17 @@ DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, do
                pLinkList = FX_NEW CPDF_LinkList(pDoc);
                pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList);
        }
-       return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y);
+       return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y).GetDict();
 }
 
 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK pDict)
 {
        if (!document)
                return NULL;
-    CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
        if (!pDict)
                return NULL;
-       CPDF_Link link = (CPDF_Dictionary*)pDict;
-
+       CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
+       CPDF_Link link((CPDF_Dictionary*)pDict);
        FPDF_DEST dest = link.GetDest(pDoc).GetObject();
        if (dest)
                return dest;
@@ -206,7 +205,7 @@ DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict)
 {
        if (!pDict)
                return NULL;
-       CPDF_Link link = (CPDF_Dictionary*)pDict;
+       CPDF_Link link((CPDF_Dictionary*)pDict);
        return link.GetAction().GetDict();
 }