Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1554)

Unified Diff: core/src/fpdfdoc/doc_link.cpp

Issue 1278053004: Add new public APIs to find the z-order for links and widgets. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fpdfdoc/doc_link.cpp
diff --git a/core/src/fpdfdoc/doc_link.cpp b/core/src/fpdfdoc/doc_link.cpp
index 15bd14c31e8724120702df2e05dffd52751421a6..3fd91d7a7f3cb0f6160dd419b7a531d477d940e1 100644
--- a/core/src/fpdfdoc/doc_link.cpp
+++ b/core/src/fpdfdoc/doc_link.cpp
@@ -6,6 +6,8 @@
#include "../../include/fpdfdoc/fpdf_doc.h"
+CPDF_LinkList::CPDF_LinkList() {}
+
CPDF_LinkList::~CPDF_LinkList() {
FX_POSITION pos = m_PageMap.GetStartPosition();
while (pos) {
@@ -15,12 +17,13 @@ CPDF_LinkList::~CPDF_LinkList() {
delete (CFX_PtrArray*)value;
}
}
+
CFX_PtrArray* CPDF_LinkList::GetPageLinks(CPDF_Page* pPage) {
FX_DWORD objnum = pPage->m_pFormDict->GetObjNum();
- if (objnum == 0) {
- return NULL;
- }
- CFX_PtrArray* pPageLinkList = NULL;
+ if (objnum == 0)
+ return nullptr;
+
+ CFX_PtrArray* pPageLinkList = nullptr;
if (!m_PageMap.Lookup((void*)(uintptr_t)objnum, (void*&)pPageLinkList)) {
pPageLinkList = new CFX_PtrArray;
m_PageMap.SetAt((void*)(uintptr_t)objnum, pPageLinkList);
@@ -28,53 +31,46 @@ CFX_PtrArray* CPDF_LinkList::GetPageLinks(CPDF_Page* pPage) {
}
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));
-}
+
CPDF_Link CPDF_LinkList::GetLinkAtPoint(CPDF_Page* pPage,
FX_FLOAT pdf_x,
- FX_FLOAT pdf_y) {
+ FX_FLOAT pdf_y,
+ int* z_order) {
CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
- if (!pPageLinkList) {
+ if (!pPageLinkList)
return CPDF_Link();
- }
+
int size = pPageLinkList->GetSize();
Tom Sepez 2015/08/07 18:14:06 Nit: wish this were consistent with the index type
Lei Zhang 2015/08/07 23:03:41 Converting |pPageLinkList| from a CFX_PtrArray to
for (int i = size - 1; i >= 0; --i) {
- CPDF_Link link((CPDF_Dictionary*)pPageLinkList->GetAt(i));
+ CPDF_Dictionary* pAnnot = (CPDF_Dictionary*)pPageLinkList->GetAt(i);
+ 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 = i;
+ return link;
}
return CPDF_Link();
}
+
void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* 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->Add(add_link ? pAnnot : nullptr);
}
}
+
CPDF_Rect CPDF_Link::GetRect() {
return m_pDict->GetRect("Rect");
}

Powered by Google App Engine
This is Rietveld 408576698