blob: 15ebfaacb4ddebf94196dc5f5a6be4250d38641c [file] [log] [blame]
jaepark98e10192016-08-15 10:51:11 -07001// Copyright 2016 PDFium Authors. All rights reserved.
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
dsinclair114e46a2016-09-29 17:18:21 -07007#include "fpdfsdk/cpdfsdk_annothandlermgr.h"
jaepark98e10192016-08-15 10:51:11 -07008
tsepez0e606b52016-11-18 16:22:41 -08009#include "core/fpdfapi/parser/cpdf_number.h"
10#include "core/fpdfapi/parser/cpdf_string.h"
dsinclair1727aee2016-09-29 13:12:56 -070011#include "core/fpdfdoc/cpdf_annot.h"
dsinclair114e46a2016-09-29 17:18:21 -070012#include "fpdfsdk/cpdfsdk_annot.h"
Dan Sinclaircbf76e62018-03-28 21:00:35 +000013#include "fpdfsdk/cpdfsdk_annotiterator.h"
dsinclair114e46a2016-09-29 17:18:21 -070014#include "fpdfsdk/cpdfsdk_baannot.h"
15#include "fpdfsdk/cpdfsdk_baannothandler.h"
16#include "fpdfsdk/cpdfsdk_datetime.h"
dsinclair735606d2016-10-05 15:47:02 -070017#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070018#include "fpdfsdk/cpdfsdk_pageview.h"
Tom Sepez11a6bec2018-07-25 23:25:55 +000019#include "fpdfsdk/cpdfsdk_widget.h"
dsinclair114e46a2016-09-29 17:18:21 -070020#include "fpdfsdk/cpdfsdk_widgethandler.h"
Tom Sepezfe91c6c2017-05-16 15:33:20 -070021#include "third_party/base/ptr_util.h"
jaepark98e10192016-08-15 10:51:11 -070022
23#ifdef PDF_ENABLE_XFA
dsinclair114e46a2016-09-29 17:18:21 -070024#include "fpdfsdk/cpdfsdk_xfawidgethandler.h"
dsinclair4d29e782016-10-04 14:02:47 -070025#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040026#include "xfa/fxfa/cxfa_ffpageview.h"
27#include "xfa/fxfa/cxfa_ffwidget.h"
jaepark98e10192016-08-15 10:51:11 -070028#endif // PDF_ENABLE_XFA
29
dsinclair735606d2016-10-05 15:47:02 -070030CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(
dsinclair8779fa82016-10-12 12:05:44 -070031 CPDFSDK_FormFillEnvironment* pFormFillEnv)
Tom Sepezfe91c6c2017-05-16 15:33:20 -070032 : m_pBAAnnotHandler(pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>()),
Lei Zhang60fa2fc2017-07-21 17:42:19 -070033 m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv))
jaepark98e10192016-08-15 10:51:11 -070034#ifdef PDF_ENABLE_XFA
Lei Zhang60fa2fc2017-07-21 17:42:19 -070035 ,
Tom Sepezfe91c6c2017-05-16 15:33:20 -070036 m_pXFAWidgetHandler(
Lei Zhang60fa2fc2017-07-21 17:42:19 -070037 pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv))
jaepark98e10192016-08-15 10:51:11 -070038#endif // PDF_ENABLE_XFA
Lei Zhang60fa2fc2017-07-21 17:42:19 -070039{
jaepark98e10192016-08-15 10:51:11 -070040}
41
42CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {}
43
jaepark98e10192016-08-15 10:51:11 -070044CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
45 CPDFSDK_PageView* pPageView) {
46 ASSERT(pPageView);
jaepark35512aa2016-08-29 17:15:08 -070047 return GetAnnotHandler(pAnnot->GetSubtype())->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070048}
49
50#ifdef PDF_ENABLE_XFA
51CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot,
52 CPDFSDK_PageView* pPageView) {
53 ASSERT(pAnnot);
54 ASSERT(pPageView);
55
jaepark956553e2016-08-31 06:49:27 -070056 return GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET)
57 ->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070058}
59#endif // PDF_ENABLE_XFA
60
61void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
jaepark35512aa2016-08-29 17:15:08 -070062 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070063 pAnnotHandler->ReleaseAnnot(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070064}
65
66void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
67 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
68
69 CPDFSDK_DateTime curTime;
tsepez0e606b52016-11-18 16:22:41 -080070 pPDFAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
71 "M", curTime.ToPDFDateTimeString(), false);
72 pPDFAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F", 0);
jaepark98e10192016-08-15 10:51:11 -070073}
74
75void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
76 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070077 GetAnnotHandler(pAnnot)->OnLoad(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070078}
79
Lei Zhanga4c7ac42018-04-17 15:12:58 +000080WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) {
81 return GetAnnotHandler(pAnnot)->GetText(pAnnot);
82}
83
Ryan Harrison275e2602017-09-18 14:23:18 -040084WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText(
Diana Gagedce2d722017-06-20 11:17:11 -070085 CPDFSDK_Annot* pAnnot) {
86 return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot);
87}
88
Ryan Harrison275e2602017-09-18 14:23:18 -040089void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot,
90 const WideString& text) {
Diana Gageab390972017-07-28 17:07:39 -070091 GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text);
Diana Gage1c7f1422017-07-24 11:19:52 -070092}
93
Lei Zhangee967722018-04-19 20:55:54 +000094bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) {
95 return GetAnnotHandler(pAnnot)->CanUndo(pAnnot);
96}
97
98bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) {
99 return GetAnnotHandler(pAnnot)->CanRedo(pAnnot);
100}
101
102bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) {
103 return GetAnnotHandler(pAnnot)->Undo(pAnnot);
104}
105
106bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) {
107 return GetAnnotHandler(pAnnot)->Redo(pAnnot);
108}
109
jaepark98e10192016-08-15 10:51:11 -0700110IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
111 CPDFSDK_Annot* pAnnot) const {
jaepark35512aa2016-08-29 17:15:08 -0700112 return GetAnnotHandler(pAnnot->GetAnnotSubtype());
jaepark98e10192016-08-15 10:51:11 -0700113}
114
115IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
jaepark956553e2016-08-31 06:49:27 -0700116 CPDF_Annot::Subtype nAnnotSubtype) const {
117 if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET)
jaepark8c541822016-08-30 13:43:05 -0700118 return m_pWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700119
120#ifdef PDF_ENABLE_XFA
jaepark956553e2016-08-31 06:49:27 -0700121 if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET)
jaepark8c541822016-08-30 13:43:05 -0700122 return m_pXFAWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700123#endif // PDF_ENABLE_XFA
124
125 return m_pBAAnnotHandler.get();
jaepark98e10192016-08-15 10:51:11 -0700126}
127
128void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
129 CPDFSDK_Annot* pAnnot,
130 CFX_RenderDevice* pDevice,
jaepark75f84a52016-09-09 15:39:09 -0700131 CFX_Matrix* pUser2Device,
132 bool bDrawAnnots) {
jaepark98e10192016-08-15 10:51:11 -0700133 ASSERT(pAnnot);
jaepark75f84a52016-09-09 15:39:09 -0700134 GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device,
135 bDrawAnnots);
jaepark98e10192016-08-15 10:51:11 -0700136}
137
tsepez4cf55152016-11-02 14:37:54 -0700138bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700139 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700140 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700141 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500142 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700143 ASSERT(*pAnnot);
144 return GetAnnotHandler(pAnnot->Get())
145 ->OnLButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700146}
147
tsepez4cf55152016-11-02 14:37:54 -0700148bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700149 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700150 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700151 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500152 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700153 ASSERT(*pAnnot);
154 return GetAnnotHandler(pAnnot->Get())
155 ->OnLButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700156}
157
tsepez4cf55152016-11-02 14:37:54 -0700158bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
jaepark98e10192016-08-15 10:51:11 -0700159 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700160 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700161 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500162 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700163 ASSERT(*pAnnot);
164 return GetAnnotHandler(pAnnot->Get())
165 ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700166}
167
tsepez4cf55152016-11-02 14:37:54 -0700168bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
jaepark98e10192016-08-15 10:51:11 -0700169 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700170 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700171 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500172 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700173 ASSERT(*pAnnot);
174 return GetAnnotHandler(pAnnot->Get())
175 ->OnMouseMove(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700176}
177
tsepez4cf55152016-11-02 14:37:54 -0700178bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
jaepark98e10192016-08-15 10:51:11 -0700179 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700180 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700181 uint32_t nFlags,
182 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500183 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700184 ASSERT(*pAnnot);
185 return GetAnnotHandler(pAnnot->Get())
186 ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700187}
188
tsepez4cf55152016-11-02 14:37:54 -0700189bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700190 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700191 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700192 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500193 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700194 ASSERT(*pAnnot);
195 return GetAnnotHandler(pAnnot->Get())
196 ->OnRButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700197}
198
tsepez4cf55152016-11-02 14:37:54 -0700199bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700200 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700201 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700202 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500203 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700204 ASSERT(*pAnnot);
205 return GetAnnotHandler(pAnnot->Get())
206 ->OnRButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700207}
208
tsepezf8074ce2016-09-27 14:29:57 -0700209void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(
210 CPDFSDK_PageView* pPageView,
211 CPDFSDK_Annot::ObservedPtr* pAnnot,
212 uint32_t nFlag) {
213 ASSERT(*pAnnot);
214 GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700215}
216
tsepezf8074ce2016-09-27 14:29:57 -0700217void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(
218 CPDFSDK_PageView* pPageView,
219 CPDFSDK_Annot::ObservedPtr* pAnnot,
220 uint32_t nFlag) {
221 ASSERT(*pAnnot);
222 GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700223}
224
tsepez4cf55152016-11-02 14:37:54 -0700225bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
226 uint32_t nChar,
227 uint32_t nFlags) {
jaepark35512aa2016-08-29 17:15:08 -0700228 return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
jaepark98e10192016-08-15 10:51:11 -0700229}
230
tsepez4cf55152016-11-02 14:37:54 -0700231bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
232 int nKeyCode,
233 int nFlag) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700234 if (CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag) ||
235 CPDFSDK_FormFillEnvironment::IsALTKeyDown(nFlag)) {
jaepark35512aa2016-08-29 17:15:08 -0700236 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
thestig7b3252f2016-11-08 21:30:11 -0800237 }
jaepark98e10192016-08-15 10:51:11 -0700238
jaepark35512aa2016-08-29 17:15:08 -0700239 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
240 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
241 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700242 CPDFSDK_Annot::ObservedPtr pNext(GetNextAnnot(
243 pFocusAnnot, !CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag)));
tsepezf8074ce2016-09-27 14:29:57 -0700244 if (pNext && pNext.Get() != pFocusAnnot) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700245 pPage->GetFormFillEnv()->SetFocusAnnot(&pNext);
tsepez4cf55152016-11-02 14:37:54 -0700246 return true;
jaepark98e10192016-08-15 10:51:11 -0700247 }
248 }
249
thestig7b3252f2016-11-08 21:30:11 -0800250 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700251}
252
tsepez4cf55152016-11-02 14:37:54 -0700253bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
254 int nKeyCode,
255 int nFlag) {
256 return false;
jaepark98e10192016-08-15 10:51:11 -0700257}
258
tsepez4cf55152016-11-02 14:37:54 -0700259bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700260 CPDFSDK_Annot::ObservedPtr* pAnnot,
261 uint32_t nFlag) {
262 ASSERT(*pAnnot);
dsinclairb402b172016-10-11 09:26:32 -0700263 return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700264}
265
tsepez4cf55152016-11-02 14:37:54 -0700266bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700267 CPDFSDK_Annot::ObservedPtr* pAnnot,
268 uint32_t nFlag) {
269 ASSERT(*pAnnot);
270 return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700271}
272
273#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700274bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700275 CPDFSDK_Annot::ObservedPtr* pSetAnnot,
276 CPDFSDK_Annot::ObservedPtr* pKillAnnot) {
tsepez4cf55152016-11-02 14:37:54 -0700277 bool bXFA = (*pSetAnnot && (*pSetAnnot)->GetXFAWidget()) ||
278 (*pKillAnnot && (*pKillAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700279
280 if (bXFA) {
281 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
jaepark956553e2016-08-31 06:49:27 -0700282 GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET))
jaepark98e10192016-08-15 10:51:11 -0700283 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
284 }
285
tsepez4cf55152016-11-02 14:37:54 -0700286 return true;
jaepark98e10192016-08-15 10:51:11 -0700287}
288#endif // PDF_ENABLE_XFA
289
290CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
291 CPDFSDK_PageView* pPageView,
292 CPDFSDK_Annot* pAnnot) {
293 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700294 return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot);
jaepark98e10192016-08-15 10:51:11 -0700295}
296
tsepez4cf55152016-11-02 14:37:54 -0700297bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
298 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500299 const CFX_PointF& point) {
jaepark98e10192016-08-15 10:51:11 -0700300 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700301 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
302 if (pAnnotHandler->CanAnswer(pAnnot))
303 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
304
tsepez4cf55152016-11-02 14:37:54 -0700305 return false;
jaepark98e10192016-08-15 10:51:11 -0700306}
307
308CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
tsepez4cf55152016-11-02 14:37:54 -0700309 bool bNext) {
jaepark98e10192016-08-15 10:51:11 -0700310#ifdef PDF_ENABLE_XFA
311 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
312 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
Tom Sepez8e631772018-06-13 21:26:56 +0000313 if (pPage && !pPage->AsPDFPage()) {
314 // For xfa annots in XFA pages not backed by PDF pages.
315 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
316 pPage->GetXFAPageView()->CreateWidgetIterator(
317 XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible |
318 XFA_WidgetStatus_Viewable |
319 XFA_WidgetStatus_Focused));
320 if (!pWidgetIterator)
321 return nullptr;
322 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
323 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
324 CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext()
325 : pWidgetIterator->MoveToPrevious();
326 if (!hNextFocus && pSDKAnnot)
327 hNextFocus = pWidgetIterator->MoveToFirst();
jaepark98e10192016-08-15 10:51:11 -0700328
Tom Sepez8e631772018-06-13 21:26:56 +0000329 return pPageView->GetAnnotByXFAWidget(hNextFocus);
330 }
jaepark98e10192016-08-15 10:51:11 -0700331#endif // PDF_ENABLE_XFA
Tom Sepez8e631772018-06-13 21:26:56 +0000332
333 // For PDF annots.
Tom Sepez11a6bec2018-07-25 23:25:55 +0000334 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot);
335 CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype());
336 return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget);
jaepark98e10192016-08-15 10:51:11 -0700337}