| // Copyright 2016 PDFium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| |
| #include "fpdfsdk/cpdfsdk_widgethandler.h" |
| |
| #include <memory> |
| |
| #include "constants/access_permissions.h" |
| #include "constants/form_flags.h" |
| #include "core/fpdfapi/page/cpdf_page.h" |
| #include "core/fpdfapi/parser/cpdf_document.h" |
| #include "core/fpdfdoc/cpdf_interactiveform.h" |
| #include "fpdfsdk/cpdfsdk_annot.h" |
| #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| #include "fpdfsdk/cpdfsdk_interactiveform.h" |
| #include "fpdfsdk/cpdfsdk_pageview.h" |
| #include "fpdfsdk/cpdfsdk_widget.h" |
| #include "fpdfsdk/formfiller/cffl_formfield.h" |
| #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" |
| #include "third_party/base/check.h" |
| #include "third_party/base/check_op.h" |
| #include "third_party/base/containers/contains.h" |
| |
| CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler() = default; |
| |
| CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() = default; |
| |
| std::unique_ptr<CPDFSDK_Annot> CPDFSDK_WidgetHandler::NewAnnot( |
| CPDF_Annot* pAnnot, |
| CPDFSDK_PageView* pPageView) { |
| CHECK(pPageView); |
| CPDFSDK_InteractiveForm* pForm = |
| GetFormFillEnvironment()->GetInteractiveForm(); |
| CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); |
| CPDF_FormControl* pCtrl = pPDFForm->GetControlByDict(pAnnot->GetAnnotDict()); |
| if (!pCtrl) |
| return nullptr; |
| |
| auto pWidget = std::make_unique<CPDFSDK_Widget>(pAnnot, pPageView, pForm); |
| pForm->AddMap(pCtrl, pWidget.get()); |
| if (pPDFForm->NeedConstructAP()) |
| pWidget->ResetAppearance(absl::nullopt, CPDFSDK_Widget::kValueUnchanged); |
| return pWidget; |
| } |