| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/cpdfsdk_pageview.h" | 7 #include "fpdfsdk/cpdfsdk_pageview.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 m_pFormFillEnv(pFormFillEnv), | 35 m_pFormFillEnv(pFormFillEnv), |
| 36 #ifndef PDF_ENABLE_XFA | 36 #ifndef PDF_ENABLE_XFA |
| 37 m_bOwnsPage(false), | 37 m_bOwnsPage(false), |
| 38 #endif // PDF_ENABLE_XFA | 38 #endif // PDF_ENABLE_XFA |
| 39 m_bEnterWidget(FALSE), | 39 m_bEnterWidget(FALSE), |
| 40 m_bExitWidget(FALSE), | 40 m_bExitWidget(FALSE), |
| 41 m_bOnWidget(FALSE), | 41 m_bOnWidget(FALSE), |
| 42 m_bValid(FALSE), | 42 m_bValid(FALSE), |
| 43 m_bLocked(FALSE), | 43 m_bLocked(FALSE), |
| 44 m_bBeingDestroyed(false) { | 44 m_bBeingDestroyed(false) { |
| 45 CPDFSDK_InterForm* pInterForm = | 45 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 46 pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 47 if (pInterForm) { | 46 if (pInterForm) { |
| 48 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 47 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 49 #ifdef PDF_ENABLE_XFA | 48 #ifdef PDF_ENABLE_XFA |
| 50 if (page->GetPDFPage()) | 49 if (page->GetPDFPage()) |
| 51 pPDFInterForm->FixPageFields(page->GetPDFPage()); | 50 pPDFInterForm->FixPageFields(page->GetPDFPage()); |
| 52 #else // PDF_ENABLE_XFA | 51 #else // PDF_ENABLE_XFA |
| 53 pPDFInterForm->FixPageFields(page); | 52 pPDFInterForm->FixPageFields(page); |
| 54 #endif // PDF_ENABLE_XFA | 53 #endif // PDF_ENABLE_XFA |
| 55 } | 54 } |
| 56 #ifndef PDF_ENABLE_XFA | 55 #ifndef PDF_ENABLE_XFA |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 189 |
| 191 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { | 190 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
| 192 if (!pAnnot) | 191 if (!pAnnot) |
| 193 return FALSE; | 192 return FALSE; |
| 194 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); | 193 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
| 195 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && | 194 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && |
| 196 pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) | 195 pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) |
| 197 return FALSE; | 196 return FALSE; |
| 198 | 197 |
| 199 if (GetFocusAnnot() == pAnnot) | 198 if (GetFocusAnnot() == pAnnot) |
| 200 m_pFormFillEnv->GetSDKDocument()->KillFocusAnnot(0); | 199 m_pFormFillEnv->KillFocusAnnot(0); |
| 201 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pFormFillEnv->GetAnnotHandlerMgr(); | 200 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 202 if (pAnnotHandler) | 201 if (pAnnotHandler) |
| 203 pAnnotHandler->ReleaseAnnot(pAnnot); | 202 pAnnotHandler->ReleaseAnnot(pAnnot); |
| 204 | 203 |
| 205 auto it = std::find(m_SDKAnnotArray.begin(), m_SDKAnnotArray.end(), pAnnot); | 204 auto it = std::find(m_SDKAnnotArray.begin(), m_SDKAnnotArray.end(), pAnnot); |
| 206 if (it != m_SDKAnnotArray.end()) | 205 if (it != m_SDKAnnotArray.end()) |
| 207 m_SDKAnnotArray.erase(it); | 206 m_SDKAnnotArray.erase(it); |
| 208 if (m_pCaptureWidget.Get() == pAnnot) | 207 if (m_pCaptureWidget.Get() == pAnnot) |
| 209 m_pCaptureWidget.Reset(); | 208 m_pCaptureWidget.Reset(); |
| 210 | 209 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return pAnnot; | 248 return pAnnot; |
| 250 } | 249 } |
| 251 return nullptr; | 250 return nullptr; |
| 252 } | 251 } |
| 253 #endif // PDF_ENABLE_XFA | 252 #endif // PDF_ENABLE_XFA |
| 254 | 253 |
| 255 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point, | 254 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point, |
| 256 uint32_t nFlag) { | 255 uint32_t nFlag) { |
| 257 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y)); | 256 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y)); |
| 258 if (!pAnnot) { | 257 if (!pAnnot) { |
| 259 m_pFormFillEnv->GetSDKDocument()->KillFocusAnnot(nFlag); | 258 m_pFormFillEnv->KillFocusAnnot(nFlag); |
| 260 return FALSE; | 259 return FALSE; |
| 261 } | 260 } |
| 262 | 261 |
| 263 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = | 262 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 264 m_pFormFillEnv->GetAnnotHandlerMgr(); | 263 m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 265 if (!pAnnotHandlerMgr->Annot_OnLButtonDown(this, &pAnnot, nFlag, point)) | 264 if (!pAnnotHandlerMgr->Annot_OnLButtonDown(this, &pAnnot, nFlag, point)) |
| 266 return FALSE; | 265 return FALSE; |
| 267 | 266 |
| 268 if (!pAnnot) | 267 if (!pAnnot) |
| 269 return FALSE; | 268 return FALSE; |
| 270 | 269 |
| 271 m_pFormFillEnv->GetSDKDocument()->SetFocusAnnot(&pAnnot); | 270 m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
| 272 return TRUE; | 271 return TRUE; |
| 273 } | 272 } |
| 274 | 273 |
| 275 #ifdef PDF_ENABLE_XFA | 274 #ifdef PDF_ENABLE_XFA |
| 276 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, | 275 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, |
| 277 uint32_t nFlag) { | 276 uint32_t nFlag) { |
| 278 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y)); | 277 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y)); |
| 279 if (!pAnnot) | 278 if (!pAnnot) |
| 280 return FALSE; | 279 return FALSE; |
| 281 | 280 |
| 282 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = | 281 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 283 m_pFormFillEnv->GetAnnotHandlerMgr(); | 282 m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 284 FX_BOOL ok = | 283 FX_BOOL ok = |
| 285 pAnnotHandlerMgr->Annot_OnRButtonDown(this, &pAnnot, nFlag, point); | 284 pAnnotHandlerMgr->Annot_OnRButtonDown(this, &pAnnot, nFlag, point); |
| 286 if (!pAnnot) | 285 if (!pAnnot) |
| 287 return FALSE; | 286 return FALSE; |
| 288 | 287 |
| 289 if (ok) | 288 if (ok) |
| 290 m_pFormFillEnv->GetSDKDocument()->SetFocusAnnot(&pAnnot); | 289 m_pFormFillEnv->SetFocusAnnot(&pAnnot); |
| 291 | 290 |
| 292 return TRUE; | 291 return TRUE; |
| 293 } | 292 } |
| 294 | 293 |
| 295 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, | 294 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, |
| 296 uint32_t nFlag) { | 295 uint32_t nFlag) { |
| 297 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = | 296 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 298 m_pFormFillEnv->GetAnnotHandlerMgr(); | 297 m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 299 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y)); | 298 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y)); |
| 300 if (!pFXAnnot) | 299 if (!pFXAnnot) |
| 301 return FALSE; | 300 return FALSE; |
| 302 | 301 |
| 303 if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pFXAnnot, nFlag, point)) | 302 if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pFXAnnot, nFlag, point)) |
| 304 m_pFormFillEnv->GetSDKDocument()->SetFocusAnnot(&pFXAnnot); | 303 m_pFormFillEnv->SetFocusAnnot(&pFXAnnot); |
| 305 | 304 |
| 306 return TRUE; | 305 return TRUE; |
| 307 } | 306 } |
| 308 #endif // PDF_ENABLE_XFA | 307 #endif // PDF_ENABLE_XFA |
| 309 | 308 |
| 310 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point, | 309 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point, |
| 311 uint32_t nFlag) { | 310 uint32_t nFlag) { |
| 312 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = | 311 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 313 m_pFormFillEnv->GetAnnotHandlerMgr(); | 312 m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 314 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y)); | 313 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 } | 391 } |
| 393 | 392 |
| 394 void CPDFSDK_PageView::LoadFXAnnots() { | 393 void CPDFSDK_PageView::LoadFXAnnots() { |
| 395 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = | 394 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = |
| 396 m_pFormFillEnv->GetAnnotHandlerMgr(); | 395 m_pFormFillEnv->GetAnnotHandlerMgr(); |
| 397 | 396 |
| 398 SetLock(TRUE); | 397 SetLock(TRUE); |
| 399 | 398 |
| 400 #ifdef PDF_ENABLE_XFA | 399 #ifdef PDF_ENABLE_XFA |
| 401 CFX_RetainPtr<CPDFXFA_Page> protector(m_page); | 400 CFX_RetainPtr<CPDFXFA_Page> protector(m_page); |
| 402 if (m_pFormFillEnv->GetSDKDocument()->GetXFADocument()->GetDocType() == | 401 if (m_pFormFillEnv->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { |
| 403 DOCTYPE_DYNAMIC_XFA) { | |
| 404 CXFA_FFPageView* pageView = m_page->GetXFAPageView(); | 402 CXFA_FFPageView* pageView = m_page->GetXFAPageView(); |
| 405 std::unique_ptr<IXFA_WidgetIterator> pWidgetHander( | 403 std::unique_ptr<IXFA_WidgetIterator> pWidgetHander( |
| 406 pageView->CreateWidgetIterator( | 404 pageView->CreateWidgetIterator( |
| 407 XFA_TRAVERSEWAY_Form, | 405 XFA_TRAVERSEWAY_Form, |
| 408 XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); | 406 XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); |
| 409 if (!pWidgetHander) { | 407 if (!pWidgetHander) { |
| 410 SetLock(FALSE); | 408 SetLock(FALSE); |
| 411 return; | 409 return; |
| 412 } | 410 } |
| 413 | 411 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 return it != annots.end(); | 489 return it != annots.end(); |
| 492 } | 490 } |
| 493 | 491 |
| 494 bool CPDFSDK_PageView::IsValidSDKAnnot(const CPDFSDK_Annot* p) const { | 492 bool CPDFSDK_PageView::IsValidSDKAnnot(const CPDFSDK_Annot* p) const { |
| 495 if (!p) | 493 if (!p) |
| 496 return false; | 494 return false; |
| 497 return pdfium::ContainsValue(m_SDKAnnotArray, p); | 495 return pdfium::ContainsValue(m_SDKAnnotArray, p); |
| 498 } | 496 } |
| 499 | 497 |
| 500 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { | 498 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
| 501 CPDFSDK_Annot* pFocusAnnot = | 499 CPDFSDK_Annot* pFocusAnnot = m_pFormFillEnv->GetFocusAnnot(); |
| 502 m_pFormFillEnv->GetSDKDocument()->GetFocusAnnot(); | |
| 503 return IsValidSDKAnnot(pFocusAnnot) ? pFocusAnnot : nullptr; | 500 return IsValidSDKAnnot(pFocusAnnot) ? pFocusAnnot : nullptr; |
| 504 } | 501 } |
| 505 | 502 |
| 506 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { | 503 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
| 507 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; | 504 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; |
| 508 CPDF_Document* pDoc = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); | 505 CPDF_Document* pDoc = m_pFormFillEnv->GetPDFDocument(); |
| 509 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; | 506 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; |
| 510 } | 507 } |
| OLD | NEW |