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_widgethandler.h" | 7 #include "fpdfsdk/cpdfsdk_widgethandler.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "core/fpdfapi/page/cpdf_page.h" | 12 #include "core/fpdfapi/page/cpdf_page.h" |
13 #include "core/fpdfapi/parser/cpdf_document.h" | 13 #include "core/fpdfapi/parser/cpdf_document.h" |
14 #include "core/fpdfdoc/cpdf_interform.h" | 14 #include "core/fpdfdoc/cpdf_interform.h" |
15 #include "fpdfsdk/cpdfsdk_annot.h" | 15 #include "fpdfsdk/cpdfsdk_annot.h" |
16 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 16 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
17 #include "fpdfsdk/cpdfsdk_interform.h" | 17 #include "fpdfsdk/cpdfsdk_interform.h" |
18 #include "fpdfsdk/cpdfsdk_pageview.h" | 18 #include "fpdfsdk/cpdfsdk_pageview.h" |
19 #include "fpdfsdk/cpdfsdk_widget.h" | 19 #include "fpdfsdk/cpdfsdk_widget.h" |
20 #include "fpdfsdk/formfiller/cffl_formfiller.h" | 20 #include "fpdfsdk/formfiller/cffl_formfiller.h" |
21 | 21 |
22 #ifdef PDF_ENABLE_XFA | 22 #ifdef PDF_ENABLE_XFA |
23 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" | 23 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" |
24 #endif // PDF_ENABLE_XFA | 24 #endif // PDF_ENABLE_XFA |
25 | 25 |
26 CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler(CPDFSDK_FormFillEnvironment* pEnv) | 26 CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler( |
27 : m_pEnv(pEnv), m_pFormFiller(nullptr) {} | 27 CPDFSDK_FormFillEnvironment* pFormFillEnv) |
| 28 : m_pFormFillEnv(pFormFillEnv), m_pFormFiller(nullptr) {} |
28 | 29 |
29 CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() {} | 30 CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() {} |
30 | 31 |
31 FX_BOOL CPDFSDK_WidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { | 32 FX_BOOL CPDFSDK_WidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
32 ASSERT(pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET); | 33 ASSERT(pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET); |
33 if (pAnnot->IsSignatureWidget()) | 34 if (pAnnot->IsSignatureWidget()) |
34 return FALSE; | 35 return FALSE; |
35 | 36 |
36 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); | 37 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); |
37 if (!pWidget->IsVisible()) | 38 if (!pWidget->IsVisible()) |
38 return FALSE; | 39 return FALSE; |
39 | 40 |
40 int nFieldFlags = pWidget->GetFieldFlags(); | 41 int nFieldFlags = pWidget->GetFieldFlags(); |
41 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) | 42 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
42 return FALSE; | 43 return FALSE; |
43 | 44 |
44 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) | 45 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) |
45 return TRUE; | 46 return TRUE; |
46 | 47 |
47 CPDF_Page* pPage = pWidget->GetPDFPage(); | 48 CPDF_Page* pPage = pWidget->GetPDFPage(); |
48 CPDF_Document* pDocument = pPage->m_pDocument; | 49 CPDF_Document* pDocument = pPage->m_pDocument; |
49 uint32_t dwPermissions = pDocument->GetUserPermissions(); | 50 uint32_t dwPermissions = pDocument->GetUserPermissions(); |
50 return (dwPermissions & FPDFPERM_FILL_FORM) || | 51 return (dwPermissions & FPDFPERM_FILL_FORM) || |
51 (dwPermissions & FPDFPERM_ANNOT_FORM); | 52 (dwPermissions & FPDFPERM_ANNOT_FORM); |
52 } | 53 } |
53 | 54 |
54 CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CPDF_Annot* pAnnot, | 55 CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CPDF_Annot* pAnnot, |
55 CPDFSDK_PageView* pPage) { | 56 CPDFSDK_PageView* pPage) { |
56 CPDFSDK_InterForm* pInterForm = m_pEnv->GetInterForm(); | 57 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
57 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl( | 58 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl( |
58 pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); | 59 pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); |
59 if (!pCtrl) | 60 if (!pCtrl) |
60 return nullptr; | 61 return nullptr; |
61 | 62 |
62 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); | 63 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); |
63 pInterForm->AddMap(pCtrl, pWidget); | 64 pInterForm->AddMap(pCtrl, pWidget); |
64 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 65 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
65 if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) | 66 if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) |
66 pWidget->ResetAppearance(nullptr, FALSE); | 67 pWidget->ResetAppearance(nullptr, FALSE); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 294 |
294 FX_BOOL CPDFSDK_WidgetHandler::HitTest(CPDFSDK_PageView* pPageView, | 295 FX_BOOL CPDFSDK_WidgetHandler::HitTest(CPDFSDK_PageView* pPageView, |
295 CPDFSDK_Annot* pAnnot, | 296 CPDFSDK_Annot* pAnnot, |
296 const CFX_FloatPoint& point) { | 297 const CFX_FloatPoint& point) { |
297 ASSERT(pPageView); | 298 ASSERT(pPageView); |
298 ASSERT(pAnnot); | 299 ASSERT(pAnnot); |
299 | 300 |
300 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot); | 301 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot); |
301 return rect.Contains(point.x, point.y); | 302 return rect.Contains(point.x, point.y); |
302 } | 303 } |
OLD | NEW |