jaepark | 8c54182 | 2016-08-30 13:43:05 -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_widgethandler.h" |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 8 | |
| 9 | #include <memory> |
| 10 | #include <vector> |
| 11 | |
Lei Zhang | a676aca | 2019-02-02 00:41:09 +0000 | [diff] [blame] | 12 | #include "constants/form_flags.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_document.h" |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 15 | #include "core/fpdfdoc/cpdf_interactiveform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 16 | #include "fpdfsdk/cpdfsdk_annot.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 17 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame] | 18 | #include "fpdfsdk/cpdfsdk_interactiveform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 19 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 20 | #include "fpdfsdk/cpdfsdk_widget.h" |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 22 | |
| 23 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 24 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 25 | #endif // PDF_ENABLE_XFA |
| 26 | |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 27 | CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler( |
| 28 | CPDFSDK_FormFillEnvironment* pFormFillEnv) |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 29 | : m_pFormFillEnv(pFormFillEnv), |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 30 | m_pFormFiller(pFormFillEnv->GetInteractiveFormFiller()) { |
| 31 | ASSERT(m_pFormFillEnv); |
| 32 | ASSERT(m_pFormFiller); |
| 33 | } |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 34 | |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 35 | CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() = default; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 36 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 37 | bool CPDFSDK_WidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | 11a6bec | 2018-07-25 23:25:55 +0000 | [diff] [blame] | 38 | CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); |
| 39 | if (pWidget->IsSignatureWidget()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 40 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 41 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 42 | if (!pWidget->IsVisible()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 43 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 44 | |
| 45 | int nFieldFlags = pWidget->GetFieldFlags(); |
Lei Zhang | a676aca | 2019-02-02 00:41:09 +0000 | [diff] [blame] | 46 | if (nFieldFlags & pdfium::form_flags::kReadOnly) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 47 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 48 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 49 | if (pWidget->GetFieldType() == FormFieldType::kPushButton) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 50 | return true; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 51 | |
| 52 | CPDF_Page* pPage = pWidget->GetPDFPage(); |
Lei Zhang | 8f63763 | 2018-05-07 23:36:26 +0000 | [diff] [blame] | 53 | uint32_t dwPermissions = pPage->GetDocument()->GetUserPermissions(); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 54 | return (dwPermissions & FPDFPERM_FILL_FORM) || |
| 55 | (dwPermissions & FPDFPERM_ANNOT_FORM); |
| 56 | } |
| 57 | |
| 58 | CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CPDF_Annot* pAnnot, |
| 59 | CPDFSDK_PageView* pPage) { |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 60 | CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); |
| 61 | CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); |
| 62 | CPDF_FormControl* pCtrl = pPDFForm->GetControlByDict(pAnnot->GetAnnotDict()); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 63 | if (!pCtrl) |
| 64 | return nullptr; |
| 65 | |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 66 | CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pForm); |
| 67 | pForm->AddMap(pCtrl, pWidget); |
| 68 | if (pPDFForm->NeedConstructAP()) |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 69 | pWidget->ResetAppearance(pdfium::nullopt, false); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 70 | return pWidget; |
| 71 | } |
| 72 | |
| 73 | #ifdef PDF_ENABLE_XFA |
| 74 | CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CXFA_FFWidget* hWidget, |
| 75 | CPDFSDK_PageView* pPage) { |
| 76 | return nullptr; |
| 77 | } |
| 78 | #endif // PDF_ENABLE_XFA |
| 79 | |
Tom Sepez | 0f35a9e | 2019-04-23 00:32:37 +0000 | [diff] [blame] | 80 | void CPDFSDK_WidgetHandler::ReleaseAnnot( |
| 81 | std::unique_ptr<CPDFSDK_Annot> pAnnot) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 82 | ASSERT(pAnnot); |
Tom Sepez | 0f35a9e | 2019-04-23 00:32:37 +0000 | [diff] [blame] | 83 | m_pFormFiller->OnDelete(pAnnot.get()); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 84 | |
Tom Sepez | 0f35a9e | 2019-04-23 00:32:37 +0000 | [diff] [blame] | 85 | std::unique_ptr<CPDFSDK_Widget> pWidget(ToCPDFSDKWidget(pAnnot.release())); |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 86 | CPDFSDK_InteractiveForm* pForm = pWidget->GetInteractiveForm(); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 87 | CPDF_FormControl* pControl = pWidget->GetFormControl(); |
Lei Zhang | 073ecf4 | 2018-10-11 16:56:00 +0000 | [diff] [blame] | 88 | pForm->RemoveMap(pControl); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 89 | } |
| 90 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 91 | void CPDFSDK_WidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, |
| 92 | CPDFSDK_Annot* pAnnot, |
| 93 | CFX_RenderDevice* pDevice, |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 94 | const CFX_Matrix& mtUser2Device, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 95 | bool bDrawAnnots) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 96 | if (pAnnot->IsSignatureWidget()) { |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 97 | pAnnot->AsBAAnnot()->DrawAppearance(pDevice, mtUser2Device, |
Tom Sepez | 522d77d | 2018-07-28 00:00:25 +0000 | [diff] [blame] | 98 | CPDF_Annot::Normal, nullptr); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 99 | } else { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 100 | m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 104 | void CPDFSDK_WidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 105 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 106 | uint32_t nFlag) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 107 | if (!(*pAnnot)->IsSignatureWidget()) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 108 | m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); |
| 109 | } |
| 110 | |
| 111 | void CPDFSDK_WidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 112 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 113 | uint32_t nFlag) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 114 | if (!(*pAnnot)->IsSignatureWidget()) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 115 | m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); |
| 116 | } |
| 117 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 118 | bool CPDFSDK_WidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 119 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 120 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 121 | const CFX_PointF& point) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 122 | return !(*pAnnot)->IsSignatureWidget() && |
| 123 | m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 124 | } |
| 125 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 126 | bool CPDFSDK_WidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 127 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 128 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 129 | const CFX_PointF& point) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 130 | return !(*pAnnot)->IsSignatureWidget() && |
| 131 | m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 132 | } |
| 133 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 134 | bool CPDFSDK_WidgetHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 135 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 136 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 137 | const CFX_PointF& point) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 138 | return !(*pAnnot)->IsSignatureWidget() && |
| 139 | m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 140 | } |
| 141 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 142 | bool CPDFSDK_WidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 143 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 144 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 145 | const CFX_PointF& point) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 146 | return !(*pAnnot)->IsSignatureWidget() && |
| 147 | m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 148 | } |
| 149 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 150 | bool CPDFSDK_WidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 151 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 152 | uint32_t nFlags, |
| 153 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 154 | const CFX_PointF& point) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 155 | return !(*pAnnot)->IsSignatureWidget() && |
| 156 | m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 157 | } |
| 158 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 159 | bool CPDFSDK_WidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 160 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 161 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 162 | const CFX_PointF& point) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 163 | return !(*pAnnot)->IsSignatureWidget() && |
| 164 | m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 165 | } |
| 166 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 167 | bool CPDFSDK_WidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 168 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 169 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 170 | const CFX_PointF& point) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 171 | return !(*pAnnot)->IsSignatureWidget() && |
| 172 | m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 173 | } |
| 174 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 175 | bool CPDFSDK_WidgetHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 176 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 177 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 178 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 179 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 180 | } |
| 181 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 182 | bool CPDFSDK_WidgetHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 183 | uint32_t nChar, |
| 184 | uint32_t nFlags) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 185 | return !pAnnot->IsSignatureWidget() && |
| 186 | m_pFormFiller->OnChar(pAnnot, nChar, nFlags); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 187 | } |
| 188 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 189 | bool CPDFSDK_WidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 190 | int nKeyCode, |
| 191 | int nFlag) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 192 | return !pAnnot->IsSignatureWidget() && |
| 193 | m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 194 | } |
| 195 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 196 | bool CPDFSDK_WidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 197 | int nKeyCode, |
| 198 | int nFlag) { |
| 199 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 200 | } |
| 201 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 202 | void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) { |
| 203 | if (pAnnot->IsSignatureWidget()) |
| 204 | return; |
| 205 | |
Tom Sepez | 4ef943b | 2018-07-26 19:06:06 +0000 | [diff] [blame] | 206 | CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 207 | if (!pWidget->IsAppearanceValid()) |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 208 | pWidget->ResetAppearance(pdfium::nullopt, false); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 209 | |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 210 | FormFieldType fieldType = pWidget->GetFieldType(); |
| 211 | if (fieldType == FormFieldType::kTextField || |
| 212 | fieldType == FormFieldType::kComboBox) { |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 213 | ObservedPtr<CPDFSDK_Annot> pObserved(pWidget); |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 214 | Optional<WideString> sValue = pWidget->OnFormat(); |
Lei Zhang | cd8ff7e | 2017-06-13 14:09:46 -0700 | [diff] [blame] | 215 | if (!pObserved) |
| 216 | return; |
| 217 | |
Lei Zhang | 4f261ff | 2018-10-10 18:44:45 +0000 | [diff] [blame] | 218 | if (sValue.has_value() && fieldType == FormFieldType::kComboBox) |
| 219 | pWidget->ResetAppearance(sValue, false); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | #ifdef PDF_ENABLE_XFA |
| 223 | CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 224 | CPDFXFA_Context* pContext = pPageView->GetFormFillEnv()->GetXFAContext(); |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 225 | if (pContext->GetFormType() == FormType::kXFAForeground) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 226 | if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) |
Lei Zhang | e858d1f | 2019-07-29 23:43:41 +0000 | [diff] [blame] | 227 | pWidget->ResetXFAAppearance(false); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 228 | } |
| 229 | #endif // PDF_ENABLE_XFA |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 232 | bool CPDFSDK_WidgetHandler::OnSetFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 233 | uint32_t nFlag) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 234 | return (*pAnnot)->IsSignatureWidget() || |
| 235 | m_pFormFiller->OnSetFocus(pAnnot, nFlag); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 238 | bool CPDFSDK_WidgetHandler::OnKillFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 239 | uint32_t nFlag) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 240 | return (*pAnnot)->IsSignatureWidget() || |
| 241 | m_pFormFiller->OnKillFocus(pAnnot, nFlag); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 244 | bool CPDFSDK_WidgetHandler::SetIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot, |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 245 | int index, |
| 246 | bool selected) { |
| 247 | return !(*pAnnot)->IsSignatureWidget() && |
| 248 | m_pFormFiller->SetIndexSelected(pAnnot, index, selected); |
| 249 | } |
| 250 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 251 | bool CPDFSDK_WidgetHandler::IsIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot, |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 252 | int index) { |
| 253 | return !(*pAnnot)->IsSignatureWidget() && |
| 254 | m_pFormFiller->IsIndexSelected(pAnnot, index); |
| 255 | } |
| 256 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 257 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 258 | bool CPDFSDK_WidgetHandler::OnXFAChangedFocus( |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 259 | ObservedPtr<CPDFSDK_Annot>* pOldAnnot, |
| 260 | ObservedPtr<CPDFSDK_Annot>* pNewAnnot) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 261 | return true; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 262 | } |
| 263 | #endif // PDF_ENABLE_XFA |
| 264 | |
| 265 | CFX_FloatRect CPDFSDK_WidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 266 | CPDFSDK_Annot* pAnnot) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 267 | if (!pAnnot->IsSignatureWidget()) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 268 | return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot)); |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 269 | return CFX_FloatRect(); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 272 | WideString CPDFSDK_WidgetHandler::GetText(CPDFSDK_Annot* pAnnot) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 273 | if (!pAnnot->IsSignatureWidget()) |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 274 | return m_pFormFiller->GetText(pAnnot); |
| 275 | return WideString(); |
| 276 | } |
| 277 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 278 | WideString CPDFSDK_WidgetHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 279 | if (!pAnnot->IsSignatureWidget()) |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 280 | return m_pFormFiller->GetSelectedText(pAnnot); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 281 | return WideString(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 284 | void CPDFSDK_WidgetHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 285 | const WideString& text) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 286 | if (!pAnnot->IsSignatureWidget()) |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 287 | m_pFormFiller->ReplaceSelection(pAnnot, text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 290 | bool CPDFSDK_WidgetHandler::CanUndo(CPDFSDK_Annot* pAnnot) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 291 | return !pAnnot->IsSignatureWidget() && m_pFormFiller->CanUndo(pAnnot); |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | bool CPDFSDK_WidgetHandler::CanRedo(CPDFSDK_Annot* pAnnot) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 295 | return !pAnnot->IsSignatureWidget() && m_pFormFiller->CanRedo(pAnnot); |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | bool CPDFSDK_WidgetHandler::Undo(CPDFSDK_Annot* pAnnot) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 299 | return !pAnnot->IsSignatureWidget() && m_pFormFiller->Undo(pAnnot); |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | bool CPDFSDK_WidgetHandler::Redo(CPDFSDK_Annot* pAnnot) { |
Lei Zhang | 7db136a | 2018-10-10 21:34:17 +0000 | [diff] [blame] | 303 | return !pAnnot->IsSignatureWidget() && m_pFormFiller->Redo(pAnnot); |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 304 | } |
| 305 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 306 | bool CPDFSDK_WidgetHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 307 | CPDFSDK_Annot* pAnnot, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 308 | const CFX_PointF& point) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 309 | ASSERT(pPageView); |
| 310 | ASSERT(pAnnot); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 311 | return GetViewBBox(pPageView, pAnnot).Contains(point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 312 | } |