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