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

Side by Side Diff: core/fpdfdoc/cpdf_annotlist.cpp

Issue 2273893002: Display content of the annotation when mouse hover. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Display content of the annotation when mouse hover. Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « core/fpdfdoc/cpdf_annot.cpp ('k') | core/fpdfdoc/cpvt_generateap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfdoc/include/cpdf_annotlist.h" 7 #include "core/fpdfdoc/include/cpdf_annotlist.h"
8 8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
12 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" 12 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h"
13 #include "core/fpdfdoc/cpvt_generateap.h" 13 #include "core/fpdfdoc/cpvt_generateap.h"
14 #include "core/fpdfdoc/include/cpdf_annot.h" 14 #include "core/fpdfdoc/include/cpdf_annot.h"
15 #include "core/fpdfdoc/include/cpdf_interform.h" 15 #include "core/fpdfdoc/include/cpdf_interform.h"
16 #include "core/fpdfdoc/include/cpdf_occontext.h" 16 #include "core/fpdfdoc/include/cpdf_occontext.h"
17 #include "core/fxge/include/cfx_renderdevice.h" 17 #include "core/fxge/include/cfx_renderdevice.h"
18 18
19 namespace {
20
21 std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot,
22 CPDF_Document* pDocument) {
23 CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict();
24 if (!pParentDict)
25 return std::unique_ptr<CPDF_Annot>();
26
27 CFX_ByteString sContents = pParentDict->GetStringBy("Contents");
28 if (sContents.IsEmpty())
29 return std::unique_ptr<CPDF_Annot>();
30
31 CPDF_Dictionary* pAnnotDict = new CPDF_Dictionary;
32 pAnnotDict->SetAtName("Type", "Annot");
33 pAnnotDict->SetAtName("Subtype", "Popup");
34 pAnnotDict->SetAtString("T", pParentDict->GetStringBy("T"));
35 pAnnotDict->SetAtString("Contents", sContents);
36
37 CFX_FloatRect rect = pParentDict->GetRectBy("Rect");
38 rect.Normalize();
39 CFX_FloatRect popupRect(0, 0, 200, 200);
40 popupRect.Translate(rect.left, rect.bottom - popupRect.Height());
41
42 pAnnotDict->SetAtRect("Rect", popupRect);
43 pAnnotDict->SetAtInteger("F", 0);
44
45 std::unique_ptr<CPDF_Annot> pPopupAnnot(
46 new CPDF_Annot(pAnnotDict, pDocument));
47 pAnnot->SetPopupAnnot(pPopupAnnot.get());
48 return pPopupAnnot;
49 }
50
51 } // namespace
52
19 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) 53 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
20 : m_pDocument(pPage->m_pDocument) { 54 : m_pDocument(pPage->m_pDocument) {
21 if (!pPage->m_pFormDict) 55 if (!pPage->m_pFormDict)
22 return; 56 return;
23 57
24 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); 58 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots");
25 if (!pAnnots) 59 if (!pAnnots)
26 return; 60 return;
27 61
28 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); 62 CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
29 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); 63 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
30 FX_BOOL bRegenerateAP = 64 FX_BOOL bRegenerateAP =
31 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); 65 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances");
32 for (size_t i = 0; i < pAnnots->GetCount(); ++i) { 66 for (size_t i = 0; i < pAnnots->GetCount(); ++i) {
33 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); 67 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i));
34 if (!pDict) 68 if (!pDict)
35 continue; 69 continue;
36 70
37 uint32_t dwObjNum = pDict->GetObjNum(); 71 uint32_t dwObjNum = pDict->GetObjNum();
38 if (dwObjNum == 0) { 72 if (dwObjNum == 0) {
39 dwObjNum = m_pDocument->AddIndirectObject(pDict); 73 dwObjNum = m_pDocument->AddIndirectObject(pDict);
40 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); 74 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum);
41 pAnnots->InsertAt(i, pAction); 75 pAnnots->InsertAt(i, pAction);
42 pAnnots->RemoveAt(i + 1); 76 pAnnots->RemoveAt(i + 1);
43 pDict = pAnnots->GetDictAt(i); 77 pDict = pAnnots->GetDictAt(i);
44 } 78 }
79
80 // Skip creating Popup annotation in the PDF document since PDFium provides
81 // its own Popup annotations.
82 if (pDict->GetStringBy("Subtype") == "Popup")
83 continue;
84
45 m_AnnotList.push_back( 85 m_AnnotList.push_back(
46 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument))); 86 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument)));
47 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && 87 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" &&
48 CPDF_InterForm::IsUpdateAPEnabled()) { 88 CPDF_InterForm::IsUpdateAPEnabled()) {
49 FPDF_GenerateAP(m_pDocument, pDict); 89 FPDF_GenerateAP(m_pDocument, pDict);
50 } 90 }
51 } 91 }
92
93 size_t nAnnotListSize = m_AnnotList.size();
94 for (size_t i = 0; i < nAnnotListSize; ++i) {
95 std::unique_ptr<CPDF_Annot> pPopupAnnot(
96 CreatePopupAnnot(m_AnnotList[i].get(), m_pDocument));
97 if (pPopupAnnot)
98 m_AnnotList.push_back(std::move(pPopupAnnot));
99 }
52 } 100 }
53 101
54 CPDF_AnnotList::~CPDF_AnnotList() {} 102 CPDF_AnnotList::~CPDF_AnnotList() {}
55 103
56 void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, 104 void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage,
57 CFX_RenderDevice* pDevice, 105 CFX_RenderDevice* pDevice,
58 CPDF_RenderContext* pContext, 106 CPDF_RenderContext* pContext,
59 FX_BOOL bPrinting, 107 FX_BOOL bPrinting,
60 CFX_Matrix* pMatrix, 108 CFX_Matrix* pMatrix,
61 FX_BOOL bWidgetPass, 109 FX_BOOL bWidgetPass,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 CPDF_RenderContext* pContext, 173 CPDF_RenderContext* pContext,
126 FX_BOOL bPrinting, 174 FX_BOOL bPrinting,
127 CFX_Matrix* pMatrix, 175 CFX_Matrix* pMatrix,
128 FX_BOOL bShowWidget, 176 FX_BOOL bShowWidget,
129 CPDF_RenderOptions* pOptions) { 177 CPDF_RenderOptions* pOptions) {
130 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN 178 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN
131 : ANNOTFLAG_INVISIBLE; 179 : ANNOTFLAG_INVISIBLE;
132 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, 180 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags,
133 pOptions, nullptr); 181 pOptions, nullptr);
134 } 182 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_annot.cpp ('k') | core/fpdfdoc/cpvt_generateap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698