diff options
author | jaepark <jaepark@google.com> | 2016-08-29 17:15:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-29 17:15:08 -0700 |
commit | 35512aa7e4acc3ceb9c6aef5d61eebfb4ae802af (patch) | |
tree | 18ad1447ba8a7d06f304e1418616d919eadbbf8c /core/fpdfdoc/cpdf_annotlist.cpp | |
parent | 07f5fd57682700bcbba20f01d52a806676fd02ff (diff) | |
download | pdfium-35512aa7e4acc3ceb9c6aef5d61eebfb4ae802af.tar.xz |
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
Diffstat (limited to 'core/fpdfdoc/cpdf_annotlist.cpp')
-rw-r--r-- | core/fpdfdoc/cpdf_annotlist.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
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<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot, + CPDF_Document* pDocument) { + CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); + if (!pParentDict) + return std::unique_ptr<CPDF_Annot>(); + + CFX_ByteString sContents = pParentDict->GetStringBy("Contents"); + if (sContents.IsEmpty()) + return std::unique_ptr<CPDF_Annot>(); + + 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<CPDF_Annot> 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<CPDF_Annot>(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<CPDF_Annot> pPopupAnnot( + CreatePopupAnnot(m_AnnotList[i].get(), m_pDocument)); + if (pPopupAnnot) + m_AnnotList.push_back(std::move(pPopupAnnot)); + } } CPDF_AnnotList::~CPDF_AnnotList() {} |