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