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