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 | |
Lei Zhang | 8153561 | 2018-10-09 21:15:17 +0000 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/render/cpdf_renderoptions.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 15 | #include "core/fpdfdoc/cpdf_annotlist.h" |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 16 | #include "core/fpdfdoc/cpdf_interactiveform.h" |
Dan Sinclair | b896699 | 2017-09-21 14:51:57 -0400 | [diff] [blame] | 17 | #include "core/fxcrt/autorestorer.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 18 | #include "fpdfsdk/cpdfsdk_annot.h" |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 19 | #include "fpdfsdk/cpdfsdk_annotiteration.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Tom Sepez | 8e94c18 | 2019-06-11 23:57:25 +0000 | [diff] [blame] | 21 | #include "fpdfsdk/cpdfsdk_helpers.h" |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 22 | #include "fpdfsdk/cpdfsdk_interactiveform.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 23 | #include "third_party/base/ptr_util.h" |
Lei Zhang | 35d4587 | 2018-10-12 19:07:03 +0000 | [diff] [blame] | 24 | #include "third_party/base/stl_util.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 25 | |
| 26 | #ifdef PDF_ENABLE_XFA |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 27 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Tom Sepez | 451ed2d | 2019-08-19 22:55:31 +0000 | [diff] [blame] | 28 | #include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 29 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 30 | #include "xfa/fxfa/cxfa_ffpageview.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 31 | #endif // PDF_ENABLE_XFA |
| 32 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 33 | CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 34 | IPDF_Page* page) |
Tom Sepez | 2aa4b2f | 2018-05-25 22:38:49 +0000 | [diff] [blame] | 35 | : m_page(page), m_pFormFillEnv(pFormFillEnv) { |
Tom Sepez | a3843c9 | 2018-06-12 19:21:46 +0000 | [diff] [blame] | 36 | ASSERT(m_page); |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 37 | CPDF_Page* pPDFPage = ToPDFPage(page); |
| 38 | if (pPDFPage) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 39 | CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm(); |
| 40 | CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); |
| 41 | pPDFForm->FixPageFields(pPDFPage); |
Tom Sepez | a3843c9 | 2018-06-12 19:21:46 +0000 | [diff] [blame] | 42 | if (!page->AsXFAPage()) |
| 43 | pPDFPage->SetView(this); |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 44 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | CPDFSDK_PageView::~CPDFSDK_PageView() { |
Tom Sepez | a3843c9 | 2018-06-12 19:21:46 +0000 | [diff] [blame] | 48 | if (!m_page->AsXFAPage()) { |
| 49 | // The call to |ReleaseAnnot| can cause the page pointed to by |m_page| to |
| 50 | // be freed, which will cause issues if we try to cleanup the pageview |
| 51 | // pointer in |m_page|. So, reset the pageview pointer before doing anything |
| 52 | // else. |
| 53 | m_page->AsPDFPage()->SetView(nullptr); |
| 54 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 55 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 56 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 57 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 58 | for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray) |
Tom Sepez | 0f35a9e | 2019-04-23 00:32:37 +0000 | [diff] [blame] | 59 | pAnnotHandlerMgr->ReleaseAnnot(pdfium::WrapUnique(pAnnot)); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 60 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 61 | m_SDKAnnotArray.clear(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 62 | m_pAnnotList.reset(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 66 | const CFX_Matrix& mtUser2Device, |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 67 | CPDF_RenderOptions* pOptions, |
| 68 | const FX_RECT& pClip) { |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 69 | m_curMatrix = mtUser2Device; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 70 | |
| 71 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 72 | IPDF_Page* pPage = GetXFAPage(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 73 | if (!pPage) |
| 74 | return; |
| 75 | |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 76 | CPDF_Document::Extension* pContext = pPage->GetDocument()->GetExtension(); |
Tom Sepez | 0126b03 | 2019-08-19 16:48:25 +0000 | [diff] [blame] | 77 | if (pContext->ContainsExtensionFullForm()) { |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 78 | static_cast<CPDFXFA_Page*>(pPage)->DrawFocusAnnot(pDevice, GetFocusAnnot(), |
| 79 | mtUser2Device, pClip); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 80 | return; |
| 81 | } |
| 82 | #endif // PDF_ENABLE_XFA |
| 83 | |
| 84 | // for pdf/static xfa. |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 85 | CPDFSDK_AnnotIteration annotIteration(this, true); |
| 86 | for (const auto& pSDKAnnot : annotIteration) { |
| 87 | m_pFormFillEnv->GetAnnotHandlerMgr()->Annot_OnDraw( |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 88 | this, pSDKAnnot.Get(), pDevice, mtUser2Device, |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 89 | pOptions->GetDrawAnnots()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 93 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(const CFX_PointF& point) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 94 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = m_pFormFillEnv->GetAnnotHandlerMgr(); |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 95 | CPDFSDK_AnnotIteration annotIteration(this, false); |
| 96 | for (const auto& pSDKAnnot : annotIteration) { |
| 97 | CFX_FloatRect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot.Get()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 98 | if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) |
| 99 | continue; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 100 | if (rc.Contains(point)) |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 101 | return pSDKAnnot.Get(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 102 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 103 | return nullptr; |
| 104 | } |
| 105 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 106 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(const CFX_PointF& point) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 107 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = m_pFormFillEnv->GetAnnotHandlerMgr(); |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 108 | CPDFSDK_AnnotIteration annotIteration(this, false); |
| 109 | for (const auto& pSDKAnnot : annotIteration) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 110 | bool bHitTest = pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET; |
| 111 | #ifdef PDF_ENABLE_XFA |
| 112 | bHitTest = bHitTest || |
| 113 | pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::XFAWIDGET; |
| 114 | #endif // PDF_ENABLE_XFA |
| 115 | if (bHitTest) { |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 116 | pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot.Get()); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 117 | if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot.Get(), point)) |
tsepez | d805eec | 2017-01-11 14:03:54 -0800 | [diff] [blame] | 118 | return pSDKAnnot.Get(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 119 | } |
| 120 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 121 | return nullptr; |
| 122 | } |
| 123 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 124 | #ifdef PDF_ENABLE_XFA |
| 125 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 126 | CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); |
| 127 | if (pSDKAnnot) |
| 128 | return pSDKAnnot; |
| 129 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 130 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pFormFillEnv->GetAnnotHandlerMgr(); |
Lei Zhang | 51d0266 | 2019-10-31 18:28:51 +0000 | [diff] [blame] | 131 | std::unique_ptr<CPDFSDK_Annot> pNewAnnot = |
| 132 | pAnnotHandler->NewXFAAnnot(pPDFAnnot, this); |
| 133 | ASSERT(pNewAnnot); |
| 134 | pSDKAnnot = pNewAnnot.get(); |
| 135 | // TODO(thestig): See if |m_SDKAnnotArray|, which takes ownership of |
| 136 | // |pNewAnnot|, can hold std::unique_ptrs instead of raw pointers. |
| 137 | m_SDKAnnotArray.push_back(pNewAnnot.release()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 138 | return pSDKAnnot; |
| 139 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 140 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 141 | bool CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 142 | IPDF_Page* pPage = pAnnot->GetXFAPage(); |
Tom Sepez | ccd9421 | 2018-05-03 13:53:02 +0000 | [diff] [blame] | 143 | if (!pPage) |
| 144 | return false; |
| 145 | |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 146 | CPDF_Document::Extension* pContext = pPage->GetDocument()->GetExtension(); |
Tom Sepez | d48bd29 | 2019-08-14 19:48:55 +0000 | [diff] [blame] | 147 | if (!pContext->ContainsExtensionForm()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 148 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 149 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 150 | ObservedPtr<CPDFSDK_Annot> pObserved(pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 151 | if (GetFocusAnnot() == pAnnot) |
Tom Sepez | bfa2a97 | 2017-07-24 11:38:31 -0700 | [diff] [blame] | 152 | m_pFormFillEnv->KillFocusAnnot(0); // May invoke JS, invalidating pAnnot. |
| 153 | |
| 154 | if (pObserved) { |
| 155 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = |
| 156 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 157 | if (pAnnotHandler) |
Tom Sepez | 0f35a9e | 2019-04-23 00:32:37 +0000 | [diff] [blame] | 158 | pAnnotHandler->ReleaseAnnot(pdfium::WrapUnique(pObserved.Get())); |
Tom Sepez | bfa2a97 | 2017-07-24 11:38:31 -0700 | [diff] [blame] | 159 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 160 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 161 | auto it = std::find(m_SDKAnnotArray.begin(), m_SDKAnnotArray.end(), pAnnot); |
| 162 | if (it != m_SDKAnnotArray.end()) |
| 163 | m_SDKAnnotArray.erase(it); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 164 | if (m_pCaptureWidget.Get() == pAnnot) |
| 165 | m_pCaptureWidget.Reset(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 166 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 167 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 168 | } |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 169 | #endif // PDF_ENABLE_XFA |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 170 | |
| 171 | CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
Tom Sepez | 7b0ff3c | 2018-10-04 22:19:32 +0000 | [diff] [blame] | 172 | return m_page->GetDocument(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | CPDF_Page* CPDFSDK_PageView::GetPDFPage() const { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 176 | return ToPDFPage(m_page); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 177 | } |
| 178 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 179 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 180 | for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 181 | if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) |
| 182 | return pAnnot; |
| 183 | } |
| 184 | return nullptr; |
| 185 | } |
| 186 | |
| 187 | #ifdef PDF_ENABLE_XFA |
| 188 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(CXFA_FFWidget* hWidget) { |
| 189 | if (!hWidget) |
| 190 | return nullptr; |
| 191 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 192 | for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray) { |
Tom Sepez | 451ed2d | 2019-08-19 22:55:31 +0000 | [diff] [blame] | 193 | if (ToXFAWidget(pAnnot)->GetXFAFFWidget() == hWidget) |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 194 | return pAnnot; |
| 195 | } |
| 196 | return nullptr; |
| 197 | } |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 198 | |
| 199 | IPDF_Page* CPDFSDK_PageView::GetXFAPage() { |
| 200 | return ToXFAPage(m_page); |
| 201 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 202 | #endif // PDF_ENABLE_XFA |
| 203 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 204 | WideString CPDFSDK_PageView::GetFocusedFormText() { |
| 205 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 206 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 207 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 208 | return pAnnotHandlerMgr->Annot_GetText(pAnnot); |
| 209 | } |
| 210 | |
| 211 | return WideString(); |
| 212 | } |
| 213 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 214 | WideString CPDFSDK_PageView::GetSelectedText() { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 215 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 216 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 217 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 218 | return pAnnotHandlerMgr->Annot_GetSelectedText(pAnnot); |
| 219 | } |
| 220 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 221 | return WideString(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 224 | void CPDFSDK_PageView::ReplaceSelection(const WideString& text) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 225 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 226 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 227 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 228 | pAnnotHandlerMgr->Annot_ReplaceSelection(pAnnot, text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 232 | bool CPDFSDK_PageView::CanUndo() { |
| 233 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 234 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 235 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 236 | return pAnnotHandlerMgr->Annot_CanUndo(pAnnot); |
| 237 | } |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | bool CPDFSDK_PageView::CanRedo() { |
| 242 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 243 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 244 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 245 | return pAnnotHandlerMgr->Annot_CanRedo(pAnnot); |
| 246 | } |
| 247 | return false; |
| 248 | } |
| 249 | |
| 250 | bool CPDFSDK_PageView::Undo() { |
| 251 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 252 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 253 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 254 | return pAnnotHandlerMgr->Annot_Undo(pAnnot); |
| 255 | } |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | bool CPDFSDK_PageView::Redo() { |
| 260 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
| 261 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 262 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 263 | return pAnnotHandlerMgr->Annot_Redo(pAnnot); |
| 264 | } |
| 265 | return false; |
| 266 | } |
| 267 | |
Lei Zhang | 63b0126 | 2017-08-31 08:54:46 -0700 | [diff] [blame] | 268 | bool CPDFSDK_PageView::OnFocus(const CFX_PointF& point, uint32_t nFlag) { |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 269 | ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); |
Lei Zhang | 63b0126 | 2017-08-31 08:54:46 -0700 | [diff] [blame] | 270 | if (!pAnnot) { |
| 271 | m_pFormFillEnv->KillFocusAnnot(nFlag); |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
| 276 | return true; |
| 277 | } |
| 278 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 279 | bool CPDFSDK_PageView::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 280 | ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 281 | if (!pAnnot) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 282 | m_pFormFillEnv->KillFocusAnnot(nFlag); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 283 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 284 | } |
| 285 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 286 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 287 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 288 | if (!pAnnotHandlerMgr->Annot_OnLButtonDown(this, &pAnnot, nFlag, point)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 289 | return false; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 290 | |
| 291 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 292 | return false; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 293 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 294 | m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
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 | |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 298 | bool CPDFSDK_PageView::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
| 299 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 300 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 301 | ObservedPtr<CPDFSDK_Annot> pFXAnnot(GetFXWidgetAtPoint(point)); |
| 302 | ObservedPtr<CPDFSDK_Annot> pFocusAnnot(GetFocusAnnot()); |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 303 | if (pFocusAnnot && pFocusAnnot != pFXAnnot) { |
| 304 | // Last focus Annot gets a chance to handle the event. |
| 305 | if (pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFocusAnnot, nFlag, point)) |
| 306 | return true; |
| 307 | } |
| 308 | return pFXAnnot && |
| 309 | pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFXAnnot, nFlag, point); |
| 310 | } |
| 311 | |
| 312 | bool CPDFSDK_PageView::OnLButtonDblClk(const CFX_PointF& point, |
| 313 | uint32_t nFlag) { |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 314 | ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 315 | if (!pAnnot) { |
| 316 | m_pFormFillEnv->KillFocusAnnot(nFlag); |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 321 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 322 | if (!pAnnotHandlerMgr->Annot_OnLButtonDblClk(this, &pAnnot, nFlag, point)) |
| 323 | return false; |
| 324 | |
| 325 | if (!pAnnot) |
| 326 | return false; |
| 327 | |
| 328 | m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
| 329 | return true; |
| 330 | } |
| 331 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 332 | bool CPDFSDK_PageView::OnRButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 333 | ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 334 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 335 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 336 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 337 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 338 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 339 | bool ok = pAnnotHandlerMgr->Annot_OnRButtonDown(this, &pAnnot, nFlag, point); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 340 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 341 | return false; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 342 | |
| 343 | if (ok) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 344 | m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 345 | |
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 | } |
| 348 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 349 | bool CPDFSDK_PageView::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Tom Sepez | b2745de | 2020-01-15 21:50:48 +0000 | [diff] [blame] | 350 | ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); |
| 351 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 352 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 353 | |
Tom Sepez | b2745de | 2020-01-15 21:50:48 +0000 | [diff] [blame] | 354 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 355 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 356 | bool ok = pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pAnnot, nFlag, point); |
| 357 | if (!pAnnot) |
| 358 | return false; |
| 359 | |
| 360 | if (ok) |
| 361 | m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 362 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 363 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 364 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 365 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 366 | bool CPDFSDK_PageView::OnMouseMove(const CFX_PointF& point, int nFlag) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 367 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 368 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Tom Sepez | c3a9173 | 2019-11-01 21:53:00 +0000 | [diff] [blame] | 369 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 370 | ObservedPtr<CPDFSDK_Annot> pFXAnnot(GetFXAnnotAtPoint(point)); |
Tom Sepez | c3a9173 | 2019-11-01 21:53:00 +0000 | [diff] [blame] | 371 | ObservedPtr<CPDFSDK_PageView> pThis(this); |
Henrique Nakashima | 6551362 | 2017-08-16 14:48:13 -0400 | [diff] [blame] | 372 | |
Henrique Nakashima | 4a65254 | 2017-08-22 10:59:49 -0400 | [diff] [blame] | 373 | if (m_bOnWidget && m_pCaptureWidget != pFXAnnot) |
| 374 | ExitWidget(pAnnotHandlerMgr, true, nFlag); |
| 375 | |
Tom Sepez | c3a9173 | 2019-11-01 21:53:00 +0000 | [diff] [blame] | 376 | // ExitWidget() may have invalidated objects. |
| 377 | if (!pThis || !pFXAnnot) |
| 378 | return false; |
Henrique Nakashima | 6551362 | 2017-08-16 14:48:13 -0400 | [diff] [blame] | 379 | |
Tom Sepez | c3a9173 | 2019-11-01 21:53:00 +0000 | [diff] [blame] | 380 | if (!m_bOnWidget) { |
| 381 | EnterWidget(pAnnotHandlerMgr, &pFXAnnot, nFlag); |
| 382 | |
| 383 | // EnterWidget() may have invalidated objects. |
| 384 | if (!pThis) |
| 385 | return false; |
| 386 | |
| 387 | if (!pFXAnnot) { |
| 388 | ExitWidget(pAnnotHandlerMgr, false, nFlag); |
| 389 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 390 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 391 | } |
Tom Sepez | c3a9173 | 2019-11-01 21:53:00 +0000 | [diff] [blame] | 392 | pAnnotHandlerMgr->Annot_OnMouseMove(this, &pFXAnnot, nFlag, point); |
| 393 | return true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Henrique Nakashima | 4a65254 | 2017-08-22 10:59:49 -0400 | [diff] [blame] | 396 | void CPDFSDK_PageView::EnterWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 397 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Henrique Nakashima | 4a65254 | 2017-08-22 10:59:49 -0400 | [diff] [blame] | 398 | uint32_t nFlag) { |
| 399 | m_bOnWidget = true; |
| 400 | m_pCaptureWidget.Reset(pAnnot->Get()); |
| 401 | pAnnotHandlerMgr->Annot_OnMouseEnter(this, pAnnot, nFlag); |
| 402 | } |
| 403 | |
| 404 | void CPDFSDK_PageView::ExitWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr, |
| 405 | bool callExitCallback, |
| 406 | uint32_t nFlag) { |
| 407 | m_bOnWidget = false; |
| 408 | if (m_pCaptureWidget) { |
| 409 | if (callExitCallback) |
| 410 | pAnnotHandlerMgr->Annot_OnMouseExit(this, &m_pCaptureWidget, nFlag); |
| 411 | |
| 412 | m_pCaptureWidget.Reset(); |
| 413 | } |
| 414 | } |
| 415 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 416 | bool CPDFSDK_PageView::OnMouseWheel(double deltaX, |
| 417 | double deltaY, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 418 | const CFX_PointF& point, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 419 | int nFlag) { |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 420 | ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point)); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 421 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 422 | return false; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 423 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 424 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 425 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
Lei Zhang | 222e1a4 | 2017-06-20 14:47:00 -0700 | [diff] [blame] | 426 | return pAnnotHandlerMgr->Annot_OnMouseWheel(this, &pAnnot, nFlag, |
| 427 | static_cast<int>(deltaY), point); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 428 | } |
| 429 | |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 430 | bool CPDFSDK_PageView::SetIndexSelected(int index, bool selected) { |
| 431 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 432 | ObservedPtr<CPDFSDK_Annot> pAnnotObserved(pAnnot); |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 433 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 434 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 435 | return pAnnotHandlerMgr->Annot_SetIndexSelected(&pAnnotObserved, index, |
| 436 | selected); |
| 437 | } |
| 438 | |
| 439 | return false; |
| 440 | } |
| 441 | |
| 442 | bool CPDFSDK_PageView::IsIndexSelected(int index) { |
| 443 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 444 | ObservedPtr<CPDFSDK_Annot> pAnnotObserved(pAnnot); |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 445 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 446 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 447 | return pAnnotHandlerMgr->Annot_IsIndexSelected(&pAnnotObserved, index); |
| 448 | } |
| 449 | |
| 450 | return false; |
| 451 | } |
| 452 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 453 | bool CPDFSDK_PageView::OnChar(int nChar, uint32_t nFlag) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 454 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 455 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 456 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 457 | return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); |
| 458 | } |
| 459 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 460 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 461 | } |
| 462 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 463 | bool CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 464 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 465 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 466 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 467 | return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 468 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 469 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 470 | } |
| 471 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 472 | bool CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
| 473 | return false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void CPDFSDK_PageView::LoadFXAnnots() { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 477 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 478 | m_pFormFillEnv->GetAnnotHandlerMgr(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 479 | |
Dan Sinclair | b896699 | 2017-09-21 14:51:57 -0400 | [diff] [blame] | 480 | AutoRestorer<bool> lock(&m_bLocked); |
Henrique Nakashima | 6551362 | 2017-08-16 14:48:13 -0400 | [diff] [blame] | 481 | m_bLocked = true; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 482 | |
| 483 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 484 | RetainPtr<CPDFXFA_Page> protector(ToXFAPage(m_page)); |
Tom Sepez | 0126b03 | 2019-08-19 16:48:25 +0000 | [diff] [blame] | 485 | auto* pContext = m_pFormFillEnv->GetDocExtension(); |
| 486 | if (pContext->ContainsExtensionFullForm()) { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 487 | CXFA_FFPageView* pageView = protector->GetXFAPageView(); |
Tom Sepez | c256469 | 2020-01-09 23:34:16 +0000 | [diff] [blame] | 488 | std::unique_ptr<IXFA_WidgetIterator> pWidgetHandler = |
| 489 | pageView->CreateFormWidgetIterator(XFA_WidgetStatus_Visible | |
| 490 | XFA_WidgetStatus_Viewable); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 491 | |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 492 | while (CXFA_FFWidget* pXFAAnnot = pWidgetHandler->MoveToNext()) { |
Lei Zhang | 51d0266 | 2019-10-31 18:28:51 +0000 | [diff] [blame] | 493 | std::unique_ptr<CPDFSDK_Annot> pNewAnnot = |
| 494 | pAnnotHandlerMgr->NewXFAAnnot(pXFAAnnot, this); |
| 495 | ASSERT(pNewAnnot); |
| 496 | CPDFSDK_Annot* pAnnot = pNewAnnot.get(); |
| 497 | m_SDKAnnotArray.push_back(pNewAnnot.release()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 498 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 499 | } |
| 500 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 501 | return; |
| 502 | } |
| 503 | #endif // PDF_ENABLE_XFA |
| 504 | |
| 505 | CPDF_Page* pPage = GetPDFPage(); |
| 506 | ASSERT(pPage); |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 507 | bool bUpdateAP = CPDF_InteractiveForm::IsUpdateAPEnabled(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 508 | // Disable the default AP construction. |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 509 | CPDF_InteractiveForm::SetUpdateAP(false); |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 510 | m_pAnnotList = pdfium::MakeUnique<CPDF_AnnotList>(pPage); |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 511 | CPDF_InteractiveForm::SetUpdateAP(bUpdateAP); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 512 | |
| 513 | const size_t nCount = m_pAnnotList->Count(); |
| 514 | for (size_t i = 0; i < nCount; ++i) { |
| 515 | CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
Lei Zhang | 4efdb51 | 2019-02-26 19:48:39 +0000 | [diff] [blame] | 516 | CheckForUnsupportedAnnot(pPDFAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 517 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 518 | if (!pAnnot) |
| 519 | continue; |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 520 | m_SDKAnnotArray.push_back(pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 521 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 522 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 523 | } |
| 524 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 525 | void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 526 | for (const auto& rc : rects) |
Lei Zhang | 77f9bff | 2017-08-29 11:34:12 -0700 | [diff] [blame] | 527 | m_pFormFillEnv->Invalidate(m_page, rc.GetOuterRect()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { |
| 531 | CFX_FloatRect rcWindow = pAnnot->GetRect(); |
Lei Zhang | 77f9bff | 2017-08-29 11:34:12 -0700 | [diff] [blame] | 532 | m_pFormFillEnv->Invalidate(m_page, rcWindow.GetOuterRect()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | int CPDFSDK_PageView::GetPageIndex() const { |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 536 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 537 | CPDF_Document::Extension* pContext = m_page->GetDocument()->GetExtension(); |
Tom Sepez | 0126b03 | 2019-08-19 16:48:25 +0000 | [diff] [blame] | 538 | if (pContext->ContainsExtensionFullForm()) { |
| 539 | CXFA_FFPageView* pPageView = m_page->AsXFAPage()->GetXFAPageView(); |
| 540 | return pPageView ? pPageView->GetLayoutItem()->GetPageIndex() : -1; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 541 | } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 542 | #endif // PDF_ENABLE_XFA |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 543 | return GetPageIndexForStaticPDF(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { |
| 547 | if (!p) |
| 548 | return false; |
| 549 | |
| 550 | const auto& annots = m_pAnnotList->All(); |
| 551 | auto it = std::find_if(annots.begin(), annots.end(), |
| 552 | [p](const std::unique_ptr<CPDF_Annot>& annot) { |
| 553 | return annot.get() == p; |
| 554 | }); |
| 555 | return it != annots.end(); |
| 556 | } |
| 557 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 558 | bool CPDFSDK_PageView::IsValidSDKAnnot(const CPDFSDK_Annot* p) const { |
| 559 | if (!p) |
| 560 | return false; |
| 561 | return pdfium::ContainsValue(m_SDKAnnotArray, p); |
| 562 | } |
| 563 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 564 | CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 565 | CPDFSDK_Annot* pFocusAnnot = m_pFormFillEnv->GetFocusAnnot(); |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 566 | return IsValidSDKAnnot(pFocusAnnot) ? pFocusAnnot : nullptr; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
Henrique Nakashima | 888af47 | 2018-06-07 19:43:42 +0000 | [diff] [blame] | 570 | const CPDF_Dictionary* pDict = GetPDFPage()->GetDict(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 571 | CPDF_Document* pDoc = m_pFormFillEnv->GetPDFDocument(); |
Lei Zhang | f97fd06 | 2019-08-09 22:18:39 +0000 | [diff] [blame] | 572 | return pDoc->GetPageIndex(pDict->GetObjNum()); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 573 | } |