From 35512aa7e4acc3ceb9c6aef5d61eebfb4ae802af Mon Sep 17 00:00:00 2001 From: jaepark Date: Mon, 29 Aug 2016 17:15:08 -0700 Subject: Display content of the annotation when mouse hover. Each annotation has its contents, and users should be able to see the contents. In this patch, PDFium creates a Popup annotation for each annotation and stores the author and the content. When a user mouse hover on the annotation, PDFium draws the corresponding Popup annotation and displays the content. Also, roll DEPS for testing/corpus to 5867fa6. BUG=62625 Review-Url: https://codereview.chromium.org/2273893002 --- core/fpdfdoc/cpdf_annotlist.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'core/fpdfdoc/cpdf_annotlist.cpp') diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp index e6c93c1d1e..4c569892c2 100644 --- a/core/fpdfdoc/cpdf_annotlist.cpp +++ b/core/fpdfdoc/cpdf_annotlist.cpp @@ -16,6 +16,40 @@ #include "core/fpdfdoc/include/cpdf_occontext.h" #include "core/fxge/include/cfx_renderdevice.h" +namespace { + +std::unique_ptr CreatePopupAnnot(CPDF_Annot* pAnnot, + CPDF_Document* pDocument) { + CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); + if (!pParentDict) + return std::unique_ptr(); + + CFX_ByteString sContents = pParentDict->GetStringBy("Contents"); + if (sContents.IsEmpty()) + return std::unique_ptr(); + + CPDF_Dictionary* pAnnotDict = new CPDF_Dictionary; + pAnnotDict->SetAtName("Type", "Annot"); + pAnnotDict->SetAtName("Subtype", "Popup"); + pAnnotDict->SetAtString("T", pParentDict->GetStringBy("T")); + pAnnotDict->SetAtString("Contents", sContents); + + CFX_FloatRect rect = pParentDict->GetRectBy("Rect"); + rect.Normalize(); + CFX_FloatRect popupRect(0, 0, 200, 200); + popupRect.Translate(rect.left, rect.bottom - popupRect.Height()); + + pAnnotDict->SetAtRect("Rect", popupRect); + pAnnotDict->SetAtInteger("F", 0); + + std::unique_ptr pPopupAnnot( + new CPDF_Annot(pAnnotDict, pDocument)); + pAnnot->SetPopupAnnot(pPopupAnnot.get()); + return pPopupAnnot; +} + +} // namespace + CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) : m_pDocument(pPage->m_pDocument) { if (!pPage->m_pFormDict) @@ -42,6 +76,12 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) pAnnots->RemoveAt(i + 1); pDict = pAnnots->GetDictAt(i); } + + // Skip creating Popup annotation in the PDF document since PDFium provides + // its own Popup annotations. + if (pDict->GetStringBy("Subtype") == "Popup") + continue; + m_AnnotList.push_back( std::unique_ptr(new CPDF_Annot(pDict, m_pDocument))); if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && @@ -49,6 +89,14 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) FPDF_GenerateAP(m_pDocument, pDict); } } + + size_t nAnnotListSize = m_AnnotList.size(); + for (size_t i = 0; i < nAnnotListSize; ++i) { + std::unique_ptr pPopupAnnot( + CreatePopupAnnot(m_AnnotList[i].get(), m_pDocument)); + if (pPopupAnnot) + m_AnnotList.push_back(std::move(pPopupAnnot)); + } } CPDF_AnnotList::~CPDF_AnnotList() {} -- cgit v1.2.3