• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/fxcrt/check.h"
26 #include "core/fxcrt/notreached.h"
27 #include "core/fxge/cfx_fillrenderoptions.h"
28 #include "core/fxge/cfx_graphstatedata.h"
29 #include "core/fxge/cfx_path.h"
30 #include "core/fxge/cfx_renderdevice.h"
31 #include "fpdfsdk/cpdfsdk_appstream.h"
32 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
33 #include "fpdfsdk/cpdfsdk_interactiveform.h"
34 #include "fpdfsdk/cpdfsdk_pageview.h"
35 #include "fpdfsdk/formfiller/cffl_fieldaction.h"
36 #include "fpdfsdk/pwl/cpwl_edit.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(eEventType);
228   param.m_wsChange = data->sChange;
229   param.m_iCommitKey = 0;
230   param.m_bShift = data->bShift;
231   param.m_iSelStart = data->nSelStart;
232   param.m_iSelEnd = data->nSelEnd;
233   param.m_wsFullText = data->sValue;
234   param.m_bKeyDown = data->bKeyDown;
235   param.m_bModifier = data->bModifier;
236   param.m_wsPrevText = data->sValue;
237   if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
238       GetFieldType() == FormFieldType::kRadioButton) {
239     CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget();
240     if (hGroupWidget &&
241         !hGroupWidget->ProcessEventUnderHandler(&param, pXFAWidgetHandler)) {
242       return false;
243     }
244   }
245 
246   bool ret = pWidget->ProcessEventUnderHandler(&param, pXFAWidgetHandler);
247   CXFA_FFDocView* pDocView = pContext->GetXFADocView();
248   if (pDocView)
249     pDocView->UpdateDocView();
250 
251   return ret;
252 }
253 
Synchronize(bool bSynchronizeElse)254 void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
255   CXFA_FFWidget* hWidget = GetMixXFAWidget();
256   if (!hWidget)
257     return;
258 
259   CXFA_Node* node = hWidget->GetNode();
260   if (!node->IsWidgetReady())
261     return;
262 
263   CPDF_FormField* pFormField = GetFormField();
264   switch (GetFieldType()) {
265     case FormFieldType::kCheckBox:
266     case FormFieldType::kRadioButton: {
267       CPDF_FormControl* pFormCtrl = GetFormControl();
268       XFA_CheckState eCheckState =
269           pFormCtrl->IsChecked() ? XFA_CheckState::kOn : XFA_CheckState::kOff;
270       node->SetCheckState(eCheckState);
271       break;
272     }
273     case FormFieldType::kTextField:
274       node->SetValue(XFA_ValuePicture::kEdit, pFormField->GetValue());
275       break;
276     case FormFieldType::kComboBox:
277     case FormFieldType::kListBox: {
278       node->ClearAllSelections();
279       for (int i = 0; i < pFormField->CountSelectedItems(); ++i) {
280         int nIndex = pFormField->GetSelectedIndex(i);
281         if (nIndex > -1 &&
282             static_cast<size_t>(nIndex) < node->CountChoiceListItems(false)) {
283           node->SetItemState(nIndex, true, false, false);
284         }
285       }
286       if (GetFieldType() == FormFieldType::kComboBox)
287         node->SetValue(XFA_ValuePicture::kEdit, pFormField->GetValue());
288       break;
289     }
290     default:
291       break;
292   }
293 
294   if (bSynchronizeElse) {
295     auto* context = static_cast<CPDFXFA_Context*>(
296         GetPageView()->GetFormFillEnv()->GetDocExtension());
297     context->GetXFADocView()->ProcessValueChanged(node);
298   }
299 }
300 
HandleXFAAAction(CPDF_AAction::AActionType type,CFFL_FieldAction * data,CPDFSDK_FormFillEnvironment * pFormFillEnv)301 bool CPDFSDK_Widget::HandleXFAAAction(
302     CPDF_AAction::AActionType type,
303     CFFL_FieldAction* data,
304     CPDFSDK_FormFillEnvironment* pFormFillEnv) {
305   auto* pContext =
306       static_cast<CPDFXFA_Context*>(pFormFillEnv->GetDocExtension());
307   if (!pContext)
308     return false;
309 
310   CXFA_FFWidget* hWidget = GetMixXFAWidget();
311   if (!hWidget)
312     return false;
313 
314   XFA_EVENTTYPE eEventType = GetXFAEventType(type, data->bWillCommit);
315   if (eEventType == XFA_EVENT_Unknown)
316     return false;
317 
318   CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
319   if (!pXFAWidgetHandler)
320     return false;
321 
322   CXFA_EventParam param(eEventType);
323   param.m_wsChange = data->sChange;
324   param.m_iCommitKey = 0;
325   param.m_bShift = data->bShift;
326   param.m_iSelStart = data->nSelStart;
327   param.m_iSelEnd = data->nSelEnd;
328   param.m_wsFullText = data->sValue;
329   param.m_bKeyDown = data->bKeyDown;
330   param.m_bModifier = data->bModifier;
331   param.m_wsPrevText = data->sValue;
332   bool ret = hWidget->ProcessEventUnderHandler(&param, pXFAWidgetHandler);
333   CXFA_FFDocView* pDocView = pContext->GetXFADocView();
334   if (pDocView)
335     pDocView->UpdateDocView();
336 
337   return ret;
338 }
339 #endif  // PDF_ENABLE_XFA
340 
IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) const341 bool CPDFSDK_Widget::IsWidgetAppearanceValid(
342     CPDF_Annot::AppearanceMode mode) const {
343   RetainPtr<const CPDF_Dictionary> pAP =
344       GetAnnotDict()->GetDictFor(pdfium::annotation::kAP);
345   if (!pAP)
346     return false;
347 
348   // Choose the right sub-ap
349   const char* ap_entry = "N";
350   if (mode == CPDF_Annot::AppearanceMode::kDown)
351     ap_entry = "D";
352   else if (mode == CPDF_Annot::AppearanceMode::kRollover)
353     ap_entry = "R";
354   if (!pAP->KeyExist(ap_entry))
355     ap_entry = "N";
356 
357   // Get the AP stream or subdirectory
358   RetainPtr<const CPDF_Object> pSub = pAP->GetDirectObjectFor(ap_entry);
359   if (!pSub)
360     return false;
361 
362   FormFieldType fieldType = GetFieldType();
363   switch (fieldType) {
364     case FormFieldType::kPushButton:
365     case FormFieldType::kComboBox:
366     case FormFieldType::kListBox:
367     case FormFieldType::kTextField:
368     case FormFieldType::kSignature:
369       return pSub->IsStream();
370     case FormFieldType::kCheckBox:
371     case FormFieldType::kRadioButton:
372       if (const CPDF_Dictionary* pSubDict = pSub->AsDictionary()) {
373         return !!pSubDict->GetStreamFor(GetAppState());
374       }
375       return false;
376     default:
377       return true;
378   }
379 }
380 
IsPushHighlighted() const381 bool CPDFSDK_Widget::IsPushHighlighted() const {
382   return GetFormControl()->GetHighlightingMode() == CPDF_FormControl::kPush;
383 }
384 
GetFieldType() const385 FormFieldType CPDFSDK_Widget::GetFieldType() const {
386   CPDF_FormField* pField = GetFormField();
387   return pField ? pField->GetFieldType() : FormFieldType::kUnknown;
388 }
389 
SetRect(const CFX_FloatRect & rect)390 void CPDFSDK_Widget::SetRect(const CFX_FloatRect& rect) {
391   DCHECK(rect.right - rect.left >= 1.0f);
392   DCHECK(rect.top - rect.bottom >= 1.0f);
393   GetMutableAnnotDict()->SetRectFor(pdfium::annotation::kRect, rect);
394 }
395 
IsAppearanceValid()396 bool CPDFSDK_Widget::IsAppearanceValid() {
397 #ifdef PDF_ENABLE_XFA
398   CPDF_Document::Extension* pContext =
399       GetPageView()->GetFormFillEnv()->GetDocExtension();
400   if (pContext && pContext->ContainsExtensionFullForm())
401     return true;
402 #endif  // PDF_ENABLE_XFA
403   return CPDFSDK_BAAnnot::IsAppearanceValid();
404 }
405 
GetLayoutOrder() const406 int CPDFSDK_Widget::GetLayoutOrder() const {
407   return 2;
408 }
409 
GetFieldFlags() const410 int CPDFSDK_Widget::GetFieldFlags() const {
411   return GetFormField()->GetFieldFlags();
412 }
413 
IsSignatureWidget() const414 bool CPDFSDK_Widget::IsSignatureWidget() const {
415   return GetFieldType() == FormFieldType::kSignature;
416 }
417 
GetFormField() const418 CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
419   CPDF_FormControl* pControl = GetFormControl();
420   return pControl ? pControl->GetField() : nullptr;
421 }
422 
GetFormControl() const423 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
424   CPDF_InteractiveForm* pPDFInteractiveForm =
425       m_pInteractiveForm->GetInteractiveForm();
426   return pPDFInteractiveForm->GetControlByDict(GetAnnotDict());
427 }
428 
GetRotate() const429 int CPDFSDK_Widget::GetRotate() const {
430   CPDF_FormControl* pCtrl = GetFormControl();
431   return pCtrl->GetRotation() % 360;
432 }
433 
434 #ifdef PDF_ENABLE_XFA
GetName() const435 WideString CPDFSDK_Widget::GetName() const {
436   return GetFormField()->GetFullName();
437 }
438 #endif  // PDF_ENABLE_XFA
439 
GetFillColor() const440 std::optional<FX_COLORREF> CPDFSDK_Widget::GetFillColor() const {
441   CFX_Color::TypeAndARGB type_argb_pair =
442       GetFormControl()->GetColorARGB(pdfium::appearance::kBG);
443 
444   if (type_argb_pair.color_type == CFX_Color::Type::kTransparent)
445     return std::nullopt;
446 
447   return ArgbToColorRef(type_argb_pair.argb);
448 }
449 
GetBorderColor() const450 std::optional<FX_COLORREF> CPDFSDK_Widget::GetBorderColor() const {
451   CFX_Color::TypeAndARGB type_argb_pair =
452       GetFormControl()->GetColorARGB(pdfium::appearance::kBC);
453   if (type_argb_pair.color_type == CFX_Color::Type::kTransparent)
454     return std::nullopt;
455 
456   return ArgbToColorRef(type_argb_pair.argb);
457 }
458 
GetTextColor() const459 std::optional<FX_COLORREF> CPDFSDK_Widget::GetTextColor() const {
460   CPDF_DefaultAppearance da = GetFormControl()->GetDefaultAppearance();
461   std::optional<CFX_Color::TypeAndARGB> maybe_type_argb_pair =
462       da.GetColorARGB();
463 
464   if (!maybe_type_argb_pair.has_value())
465     return std::nullopt;
466 
467   if (maybe_type_argb_pair.value().color_type == CFX_Color::Type::kTransparent)
468     return std::nullopt;
469 
470   return ArgbToColorRef(maybe_type_argb_pair.value().argb);
471 }
472 
GetFontSize() const473 float CPDFSDK_Widget::GetFontSize() const {
474   CPDF_FormControl* pFormCtrl = GetFormControl();
475   CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
476   float fFontSize;
477   pDa.GetFont(&fFontSize);
478   return fFontSize;
479 }
480 
GetSelectedIndex(int nIndex) const481 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
482 #ifdef PDF_ENABLE_XFA
483   if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
484     CXFA_Node* node = hWidget->GetNode();
485     if (node->IsWidgetReady()) {
486       if (nIndex < node->CountSelectedItems())
487         return node->GetSelectedItem(nIndex);
488     }
489   }
490 #endif  // PDF_ENABLE_XFA
491   CPDF_FormField* pFormField = GetFormField();
492   return pFormField->GetSelectedIndex(nIndex);
493 }
494 
GetValue() const495 WideString CPDFSDK_Widget::GetValue() const {
496 #ifdef PDF_ENABLE_XFA
497   if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
498     CXFA_Node* node = hWidget->GetNode();
499     if (node->IsWidgetReady())
500       return node->GetValue(XFA_ValuePicture::kDisplay);
501   }
502 #endif  // PDF_ENABLE_XFA
503   CPDF_FormField* pFormField = GetFormField();
504   return pFormField->GetValue();
505 }
506 
GetExportValue() const507 WideString CPDFSDK_Widget::GetExportValue() const {
508   CPDF_FormControl* pFormCtrl = GetFormControl();
509   return pFormCtrl->GetExportValue();
510 }
511 
GetOptionLabel(int nIndex) const512 WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
513   CPDF_FormField* pFormField = GetFormField();
514   return pFormField->GetOptionLabel(nIndex);
515 }
516 
GetSelectExportText(int nIndex) const517 WideString CPDFSDK_Widget::GetSelectExportText(int nIndex) const {
518   if (nIndex < 0)
519     return WideString();
520 
521   CPDF_FormField* pFormField = GetFormField();
522   if (!pFormField)
523     return WideString();
524 
525   WideString swRet = pFormField->GetOptionValue(nIndex);
526   if (!swRet.IsEmpty())
527     return swRet;
528 
529   return pFormField->GetOptionLabel(nIndex);
530 }
531 
CountOptions() const532 int CPDFSDK_Widget::CountOptions() const {
533   CPDF_FormField* pFormField = GetFormField();
534   return pFormField->CountOptions();
535 }
536 
IsOptionSelected(int nIndex) const537 bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
538 #ifdef PDF_ENABLE_XFA
539   if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
540     CXFA_Node* node = hWidget->GetNode();
541     if (node->IsWidgetReady()) {
542       if (nIndex > -1 &&
543           static_cast<size_t>(nIndex) < node->CountChoiceListItems(false)) {
544         return node->GetItemState(nIndex);
545       }
546       return false;
547     }
548   }
549 #endif  // PDF_ENABLE_XFA
550   CPDF_FormField* pFormField = GetFormField();
551   return pFormField->IsItemSelected(nIndex);
552 }
553 
GetTopVisibleIndex() const554 int CPDFSDK_Widget::GetTopVisibleIndex() const {
555   CPDF_FormField* pFormField = GetFormField();
556   return pFormField->GetTopVisibleIndex();
557 }
558 
IsChecked() const559 bool CPDFSDK_Widget::IsChecked() const {
560 #ifdef PDF_ENABLE_XFA
561   if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
562     CXFA_Node* node = hWidget->GetNode();
563     if (node->IsWidgetReady())
564       return node->GetCheckState() == XFA_CheckState::kOn;
565   }
566 #endif  // PDF_ENABLE_XFA
567   CPDF_FormControl* pFormCtrl = GetFormControl();
568   return pFormCtrl->IsChecked();
569 }
570 
GetAlignment() const571 int CPDFSDK_Widget::GetAlignment() const {
572   CPDF_FormControl* pFormCtrl = GetFormControl();
573   return pFormCtrl->GetControlAlignment();
574 }
575 
GetMaxLen() const576 int CPDFSDK_Widget::GetMaxLen() const {
577   CPDF_FormField* pFormField = GetFormField();
578   return pFormField->GetMaxLen();
579 }
580 
SetCheck(bool bChecked)581 void CPDFSDK_Widget::SetCheck(bool bChecked) {
582   CPDF_FormControl* pFormCtrl = GetFormControl();
583   CPDF_FormField* pFormField = pFormCtrl->GetField();
584   pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
585                            NotificationOption::kDoNotNotify);
586 #ifdef PDF_ENABLE_XFA
587   if (!IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode::kNormal))
588     ResetXFAAppearance(CPDFSDK_Widget::kValueChanged);
589   Synchronize(true);
590 #endif  // PDF_ENABLE_XFA
591 }
592 
SetValue(const WideString & sValue)593 void CPDFSDK_Widget::SetValue(const WideString& sValue) {
594   CPDF_FormField* pFormField = GetFormField();
595   pFormField->SetValue(sValue, NotificationOption::kDoNotNotify);
596 #ifdef PDF_ENABLE_XFA
597   Synchronize(true);
598 #endif  // PDF_ENABLE_XFA
599 }
600 
SetOptionSelection(int index)601 void CPDFSDK_Widget::SetOptionSelection(int index) {
602   CPDF_FormField* pFormField = GetFormField();
603   pFormField->SetItemSelection(index, NotificationOption::kDoNotNotify);
604 #ifdef PDF_ENABLE_XFA
605   Synchronize(true);
606 #endif  // PDF_ENABLE_XFA
607 }
608 
ClearSelection()609 void CPDFSDK_Widget::ClearSelection() {
610   CPDF_FormField* pFormField = GetFormField();
611   pFormField->ClearSelection(NotificationOption::kDoNotNotify);
612 #ifdef PDF_ENABLE_XFA
613   Synchronize(true);
614 #endif  // PDF_ENABLE_XFA
615 }
616 
SetTopVisibleIndex(int index)617 void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
618 
SetAppModified()619 void CPDFSDK_Widget::SetAppModified() {
620   m_bAppModified = true;
621 }
622 
ClearAppModified()623 void CPDFSDK_Widget::ClearAppModified() {
624   m_bAppModified = false;
625 }
626 
IsAppModified() const627 bool CPDFSDK_Widget::IsAppModified() const {
628   return m_bAppModified;
629 }
630 
631 #ifdef PDF_ENABLE_XFA
ResetXFAAppearance(ValueChanged bValueChanged)632 void CPDFSDK_Widget::ResetXFAAppearance(ValueChanged bValueChanged) {
633   switch (GetFieldType()) {
634     case FormFieldType::kTextField:
635     case FormFieldType::kComboBox: {
636       ResetAppearance(OnFormat(), kValueChanged);
637       break;
638     }
639     default:
640       ResetAppearance(std::nullopt, kValueUnchanged);
641       break;
642   }
643 }
644 #endif  // PDF_ENABLE_XFA
645 
ResetAppearance(std::optional<WideString> sValue,ValueChanged bValueChanged)646 void CPDFSDK_Widget::ResetAppearance(std::optional<WideString> sValue,
647                                      ValueChanged bValueChanged) {
648   SetAppModified();
649 
650   m_nAppearanceAge++;
651   if (bValueChanged == kValueChanged)
652     m_nValueAge++;
653 
654   CPDFSDK_AppStream appStream(this, GetAPDict().Get());
655   switch (GetFieldType()) {
656     case FormFieldType::kPushButton:
657       appStream.SetAsPushButton();
658       break;
659     case FormFieldType::kCheckBox:
660       appStream.SetAsCheckBox();
661       break;
662     case FormFieldType::kRadioButton:
663       appStream.SetAsRadioButton();
664       break;
665     case FormFieldType::kComboBox:
666       appStream.SetAsComboBox(sValue);
667       break;
668     case FormFieldType::kListBox:
669       appStream.SetAsListBox();
670       break;
671     case FormFieldType::kTextField:
672       appStream.SetAsTextField(sValue);
673       break;
674     default:
675       break;
676   }
677 
678   ClearCachedAnnotAP();
679 }
680 
OnFormat()681 std::optional<WideString> CPDFSDK_Widget::OnFormat() {
682   CPDF_FormField* pFormField = GetFormField();
683   DCHECK(pFormField);
684   return m_pInteractiveForm->OnFormat(pFormField);
685 }
686 
ResetFieldAppearance()687 void CPDFSDK_Widget::ResetFieldAppearance() {
688   CPDF_FormField* pFormField = GetFormField();
689   DCHECK(pFormField);
690   m_pInteractiveForm->ResetFieldAppearance(pFormField, std::nullopt);
691 }
692 
OnDraw(CFX_RenderDevice * pDevice,const CFX_Matrix & mtUser2Device,bool bDrawAnnots)693 void CPDFSDK_Widget::OnDraw(CFX_RenderDevice* pDevice,
694                             const CFX_Matrix& mtUser2Device,
695                             bool bDrawAnnots) {
696   if (IsSignatureWidget()) {
697     DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::AppearanceMode::kNormal);
698     return;
699   }
700 
701   GetInteractiveFormFiller()->OnDraw(GetPageView(), this, pDevice,
702                                      mtUser2Device);
703 }
704 
DoHitTest(const CFX_PointF & point)705 bool CPDFSDK_Widget::DoHitTest(const CFX_PointF& point) {
706   if (IsSignatureWidget() || !IsVisible())
707     return false;
708 
709   if (GetFieldFlags() & pdfium::form_flags::kReadOnly)
710     return false;
711 
712   bool do_hit_test = GetFieldType() == FormFieldType::kPushButton;
713   if (!do_hit_test) {
714     uint32_t perms = GetPDFPage()->GetDocument()->GetUserPermissions(
715         /*get_owner_perms=*/true);
716     do_hit_test = (perms & pdfium::access_permissions::kFillForm) ||
717                   (perms & pdfium::access_permissions::kModifyAnnotation);
718   }
719   return do_hit_test && GetViewBBox().Contains(point);
720 }
721 
GetViewBBox()722 CFX_FloatRect CPDFSDK_Widget::GetViewBBox() {
723   if (IsSignatureWidget())
724     return CFX_FloatRect();
725 
726   auto* form_filler = GetInteractiveFormFiller();
727   return CFX_FloatRect(form_filler->GetViewBBox(GetPageView(), this));
728 }
729 
OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags)730 void CPDFSDK_Widget::OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) {
731   if (IsSignatureWidget())
732     return;
733 
734   ObservedPtr<CPDFSDK_Widget> observer(this);
735   GetInteractiveFormFiller()->OnMouseEnter(GetPageView(), observer, nFlags);
736 }
737 
OnMouseExit(Mask<FWL_EVENTFLAG> nFlags)738 void CPDFSDK_Widget::OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) {
739   if (IsSignatureWidget())
740     return;
741 
742   ObservedPtr<CPDFSDK_Widget> observer(this);
743   GetInteractiveFormFiller()->OnMouseExit(GetPageView(), observer, nFlags);
744 }
745 
OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)746 bool CPDFSDK_Widget::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
747                                    const CFX_PointF& point) {
748   if (IsSignatureWidget())
749     return false;
750 
751   ObservedPtr<CPDFSDK_Widget> observer(this);
752   return GetInteractiveFormFiller()->OnLButtonDown(GetPageView(), observer,
753                                                    nFlags, point);
754 }
755 
OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)756 bool CPDFSDK_Widget::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
757                                  const CFX_PointF& point) {
758   if (IsSignatureWidget())
759     return false;
760 
761   ObservedPtr<CPDFSDK_Widget> observer(this);
762   return GetInteractiveFormFiller()->OnLButtonUp(GetPageView(), observer,
763                                                  nFlags, point);
764 }
765 
OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)766 bool CPDFSDK_Widget::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
767                                      const CFX_PointF& point) {
768   if (IsSignatureWidget())
769     return false;
770 
771   ObservedPtr<CPDFSDK_Widget> observer(this);
772   return GetInteractiveFormFiller()->OnLButtonDblClk(GetPageView(), observer,
773                                                      nFlags, point);
774 }
775 
OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)776 bool CPDFSDK_Widget::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
777                                  const CFX_PointF& point) {
778   if (IsSignatureWidget())
779     return false;
780 
781   ObservedPtr<CPDFSDK_Widget> observer(this);
782   return GetInteractiveFormFiller()->OnMouseMove(GetPageView(), observer,
783                                                  nFlags, point);
784 }
785 
OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point,const CFX_Vector & delta)786 bool CPDFSDK_Widget::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
787                                   const CFX_PointF& point,
788                                   const CFX_Vector& delta) {
789   if (IsSignatureWidget())
790     return false;
791 
792   ObservedPtr<CPDFSDK_Widget> observer(this);
793   return GetInteractiveFormFiller()->OnMouseWheel(GetPageView(), observer,
794                                                   nFlags, point, delta);
795 }
796 
OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)797 bool CPDFSDK_Widget::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
798                                    const CFX_PointF& point) {
799   if (IsSignatureWidget())
800     return false;
801 
802   ObservedPtr<CPDFSDK_Widget> observer(this);
803   return GetInteractiveFormFiller()->OnRButtonDown(GetPageView(), observer,
804                                                    nFlags, point);
805 }
806 
OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,const CFX_PointF & point)807 bool CPDFSDK_Widget::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
808                                  const CFX_PointF& point) {
809   if (IsSignatureWidget())
810     return false;
811 
812   ObservedPtr<CPDFSDK_Widget> observer(this);
813   return GetInteractiveFormFiller()->OnRButtonUp(GetPageView(), observer,
814                                                  nFlags, point);
815 }
816 
OnChar(uint32_t nChar,Mask<FWL_EVENTFLAG> nFlags)817 bool CPDFSDK_Widget::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
818   return !IsSignatureWidget() &&
819          GetInteractiveFormFiller()->OnChar(this, nChar, nFlags);
820 }
821 
OnKeyDown(FWL_VKEYCODE nKeyCode,Mask<FWL_EVENTFLAG> nFlags)822 bool CPDFSDK_Widget::OnKeyDown(FWL_VKEYCODE nKeyCode,
823                                Mask<FWL_EVENTFLAG> nFlags) {
824   return !IsSignatureWidget() &&
825          GetInteractiveFormFiller()->OnKeyDown(this, nKeyCode, nFlags);
826 }
827 
OnSetFocus(Mask<FWL_EVENTFLAG> nFlags)828 bool CPDFSDK_Widget::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) {
829   if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype()))
830     return false;
831 
832   if (IsSignatureWidget())
833     return true;
834 
835   ObservedPtr<CPDFSDK_Widget> observer(this);
836   return GetInteractiveFormFiller()->OnSetFocus(observer, nFlags);
837 }
838 
OnKillFocus(Mask<FWL_EVENTFLAG> nFlags)839 bool CPDFSDK_Widget::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) {
840   if (!IsFocusableAnnot(GetPDFAnnot()->GetSubtype()))
841     return false;
842 
843   if (IsSignatureWidget())
844     return true;
845 
846   ObservedPtr<CPDFSDK_Widget> observer(this);
847   return GetInteractiveFormFiller()->OnKillFocus(observer, nFlags);
848 }
849 
CanUndo()850 bool CPDFSDK_Widget::CanUndo() {
851   return !IsSignatureWidget() && GetInteractiveFormFiller()->CanUndo(this);
852 }
853 
CanRedo()854 bool CPDFSDK_Widget::CanRedo() {
855   return !IsSignatureWidget() && GetInteractiveFormFiller()->CanRedo(this);
856 }
857 
Undo()858 bool CPDFSDK_Widget::Undo() {
859   return !IsSignatureWidget() && GetInteractiveFormFiller()->Undo(this);
860 }
861 
Redo()862 bool CPDFSDK_Widget::Redo() {
863   return !IsSignatureWidget() && GetInteractiveFormFiller()->Redo(this);
864 }
865 
GetText()866 WideString CPDFSDK_Widget::GetText() {
867   if (IsSignatureWidget())
868     return WideString();
869   return GetInteractiveFormFiller()->GetText(this);
870 }
871 
GetSelectedText()872 WideString CPDFSDK_Widget::GetSelectedText() {
873   if (IsSignatureWidget())
874     return WideString();
875   return GetInteractiveFormFiller()->GetSelectedText(this);
876 }
877 
ReplaceAndKeepSelection(const WideString & text)878 void CPDFSDK_Widget::ReplaceAndKeepSelection(const WideString& text) {
879   if (IsSignatureWidget())
880     return;
881 
882   GetInteractiveFormFiller()->ReplaceAndKeepSelection(this, text);
883 }
884 
ReplaceSelection(const WideString & text)885 void CPDFSDK_Widget::ReplaceSelection(const WideString& text) {
886   if (IsSignatureWidget())
887     return;
888 
889   GetInteractiveFormFiller()->ReplaceSelection(this, text);
890 }
891 
SelectAllText()892 bool CPDFSDK_Widget::SelectAllText() {
893   return !IsSignatureWidget() &&
894          GetInteractiveFormFiller()->SelectAllText(this);
895 }
896 
SetIndexSelected(int index,bool selected)897 bool CPDFSDK_Widget::SetIndexSelected(int index, bool selected) {
898   ObservedPtr<CPDFSDK_Widget> observer(this);
899   return !IsSignatureWidget() && GetInteractiveFormFiller()->SetIndexSelected(
900                                      observer, index, selected);
901 }
902 
IsIndexSelected(int index)903 bool CPDFSDK_Widget::IsIndexSelected(int index) {
904   ObservedPtr<CPDFSDK_Widget> observer(this);
905   return !IsSignatureWidget() &&
906          GetInteractiveFormFiller()->IsIndexSelected(observer, index);
907 }
908 
DrawAppearance(CFX_RenderDevice * pDevice,const CFX_Matrix & mtUser2Device,CPDF_Annot::AppearanceMode mode)909 void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
910                                     const CFX_Matrix& mtUser2Device,
911                                     CPDF_Annot::AppearanceMode mode) {
912   FormFieldType fieldType = GetFieldType();
913 
914   if ((fieldType == FormFieldType::kCheckBox ||
915        fieldType == FormFieldType::kRadioButton) &&
916       mode == CPDF_Annot::AppearanceMode::kNormal &&
917       !IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode::kNormal)) {
918     CFX_GraphStateData gsd;
919     gsd.set_line_width(0.0f);
920 
921     CFX_Path path;
922     path.AppendFloatRect(GetRect());
923     pDevice->DrawPath(path, &mtUser2Device, &gsd, 0, 0xFFAAAAAA,
924                       CFX_FillRenderOptions::EvenOddOptions());
925   } else {
926     CPDFSDK_BAAnnot::DrawAppearance(pDevice, mtUser2Device, mode);
927   }
928 }
929 
UpdateField()930 void CPDFSDK_Widget::UpdateField() {
931   CPDF_FormField* pFormField = GetFormField();
932   DCHECK(pFormField);
933   m_pInteractiveForm->UpdateField(pFormField);
934 }
935 
DrawShadow(CFX_RenderDevice * pDevice,CPDFSDK_PageView * pPageView)936 void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
937                                 CPDFSDK_PageView* pPageView) {
938   FormFieldType fieldType = GetFieldType();
939   if (!m_pInteractiveForm->IsNeedHighLight(fieldType))
940     return;
941 
942   CFX_Matrix page2device = pPageView->GetCurrentMatrix();
943   CFX_FloatRect rcDevice = GetRect();
944   CFX_PointF tmp =
945       page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom));
946   rcDevice.left = tmp.x;
947   rcDevice.bottom = tmp.y;
948 
949   tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top));
950   rcDevice.right = tmp.x;
951   rcDevice.top = tmp.y;
952   rcDevice.Normalize();
953 
954   pDevice->FillRect(
955       rcDevice.ToFxRect(),
956       AlphaAndColorRefToArgb(
957           static_cast<int>(m_pInteractiveForm->GetHighlightAlpha()),
958           m_pInteractiveForm->GetHighlightColor(fieldType)));
959 }
960 
GetClientRect() const961 CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
962   CFX_FloatRect rcWindow = GetRotatedRect();
963   float fBorderWidth = GetBorderWidth();
964   switch (GetBorderStyle()) {
965     case BorderStyle::kBeveled:
966     case BorderStyle::kInset:
967       fBorderWidth *= 2.0f;
968       break;
969     default:
970       break;
971   }
972   return rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
973 }
974 
GetRotatedRect() const975 CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
976   CFX_FloatRect rectAnnot = GetRect();
977   float fWidth = rectAnnot.Width();
978   float fHeight = rectAnnot.Height();
979 
980   CPDF_FormControl* pControl = GetFormControl();
981   CFX_FloatRect rcPWLWindow;
982   switch (abs(pControl->GetRotation() % 360)) {
983     case 0:
984     case 180:
985     default:
986       rcPWLWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
987       break;
988     case 90:
989     case 270:
990       rcPWLWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
991       break;
992   }
993 
994   return rcPWLWindow;
995 }
996 
GetMatrix() const997 CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
998   CFX_Matrix mt;
999   CPDF_FormControl* pControl = GetFormControl();
1000   CFX_FloatRect rcAnnot = GetRect();
1001   float fWidth = rcAnnot.Width();
1002   float fHeight = rcAnnot.Height();
1003 
1004   switch (abs(pControl->GetRotation() % 360)) {
1005     default:
1006     case 0:
1007       break;
1008     case 90:
1009       mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
1010       break;
1011     case 180:
1012       mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
1013       break;
1014     case 270:
1015       mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
1016       break;
1017   }
1018 
1019   return mt;
1020 }
1021 
GetTextPWLColor() const1022 CFX_Color CPDFSDK_Widget::GetTextPWLColor() const {
1023   CPDF_FormControl* pFormCtrl = GetFormControl();
1024   std::optional<CFX_Color> crText =
1025       pFormCtrl->GetDefaultAppearance().GetColor();
1026   return crText.value_or(CFX_Color(CFX_Color::Type::kGray, 0));
1027 }
1028 
GetBorderPWLColor() const1029 CFX_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1030   CPDF_FormControl* pFormCtrl = GetFormControl();
1031   return pFormCtrl->GetOriginalBorderColor();
1032 }
1033 
GetFillPWLColor() const1034 CFX_Color CPDFSDK_Widget::GetFillPWLColor() const {
1035   CPDF_FormControl* pFormCtrl = GetFormControl();
1036   return pFormCtrl->GetOriginalBackgroundColor();
1037 }
1038 
OnAAction(CPDF_AAction::AActionType type,CFFL_FieldAction * data,const CPDFSDK_PageView * pPageView)1039 bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1040                                CFFL_FieldAction* data,
1041                                const CPDFSDK_PageView* pPageView) {
1042   CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
1043 
1044 #ifdef PDF_ENABLE_XFA
1045   if (HandleXFAAAction(type, data, pFormFillEnv))
1046     return true;
1047 #endif  // PDF_ENABLE_XFA
1048 
1049   CPDF_Action action = GetAAction(type);
1050   if (action.GetType() != CPDF_Action::Type::kUnknown) {
1051     pFormFillEnv->DoActionField(action, type, GetFormField(), data);
1052   }
1053   return false;
1054 }
1055 
OnLoad()1056 void CPDFSDK_Widget::OnLoad() {
1057   ObservedPtr<CPDFSDK_Widget> pObserved(this);
1058   if (pObserved->IsSignatureWidget()) {
1059     return;
1060   }
1061   if (!pObserved->IsAppearanceValid()) {
1062     pObserved->ResetAppearance(std::nullopt, CPDFSDK_Widget::kValueUnchanged);
1063   }
1064   FormFieldType field_type = pObserved->GetFieldType();
1065   if (field_type == FormFieldType::kTextField ||
1066       field_type == FormFieldType::kComboBox) {
1067     std::optional<WideString> sValue = pObserved->OnFormat();
1068     if (!pObserved) {
1069       return;
1070     }
1071     if (sValue.has_value() && field_type == FormFieldType::kComboBox) {
1072       pObserved->ResetAppearance(sValue, CPDFSDK_Widget::kValueUnchanged);
1073     }
1074   }
1075 #ifdef PDF_ENABLE_XFA
1076   auto* pContext =
1077       pObserved->GetPageView()->GetFormFillEnv()->GetDocExtension();
1078   if (pContext && pContext->ContainsExtensionForegroundForm()) {
1079     if (!pObserved->IsAppearanceValid() && !pObserved->GetValue().IsEmpty()) {
1080       pObserved->ResetXFAAppearance(CPDFSDK_Widget::kValueUnchanged);
1081     }
1082   }
1083 #endif  // PDF_ENABLE_XFA
1084 }
1085 
GetAAction(CPDF_AAction::AActionType eAAT)1086 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1087   switch (eAAT) {
1088     case CPDF_AAction::kCursorEnter:
1089     case CPDF_AAction::kCursorExit:
1090     case CPDF_AAction::kButtonDown:
1091     case CPDF_AAction::kButtonUp:
1092     case CPDF_AAction::kGetFocus:
1093     case CPDF_AAction::kLoseFocus:
1094     case CPDF_AAction::kPageOpen:
1095     case CPDF_AAction::kPageClose:
1096     case CPDF_AAction::kPageVisible:
1097     case CPDF_AAction::kPageInvisible:
1098       return CPDFSDK_BAAnnot::GetAAction(eAAT);
1099 
1100     case CPDF_AAction::kKeyStroke:
1101     case CPDF_AAction::kFormat:
1102     case CPDF_AAction::kValidate:
1103     case CPDF_AAction::kCalculate: {
1104       CPDF_FormField* pField = GetFormField();
1105       if (pField->GetAdditionalAction().HasDict())
1106         return pField->GetAdditionalAction().GetAction(eAAT);
1107       return CPDFSDK_BAAnnot::GetAAction(eAAT);
1108     }
1109     default:
1110       break;
1111   }
1112 
1113   return CPDF_Action(nullptr);
1114 }
1115 
GetInteractiveFormFiller()1116 CFFL_InteractiveFormFiller* CPDFSDK_Widget::GetInteractiveFormFiller() {
1117   return GetPageView()->GetFormFillEnv()->GetInteractiveFormFiller();
1118 }
1119