Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdfsdk_pageview.cpp
Go to the documentation of this file.
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_pageview.h"
8
9#include <memory>
10#include <utility>
11#include <vector>
12
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"
28
29#ifdef PDF_ENABLE_XFA
30#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
31#include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h"
32#include "xfa/fxfa/cxfa_ffpageview.h"
33#endif // PDF_ENABLE_XFA
34
35CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv,
36 IPDF_Page* page)
38 DCHECK(m_page);
39 CPDF_Page* pPDFPage = ToPDFPage(page);
40 if (pPDFPage) {
41 CPDFSDK_InteractiveForm* pForm = pFormFillEnv->GetInteractiveForm();
43 pPDFForm->FixPageFields(pPDFPage);
44 if (!page->AsXFAPage())
45 pPDFPage->SetView(this);
46 }
47}
48
49CPDFSDK_PageView::~CPDFSDK_PageView() {
50 if (!m_page->AsXFAPage()) {
51 // Deleting from `m_SDKAnnotArray` below can cause the page pointed to by
52 // `m_page` to be freed, which will cause issues if we try to cleanup the
53 // pageview pointer in `m_page`. So, reset the pageview pointer before doing
54 // anything else.
55 m_page->AsPDFPage()->SetView(nullptr);
56 }
57
58 // Manually reset elements to ensure they are deleted in order.
59 for (std::unique_ptr<CPDFSDK_Annot>& pAnnot : m_SDKAnnotArray)
60 pAnnot.reset();
61
62 m_SDKAnnotArray.clear();
63 m_pAnnotList.reset();
64}
65
66void CPDFSDK_PageView::ClearPage(CPDF_Page* pPage) {
69}
70
71void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice,
72 const CFX_Matrix& mtUser2Device,
73 CPDF_RenderOptions* pOptions,
74 const FX_RECT& pClip) {
75 m_curMatrix = mtUser2Device;
76
77#ifdef PDF_ENABLE_XFA
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);
84 return;
85 }
86#endif // PDF_ENABLE_XFA
87
88 // for pdf/static xfa.
89 auto annot_iteration = CPDFSDK_AnnotIteration::CreateForDrawing(this);
90 for (const auto& pSDKAnnot : annot_iteration) {
91 pSDKAnnot->OnDraw(pDevice, mtUser2Device, pOptions->GetDrawAnnots());
92 }
93}
94
95std::unique_ptr<CPDFSDK_Annot> CPDFSDK_PageView::NewAnnot(CPDF_Annot* annot) {
96 const CPDF_Annot::Subtype sub_type = annot->GetSubtype();
97 if (sub_type == CPDF_Annot::Subtype::WIDGET) {
98 CPDFSDK_InteractiveForm* form = m_pFormFillEnv->GetInteractiveForm();
100 CPDF_FormControl* form_control =
102 if (!form_control)
103 return nullptr;
104
105 auto ret = std::make_unique<CPDFSDK_Widget>(annot, this, form);
106 form->AddMap(form_control, ret.get());
107 if (pdf_form->NeedConstructAP())
108 ret->ResetAppearance(std::nullopt, CPDFSDK_Widget::kValueUnchanged);
109 return ret;
110 }
111
112#ifdef PDF_ENABLE_XFA
113 if (sub_type == CPDF_Annot::Subtype::XFAWIDGET)
114 return nullptr;
115#endif // PDF_ENABLE_XFA
116
117 return std::make_unique<CPDFSDK_BAAnnot>(annot, this);
118}
119
120CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(const CFX_PointF& point) {
121 CPDFSDK_AnnotIteration annot_iteration(this);
122 for (const auto& pSDKAnnot : annot_iteration) {
123 CFX_FloatRect rc = pSDKAnnot->GetViewBBox();
124 if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP)
125 continue;
126 if (rc.Contains(point))
127 return pSDKAnnot.Get();
128 }
129 return nullptr;
130}
131
132CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(const CFX_PointF& point) {
133 CPDFSDK_AnnotIteration annot_iteration(this);
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;
137#ifdef PDF_ENABLE_XFA
138 do_hit_test = do_hit_test || sub_type == CPDF_Annot::Subtype::XFAWIDGET;
139#endif // PDF_ENABLE_XFA
140 if (do_hit_test && pSDKAnnot->DoHitTest(point))
141 return pSDKAnnot.Get();
142 }
143 return nullptr;
144}
145
146#ifdef PDF_ENABLE_XFA
147CPDFSDK_Annot* CPDFSDK_PageView::AddAnnotForFFWidget(CXFA_FFWidget* pWidget) {
148 CPDFSDK_Annot* pSDKAnnot = GetAnnotForFFWidget(pWidget);
149 if (pSDKAnnot)
150 return pSDKAnnot;
151
152 m_SDKAnnotArray.push_back(std::make_unique<CPDFXFA_Widget>(pWidget, this));
153 return m_SDKAnnotArray.back().get();
154}
155
156void CPDFSDK_PageView::DeleteAnnotForFFWidget(CXFA_FFWidget* pWidget) {
157 ObservedPtr<CPDFSDK_Annot> pAnnot(GetAnnotForFFWidget(pWidget));
158 if (!pAnnot) {
159 return;
160 }
161 IPDF_Page* pPage = pAnnot->GetXFAPage();
162 if (!pPage) {
163 return;
164 }
165 CPDF_Document::Extension* pContext = pPage->GetDocument()->GetExtension();
166 if (pContext && !pContext->ContainsExtensionForm()) {
167 return;
168 }
169 if (GetFocusAnnot() == pAnnot) {
170 // May invoke JS, invalidating pAnnot.
171 m_pFormFillEnv->KillFocusAnnot({});
172 }
173 if (pAnnot) {
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);
178 }
179 if (m_pCaptureWidget.Get() == pAnnot) {
180 m_pCaptureWidget.Reset();
181 }
182}
183
184CPDFXFA_Page* CPDFSDK_PageView::XFAPageIfNotBackedByPDFPage() {
185 auto* pPage = static_cast<CPDFXFA_Page*>(GetXFAPage());
186 return pPage && !pPage->AsPDFPage() ? pPage : nullptr;
187}
188#endif // PDF_ENABLE_XFA
189
190CPDF_Document* CPDFSDK_PageView::GetPDFDocument() {
191 return m_page->GetDocument();
192}
193
194CPDF_Page* CPDFSDK_PageView::GetPDFPage() const {
195 return ToPDFPage(m_page);
196}
197
198CPDFSDK_InteractiveForm* CPDFSDK_PageView::GetInteractiveForm() const {
199 return m_pFormFillEnv->GetInteractiveForm();
200}
201
202std::vector<CPDFSDK_Annot*> CPDFSDK_PageView::GetAnnotList() const {
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());
207 return list;
208}
209
210CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(const CPDF_Dictionary* pDict) {
211 for (std::unique_ptr<CPDFSDK_Annot>& pAnnot : m_SDKAnnotArray) {
212 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
213 if (pPDFAnnot && pPDFAnnot->GetAnnotDict() == pDict)
214 return pAnnot.get();
215 }
216 return nullptr;
217}
218
219#ifdef PDF_ENABLE_XFA
220CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotForFFWidget(CXFA_FFWidget* pWidget) {
221 if (!pWidget)
222 return nullptr;
223
224 for (std::unique_ptr<CPDFSDK_Annot>& pAnnot : m_SDKAnnotArray) {
225 CPDFXFA_Widget* pCurrentWidget = pAnnot->AsXFAWidget();
226 if (pCurrentWidget && pCurrentWidget->GetXFAFFWidget() == pWidget)
227 return pAnnot.get();
228 }
229 return nullptr;
230}
231
232IPDF_Page* CPDFSDK_PageView::GetXFAPage() {
233 return ToXFAPage(m_page);
234}
235#endif // PDF_ENABLE_XFA
236
237WideString CPDFSDK_PageView::GetFocusedFormText() {
239 return annot ? annot->GetText() : WideString();
240}
241
242CPDFSDK_Annot* CPDFSDK_PageView::GetNextAnnot(CPDFSDK_Annot* pAnnot) {
243#ifdef PDF_ENABLE_XFA
244 CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage();
245 if (pXFAPage)
246 return pXFAPage->GetNextXFAAnnot(pAnnot);
247#endif // PDF_ENABLE_XFA
248 CPDFSDK_AnnotIterator ai(this, GetFormFillEnv()->GetFocusableAnnotSubtypes());
249 return ai.GetNextAnnot(pAnnot);
250}
251
252CPDFSDK_Annot* CPDFSDK_PageView::GetPrevAnnot(CPDFSDK_Annot* pAnnot) {
253#ifdef PDF_ENABLE_XFA
254 CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage();
255 if (pXFAPage)
256 return pXFAPage->GetPrevXFAAnnot(pAnnot);
257#endif // PDF_ENABLE_XFA
258 CPDFSDK_AnnotIterator ai(this, GetFormFillEnv()->GetFocusableAnnotSubtypes());
259 return ai.GetPrevAnnot(pAnnot);
260}
261
263#ifdef PDF_ENABLE_XFA
264 CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage();
265 if (pXFAPage)
266 return pXFAPage->GetFirstXFAAnnot(this);
267#endif // PDF_ENABLE_XFA
268 CPDFSDK_AnnotIterator ai(this, GetFormFillEnv()->GetFocusableAnnotSubtypes());
269 return ai.GetFirstAnnot();
270}
271
273#ifdef PDF_ENABLE_XFA
274 CPDFXFA_Page* pXFAPage = XFAPageIfNotBackedByPDFPage();
275 if (pXFAPage)
276 return pXFAPage->GetLastXFAAnnot(this);
277#endif // PDF_ENABLE_XFA
278 CPDFSDK_AnnotIterator ai(this, GetFormFillEnv()->GetFocusableAnnotSubtypes());
279 return ai.GetLastAnnot();
280}
281
282WideString CPDFSDK_PageView::GetSelectedText() {
284 if (!annot)
285 return WideString();
286 return annot->GetSelectedText();
287}
288
289void CPDFSDK_PageView::ReplaceAndKeepSelection(const WideString& text) {
291 if (annot)
293}
294
295void CPDFSDK_PageView::ReplaceSelection(const WideString& text) {
297 if (annot)
298 annot->ReplaceSelection(text);
299}
300
301bool CPDFSDK_PageView::SelectAllText() {
303 return annot && annot->SelectAllText();
304}
305
306bool CPDFSDK_PageView::CanUndo() {
308 return annot && annot->CanUndo();
309}
310
311bool CPDFSDK_PageView::CanRedo() {
313 return annot && annot->CanRedo();
314}
315
316bool CPDFSDK_PageView::Undo() {
318 return annot && annot->Undo();
319}
320
321bool CPDFSDK_PageView::Redo() {
323 return annot && annot->Redo();
324}
325
326bool CPDFSDK_PageView::OnFocus(Mask<FWL_EVENTFLAG> nFlags,
327 const CFX_PointF& point) {
328 ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
329 if (!pAnnot) {
330 m_pFormFillEnv->KillFocusAnnot(nFlags);
331 return false;
332 }
333
334 m_pFormFillEnv->SetFocusAnnot(pAnnot);
335 return true;
336}
337
338bool CPDFSDK_PageView::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
339 const CFX_PointF& point) {
340 ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
341 if (!pAnnot) {
342 m_pFormFillEnv->KillFocusAnnot(nFlags);
343 return false;
344 }
345
346 if (!CPDFSDK_Annot::OnLButtonDown(pAnnot, nFlags, point))
347 return false;
348
349 if (!pAnnot)
350 return false;
351
352 m_pFormFillEnv->SetFocusAnnot(pAnnot);
353 return true;
354}
355
356bool CPDFSDK_PageView::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
357 const CFX_PointF& point) {
358 ObservedPtr<CPDFSDK_Annot> pFXAnnot(GetFXWidgetAtPoint(point));
359 ObservedPtr<CPDFSDK_Annot> pFocusAnnot(GetFocusAnnot());
360 if (pFocusAnnot && pFocusAnnot != pFXAnnot) {
361 // Last focus Annot gets a chance to handle the event.
362 if (CPDFSDK_Annot::OnLButtonUp(pFocusAnnot, nFlags, point))
363 return true;
364 }
365 return pFXAnnot && CPDFSDK_Annot::OnLButtonUp(pFXAnnot, nFlags, point);
366}
367
368bool CPDFSDK_PageView::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
369 const CFX_PointF& point) {
370 ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
371 if (!pAnnot) {
372 m_pFormFillEnv->KillFocusAnnot(nFlags);
373 return false;
374 }
375
376 if (!CPDFSDK_Annot::OnLButtonDblClk(pAnnot, nFlags, point))
377 return false;
378
379 if (!pAnnot)
380 return false;
381
382 m_pFormFillEnv->SetFocusAnnot(pAnnot);
383 return true;
384}
385
386bool CPDFSDK_PageView::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
387 const CFX_PointF& point) {
388 ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
389 if (!pAnnot)
390 return false;
391
392 bool ok = CPDFSDK_Annot::OnRButtonDown(pAnnot, nFlags, point);
393 if (!pAnnot)
394 return false;
395
396 if (ok)
397 m_pFormFillEnv->SetFocusAnnot(pAnnot);
398
399 return true;
400}
401
402bool CPDFSDK_PageView::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
403 const CFX_PointF& point) {
404 ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
405 if (!pAnnot)
406 return false;
407
408 bool ok = CPDFSDK_Annot::OnRButtonUp(pAnnot, nFlags, point);
409 if (!pAnnot)
410 return false;
411
412 if (ok)
413 m_pFormFillEnv->SetFocusAnnot(pAnnot);
414
415 return true;
416}
417
418bool CPDFSDK_PageView::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
419 const CFX_PointF& point) {
420 ObservedPtr<CPDFSDK_Annot> pFXAnnot(GetFXAnnotAtPoint(point));
421 ObservedPtr<CPDFSDK_PageView> pThis(this);
422
423 if (pThis->m_bOnWidget && pThis->m_pCaptureWidget != pFXAnnot) {
424 pThis->ExitWidget(true, nFlags);
425 }
426
427 // ExitWidget() may have invalidated objects.
428 if (!pThis || !pFXAnnot)
429 return false;
430
431 if (!pThis->m_bOnWidget) {
432 pThis->EnterWidget(pFXAnnot, nFlags);
433
434 // EnterWidget() may have invalidated objects.
435 if (!pThis)
436 return false;
437
438 if (!pFXAnnot) {
439 pThis->ExitWidget(false, nFlags);
440 return true;
441 }
442 }
443 CPDFSDK_Annot::OnMouseMove(pFXAnnot, nFlags, point);
444 return true;
445}
446
447void CPDFSDK_PageView::EnterWidget(ObservedPtr<CPDFSDK_Annot>& pAnnot,
448 Mask<FWL_EVENTFLAG> nFlags) {
449 m_bOnWidget = true;
450 m_pCaptureWidget = pAnnot;
451 CPDFSDK_Annot::OnMouseEnter(m_pCaptureWidget, nFlags);
452}
453
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) {
459 return;
460 }
461
462 if (callExitCallback) {
463 CPDFSDK_Annot::OnMouseExit(pThis->m_pCaptureWidget, nFlags);
464
465 // OnMouseExit() may have invalidated |this|.
466 if (!pThis) {
467 return;
468 }
469 }
470 pThis->m_pCaptureWidget.Reset();
471}
472
473bool CPDFSDK_PageView::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
474 const CFX_PointF& point,
475 const CFX_Vector& delta) {
476 ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
477 if (!pAnnot)
478 return false;
479
480 return CPDFSDK_Annot::OnMouseWheel(pAnnot, nFlags, point, delta);
481}
482
483bool CPDFSDK_PageView::SetIndexSelected(int index, bool selected) {
485 return annot && annot->SetIndexSelected(index, selected);
486}
487
488bool CPDFSDK_PageView::IsIndexSelected(int index) {
490 return annot && annot->IsIndexSelected(index);
491}
492
493bool CPDFSDK_PageView::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
494 ObservedPtr<CPDFSDK_Annot> pAnnot(GetFocusAnnot());
495 return pAnnot && CPDFSDK_Annot::OnChar(pAnnot, nChar, nFlags);
496}
497
498bool CPDFSDK_PageView::OnKeyDown(FWL_VKEYCODE nKeyCode,
499 Mask<FWL_EVENTFLAG> nFlags) {
500 ObservedPtr<CPDFSDK_Annot> pAnnot(GetFocusAnnot());
501 if (!pAnnot) {
502 // If pressed key is not tab then no action is needed.
503 if (nKeyCode != FWL_VKEY_Tab)
504 return false;
505
506 // If ctrl key or alt key is pressed, then no action is needed.
508 return false;
509
510 ObservedPtr<CPDFSDK_Annot> end_annot(CPWL_Wnd::IsSHIFTKeyDown(nFlags)
511 ? GetLastFocusableAnnot()
512 : GetFirstFocusableAnnot());
513 return end_annot && m_pFormFillEnv->SetFocusAnnot(end_annot);
514 }
515
517 return CPDFSDK_Annot::OnKeyDown(pAnnot, nKeyCode, nFlags);
518
519 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
520 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
521 ObservedPtr<CPDFSDK_Annot> pNext(CPWL_Wnd::IsSHIFTKeyDown(nFlags)
522 ? GetPrevAnnot(pFocusAnnot)
523 : GetNextAnnot(pFocusAnnot));
524 if (!pNext)
525 return false;
526 if (pNext.Get() != pFocusAnnot) {
528 return true;
529 }
530 }
531
532 // Check |pAnnot| again because JS may have destroyed it in GetNextAnnot().
533 if (!pAnnot)
534 return false;
535
536 return CPDFSDK_Annot::OnKeyDown(pAnnot, nKeyCode, nFlags);
537}
538
539void CPDFSDK_PageView::LoadFXAnnots() {
540 AutoRestorer<bool> lock(&m_bLocked);
541 m_bLocked = true;
542
543#ifdef PDF_ENABLE_XFA
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});
551
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();
556 }
557 return;
558 }
559#endif // PDF_ENABLE_XFA
560
561 CPDF_Page* pPage = GetPDFPage();
562 DCHECK(pPage);
564 // Disable the default AP construction.
566 m_pAnnotList = std::make_unique<CPDF_AnnotList>(pPage);
568
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);
574 if (!pAnnot)
575 continue;
576 m_SDKAnnotArray.push_back(std::move(pAnnot));
577 m_SDKAnnotArray.back()->OnLoad();
578 }
579}
580
581void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) {
582 for (const auto& rc : rects)
583 m_pFormFillEnv->Invalidate(m_page, rc.GetOuterRect());
584}
585
586void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) {
587 CFX_FloatRect rcWindow = pAnnot->GetRect();
588 m_pFormFillEnv->Invalidate(m_page, rcWindow.GetOuterRect());
589}
590
591int CPDFSDK_PageView::GetPageIndex() const {
592#ifdef PDF_ENABLE_XFA
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;
597 }
598#endif // PDF_ENABLE_XFA
599 return GetPageIndexForStaticPDF();
600}
601
602bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const {
603 return p && m_pAnnotList->Contains(p);
604}
605
606bool CPDFSDK_PageView::IsValidSDKAnnot(const CPDFSDK_Annot* p) const {
607 return p && pdfium::Contains(m_SDKAnnotArray, fxcrt::MakeFakeUniquePtr(p));
608}
609
610CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() {
611 CPDFSDK_Annot* pFocusAnnot = m_pFormFillEnv->GetFocusAnnot();
612 return IsValidSDKAnnot(pFocusAnnot) ? pFocusAnnot : nullptr;
613}
614
615int CPDFSDK_PageView::GetPageIndexForStaticPDF() const {
616 CPDF_Document* pDoc = m_pFormFillEnv->GetPDFDocument();
617 return pDoc->GetPageIndex(GetPDFPage()->GetDict()->GetObjNum());
618}
#define DCHECK
Definition check.h:33
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CPDFSDK_AnnotIteration(CPDFSDK_PageView *page_view)
static CPDFSDK_AnnotIteration CreateForDrawing(CPDFSDK_PageView *page_view)
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
virtual bool Redo()=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 bool CanUndo()=0
virtual WideString GetText()=0
static bool OnMouseMove(ObservedPtr< CPDFSDK_Annot > &pAnnot, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point)
virtual bool CanRedo()=0
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)
virtual bool Undo()=0
CPDFSDK_InteractiveForm * GetInteractiveForm()
void RemovePageView(IPDF_Page *pUnderlyingPage)
bool SetFocusAnnot(ObservedPtr< CPDFSDK_Annot > &pAnnot) override
void AddMap(CPDF_FormControl *pControl, CPDFSDK_Widget *pWidget)
CPDF_InteractiveForm * GetInteractiveForm() const
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
Definition cpdf_annot.h:83
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
int GetPageIndex(uint32_t objnum)
static void SetUpdateAP(bool bUpdateAP)
CPDF_FormControl * GetControlByDict(const CPDF_Dictionary *pWidgetDict) const
void FixPageFields(CPDF_Page *pPage)
void SetView(View *pView)
Definition cpdf_page.h:92
static bool IsCTRLKeyDown(Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:128
static bool IsALTKeyDown(Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:133
virtual CPDFXFA_Page * AsXFAPage()=0
WideString()=default
void CheckForUnsupportedAnnot(const CPDF_Annot *pAnnot)
@ FWL_VKEY_Tab
CFX_VTemplate< int32_t > CFX_Vector
CFX_PTemplate< float > CFX_PointF
CPDF_Page * ToPDFPage(IPDF_Page *pBase)
Definition ipdf_page.h:50
fxcrt::WideString WideString
Definition widestring.h:207