dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_pageview.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 8 | |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 9 | #include <memory> |
| 10 | #include <vector> |
| 11 | |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_document.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/render/cpdf_renderoptions.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpdf_annotlist.h" |
| 15 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 16 | #include "fpdfsdk/cpdfsdk_annot.h" |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 17 | #include "fpdfsdk/cpdfsdk_annotiteration.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 18 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 19 | #include "fpdfsdk/cpdfsdk_interform.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 20 | #include "third_party/base/ptr_util.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 21 | |
| 22 | #ifdef PDF_ENABLE_XFA |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 23 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 24 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 25 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 26 | #include "xfa/fxfa/cxfa_ffwidgethandler.h" |
| 27 | #include "xfa/fxfa/cxfa_rendercontext.h" |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 28 | #include "xfa/fxgraphics/cxfa_graphics.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 29 | #endif // PDF_ENABLE_XFA |
| 30 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 31 | CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 32 | UnderlyingPageType* page) |
| 33 | : m_page(page), |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 34 | m_pFormFillEnv(pFormFillEnv), |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 35 | #ifndef PDF_ENABLE_XFA |
| 36 | m_bOwnsPage(false), |
| 37 | #endif // PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 38 | m_bOnWidget(false), |
| 39 | m_bValid(false), |
| 40 | m_bLocked(false), |
dsinclair | bcf4623 | 2016-10-03 13:02:27 -0700 | [diff] [blame] | 41 | m_bBeingDestroyed(false) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 42 | CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
Lei Zhang | 222e1a4 | 2017-06-20 14:47:00 -0700 | [diff] [blame] | 43 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 44 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 222e1a4 | 2017-06-20 14:47:00 -0700 | [diff] [blame] | 45 | if (page->GetPDFPage()) |
| 46 | pPDFInterForm->FixPageFields(page->GetPDFPage()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 47 | #else // PDF_ENABLE_XFA |
Lei Zhang | 222e1a4 | 2017-06-20 14:47:00 -0700 | [diff] [blame] | 48 | pPDFInterForm->FixPageFields(page); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 49 | m_page->SetView(this); |
| 50 | #endif // PDF_ENABLE_XFA |
| 51 | } |
| 52 | |
| 53 | CPDFSDK_PageView::~CPDFSDK_PageView() { |
| 54 | #ifndef PDF_ENABLE_XFA |
| 55 | // The call to |ReleaseAnnot| can cause the page pointed to by |m_page| to |
| 56 | // be freed, which will cause issues if we try to cleanup the pageview pointer |
| 57 | // in |m_page|. So, reset the pageview pointer before doing anything else. |
| 58 | m_page->SetView(nullptr); |
| 59 | #endif // PDF_ENABLE_XFA |
| 60 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 61 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 62 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 63 | for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray) |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 64 | pAnnotHandlerMgr->ReleaseAnnot(pAnnot); |
| 65 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 66 | m_SDKAnnotArray.clear(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 67 | m_pAnnotList.reset(); |
| 68 | |
| 69 | #ifndef PDF_ENABLE_XFA |
| 70 | if (m_bOwnsPage) |
| 71 | delete m_page; |
| 72 | #endif // PDF_ENABLE_XFA |
| 73 | } |
| 74 | |
| 75 | void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
| 76 | CFX_Matrix* pUser2Device, |
| 77 | #ifdef PDF_ENABLE_XFA |
| 78 | CPDF_RenderOptions* pOptions, |
| 79 | const FX_RECT& pClip) { |
| 80 | #else |
| 81 | CPDF_RenderOptions* pOptions) { |
| 82 | #endif // PDF_ENABLE_XFA |
| 83 | m_curMatrix = *pUser2Device; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 84 | |
| 85 | #ifdef PDF_ENABLE_XFA |
| 86 | CPDFXFA_Page* pPage = GetPDFXFAPage(); |
| 87 | if (!pPage) |
| 88 | return; |
| 89 | |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 90 | if (pPage->GetContext()->GetDocType() == XFA_DocType::Dynamic) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 91 | CFX_RectF rectClip( |
| 92 | static_cast<float>(pClip.left), static_cast<float>(pClip.top), |
| 93 | static_cast<float>(pClip.Width()), static_cast<float>(pClip.Height())); |
Dan Sinclair | cf53b78 | 2017-05-04 14:08:01 -0400 | [diff] [blame] | 94 | |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 95 | CXFA_Graphics gs(pDevice); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 96 | gs.SetClipRect(rectClip); |
Dan Sinclair | cf53b78 | 2017-05-04 14:08:01 -0400 | [diff] [blame] | 97 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 98 | CXFA_FFPageView* xfaView = pPage->GetXFAPageView(); |
Dan Sinclair | cf53b78 | 2017-05-04 14:08:01 -0400 | [diff] [blame] | 99 | CXFA_RenderContext renderContext(xfaView, rectClip, *pUser2Device); |
| 100 | renderContext.DoRender(&gs); |
| 101 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 102 | CXFA_FFDocView* docView = xfaView->GetDocView(); |
| 103 | if (!docView) |
| 104 | return; |
| 105 | CPDFSDK_Annot* annot = GetFocusAnnot(); |
| 106 | if (!annot) |
| 107 | return; |
| 108 | // Render the focus widget |
| 109 | docView->GetWidgetHandler()->RenderWidget(annot->GetXFAWidget(), &gs, |
Lei Zhang | 7c9d4c2 | 2017-08-17 13:53:52 -0700 | [diff] [blame] | 110 | *pUser2Device, false); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 111 | return; |
| 112 | } |
| 113 | #endif // PDF_ENABLE_XFA |
| 114 | |
| 115 | // for pdf/static xfa. |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 116 | CPDFSDK_AnnotIteration annotIteration(this, true); |
| 117 | for (const auto& pSDKAnnot : annotIteration) { |
| 118 | m_pFormFillEnv->GetAnnotHandlerMgr()->Annot_OnDraw( |
| 119 | this, pSDKAnnot.Get(), pDevice, pUser2Device, pOptions->m_bDrawAnnots); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 123 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(const CFX_PointF& point) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 124 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = m_pFormFillEnv->GetAnnotHandlerMgr(); |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 125 | CPDFSDK_AnnotIteration annotIteration(this, false); |
| 126 | for (const auto& pSDKAnnot : annotIteration) { |
| 127 | CFX_FloatRect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot.Get()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 128 | if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) |
| 129 | continue; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 130 | if (rc.Contains(point)) |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 131 | return pSDKAnnot.Get(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 132 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 133 | return nullptr; |
| 134 | } |
| 135 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 136 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(const CFX_PointF& point) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 137 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = m_pFormFillEnv->GetAnnotHandlerMgr(); |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 138 | CPDFSDK_AnnotIteration annotIteration(this, false); |
| 139 | for (const auto& pSDKAnnot : annotIteration) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 140 | bool bHitTest = pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET; |
| 141 | #ifdef PDF_ENABLE_XFA |
| 142 | bHitTest = bHitTest || |
| 143 | pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::XFAWIDGET; |
| 144 | #endif // PDF_ENABLE_XFA |
| 145 | if (bHitTest) { |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 146 | pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot.Get()); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 147 | if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot.Get(), point)) |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 148 | return pSDKAnnot.Get(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 151 | return nullptr; |
| 152 | } |
| 153 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 154 | #ifdef PDF_ENABLE_XFA |
| 155 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) { |
| 156 | if (!pPDFAnnot) |
| 157 | return nullptr; |
| 158 | |
| 159 | CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); |
| 160 | if (pSDKAnnot) |
| 161 | return pSDKAnnot; |
| 162 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 163 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 164 | pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
| 165 | if (!pSDKAnnot) |
| 166 | return nullptr; |
| 167 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 168 | m_SDKAnnotArray.push_back(pSDKAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 169 | return pSDKAnnot; |
| 170 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 171 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 172 | bool CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 173 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 174 | return false; |
Tom Sepez | bfa2a97 | 2017-07-24 11:38:31 -0700 | [diff] [blame] | 175 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 176 | CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 177 | if (!pPage || (pPage->GetContext()->GetDocType() != XFA_DocType::Static && |
| 178 | pPage->GetContext()->GetDocType() != XFA_DocType::Dynamic)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 179 | return false; |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 180 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 181 | |
Tom Sepez | bfa2a97 | 2017-07-24 11:38:31 -0700 | [diff] [blame] | 182 | CPDFSDK_Annot::ObservedPtr pObserved(pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 183 | if (GetFocusAnnot() == pAnnot) |
Tom Sepez | bfa2a97 | 2017-07-24 11:38:31 -0700 | [diff] [blame] | 184 | m_pFormFillEnv->KillFocusAnnot(0); // May invoke JS, invalidating pAnnot. |
| 185 | |
| 186 | if (pObserved) { |
| 187 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = |
| 188 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 189 | if (pAnnotHandler) |
| 190 | pAnnotHandler->ReleaseAnnot(pObserved.Get()); |
| 191 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 192 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 193 | auto it = std::find(m_SDKAnnotArray.begin(), m_SDKAnnotArray.end(), pAnnot); |
| 194 | if (it != m_SDKAnnotArray.end()) |
| 195 | m_SDKAnnotArray.erase(it); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 196 | if (m_pCaptureWidget.Get() == pAnnot) |
| 197 | m_pCaptureWidget.Reset(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 198 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 199 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 200 | } |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 201 | #endif // PDF_ENABLE_XFA |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 202 | |
| 203 | CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
| 204 | if (m_page) { |
| 205 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 206 | return m_page->GetContext()->GetPDFDoc(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 207 | #else // PDF_ENABLE_XFA |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 208 | return m_page->m_pDocument.Get(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 209 | #endif // PDF_ENABLE_XFA |
| 210 | } |
| 211 | return nullptr; |
| 212 | } |
| 213 | |
| 214 | CPDF_Page* CPDFSDK_PageView::GetPDFPage() const { |
| 215 | #ifdef PDF_ENABLE_XFA |
| 216 | return m_page ? m_page->GetPDFPage() : nullptr; |
| 217 | #else // PDF_ENABLE_XFA |
| 218 | return m_page; |
| 219 | #endif // PDF_ENABLE_XFA |
| 220 | } |
| 221 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 222 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 223 | for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 224 | if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) |
| 225 | return pAnnot; |
| 226 | } |
| 227 | return nullptr; |
| 228 | } |
| 229 | |
| 230 | #ifdef PDF_ENABLE_XFA |
| 231 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(CXFA_FFWidget* hWidget) { |
| 232 | if (!hWidget) |
| 233 | return nullptr; |
| 234 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 235 | for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 236 | if (pAnnot->GetXFAWidget() == hWidget) |
| 237 | return pAnnot; |
| 238 | } |
| 239 | return nullptr; |
| 240 | } |
| 241 | #endif // PDF_ENABLE_XFA |
| 242 | |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 243 | CFX_WideString CPDFSDK_PageView::GetSelectedText() { |
| 244 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 245 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 246 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 247 | return pAnnotHandlerMgr->Annot_GetSelectedText(pAnnot); |
| 248 | } |
| 249 | |
| 250 | return CFX_WideString(); |
| 251 | } |
| 252 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 253 | void CPDFSDK_PageView::ReplaceSelection(const CFX_WideString& text) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 254 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 255 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 256 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 257 | pAnnotHandlerMgr->Annot_ReplaceSelection(pAnnot, text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 261 | bool CPDFSDK_PageView::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 262 | CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point)); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 263 | if (!pAnnot) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 264 | m_pFormFillEnv->KillFocusAnnot(nFlag); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 265 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 266 | } |
| 267 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 268 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 269 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 270 | if (!pAnnotHandlerMgr->Annot_OnLButtonDown(this, &pAnnot, nFlag, point)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 271 | return false; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 272 | |
| 273 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 274 | return false; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 275 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 276 | m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 277 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 281 | bool CPDFSDK_PageView::OnRButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 282 | CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point)); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 283 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 284 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 285 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 286 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 287 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 288 | bool ok = pAnnotHandlerMgr->Annot_OnRButtonDown(this, &pAnnot, nFlag, point); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 289 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 290 | return false; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 291 | |
| 292 | if (ok) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 293 | m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 294 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 295 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 298 | bool CPDFSDK_PageView::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 299 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 300 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 301 | CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point)); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 302 | if (!pFXAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 303 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 304 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 305 | if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pFXAnnot, nFlag, point)) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 306 | m_pFormFillEnv->SetFocusAnnot(&pFXAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 307 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 308 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 309 | } |
| 310 | #endif // PDF_ENABLE_XFA |
| 311 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 312 | bool CPDFSDK_PageView::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 313 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 314 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 315 | CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point)); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 316 | CPDFSDK_Annot::ObservedPtr pFocusAnnot(GetFocusAnnot()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 317 | if (pFocusAnnot && pFocusAnnot != pFXAnnot) { |
| 318 | // Last focus Annot gets a chance to handle the event. |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 319 | if (pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFocusAnnot, nFlag, point)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 320 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 321 | } |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 322 | return pFXAnnot && |
| 323 | pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFXAnnot, nFlag, point); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 326 | bool CPDFSDK_PageView::OnMouseMove(const CFX_PointF& point, int nFlag) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 327 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 328 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 329 | CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXAnnotAtPoint(point)); |
Henrique Nakashima | 6551362 | 2017-08-16 14:48:13 -0400 | [diff] [blame] | 330 | |
Henrique Nakashima | 4a65254 | 2017-08-22 10:59:49 -0400 | [diff] [blame] | 331 | if (m_bOnWidget && m_pCaptureWidget != pFXAnnot) |
| 332 | ExitWidget(pAnnotHandlerMgr, true, nFlag); |
| 333 | |
| 334 | if (pFXAnnot) { |
| 335 | if (!m_bOnWidget) { |
| 336 | EnterWidget(pAnnotHandlerMgr, &pFXAnnot, nFlag); |
Henrique Nakashima | 6551362 | 2017-08-16 14:48:13 -0400 | [diff] [blame] | 337 | |
| 338 | // Annot_OnMouseEnter may have invalidated pFXAnnot. |
| 339 | if (!pFXAnnot) { |
Henrique Nakashima | 4a65254 | 2017-08-22 10:59:49 -0400 | [diff] [blame] | 340 | ExitWidget(pAnnotHandlerMgr, false, nFlag); |
Henrique Nakashima | 6551362 | 2017-08-16 14:48:13 -0400 | [diff] [blame] | 341 | return true; |
| 342 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 343 | } |
Henrique Nakashima | 4a65254 | 2017-08-22 10:59:49 -0400 | [diff] [blame] | 344 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 345 | pAnnotHandlerMgr->Annot_OnMouseMove(this, &pFXAnnot, nFlag, point); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 346 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 347 | } |
Henrique Nakashima | 6551362 | 2017-08-16 14:48:13 -0400 | [diff] [blame] | 348 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 349 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Henrique Nakashima | 4a65254 | 2017-08-22 10:59:49 -0400 | [diff] [blame] | 352 | void CPDFSDK_PageView::EnterWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr, |
| 353 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 354 | uint32_t nFlag) { |
| 355 | m_bOnWidget = true; |
| 356 | m_pCaptureWidget.Reset(pAnnot->Get()); |
| 357 | pAnnotHandlerMgr->Annot_OnMouseEnter(this, pAnnot, nFlag); |
| 358 | } |
| 359 | |
| 360 | void CPDFSDK_PageView::ExitWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr, |
| 361 | bool callExitCallback, |
| 362 | uint32_t nFlag) { |
| 363 | m_bOnWidget = false; |
| 364 | if (m_pCaptureWidget) { |
| 365 | if (callExitCallback) |
| 366 | pAnnotHandlerMgr->Annot_OnMouseExit(this, &m_pCaptureWidget, nFlag); |
| 367 | |
| 368 | m_pCaptureWidget.Reset(); |
| 369 | } |
| 370 | } |
| 371 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 372 | bool CPDFSDK_PageView::OnMouseWheel(double deltaX, |
| 373 | double deltaY, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 374 | const CFX_PointF& point, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 375 | int nFlag) { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 376 | CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point)); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 377 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 378 | return false; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 379 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 380 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 381 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Lei Zhang | 222e1a4 | 2017-06-20 14:47:00 -0700 | [diff] [blame] | 382 | return pAnnotHandlerMgr->Annot_OnMouseWheel(this, &pAnnot, nFlag, |
| 383 | static_cast<int>(deltaY), point); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 384 | } |
| 385 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 386 | bool CPDFSDK_PageView::OnChar(int nChar, uint32_t nFlag) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 387 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 388 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 389 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 390 | return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); |
| 391 | } |
| 392 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 393 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 394 | } |
| 395 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 396 | bool CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 397 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 398 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 399 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 400 | return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 401 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 402 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 403 | } |
| 404 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 405 | bool CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
| 406 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void CPDFSDK_PageView::LoadFXAnnots() { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 410 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 411 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 412 | |
Henrique Nakashima | 6551362 | 2017-08-16 14:48:13 -0400 | [diff] [blame] | 413 | CFX_AutoRestorer<bool> lock(&m_bLocked); |
| 414 | m_bLocked = true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 415 | |
| 416 | #ifdef PDF_ENABLE_XFA |
| 417 | CFX_RetainPtr<CPDFXFA_Page> protector(m_page); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 418 | if (m_pFormFillEnv->GetXFAContext()->GetDocType() == XFA_DocType::Dynamic) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 419 | CXFA_FFPageView* pageView = m_page->GetXFAPageView(); |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 420 | std::unique_ptr<IXFA_WidgetIterator> pWidgetHandler( |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 421 | pageView->CreateWidgetIterator( |
| 422 | XFA_TRAVERSEWAY_Form, |
| 423 | XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 424 | if (!pWidgetHandler) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 425 | return; |
| 426 | } |
| 427 | |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 428 | while (CXFA_FFWidget* pXFAAnnot = pWidgetHandler->MoveToNext()) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 429 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); |
| 430 | if (!pAnnot) |
| 431 | continue; |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 432 | m_SDKAnnotArray.push_back(pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 433 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 434 | } |
| 435 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 436 | return; |
| 437 | } |
| 438 | #endif // PDF_ENABLE_XFA |
| 439 | |
| 440 | CPDF_Page* pPage = GetPDFPage(); |
| 441 | ASSERT(pPage); |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 442 | bool bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 443 | // Disable the default AP construction. |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 444 | CPDF_InterForm::SetUpdateAP(false); |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 445 | m_pAnnotList = pdfium::MakeUnique<CPDF_AnnotList>(pPage); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 446 | CPDF_InterForm::SetUpdateAP(bUpdateAP); |
| 447 | |
| 448 | const size_t nCount = m_pAnnotList->Count(); |
| 449 | for (size_t i = 0; i < nCount; ++i) { |
| 450 | CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
| 451 | CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); |
| 452 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 453 | if (!pAnnot) |
| 454 | continue; |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 455 | m_SDKAnnotArray.push_back(pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 456 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 457 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 458 | } |
| 459 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 460 | void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 461 | for (const auto& rc : rects) |
Lei Zhang | 77f9bff | 2017-08-29 11:34:12 -0700 | [diff] [blame] | 462 | m_pFormFillEnv->Invalidate(m_page, rc.GetOuterRect()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { |
| 466 | CFX_FloatRect rcWindow = pAnnot->GetRect(); |
Lei Zhang | 77f9bff | 2017-08-29 11:34:12 -0700 | [diff] [blame] | 467 | m_pFormFillEnv->Invalidate(m_page, rcWindow.GetOuterRect()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | int CPDFSDK_PageView::GetPageIndex() const { |
| 471 | if (!m_page) |
| 472 | return -1; |
| 473 | |
| 474 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 475 | switch (m_page->GetContext()->GetDocType()) { |
| 476 | case XFA_DocType::Dynamic: { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 477 | CXFA_FFPageView* pPageView = m_page->GetXFAPageView(); |
| 478 | return pPageView ? pPageView->GetPageIndex() : -1; |
| 479 | } |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 480 | case XFA_DocType::Static: |
| 481 | case XFA_DocType::PDF: |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 482 | return GetPageIndexForStaticPDF(); |
| 483 | default: |
| 484 | return -1; |
| 485 | } |
| 486 | #else // PDF_ENABLE_XFA |
| 487 | return GetPageIndexForStaticPDF(); |
| 488 | #endif // PDF_ENABLE_XFA |
| 489 | } |
| 490 | |
| 491 | bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { |
| 492 | if (!p) |
| 493 | return false; |
| 494 | |
| 495 | const auto& annots = m_pAnnotList->All(); |
| 496 | auto it = std::find_if(annots.begin(), annots.end(), |
| 497 | [p](const std::unique_ptr<CPDF_Annot>& annot) { |
| 498 | return annot.get() == p; |
| 499 | }); |
| 500 | return it != annots.end(); |
| 501 | } |
| 502 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 503 | bool CPDFSDK_PageView::IsValidSDKAnnot(const CPDFSDK_Annot* p) const { |
| 504 | if (!p) |
| 505 | return false; |
| 506 | return pdfium::ContainsValue(m_SDKAnnotArray, p); |
| 507 | } |
| 508 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 509 | CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 510 | CPDFSDK_Annot* pFocusAnnot = m_pFormFillEnv->GetFocusAnnot(); |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 511 | return IsValidSDKAnnot(pFocusAnnot) ? pFocusAnnot : nullptr; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 515 | CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict.Get(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 516 | CPDF_Document* pDoc = m_pFormFillEnv->GetPDFDocument(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 517 | return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; |
| 518 | } |