7#include "fpdfsdk/cpdfsdk_pageview.h"
13#include "core/fpdfapi/parser/cpdf_dictionary.h"
14#include "core/fpdfapi/parser/cpdf_document.h"
15#include "core/fpdfapi/render/cpdf_renderoptions.h"
16#include "core/fpdfdoc/cpdf_annotlist.h"
17#include "core/fpdfdoc/cpdf_interactiveform.h"
18#include "core/fxcrt/autorestorer.h"
19#include "core/fxcrt/check.h"
20#include "core/fxcrt/containers/contains.h"
21#include "core/fxcrt/stl_util.h"
22#include "fpdfsdk/cpdfsdk_annot.h"
23#include "fpdfsdk/cpdfsdk_annotiteration.h"
24#include "fpdfsdk/cpdfsdk_annotiterator.h"
25#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
26#include "fpdfsdk/cpdfsdk_helpers.h"
27#include "fpdfsdk/cpdfsdk_interactiveform.h"
30#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
31#include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h"
32#include "xfa/fxfa/cxfa_ffpageview.h"
50 if (!m_page->AsXFAPage()) {
55 m_page->AsPDFPage()->SetView(
nullptr);
59 for (std::unique_ptr<CPDFSDK_Annot>& pAnnot : m_SDKAnnotArray)
62 m_SDKAnnotArray.clear();
75 m_curMatrix
= mtUser2Device;
78 IPDF_Page* pPage = GetXFAPage();
79 CPDF_Document::Extension* pContext =
80 pPage ? pPage->GetDocument()->GetExtension() :
nullptr;
81 if (pContext && pContext->ContainsExtensionFullForm()) {
82 static_cast<CPDFXFA_Page*>(pPage)->DrawFocusAnnot(pDevice, GetFocusAnnot(),
83 mtUser2Device, pClip);
90 for (
const auto& pSDKAnnot : annot_iteration) {
91 pSDKAnnot->OnDraw(pDevice, mtUser2Device, pOptions->GetDrawAnnots());
95std::unique_ptr<CPDFSDK_Annot> CPDFSDK_PageView::NewAnnot(
CPDF_Annot* annot) {
98 CPDFSDK_InteractiveForm* form = m_pFormFillEnv->GetInteractiveForm();
105 auto ret =
std::make_unique<CPDFSDK_Widget>(annot,
this, form);
113 if (sub_type == CPDF_Annot::Subtype::XFAWIDGET)
122 for (
const auto& pSDKAnnot : annot_iteration) {
123 CFX_FloatRect rc = pSDKAnnot->GetViewBBox();
124 if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP)
126 if (rc.Contains(point))
127 return pSDKAnnot.Get();
134 for (
const auto& pSDKAnnot : annot_iteration) {
135 const CPDF_Annot::Subtype sub_type = pSDKAnnot->GetAnnotSubtype();
136 bool do_hit_test = sub_type == CPDF_Annot::Subtype::WIDGET;
138 do_hit_test = do_hit_test || sub_type == CPDF_Annot::Subtype::XFAWIDGET;
140 if (do_hit_test && pSDKAnnot->DoHitTest(point))
141 return pSDKAnnot.Get();
147CPDFSDK_Annot* CPDFSDK_PageView::AddAnnotForFFWidget(CXFA_FFWidget* pWidget) {
148 CPDFSDK_Annot* pSDKAnnot = GetAnnotForFFWidget(pWidget);
152 m_SDKAnnotArray.push_back(std::make_unique<CPDFXFA_Widget>(pWidget,
this));
153 return m_SDKAnnotArray.back().get();
156void CPDFSDK_PageView::DeleteAnnotForFFWidget(CXFA_FFWidget* pWidget) {
157 ObservedPtr<CPDFSDK_Annot> pAnnot(GetAnnotForFFWidget(pWidget));
161 IPDF_Page* pPage = pAnnot->GetXFAPage();
165 CPDF_Document::Extension* pContext = pPage->GetDocument()->GetExtension();
166 if (pContext && !pContext->ContainsExtensionForm()) {
169 if (GetFocusAnnot() == pAnnot) {
171 m_pFormFillEnv->KillFocusAnnot({});
174 auto it = std::find(m_SDKAnnotArray.begin(), m_SDKAnnotArray.end(),
175 fxcrt::MakeFakeUniquePtr(pAnnot.Get()));
176 if (it != m_SDKAnnotArray.end())
177 m_SDKAnnotArray.erase(it);
179 if (m_pCaptureWidget.Get() == pAnnot) {
180 m_pCaptureWidget.Reset();
184CPDFXFA_Page* CPDFSDK_PageView::XFAPageIfNotBackedByPDFPage() {
185 auto* pPage =
static_cast<CPDFXFA_Page*>(GetXFAPage());
186 return pPage && !pPage->AsPDFPage() ? pPage :
nullptr;
191 return m_page->GetDocument();
195 return ToPDFPage(m_page);
198CPDFSDK_InteractiveForm* CPDFSDK_PageView::GetInteractiveForm()
const {
199 return m_pFormFillEnv->GetInteractiveForm();
203 std::vector<CPDFSDK_Annot*> list;
204 list.reserve(m_SDKAnnotArray.size());
205 for (
const std::unique_ptr<CPDFSDK_Annot>& elem : m_SDKAnnotArray)
206 list.push_back(elem.get());
211 for (std::unique_ptr<CPDFSDK_Annot>& pAnnot : m_SDKAnnotArray) {
212 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
213 if (pPDFAnnot && pPDFAnnot->GetAnnotDict() == pDict)
220CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotForFFWidget(CXFA_FFWidget* pWidget) {
224 for (std::unique_ptr<CPDFSDK_Annot>& pAnnot : m_SDKAnnotArray) {
225 CPDFXFA_Widget* pCurrentWidget = pAnnot->AsXFAWidget();
226 if (pCurrentWidget && pCurrentWidget->GetXFAFFWidget() == pWidget)
232IPDF_Page* CPDFSDK_PageView::GetXFAPage() {
233 return ToXFAPage(m_page);
244 CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage();
246 return pXFAPage->GetNextXFAAnnot(pAnnot);
254 CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage();
256 return pXFAPage->GetPrevXFAAnnot(pAnnot);
264 CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage();
266 return pXFAPage->GetFirstXFAAnnot(
this);
274 CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage();
276 return pXFAPage->GetLastXFAAnnot(
this);
328 ObservedPtr<
CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
330 m_pFormFillEnv->KillFocusAnnot(nFlags);
334 m_pFormFillEnv->SetFocusAnnot(pAnnot);
340 ObservedPtr<
CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
342 m_pFormFillEnv->KillFocusAnnot(nFlags);
352 m_pFormFillEnv->SetFocusAnnot(pAnnot);
358 ObservedPtr<
CPDFSDK_Annot> pFXAnnot(GetFXWidgetAtPoint(point));
360 if (pFocusAnnot && pFocusAnnot != pFXAnnot) {
370 ObservedPtr<
CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
372 m_pFormFillEnv->KillFocusAnnot(nFlags);
382 m_pFormFillEnv->SetFocusAnnot(pAnnot);
388 ObservedPtr<
CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
397 m_pFormFillEnv->SetFocusAnnot(pAnnot);
404 ObservedPtr<
CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
413 m_pFormFillEnv->SetFocusAnnot(pAnnot);
420 ObservedPtr<
CPDFSDK_Annot> pFXAnnot(GetFXAnnotAtPoint(point));
421 ObservedPtr<CPDFSDK_PageView> pThis(
this);
423 if (pThis->m_bOnWidget && pThis->m_pCaptureWidget != pFXAnnot) {
424 pThis->ExitWidget(
true, nFlags);
428 if (!pThis || !pFXAnnot)
431 if (!pThis->m_bOnWidget) {
432 pThis->EnterWidget(pFXAnnot, nFlags);
439 pThis->ExitWidget(
false, nFlags);
447void CPDFSDK_PageView::EnterWidget(ObservedPtr<
CPDFSDK_Annot>& pAnnot,
448 Mask<FWL_EVENTFLAG> nFlags) {
450 m_pCaptureWidget = pAnnot;
451 CPDFSDK_Annot::OnMouseEnter(m_pCaptureWidget, nFlags);
454void CPDFSDK_PageView::ExitWidget(
bool callExitCallback,
455 Mask<FWL_EVENTFLAG> nFlags) {
456 ObservedPtr<CPDFSDK_PageView> pThis(
this);
457 pThis->m_bOnWidget =
false;
458 if (!pThis->m_pCaptureWidget) {
462 if (callExitCallback) {
470 pThis->m_pCaptureWidget.Reset();
476 ObservedPtr<
CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
493bool CPDFSDK_PageView::
OnChar(uint32_t nChar,
Mask<FWL_EVENTFLAG> nFlags) {
499 Mask<FWL_EVENTFLAG> nFlags) {
510 ObservedPtr<
CPDFSDK_Annot> end_annot(CPWL_Wnd::IsSHIFTKeyDown(nFlags)
511 ? GetLastFocusableAnnot()
512 : GetFirstFocusableAnnot());
513 return end_annot && m_pFormFillEnv->SetFocusAnnot(end_annot);
521 ObservedPtr<
CPDFSDK_Annot> pNext(CPWL_Wnd::IsSHIFTKeyDown(nFlags)
522 ? GetPrevAnnot(pFocusAnnot)
523 : GetNextAnnot(pFocusAnnot));
526 if (pNext.Get() != pFocusAnnot) {
544 RetainPtr<CPDFXFA_Page> protector(ToXFAPage(m_page));
545 CPDF_Document::Extension* pContext = m_pFormFillEnv->GetDocExtension();
546 if (pContext && pContext->ContainsExtensionFullForm()) {
547 CXFA_FFPageView* pageView = protector->GetXFAPageView();
548 CXFA_FFPageWidgetIterator pWidgetHandler(
549 pageView, Mask<XFA_WidgetStatus>{XFA_WidgetStatus::kVisible,
550 XFA_WidgetStatus::kViewable});
552 while (CXFA_FFWidget* pXFAAnnot = pWidgetHandler.MoveToNext()) {
553 m_SDKAnnotArray.push_back(
554 std::make_unique<CPDFXFA_Widget>(pXFAAnnot,
this));
555 m_SDKAnnotArray.back()->OnLoad();
566 m_pAnnotList = std::make_unique<CPDF_AnnotList>(pPage);
569 const size_t nCount = m_pAnnotList->Count();
570 for (size_t i = 0; i < nCount; ++i) {
571 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
573 std::unique_ptr<CPDFSDK_Annot> pAnnot = NewAnnot(pPDFAnnot);
576 m_SDKAnnotArray.push_back(std::move(pAnnot));
577 m_SDKAnnotArray.back()->OnLoad();
581void CPDFSDK_PageView::
UpdateRects(
const std::vector<CFX_FloatRect>& rects) {
582 for (
const auto& rc : rects)
583 m_pFormFillEnv->Invalidate(m_page, rc.GetOuterRect());
588 m_pFormFillEnv->Invalidate(m_page, rcWindow.GetOuterRect());
593 CPDF_Document::Extension* pContext = m_page->GetDocument()->GetExtension();
594 if (pContext && pContext->ContainsExtensionFullForm()) {
595 CXFA_FFPageView* pPageView = m_page->AsXFAPage()->GetXFAPageView();
596 return pPageView ? pPageView->GetLayoutItem()->GetPageIndex() : -1;
599 return GetPageIndexForStaticPDF();
603 return p && m_pAnnotList->Contains(p);
607 return p && pdfium::Contains(m_SDKAnnotArray, fxcrt::MakeFakeUniquePtr(p));
611 CPDFSDK_Annot* pFocusAnnot = m_pFormFillEnv->GetFocusAnnot();
615int CPDFSDK_PageView::GetPageIndexForStaticPDF()
const {
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CPDFSDK_AnnotIteration(CPDFSDK_PageView *page_view)
static CPDFSDK_AnnotIteration CreateForDrawing(CPDFSDK_PageView *page_view)
CPDFSDK_Annot * GetFirstAnnot()
CPDFSDK_Annot * GetLastAnnot()
CPDFSDK_Annot * GetNextAnnot(CPDFSDK_Annot *pAnnot)
CPDFSDK_Annot * GetPrevAnnot(CPDFSDK_Annot *pAnnot)
virtual bool SetIndexSelected(int index, bool selected)=0
virtual bool IsIndexSelected(int index)=0
static bool OnRButtonUp(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
static bool OnKeyDown(ObservedPtr< CPDFSDK_Annot > &pAnnot, FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlags)
virtual void ReplaceSelection(const WideString &text)=0
static bool OnRButtonDown(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
virtual WideString GetText()=0
static bool OnMouseMove(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
virtual CFX_FloatRect GetRect() const =0
static bool OnLButtonUp(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
static bool OnMouseWheel(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point, const CFX_Vector &delta)
virtual WideString GetSelectedText()=0
virtual bool SelectAllText()=0
static bool OnChar(ObservedPtr< CPDFSDK_Annot > &pAnnot, uint32_t nChar, Mask< FWL_EVENTFLAG > nFlags)
virtual void ReplaceAndKeepSelection(const WideString &text)=0
static bool OnLButtonDblClk(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
static void OnMouseExit(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags)
static bool OnLButtonDown(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
CPDFSDK_Annot * GetFocusAnnot()
bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlags)
CPDF_Document * GetPDFDocument()
std::vector< CPDFSDK_Annot * > GetAnnotList() const
bool OnMouseMove(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
CPDFSDK_Annot * GetNextAnnot(CPDFSDK_Annot *pAnnot)
CPDFSDK_Annot * GetPrevAnnot(CPDFSDK_Annot *pAnnot)
void ReplaceSelection(const WideString &text)
bool OnFocus(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
CPDFSDK_Annot * GetLastFocusableAnnot()
bool IsValidSDKAnnot(const CPDFSDK_Annot *p) const
bool IsBeingDestroyed() const
CPDFSDK_PageView(CPDFSDK_FormFillEnvironment *pFormFillEnv, IPDF_Page *page)
void PageView_OnDraw(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device, CPDF_RenderOptions *pOptions, const FX_RECT &pClip)
bool OnRButtonUp(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
void ClearPage(CPDF_Page *pPage) override
bool OnLButtonDblClk(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
CPDFSDK_FormFillEnvironment * GetFormFillEnv() const
void UpdateRects(const std::vector< CFX_FloatRect > &rects)
CPDF_Page * GetPDFPage() const
void UpdateView(CPDFSDK_Annot *pAnnot)
bool OnRButtonDown(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
WideString GetFocusedFormText()
CPDFSDK_Annot * GetAnnotByDict(const CPDF_Dictionary *pDict)
WideString GetSelectedText()
void ReplaceAndKeepSelection(const WideString &text)
bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
bool IsIndexSelected(int index)
bool OnMouseWheel(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point, const CFX_Vector &delta)
bool IsValidAnnot(const CPDF_Annot *p) const
bool SetIndexSelected(int index, bool selected)
CPDFSDK_Annot * GetFirstFocusableAnnot()
bool OnChar(uint32_t nChar, Mask< FWL_EVENTFLAG > nFlags)
Subtype GetSubtype() const
const CPDF_Dictionary * GetAnnotDict() const
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
int GetPageIndex(uint32_t objnum)
void SetView(View *pView)
static bool IsCTRLKeyDown(Mask< FWL_EVENTFLAG > nFlag)
static bool IsALTKeyDown(Mask< FWL_EVENTFLAG > nFlag)
virtual CPDFXFA_Page * AsXFAPage()=0
void CheckForUnsupportedAnnot(const CPDF_Annot *pAnnot)
CFX_VTemplate< int32_t > CFX_Vector
CFX_PTemplate< float > CFX_PointF
CPDF_Page * ToPDFPage(IPDF_Page *pBase)
fxcrt::WideString WideString