summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc/doc_link.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-08-14 19:24:08 -0700
committerLei Zhang <thestig@chromium.org>2015-08-14 19:24:08 -0700
commitbdf72c353af5b8a34ef5efdeddfff36d2089a158 (patch)
tree34258c3019152b41bbfd8f3332683dbc25c0c9da /core/src/fpdfdoc/doc_link.cpp
parent88f0bafb4163d297b51055124d4d35b769905216 (diff)
downloadpdfium-bdf72c353af5b8a34ef5efdeddfff36d2089a158.tar.xz
Merge to XFA: Add new public APIs to find the z-order for links and widgets.
- Implement FPDFLink_GetLinkZOrderAtPoint(). - Implement FPDFPage_FormFieldZOrderAtPoint(). - Mark FPDPage_HasFormFieldAtPoint() as deprecated. - Modify CPDF_LinkList and CPDF_InterForm to support new APIs. - Clean up dead code in CPDF_LinkList and CPDF_InterForm. BUG=chromium:515837 R=jun_fang@foxitsoftware.com, tsepez@chromium.org Review URL: https://codereview.chromium.org/1278053004 . (cherry picked from commit 24fbf134d43a7ec4226de3db601f0a617bbe428b) Review URL: https://codereview.chromium.org/1295893005 .
Diffstat (limited to 'core/src/fpdfdoc/doc_link.cpp')
-rw-r--r--core/src/fpdfdoc/doc_link.cpp99
1 files changed, 46 insertions, 53 deletions
diff --git a/core/src/fpdfdoc/doc_link.cpp b/core/src/fpdfdoc/doc_link.cpp
index 15bd14c31e..fbf18f99e5 100644
--- a/core/src/fpdfdoc/doc_link.cpp
+++ b/core/src/fpdfdoc/doc_link.cpp
@@ -6,75 +6,68 @@
#include "../../include/fpdfdoc/fpdf_doc.h"
+CPDF_LinkList::CPDF_LinkList() {
+}
+
CPDF_LinkList::~CPDF_LinkList() {
- FX_POSITION pos = m_PageMap.GetStartPosition();
- while (pos) {
- void* key;
- void* value;
- m_PageMap.GetNextAssoc(pos, key, value);
- delete (CFX_PtrArray*)value;
- }
}
-CFX_PtrArray* CPDF_LinkList::GetPageLinks(CPDF_Page* pPage) {
+
+const std::vector<CPDF_Dictionary*>* CPDF_LinkList::GetPageLinks(
+ CPDF_Page* pPage) {
FX_DWORD objnum = pPage->m_pFormDict->GetObjNum();
- if (objnum == 0) {
- return NULL;
- }
- CFX_PtrArray* pPageLinkList = NULL;
- if (!m_PageMap.Lookup((void*)(uintptr_t)objnum, (void*&)pPageLinkList)) {
- pPageLinkList = new CFX_PtrArray;
- m_PageMap.SetAt((void*)(uintptr_t)objnum, pPageLinkList);
- LoadPageLinks(pPage, pPageLinkList);
- }
- return pPageLinkList;
-}
-int CPDF_LinkList::CountLinks(CPDF_Page* pPage) {
- CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
- if (pPageLinkList == NULL) {
- return 0;
- }
- return pPageLinkList->GetSize();
-}
-CPDF_Link CPDF_LinkList::GetLink(CPDF_Page* pPage, int index) {
- CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
- if (!pPageLinkList) {
- return CPDF_Link();
- }
- return CPDF_Link((CPDF_Dictionary*)pPageLinkList->GetAt(index));
+ if (objnum == 0)
+ return nullptr;
+
+ auto it = m_PageMap.find(objnum);
+ if (it != m_PageMap.end())
+ return &it->second;
+
+ // std::map::operator[] forces the creation of a map entry.
+ std::vector<CPDF_Dictionary*>& page_link_list = m_PageMap[objnum];
+ LoadPageLinks(pPage, &page_link_list);
+ return &page_link_list;
}
+
CPDF_Link CPDF_LinkList::GetLinkAtPoint(CPDF_Page* pPage,
FX_FLOAT pdf_x,
- FX_FLOAT pdf_y) {
- CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
- if (!pPageLinkList) {
+ FX_FLOAT pdf_y,
+ int* z_order) {
+ const std::vector<CPDF_Dictionary*>* pPageLinkList = GetPageLinks(pPage);
+ 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));
+
+ for (size_t i = pPageLinkList->size(); i > 0; --i) {
+ size_t annot_index = i - 1;
+ CPDF_Dictionary* pAnnot = (*pPageLinkList)[annot_index];
+ if (!pAnnot)
+ continue;
+
+ CPDF_Link link(pAnnot);
CPDF_Rect rect = link.GetRect();
- if (rect.Contains(pdf_x, pdf_y)) {
- return link;
- }
+ if (!rect.Contains(pdf_x, pdf_y))
+ continue;
+
+ if (z_order)
+ *z_order = annot_index;
+ return link;
}
return CPDF_Link();
}
-void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList) {
+
+void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage,
+ std::vector<CPDF_Dictionary*>* pList) {
CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots");
- if (pAnnotList == NULL) {
+ if (!pAnnotList)
return;
- }
- for (FX_DWORD i = 0; i < pAnnotList->GetCount(); i++) {
+
+ for (FX_DWORD i = 0; i < pAnnotList->GetCount(); ++i) {
CPDF_Dictionary* pAnnot = pAnnotList->GetDict(i);
- if (pAnnot == NULL) {
- continue;
- }
- if (pAnnot->GetString("Subtype") != "Link") {
- continue;
- }
- pList->Add(pAnnot);
+ bool add_link = (pAnnot && pAnnot->GetString("Subtype") == "Link");
+ // Add non-links as nullptrs to preserve z-order.
+ pList->push_back(add_link ? pAnnot : nullptr);
}
}
+
CPDF_Rect CPDF_Link::GetRect() {
return m_pDict->GetRect("Rect");
}