xref: /aosp_15_r20/external/pdfium/fpdfsdk/cpdfsdk_widget.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2016 The PDFium Authors
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 
7 #include "fpdfsdk/cpdfsdk_widget.h"
8 
9 #include "constants/access_permissions.h"
10 #include "constants/annotation_common.h"
11 #include "constants/appearance.h"
12 #include "constants/form_flags.h"
13 #include "core/fpdfapi/parser/cpdf_array.h"
14 #include "core/fpdfapi/parser/cpdf_dictionary.h"
15 #include "core/fpdfapi/parser/cpdf_document.h"
16 #include "core/fpdfapi/parser/cpdf_reference.h"
17 #include "core/fpdfapi/parser/cpdf_stream.h"
18 #include "core/fpdfapi/parser/cpdf_string.h"
19 #include "core/fpdfdoc/cpdf_bafontmap.h"
20 #include "core/fpdfdoc/cpdf_defaultappearance.h"
21 #include "core/fpdfdoc/cpdf_formcontrol.h"
22 #include "core/fpdfdoc/cpdf_formfield.h"
23 #include "core/fpdfdoc/cpdf_iconfit.h"
24 #include "core/fpdfdoc/cpdf_interactiveform.h"
25 #include "core/fxge/cfx_fillrenderoptions.h"
26 #include "core/fxge/cfx_graphstatedata.h"
27 #include "core/fxge/cfx_path.h"
28 #include "core/fxge/cfx_renderdevice.h"
29 #include "fpdfsdk/cpdfsdk_appstream.h"
30 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
31 #include "fpdfsdk/cpdfsdk_interactiveform.h"
32 #include "fpdfsdk/cpdfsdk_pageview.h"
33 #include "fpdfsdk/formfiller/cffl_fieldaction.h"
34 #include "fpdfsdk/pwl/cpwl_edit.h"
35 #include "third_party/base/check.h"
36 #include "third_party/base/notreached.h"
37 
38 #ifdef PDF_ENABLE_XFA
39 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
40 #include "xfa/fxfa/cxfa_eventparam.h"
41 #include "xfa/fxfa/cxfa_ffdocview.h"
42 #include "xfa/fxfa/cxfa_ffwidget.h"
43 #include "xfa/fxfa/cxfa_ffwidgethandler.h"
44 #include "xfa/fxfa/parser/cxfa_node.h"
45 #endif  // PDF_ENABLE_XFA
46 
CPDFSDK_Widget(CPDF_Annot * pAnnot,CPDFSDK_PageView * pPageView,CPDFSDK_InteractiveForm * pInteractiveForm)47 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
48                                CPDFSDK_PageView* pPageView,
49                                CPDFSDK_InteractiveForm* pInteractiveForm)
50     : CPDFSDK_BAAnnot(pAnnot, pPageView),
51       m_pInteractiveForm(pInteractiveForm) {}
52 
~CPDFSDK_Widget()53 CPDFSDK_Widget::~CPDFSDK_Widget() {
54   GetInteractiveFormFiller()->OnDelete(this);
55   m_pInteractiveForm->RemoveMap(GetFormControl());
56 }
57 
58 #ifdef PDF_ENABLE_XFA
GetMixXFAWidget() const59 CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
60   CPDF_Document::Extension* pContext =
61       GetPageView()->GetFormFillEnv()->GetDocExtension();
62   if (!pContext || !pContext->ContainsExtensionForegroundForm())
63     return nullptr;
64 
65   CXFA_FFDocView* pDocView =
66       static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView();
67   if (!pDocView)
68     return nullptr;
69 
70   WideString sName;
71   if (GetFieldType() == FormFieldType::kRadioButton) {
72     sName = GetAnnotName();
73     if (sName.IsEmpty())
74       sName = GetName();
75   } else {
76     sName = GetName();
77   }
78 
79   if (sName.IsEmpty())
80     return nullptr;
81 
82   return pDocView->GetWidgetByName(sName, nullptr);
83 }
84 
GetGroupMixXFAWidget() const85 CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() const {
86   CPDF_Document::Extension* pContext =
87       GetPageView()->GetFormFillEnv()->GetDocExtension();
88   if (!pContext || !pContext->ContainsExtensionForegroundForm())
89     return nullptr;
90 
91   CXFA_FFDocView* pDocView =
92       static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView();
93   if (!pDocView)
94     return nullptr;
95 
96   WideString sName = GetName();
97   return !sName.IsEmpty() ? pDocView->GetWidgetByName(sName, nullptr) : nullptr;
98 }
99 
GetXFAWidgetHandler() const100 CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
101   CPDF_Document::Extension* pContext =
102       GetPageView()->GetFormFillEnv()->GetDocExtension();
103   if (!pContext || !pContext->ContainsExtensionForegroundForm())
104     return nullptr;
105 
106   CXFA_FFDocView* pDocView =
107       static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView();
108   return pDocView ? pDocView->GetWidgetHandler() : nullptr;
109 }
110 
GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT)111 static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
112   XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
113 
114   switch (eXFAAAT) {
115     case PDFSDK_XFA_Click:
116       eEventType = XFA_EVENT_Click;
117       break;
118     case PDFSDK_XFA_Full:
119       eEventType = XFA_EVENT_Full;
120       break;
121     case PDFSDK_XFA_PreOpen:
122       eEventType = XFA_EVENT_PreOpen;
123       break;
124     case PDFSDK_XFA_PostOpen:
125       eEventType = XFA_EVENT_PostOpen;
126       break;
127   }
128 
129   return eEventType;
130 }
131 
GetXFAEventType(CPDF_AAction::AActionType eAAT,bool bWillCommit)132 static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
133                                      bool bWillCommit) {
134   XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
135 
136   switch (eAAT) {
137     case CPDF_AAction::kCursorEnter:
138       eEventType = XFA_EVENT_MouseEnter;
139       break;
140     case CPDF_AAction::kCursorExit:
141       eEventType = XFA_EVENT_MouseExit;
142       break;
143     case CPDF_AAction::kButtonDown:
144       eEventType = XFA_EVENT_MouseDown;
145       break;
146     case CPDF_AAction::kButtonUp:
147       eEventType = XFA_EVENT_MouseUp;
148       break;
149     case CPDF_AAction::kGetFocus:
150       eEventType = XFA_EVENT_Enter;
151       break;
152     case CPDF_AAction::kLoseFocus:
153       eEventType = XFA_EVENT_Exit;
154       break;
155     case CPDF_AAction::kPageOpen:
156     case CPDF_AAction::kPageClose:
157     case CPDF_AAction::kPageVisible:
158     case CPDF_AAction::kPageInvisible:
159       break;
160     case CPDF_AAction::kKeyStroke:
161       if (!bWillCommit)
162         eEventType = XFA_EVENT_Change;
163       break;
164     case CPDF_AAction::kValidate:
165       eEventType = XFA_EVENT_Validate;
166       break;
167     case CPDF_AAction::kOpenPage:
168     case CPDF_AAction::kClosePage:
169     case CPDF_AAction::kFormat:
170     case CPDF_AAction::kCalculate:
171     case CPDF_AAction::kCloseDocument:
172     case CPDF_AAction::kSaveDocument:
173     case CPDF_AAction::kDocumentSaved:
174     case CPDF_AAction::kPrintDocument:
175     case CPDF_AAction::kDocumentPrinted:
176       break;
177     case CPDF_AAction::kDocumentOpen:
178     case CPDF_AAction::kNumberOfActions:
179       NOTREACHED_NORETURN();
180   }
181 
182   return eEventType;
183 }
184 
HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const185 bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const {
186   CXFA_FFWidget* pWidget = GetMixXFAWidget();
187   if (!pWidget)
188     return false;
189 
190   CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
191   if (!pXFAWidgetHandler)
192     return false;
193 
194   XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
195   if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
196       GetFieldType() == FormFieldType::kRadioButton) {
197     CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget();
198     if (hGroupWidget &&
199         hGroupWidget->HasEventUnderHandler(eEventType, pXFAWidgetHandler)) {
200       return true;
201     }
202   }
203 
204   return pWidget->HasEventUnderHandler(eEventType, pXFAWidgetHandler);
205 }
206 
OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,CFFL_FieldAction * data,const CPDFSDK_PageView * pPageView)207 bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
208                                   CFFL_FieldAction* data,
209                                   const CPDFSDK_PageView* pPageView) {
210   auto* pContext = static_cast<CPDFXFA_Context*>(
211       GetPageView()->GetFormFillEnv()->GetDocExtension());
212   if (!pContext)
213     return false;
214 
215   CXFA_FFWidget* pWidget = GetMixXFAWidget();
216   if (!pWidget)
217     return false;
218 
219   XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
220   if (eEventType == XFA_EVENT_Unknown)
221     return false;
222 
223   CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
224   if (!pXFAWidgetHandler)
225     return false;
226 
227   CXFA_EventParam param;
228   param.m_eType = eEventType;
229   param.m_wsChange = data->sChange;
230   param.m_iCommitKey = 0;
231   param.m_bShift = data->bShift;
232   param.m_iSelStart = data->nSelStart;
233   param.m_iSelEnd = data->nSelEnd;
234   param.m_wsFullText = data->sValue;
235   param.m_bKeyDown = data->bKeyDown;
236   param.m_bModifier = data->bModifier;
237   param.m_wsPrevText = data->sValue;
238   if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
239       GetFieldType() == FormFieldType::kRadioButton) {
240     CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget();
241     if (hGroupWidget &&
242         !hGroupWidget->ProcessEventUnderHandler(&param, pXFAWidgetHandler)) {
243       return false;
244     }
245   }
246 
247   bool ret = pWidget->ProcessEventUnderHandler(&param, pXFAWidgetHandler);
248   CXFA_FFDocView* pDocView = pContext->GetXFADocView();
249   if (pDocView)
250     pDocView->UpdateDocView();
251 
252   return ret;
253 }
254 
Synchronize(bool bSynchronizeElse)255 void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
256   CXFA_FFWidget* hWidget = GetMixXFAWidget();
257   if (!hWidget)
258     return;
259 
260   CXFA_Node* node = hWidget->GetNode();
261   if (!node->IsWidgetReady())
262     return;
263 
264   CPDF_FormField* pFormField = GetFormField();
265   switch (GetFieldType()) {
266     case FormFieldType::kCheckBox:
267     case FormFieldType::kRadioButton: {
268       CPDF_FormControl* pFormCtrl = GetFormControl();
269       XFA_CheckState eCheckState =
270           pFormCtrl->IsChecked() ? XFA_CheckState::kOn : XFA_CheckState::kOff;
271       node->SetCheckState(eCheckState);
272       break;
273     }
274     case FormFieldType::kTextField:
275       node->SetValue(XFA_ValuePicture::kEdit, pFormField->GetValue());
276       break;
277     case FormFieldType::kComboBox:
278     case FormFieldType::kListBox: {
279       node->ClearAllSelections();
280       for (int i = 0; i < pFormField->CountSelectedItems(); ++i) {
281         int nIndex = pFormField->GetSelectedIndex(i);
282         if (nIndex > -1 &&
283             static_cast<size_t>(nIndex) < node->CountChoiceListItems(false)) {
284           node->SetItemState(nIndex, true, false, false);
285         }
286       }
287       if (GetFieldType() == FormFieldType::kComboBox)
288         node->SetValue(XFA_ValuePicture::kEdit, pFormField->GetValue());
289       break;
290     }
291     default:
292       break;
293   }
294 
295   if (bSynchronizeElse) {
296     auto* context = static_cast<CPDFXFA_Context*>(
297         GetPageView()->GetFormFillEnv()->GetDocExtension());
298     context->GetXFADocView()->ProcessValueChanged(node);
299   }
300 }
301 
HandleXFAAAction(CPDF_AAction::AActionType type,CFFL_FieldAction * data,CPDFSDK_FormFillEnvironment * pFormFillEnv)302 bool CPDFSDK_Widget::HandleXFAAAction(
303     CPDF_AAction::AActionType type,
304     CFFL_FieldAction* data,
305     CPDFSDK_FormFillEnvironment* pFormFillEnv) {
306   auto* pContext =
307       static_cast<CPDFXFA_Context*>(pFormFillEnv->GetDocExtension());
308   if (!pContext)
309     return false;
310 
311   CXFA_FFWidget* hWidget = GetMixXFAWidget();
312   if (!hWidget)
313     return false;
314 
315   XFA_EVENTTYPE eEventType = GetXFAEventType(type, data->bWillCommit);
316   if (eEventType == XFA_EVENT_Unknown)
317     return false;
318 
319   CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
320   if (!pXFAWidgetHandler)
321     return false;
322 
323   CXFA_EventParam param;
324   param.m_eType = eEventType;
325   param.m_wsChange = data->sChange;
326   param.m_iCommitKey = 0;
327   param.m_bShift = data->bShift;
328   param.m_iSelStart = data->nSelStart;
329   param.m_iSelEnd = data->nSelEnd;
330   param.m_wsFullText = data->sValue;
331   param.m_bKeyDown = data->bKeyDown;
332   param.m_bModifier = data->bModifier;
333   param.m_wsPrevText = data->sValue;
334   bool ret = hWidget->ProcessEventUnderHandler(&param, pXFAWidgetHandler);
335   CXFA_FFDocView* pDocView = pContext->GetXFADocView();
336   if (pDocView)
337     pDocView->UpdateDocView();
338 
339   return ret;
340 }
341 #endif  // PDF_ENABLE_XFA
342 
IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) const343 bool CPDFSDK_Widget::IsWidgetAppearanceValid(
344     CPDF_Annot::AppearanceMode mode) const {
345   RetainPtr<const CPDF_Dictionary> pAP =
346       GetAnnotDict()->GetDictFor(pdfium::annotation::kAP);
347   if (!pAP)
348     return false;
349 
350   // Choose the right sub-ap
351   const char* ap_entry = "N";
352   if (mode == CPDF_Annot::AppearanceMode::kDown)
353     ap_entry = "D";
354   else if (mode == CPDF_Annot::AppearanceMode::kRollover)
355     ap_entry = "R";
356   if (!pAP->KeyExist(ap_entry))
357     ap_entry = "N";
358 
359   // Get the AP stream or subdirectory
360   RetainPtr<const CPDF_Object> pSub = pAP->GetDirectObjectFor(ap_entry);
361   if (!pSub)
362     return false;
363 
364   FormFieldType fieldType = GetFieldType();
365   switch (fieldType) {
366     case FormFieldType::kPushButton:
367     case FormFieldType::kComboBox:
368     case FormFieldType::kListBox:
369     case FormFieldType::kTextField:
370     case FormFieldType::kSignature:
371       return pSub->IsStream();
372     case FormFieldType::kCheckBox:
373     case FormFieldType::kRadioButton:
374       if (const CPDF_Dictionary* pSubDict = pSub->AsDictionary()) {
375         return !!pSubDict->GetStreamFor(GetAppState());
376       }
377       return false;
378     default:
379       return true;
380   }
381 }
382 
IsPushHighlighted() const383 bool CPDFSDK_Widget::IsPushHighlighted() const {
384   return GetFormControl()->GetHighlightingMode() == CPDF_FormControl::kPush;
385 }
386 
GetFieldType() const387 FormFieldType CPDFSDK_Widget::GetFieldType() const {
388   CPDF_FormField* pField = GetFormField();
389   return pField ? pField->GetFieldType() : FormFieldType::kUnknown;
390 }
391 
SetRect(const CFX_FloatRect & rect)392 void CPDFSDK_Widget::SetRect(const CFX_FloatRect& rect) {
393   DCHECK(rect.right - rect.left >= 1.0f);
394   DCHECK(rect.top - rect.bottom >= 1.0f);
395   GetMutableAnnotDict()->SetRectFor(pdfium::annotation::kRect, rect);
396 }
397 
IsAppearanceValid()398 bool CPDFSDK_Widget::IsAppearanceValid() {
399 #ifdef PDF_ENABLE_XFA
400   CPDF_Document::Extension* pContext =
401       GetPageView()->GetFormFillEnv()->GetDocExtension();
402   if (pContext && pContext->ContainsExtensionFullForm())
403     return true;
404 #endif  // PDF_ENABLE_XFA
405   return CPDFSDK_BAAnnot::IsAppearanceValid();
406 }
407 
GetLayoutOrder() const408 int CPDFSDK_Widget::GetLayoutOrder() const {
409   return 2;
410 }
411 
GetFieldFlags() const412 int CPDFSDK_Widget::GetFieldFlags() const {
413   return GetFormField()->GetFieldFlags();
414 }
415 
IsSignatureWidget() const416 bool CPDFSDK_Widget::IsSignatureWidget() const {
417   return GetFieldType() == FormFieldType::kSignature;
418 }
419 
GetFormField() const420 CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
421   CPDF_FormControl* pControl = GetFormControl();
422   return pControl ? pControl->GetField() : nullptr;
423 }
424 
GetFormControl() const425 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
426   CPDF_InteractiveForm* pPDFInteractiveForm =
427       m_pInteractiveForm->GetInteractiveForm();
428   return pPDFInteractiveForm->GetControlByDict(GetAnnotDict());
429 }
430 
GetRotate() const431 int CPDFSDK_Widget::GetRotate() const {
432   CPDF_FormControl* pCtrl = GetFormControl();
433   return pCtrl->GetRotation() % 360;
434 }
435 
436 #ifdef PDF_ENABLE_XFA
GetName() const437 WideString CPDFSDK_Widget::GetName() const {
438   return GetFormField()->GetFullName();
439 }
440 #endif  // PDF_ENABLE_XFA
441 
GetFillColor() const442 absl::optional<FX_COLORREF> CPDFSDK_Widget::GetFillColor() const {
443   CFX_Color::TypeAndARGB type_argb_pair =
444       GetFormControl()->GetColorARGB(pdfium::appearance::kBG);
445 
446   if (type_argb_pair.color_type == CFX_Color::Type::kTransparent)
447     return absl::nullopt;
448 
449   return ArgbToColorRef(type_argb_pair.argb);
450 }
451 
GetBorderColor() const452 absl::optional<FX_COLORREF> CPDFSDK_Widget::GetBorderColor() const {
453   CFX_Color::TypeAndARGB type_argb_pair =
454       GetFormControl()->GetColorARGB(pdfium::appearance::kBC);
455   if (type_argb_pair.color_type == CFX_Color::Type::kTransparent)
456     return absl::nullopt;
457 
458   return ArgbToColorRef(type_argb_pair.argb);
459 }
460 
GetTextColor() const461 absl::optional<FX_COLORREF> CPDFSDK_Widget::GetTextColor() const {
462   CPDF_DefaultAppearance da = GetFormControl()->GetDefaultAppearance();
463   absl::optional<CFX_Color::TypeAndARGB> maybe_type_argb_pair =
464       da.GetColorARGB();
465 
466   if (!maybe_type_argb_pair.has_value())
467     return absl::nullopt;
468 
469   if (maybe_type_argb_pair.value().color_type == CFX_Color::Type::kTransparent)
470     return absl::nullopt;
471 
472   return ArgbToColorRef(maybe_type_argb_pair.value().argb);
473 }
474 
GetFontSize() const475 float CPDFSDK_Widget::GetFontSize() const {
476   CPDF_FormControl* pFormCtrl = GetFormControl();
477   CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
478   float fFontSize;
479   pDa.GetFont(&fFontSize);
480   return fFontSize;
481 }
482 
GetSelectedIndex(int nIndex) const483 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
484 #ifdef PDF_ENABLE_XFA
485   if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
486     CXFA_Node* node = hWidget->GetNode();
487     if (node->IsWidgetReady()) {
488       if (nIndex < node->CountSelectedItems())
489         return node->GetSelectedItem(nIndex);
490     }
491   }
492 #endif  // PDF_ENABLE_XFA
493   CPDF_FormField* pFormField = GetFormField();
494   return pFormField->GetSelectedIndex(nIndex);
495 }
496 
GetValue() const497 WideString CPDFSDK_Widget::GetValue() const {
498 #ifdef PDF_ENABLE_XFA
499   if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
500     CXFA_Node* node = hWidget->GetNode();
501     if (node->IsWidgetReady())
502       return node->GetValue(XFA_ValuePicture::kDisplay);
503   }
504 #endif  // PDF_ENABLE_XFA
505   CPDF_FormField* pFormField = GetFormField();
506   return pFormField->GetValue();
507 }
508 
GetExportValue() const509 WideString CPDFSDK_Widget::GetExportValue() const {
510   CPDF_FormControl* pFormCtrl = GetFormControl();
511   return pFormCtrl->GetExportValue();
512 }
513 
GetOptionLabel(int nIndex) const514 WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
515   CPDF_FormField* pFormField = GetFormField();
516   return pFormField->GetOptionLabel(nIndex);
517 }
518 
GetSelectExportText(int nIndex) const519 WideString CPDFSDK_Widget::GetSelectExportText(int nIndex) const {
520   if (nIndex < 0)
521     return WideString();
522 
523   CPDF_FormField* pFormField = GetFormField();
524   if (!pFormField)
525     return WideString();
526 
527   WideString swRet = pFormField->GetOptionValue(nIndex);
528   if (!swRet.IsEmpty())
529     return swRet;
530 
531   return pFormField->GetOptionLabel(nIndex);
532 }
533 
CountOptions() const534 int CPDFSDK_Widget::CountOptions() const {
535   CPDF_FormField* pFormField = GetFormField();
536   return pFormField->CountOptions();
537 }
538 
IsOptionSelected(int nIndex) const539 bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
540 #ifdef PDF_ENABLE_XFA
541   if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
542     CXFA_Node* node = hWidget->GetNode();
543     if (node->IsWidgetReady()) {
544       if (nIndex > -1 &&
545           static_cast<size_t>(nIndex) < node->CountChoiceListItems(false)) {
546         return node->GetItemState(nIndex);
547       }
548       return false;
549     }
550   }
551 #endif  // PDF_ENABLE_XFA
552   CPDF_FormField* pFormField = GetFormField();
553   return pFormField->IsItemSelected(nIndex);
554 }
555 
GetTopVisibleIndex() const556 int CPDFSDK_Widget::GetTopVisibleIndex() const {
557   CPDF_FormField* pFormField = GetFormField();
558   return pFormField->GetTopVisibleIndex();
559 }
560 
IsChecked() const561 bool CPDFSDK_Widget::IsChecked() const {
562 #ifdef PDF_ENABLE_XFA
563   if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
564     CXFA_Node* node = hWidget->GetNode();
565     if (node->IsWidgetReady())
566       return node->GetCheckState() == XFA_CheckState::kOn;
567   }
568 #endif  // PDF_ENABLE_XFA
569   CPDF_FormControl* pFormCtrl = GetFormControl();
570   return pFormCtrl->IsChecked();
571 }
572 
GetAlignment() const573 int CPDFSDK_Widget::GetAlignment() const {
574   CPDF_FormControl* pFormCtrl = GetFormControl();
575   return pFormCtrl->GetControlAlignment();
576 }
577 
GetMaxLen() const578 int CPDFSDK_Widget::GetMaxLen() const {
579   CPDF_FormField* pFormField = GetFormField();
580   return pFormField->GetMaxLen();
581 }
582 
SetCheck(bool bChecked)583 void CPDFSDK_Widget::SetCheck(bool bChecked) {
584   CPDF_FormControl* pFormCtrl = GetFormControl();
585   CPDF_FormField* pFormField = pFormCtrl->GetField();
586   pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
587                            NotificationOption::kDoNotNotify);
588 #ifdef PDF_ENABLE_XFA
589   if (!IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode::kNormal))
590     ResetXFAAppearance(CPDFSDK_Widget::kValueChanged);
591   Synchronize(true);
592 #endif  // PDF_ENABLE_XFA
593 }
594 
SetValue(const WideString & sValue)595 void CPDFSDK_Widget::SetValue(const WideString& sValue) {
596   CPDF_FormField* pFormField = GetFormField();
597   pFormField->SetValue(sValue, NotificationOption::kDoNotNotify);
598 #ifdef PDF_ENABLE_XFA
599   Synchronize(true);
600 #endif  // PDF_ENABLE_XFA
601 }
602 
SetOptionSelection(int index)603 void CPDFSDK_Widget::SetOptionSelection(int index) {
604   CPDF_FormField* pFormField = GetFormField();
605   pFormField->SetItemSelection(index, NotificationOption::kDoNotNotify);
606 #ifdef PDF_ENABLE_XFA
607   Synchronize(true);
608 #endif  // PDF_ENABLE_XFA
609 }
610 
ClearSelection()611 void CPDFSDK_Widget::ClearSelection() {
612   CPDF_FormField* pFormField = GetFormField();
613   pFormField->ClearSelection(NotificationOption::kDoNotNotify);
614 #ifdef PDF_ENABLE_XFA
615   Synchronize(true);
616 #endif  // PDF_ENABLE_XFA
617 }
618 
SetTopVisibleIndex(int index)619 void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
620 
SetAppModified()621 void CPDFSDK_Widget::SetAppModified() {
622   m_bAppModified = true;
623 }
624 
ClearAppModified()625 void CPDFSDK_Widget::ClearAppModified() {
626   m_bAppModified = false;
627 }
628 
IsAppModified() const629 bool CPDFSDK_Widget::IsAppModified() const {
630   return m_bAppModified;
631 }
632 
633 #ifdef PDF_ENABLE_XFA
ResetXFAAppearance(ValueChanged bValueChanged)634 void CPDFSDK_Widget::ResetXFAAppearance(ValueChanged bValueChanged) {
635   switch (GetFieldType()) {
636     case FormFieldType::kTextField:
637     case FormFieldType::kComboBox: {
638       ResetAppearance(OnFormat(), kValueChanged);
639       break;
640     }
641     default:
642       ResetAppearance(absl::nullopt, kValueUnchanged);
643       break;
644   }
645 }
646 #endif  // PDF_ENABLE_XFA
647 
ResetAppearance(absl::optional<WideString> sValue,ValueChanged bValueChanged)648 void CPDFSDK_Widget::ResetAppearance(absl::optional<WideString> sValue,
649                                      ValueChanged bValueChanged) {
650   SetAppModified();
651 
652   m_nAppearanceAge++;
653   if (bValueChanged == kValueChanged)
654     m_nValueAge++;
655 
656   CPDFSDK_AppStream appStream(this, GetAPDict().Get());
657   switch (GetFieldType()) {
658     case FormFieldType::kPushButton:
659       appStream.SetAsPushButton();
660       break;
661     case FormFieldType::kCheckBox:
662       appStream.SetAsCheckBox();
663       break;
664     case FormFieldType::kRadioButton:
665       appStream.SetAsRadioButton();
666       break;
667     case FormFieldType::kComboBox:
668       appStream.SetAsComboBox(sValue);
669       break;
670     case FormFieldType::kListBox:
671       appStream.SetAsListBox();
672       break;
673     case FormFieldType::kTextField:
674       appStream.SetAsTextField(sValue);
675       break;
676     default:
677       break;
678   }
679 
680   ClearCachedAnnotAP();
681 }
682 
OnFormat()683 absl::optional<WideString> CPDFSDK_Widget::OnFormat() {
684   CPDF_FormField* pFormField = GetFormField();
685   DCHECK(pFormField);
686   return m_pInteractiveForm->OnFormat(pFormField);
687 }
688 
ResetFieldAppearance()689 void CPDFSDK_Widget::ResetFieldAppearance() {
690   CPDF_FormField* pFormField = GetFormField();
691   DCHECK(pFormField);
692   m_pInteractiveForm->ResetFieldAppearance(pFormField, absl::nullopt);
693 }
694 
OnDraw(CFX_RenderDevice * pDevice,const CFX_Matrix & mtUser2Device,bool bDrawAnnots)695 void CPDFSDK_Widget::OnDraw(CFX_RenderDevice* pDevice,
696                             const CFX_Matrix& mtUser2Device,
697                             bool bDrawAnnots) {
698   if (IsSignatureWidget()) {
699     DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::AppearanceMode::kNormal);
700     return;
701   }
702 
703   GetInteractiveFormFiller()->OnDraw(GetPageView(), this, pDevice,
704                                      mtUser2Device);
705 }
706 
DoHitTest(const CFX_PointF & point)707 bool CPDFSDK_Widget::DoHitTest(const CFX_PointF& point) {
708   if (IsSignatureWidget() || !IsVisible())
709     return false;
710 
711   if (GetFieldFlags() & pdfium::form_flags::kReadOnly)
712     return false;
713 
714   bool do_hit_test = GetFieldType() == FormFieldType::kPushButton;
715   if (!do_hit_test) {
716     uint32_t perms = GetPDFPage()->GetDocument()->GetUserPermissions();
717     do_hit_test = (perms & pdfium::access_permissions::kFillForm) ||
718                   (perms & pdfium::access_permissions::kModifyAnnotation);
719   }
720   return do_hit_test && GetViewBBox().Contains(point);
721 }
722 
GetViewBBox()723 CFX_FloatRect CPDFSDK_Widget::GetViewBBox() {
724   if (IsSignatureWidget())
725     return CFX_FloatRect();
726 
727   auto* form_filler = GetInteractiveFormFiller();
728   return CFX_FloatRect(form_filler->GetViewBBox(GetPageView(), this));
729 }
730 
OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags)731 void CPDFSDK_Widget::OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) {
732   if (IsSignatureWidget())
733     return;
734 
735   ObservedPtr<CPDFSDK_Widget> observer(this);
736   GetInteractiveFormFiller()->OnMouseEnter(GetPageView(), observer, nFlags);
737 }
738 
OnMouseExit(Mask<FWL_EVENTFLAG> nFlags)739 void CPDFSDK_Widget::OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) {
740   if (IsSignatureWidget())
741     return;
742 
743   ObservedPtr<CPDFSDK_Widget> observer(this);
744   GetInteractiveFormFiller()->OnMouseExit(GetPageView(), observer, nFlags);
745 }
746 
OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)747 bool CPDFSDK_Widget::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
748                                    const CFX_PointF& point) {
749   if (IsSignatureWidget())
750     return false;
751 
752   ObservedPtr<CPDFSDK_Widget> observer(this);
753   return GetInteractiveFormFiller()->OnLButtonDown(GetPageView(), observer,
754                                                    nFlags, point);
755 }
756 
OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)757 bool CPDFSDK_Widget::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
758                                  const CFX_PointF& point) {
759   if (IsSignatureWidget())
760     return false;
761 
762   ObservedPtr<CPDFSDK_Widget> observer(this);
763   return GetInteractiveFormFiller()->OnLButtonUp(GetPageView(), observer,
764                                                  nFlags, point);
765 }
766 
OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)767 bool CPDFSDK_Widget::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
768                                      const CFX_PointF& point) {
769   if (IsSignatureWidget())
770     return false;
771 
772   ObservedPtr<CPDFSDK_Widget> observer(this);
773   return GetInteractiveFormFiller()->OnLButtonDblClk(GetPageView(), observer,
774                                                      nFlags, point);
775 }
776 
OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)777 bool CPDFSDK_Widget::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
778                                  const CFX_PointF& point) {
779   if (IsSignatureWidget())
780     return false;
781 
782   ObservedPtr<CPDFSDK_Widget> observer(this);
783   return GetInteractiveFormFiller()->OnMouseMove(GetPageView(), observer,
784                                                  nFlags, point);
785 }
786 
OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point,const CFX_Vector & delta)787 bool CPDFSDK_Widget::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
788                                   const CFX_PointF& point,
789                                   const CFX_Vector& delta) {
790   if (IsSignatureWidget())
791     return false;
792 
793   ObservedPtr<CPDFSDK_Widget> observer(this);
794   return GetInteractiveFormFiller()->OnMouseWheel(GetPageView(), observer,
795                                                   nFlags, point, delta);
796 }
797 
OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)798 bool CPDFSDK_Widget::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
799                                    const CFX_PointF& point) {
800   if (IsSignatureWidget())
801     return false;
802 
803   ObservedPtr<CPDFSDK_Widget> observer(this);
804   return GetInteractiveFormFiller()->OnRButtonDown(GetPageView(), observer,
805                                                    nFlags, point);
806 }
807 
OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)808 bool CPDFSDK_Widget::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
809                                  const CFX_PointF& point) {
810   if (IsSignatureWidget())
811     return false;
812 
813   ObservedPtr<CPDFSDK_Widget> observer(this);
814   return GetInteractiveFormFiller()->OnRButtonUp(GetPageView(), observer,
815                                                  nFlags, point);
816 }
817 
OnChar(uint32_t nChar,Mask<FWL_EVENTFLAG> nFlags)818 bool CPDFSDK_Widget::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
819   return !IsSignatureWidget() &&
820          GetInteractiveFormFiller()->OnChar(this, nChar, nFlags);
821 }
822 
OnKeyDown(FWL_VKEYCODE nKeyCode,Mask<FWL_EVENTFLAG> nFlags)823 bool CPDFSDK_Widget::OnKeyDown(FWL_VKEYCODE nKeyCode,
824                                Mask<FWL_EVENTFLAG> nFlags) {
825   return !IsSignatureWidget() &&
826          GetInteractiveFormFiller()->OnKeyDown(this, nKeyCode, nFlags);
827 }
828 
OnSetFocus(Mask<FWL_EVENTFLAG> nFlags)829 bool CPDFSDK_Widget::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) {
830   if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype()))
831     return false;
832 
833   if (IsSignatureWidget())
834     return true;
835 
836   ObservedPtr<CPDFSDK_Widget> observer(this);
837   return GetInteractiveFormFiller()->OnSetFocus(observer, nFlags);
838 }
839 
OnKillFocus(Mask<FWL_EVENTFLAG> nFlags)840 bool CPDFSDK_Widget::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) {
841   if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype()))
842     return false;
843 
844   if (IsSignatureWidget())
845     return true;
846 
847   ObservedPtr<CPDFSDK_Widget> observer(this);
848   return GetInteractiveFormFiller()->OnKillFocus(observer, nFlags);
849 }
850 
CanUndo()851 bool CPDFSDK_Widget::CanUndo() {
852   return !IsSignatureWidget() && GetInteractiveFormFiller()->CanUndo(this);
853 }
854 
CanRedo()855 bool CPDFSDK_Widget::CanRedo() {
856   return !IsSignatureWidget() && GetInteractiveFormFiller()->CanRedo(this);
857 }
858 
Undo()859 bool CPDFSDK_Widget::Undo() {
860   return !IsSignatureWidget() && GetInteractiveFormFiller()->Undo(this);
861 }
862 
Redo()863 bool CPDFSDK_Widget::Redo() {
864   return !IsSignatureWidget() && GetInteractiveFormFiller()->Redo(this);
865 }
866 
GetText()867 WideString CPDFSDK_Widget::GetText() {
868   if (IsSignatureWidget())
869     return WideString();
870   return GetInteractiveFormFiller()->GetText(this);
871 }
872 
GetSelectedText()873 WideString CPDFSDK_Widget::GetSelectedText() {
874   if (IsSignatureWidget())
875     return WideString();
876   return GetInteractiveFormFiller()->GetSelectedText(this);
877 }
878 
ReplaceAndKeepSelection(const WideString & text)879 void CPDFSDK_Widget::ReplaceAndKeepSelection(const WideString& text) {
880   if (IsSignatureWidget())
881     return;
882 
883   GetInteractiveFormFiller()->ReplaceAndKeepSelection(this, text);
884 }
885 
ReplaceSelection(const WideString & text)886 void CPDFSDK_Widget::ReplaceSelection(const WideString& text) {
887   if (IsSignatureWidget())
888     return;
889 
890   GetInteractiveFormFiller()->ReplaceSelection(this, text);
891 }
892 
SelectAllText()893 bool CPDFSDK_Widget::SelectAllText() {
894   return !IsSignatureWidget() &&
895          GetInteractiveFormFiller()->SelectAllText(this);
896 }
897 
SetIndexSelected(int index,bool selected)898 bool CPDFSDK_Widget::SetIndexSelected(int index, bool selected) {
899   ObservedPtr<CPDFSDK_Widget> observer(this);
900   return !IsSignatureWidget() && GetInteractiveFormFiller()->SetIndexSelected(
901                                      observer, index, selected);
902 }
903 
IsIndexSelected(int index)904 bool CPDFSDK_Widget::IsIndexSelected(int index) {
905   ObservedPtr<CPDFSDK_Widget> observer(this);
906   return !IsSignatureWidget() &&
907          GetInteractiveFormFiller()->IsIndexSelected(observer, index);
908 }
909 
DrawAppearance(CFX_RenderDevice * pDevice,const CFX_Matrix & mtUser2Device,CPDF_Annot::AppearanceMode mode)910 void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
911                                     const CFX_Matrix& mtUser2Device,
912                                     CPDF_Annot::AppearanceMode mode) {
913   FormFieldType fieldType = GetFieldType();
914 
915   if ((fieldType == FormFieldType::kCheckBox ||
916        fieldType == FormFieldType::kRadioButton) &&
917       mode == CPDF_Annot::AppearanceMode::kNormal &&
918       !IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode::kNormal)) {
919     CFX_GraphStateData gsd;
920     gsd.m_LineWidth = 0.0f;
921 
922     CFX_Path path;
923     path.AppendFloatRect(GetRect());
924     pDevice->DrawPath(path, &mtUser2Device, &gsd, 0, 0xFFAAAAAA,
925                       CFX_FillRenderOptions::EvenOddOptions());
926   } else {
927     CPDFSDK_BAAnnot::DrawAppearance(pDevice, mtUser2Device, mode);
928   }
929 }
930 
UpdateField()931 void CPDFSDK_Widget::UpdateField() {
932   CPDF_FormField* pFormField = GetFormField();
933   DCHECK(pFormField);
934   m_pInteractiveForm->UpdateField(pFormField);
935 }
936 
DrawShadow(CFX_RenderDevice * pDevice,CPDFSDK_PageView * pPageView)937 void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
938                                 CPDFSDK_PageView* pPageView) {
939   FormFieldType fieldType = GetFieldType();
940   if (!m_pInteractiveForm->IsNeedHighLight(fieldType))
941     return;
942 
943   CFX_Matrix page2device = pPageView->GetCurrentMatrix();
944   CFX_FloatRect rcDevice = GetRect();
945   CFX_PointF tmp =
946       page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom));
947   rcDevice.left = tmp.x;
948   rcDevice.bottom = tmp.y;
949 
950   tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top));
951   rcDevice.right = tmp.x;
952   rcDevice.top = tmp.y;
953   rcDevice.Normalize();
954 
955   pDevice->FillRect(
956       rcDevice.ToFxRect(),
957       AlphaAndColorRefToArgb(
958           static_cast<int>(m_pInteractiveForm->GetHighlightAlpha()),
959           m_pInteractiveForm->GetHighlightColor(fieldType)));
960 }
961 
GetClientRect() const962 CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
963   CFX_FloatRect rcWindow = GetRotatedRect();
964   float fBorderWidth = GetBorderWidth();
965   switch (GetBorderStyle()) {
966     case BorderStyle::kBeveled:
967     case BorderStyle::kInset:
968       fBorderWidth *= 2.0f;
969       break;
970     default:
971       break;
972   }
973   return rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
974 }
975 
GetRotatedRect() const976 CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
977   CFX_FloatRect rectAnnot = GetRect();
978   float fWidth = rectAnnot.Width();
979   float fHeight = rectAnnot.Height();
980 
981   CPDF_FormControl* pControl = GetFormControl();
982   CFX_FloatRect rcPWLWindow;
983   switch (abs(pControl->GetRotation() % 360)) {
984     case 0:
985     case 180:
986     default:
987       rcPWLWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
988       break;
989     case 90:
990     case 270:
991       rcPWLWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
992       break;
993   }
994 
995   return rcPWLWindow;
996 }
997 
GetMatrix() const998 CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
999   CFX_Matrix mt;
1000   CPDF_FormControl* pControl = GetFormControl();
1001   CFX_FloatRect rcAnnot = GetRect();
1002   float fWidth = rcAnnot.Width();
1003   float fHeight = rcAnnot.Height();
1004 
1005   switch (abs(pControl->GetRotation() % 360)) {
1006     default:
1007     case 0:
1008       break;
1009     case 90:
1010       mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
1011       break;
1012     case 180:
1013       mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
1014       break;
1015     case 270:
1016       mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
1017       break;
1018   }
1019 
1020   return mt;
1021 }
1022 
GetTextPWLColor() const1023 CFX_Color CPDFSDK_Widget::GetTextPWLColor() const {
1024   CPDF_FormControl* pFormCtrl = GetFormControl();
1025   absl::optional<CFX_Color> crText =
1026       pFormCtrl->GetDefaultAppearance().GetColor();
1027   return crText.value_or(CFX_Color(CFX_Color::Type::kGray, 0));
1028 }
1029 
GetBorderPWLColor() const1030 CFX_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1031   CPDF_FormControl* pFormCtrl = GetFormControl();
1032   return pFormCtrl->GetOriginalBorderColor();
1033 }
1034 
GetFillPWLColor() const1035 CFX_Color CPDFSDK_Widget::GetFillPWLColor() const {
1036   CPDF_FormControl* pFormCtrl = GetFormControl();
1037   return pFormCtrl->GetOriginalBackgroundColor();
1038 }
1039 
OnAAction(CPDF_AAction::AActionType type,CFFL_FieldAction * data,const CPDFSDK_PageView * pPageView)1040 bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1041                                CFFL_FieldAction* data,
1042                                const CPDFSDK_PageView* pPageView) {
1043   CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
1044 
1045 #ifdef PDF_ENABLE_XFA
1046   if (HandleXFAAAction(type, data, pFormFillEnv))
1047     return true;
1048 #endif  // PDF_ENABLE_XFA
1049 
1050   CPDF_Action action = GetAAction(type);
1051   if (action.GetType() != CPDF_Action::Type::kUnknown) {
1052     pFormFillEnv->DoActionField(action, type, GetFormField(), data);
1053   }
1054   return false;
1055 }
1056 
OnLoad()1057 void CPDFSDK_Widget::OnLoad() {
1058   if (IsSignatureWidget())
1059     return;
1060 
1061   if (!IsAppearanceValid())
1062     ResetAppearance(absl::nullopt, CPDFSDK_Widget::kValueUnchanged);
1063 
1064   FormFieldType field_type = GetFieldType();
1065   if (field_type == FormFieldType::kTextField ||
1066       field_type == FormFieldType::kComboBox) {
1067     ObservedPtr<CPDFSDK_Annot> pObserved(this);
1068     absl::optional<WideString> sValue = OnFormat();
1069     if (!pObserved)
1070       return;
1071 
1072     if (sValue.has_value() && field_type == FormFieldType::kComboBox)
1073       ResetAppearance(sValue, CPDFSDK_Widget::kValueUnchanged);
1074   }
1075 
1076 #ifdef PDF_ENABLE_XFA
1077   auto* pContext = GetPageView()->GetFormFillEnv()->GetDocExtension();
1078   if (pContext && pContext->ContainsExtensionForegroundForm()) {
1079     if (!IsAppearanceValid() && !GetValue().IsEmpty())
1080       ResetXFAAppearance(CPDFSDK_Widget::kValueUnchanged);
1081   }
1082 #endif  // PDF_ENABLE_XFA
1083 }
1084 
GetAAction(CPDF_AAction::AActionType eAAT)1085 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1086   switch (eAAT) {
1087     case CPDF_AAction::kCursorEnter:
1088     case CPDF_AAction::kCursorExit:
1089     case CPDF_AAction::kButtonDown:
1090     case CPDF_AAction::kButtonUp:
1091     case CPDF_AAction::kGetFocus:
1092     case CPDF_AAction::kLoseFocus:
1093     case CPDF_AAction::kPageOpen:
1094     case CPDF_AAction::kPageClose:
1095     case CPDF_AAction::kPageVisible:
1096     case CPDF_AAction::kPageInvisible:
1097       return CPDFSDK_BAAnnot::GetAAction(eAAT);
1098 
1099     case CPDF_AAction::kKeyStroke:
1100     case CPDF_AAction::kFormat:
1101     case CPDF_AAction::kValidate:
1102     case CPDF_AAction::kCalculate: {
1103       CPDF_FormField* pField = GetFormField();
1104       if (pField->GetAdditionalAction().HasDict())
1105         return pField->GetAdditionalAction().GetAction(eAAT);
1106       return CPDFSDK_BAAnnot::GetAAction(eAAT);
1107     }
1108     default:
1109       break;
1110   }
1111 
1112   return CPDF_Action(nullptr);
1113 }
1114 
GetInteractiveFormFiller()1115 CFFL_InteractiveFormFiller* CPDFSDK_Widget::GetInteractiveFormFiller() {
1116   return GetPageView()->GetFormFillEnv()->GetInteractiveFormFiller();
1117 }
1118