blob: 37d5274bab70e2d423cdc1a83a93044a97d35973 [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"
19#include "fpdfsdk/cpdfsdk_widgethandler.h"
Tom Sepezfe91c6c2017-05-16 15:33:20 -070020#include "third_party/base/ptr_util.h"
jaepark98e10192016-08-15 10:51:11 -070021
22#ifdef PDF_ENABLE_XFA
dsinclair114e46a2016-09-29 17:18:21 -070023#include "fpdfsdk/cpdfsdk_xfawidgethandler.h"
dsinclair4d29e782016-10-04 14:02:47 -070024#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040025#include "xfa/fxfa/cxfa_ffpageview.h"
26#include "xfa/fxfa/cxfa_ffwidget.h"
jaepark98e10192016-08-15 10:51:11 -070027#endif // PDF_ENABLE_XFA
28
dsinclair735606d2016-10-05 15:47:02 -070029CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(
dsinclair8779fa82016-10-12 12:05:44 -070030 CPDFSDK_FormFillEnvironment* pFormFillEnv)
Tom Sepezfe91c6c2017-05-16 15:33:20 -070031 : m_pBAAnnotHandler(pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>()),
Lei Zhang60fa2fc2017-07-21 17:42:19 -070032 m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv))
jaepark98e10192016-08-15 10:51:11 -070033#ifdef PDF_ENABLE_XFA
Lei Zhang60fa2fc2017-07-21 17:42:19 -070034 ,
Tom Sepezfe91c6c2017-05-16 15:33:20 -070035 m_pXFAWidgetHandler(
Lei Zhang60fa2fc2017-07-21 17:42:19 -070036 pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv))
jaepark98e10192016-08-15 10:51:11 -070037#endif // PDF_ENABLE_XFA
Lei Zhang60fa2fc2017-07-21 17:42:19 -070038{
jaepark98e10192016-08-15 10:51:11 -070039}
40
41CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {}
42
jaepark98e10192016-08-15 10:51:11 -070043CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
44 CPDFSDK_PageView* pPageView) {
45 ASSERT(pPageView);
jaepark35512aa2016-08-29 17:15:08 -070046 return GetAnnotHandler(pAnnot->GetSubtype())->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070047}
48
49#ifdef PDF_ENABLE_XFA
50CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot,
51 CPDFSDK_PageView* pPageView) {
52 ASSERT(pAnnot);
53 ASSERT(pPageView);
54
jaepark956553e2016-08-31 06:49:27 -070055 return GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET)
56 ->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070057}
58#endif // PDF_ENABLE_XFA
59
60void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
jaepark35512aa2016-08-29 17:15:08 -070061 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070062 pAnnotHandler->ReleaseAnnot(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070063}
64
65void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
66 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
67
68 CPDFSDK_DateTime curTime;
tsepez0e606b52016-11-18 16:22:41 -080069 pPDFAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
70 "M", curTime.ToPDFDateTimeString(), false);
71 pPDFAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F", 0);
jaepark98e10192016-08-15 10:51:11 -070072}
73
74void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
75 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070076 GetAnnotHandler(pAnnot)->OnLoad(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070077}
78
Lei Zhanga4c7ac42018-04-17 15:12:58 +000079WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) {
80 return GetAnnotHandler(pAnnot)->GetText(pAnnot);
81}
82
Ryan Harrison275e2602017-09-18 14:23:18 -040083WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText(
Diana Gagedce2d722017-06-20 11:17:11 -070084 CPDFSDK_Annot* pAnnot) {
85 return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot);
86}
87
Ryan Harrison275e2602017-09-18 14:23:18 -040088void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot,
89 const WideString& text) {
Diana Gageab390972017-07-28 17:07:39 -070090 GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text);
Diana Gage1c7f1422017-07-24 11:19:52 -070091}
92
Lei Zhangee967722018-04-19 20:55:54 +000093bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) {
94 return GetAnnotHandler(pAnnot)->CanUndo(pAnnot);
95}
96
97bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) {
98 return GetAnnotHandler(pAnnot)->CanRedo(pAnnot);
99}
100
101bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) {
102 return GetAnnotHandler(pAnnot)->Undo(pAnnot);
103}
104
105bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) {
106 return GetAnnotHandler(pAnnot)->Redo(pAnnot);
107}
108
jaepark98e10192016-08-15 10:51:11 -0700109IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
110 CPDFSDK_Annot* pAnnot) const {
jaepark35512aa2016-08-29 17:15:08 -0700111 return GetAnnotHandler(pAnnot->GetAnnotSubtype());
jaepark98e10192016-08-15 10:51:11 -0700112}
113
114IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
jaepark956553e2016-08-31 06:49:27 -0700115 CPDF_Annot::Subtype nAnnotSubtype) const {
116 if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET)
jaepark8c541822016-08-30 13:43:05 -0700117 return m_pWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700118
119#ifdef PDF_ENABLE_XFA
jaepark956553e2016-08-31 06:49:27 -0700120 if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET)
jaepark8c541822016-08-30 13:43:05 -0700121 return m_pXFAWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700122#endif // PDF_ENABLE_XFA
123
124 return m_pBAAnnotHandler.get();
jaepark98e10192016-08-15 10:51:11 -0700125}
126
127void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
128 CPDFSDK_Annot* pAnnot,
129 CFX_RenderDevice* pDevice,
jaepark75f84a52016-09-09 15:39:09 -0700130 CFX_Matrix* pUser2Device,
131 bool bDrawAnnots) {
jaepark98e10192016-08-15 10:51:11 -0700132 ASSERT(pAnnot);
jaepark75f84a52016-09-09 15:39:09 -0700133 GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device,
134 bDrawAnnots);
jaepark98e10192016-08-15 10:51:11 -0700135}
136
tsepez4cf55152016-11-02 14:37:54 -0700137bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700138 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700139 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700140 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500141 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700142 ASSERT(*pAnnot);
143 return GetAnnotHandler(pAnnot->Get())
144 ->OnLButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700145}
146
tsepez4cf55152016-11-02 14:37:54 -0700147bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700148 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700149 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700150 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500151 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700152 ASSERT(*pAnnot);
153 return GetAnnotHandler(pAnnot->Get())
154 ->OnLButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700155}
156
tsepez4cf55152016-11-02 14:37:54 -0700157bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
jaepark98e10192016-08-15 10:51:11 -0700158 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700159 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700160 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500161 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700162 ASSERT(*pAnnot);
163 return GetAnnotHandler(pAnnot->Get())
164 ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700165}
166
tsepez4cf55152016-11-02 14:37:54 -0700167bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
jaepark98e10192016-08-15 10:51:11 -0700168 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700169 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700170 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500171 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700172 ASSERT(*pAnnot);
173 return GetAnnotHandler(pAnnot->Get())
174 ->OnMouseMove(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700175}
176
tsepez4cf55152016-11-02 14:37:54 -0700177bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
jaepark98e10192016-08-15 10:51:11 -0700178 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700179 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700180 uint32_t nFlags,
181 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500182 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700183 ASSERT(*pAnnot);
184 return GetAnnotHandler(pAnnot->Get())
185 ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700186}
187
tsepez4cf55152016-11-02 14:37:54 -0700188bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700189 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700190 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700191 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500192 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700193 ASSERT(*pAnnot);
194 return GetAnnotHandler(pAnnot->Get())
195 ->OnRButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700196}
197
tsepez4cf55152016-11-02 14:37:54 -0700198bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700199 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700200 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700201 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500202 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700203 ASSERT(*pAnnot);
204 return GetAnnotHandler(pAnnot->Get())
205 ->OnRButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700206}
207
tsepezf8074ce2016-09-27 14:29:57 -0700208void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(
209 CPDFSDK_PageView* pPageView,
210 CPDFSDK_Annot::ObservedPtr* pAnnot,
211 uint32_t nFlag) {
212 ASSERT(*pAnnot);
213 GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700214}
215
tsepezf8074ce2016-09-27 14:29:57 -0700216void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(
217 CPDFSDK_PageView* pPageView,
218 CPDFSDK_Annot::ObservedPtr* pAnnot,
219 uint32_t nFlag) {
220 ASSERT(*pAnnot);
221 GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700222}
223
tsepez4cf55152016-11-02 14:37:54 -0700224bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
225 uint32_t nChar,
226 uint32_t nFlags) {
jaepark35512aa2016-08-29 17:15:08 -0700227 return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
jaepark98e10192016-08-15 10:51:11 -0700228}
229
tsepez4cf55152016-11-02 14:37:54 -0700230bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
231 int nKeyCode,
232 int nFlag) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700233 if (CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag) ||
234 CPDFSDK_FormFillEnvironment::IsALTKeyDown(nFlag)) {
jaepark35512aa2016-08-29 17:15:08 -0700235 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
thestig7b3252f2016-11-08 21:30:11 -0800236 }
jaepark98e10192016-08-15 10:51:11 -0700237
jaepark35512aa2016-08-29 17:15:08 -0700238 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
239 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
240 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700241 CPDFSDK_Annot::ObservedPtr pNext(GetNextAnnot(
242 pFocusAnnot, !CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag)));
tsepezf8074ce2016-09-27 14:29:57 -0700243 if (pNext && pNext.Get() != pFocusAnnot) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700244 pPage->GetFormFillEnv()->SetFocusAnnot(&pNext);
tsepez4cf55152016-11-02 14:37:54 -0700245 return true;
jaepark98e10192016-08-15 10:51:11 -0700246 }
247 }
248
thestig7b3252f2016-11-08 21:30:11 -0800249 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700250}
251
tsepez4cf55152016-11-02 14:37:54 -0700252bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
253 int nKeyCode,
254 int nFlag) {
255 return false;
jaepark98e10192016-08-15 10:51:11 -0700256}
257
tsepez4cf55152016-11-02 14:37:54 -0700258bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700259 CPDFSDK_Annot::ObservedPtr* pAnnot,
260 uint32_t nFlag) {
261 ASSERT(*pAnnot);
dsinclairb402b172016-10-11 09:26:32 -0700262 return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700263}
264
tsepez4cf55152016-11-02 14:37:54 -0700265bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700266 CPDFSDK_Annot::ObservedPtr* pAnnot,
267 uint32_t nFlag) {
268 ASSERT(*pAnnot);
269 return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700270}
271
272#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700273bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700274 CPDFSDK_Annot::ObservedPtr* pSetAnnot,
275 CPDFSDK_Annot::ObservedPtr* pKillAnnot) {
tsepez4cf55152016-11-02 14:37:54 -0700276 bool bXFA = (*pSetAnnot && (*pSetAnnot)->GetXFAWidget()) ||
277 (*pKillAnnot && (*pKillAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700278
279 if (bXFA) {
280 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
jaepark956553e2016-08-31 06:49:27 -0700281 GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET))
jaepark98e10192016-08-15 10:51:11 -0700282 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
283 }
284
tsepez4cf55152016-11-02 14:37:54 -0700285 return true;
jaepark98e10192016-08-15 10:51:11 -0700286}
287#endif // PDF_ENABLE_XFA
288
289CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
290 CPDFSDK_PageView* pPageView,
291 CPDFSDK_Annot* pAnnot) {
292 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700293 return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot);
jaepark98e10192016-08-15 10:51:11 -0700294}
295
tsepez4cf55152016-11-02 14:37:54 -0700296bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
297 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500298 const CFX_PointF& point) {
jaepark98e10192016-08-15 10:51:11 -0700299 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700300 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
301 if (pAnnotHandler->CanAnswer(pAnnot))
302 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
303
tsepez4cf55152016-11-02 14:37:54 -0700304 return false;
jaepark98e10192016-08-15 10:51:11 -0700305}
306
307CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
tsepez4cf55152016-11-02 14:37:54 -0700308 bool bNext) {
jaepark98e10192016-08-15 10:51:11 -0700309#ifdef PDF_ENABLE_XFA
310 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
311 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
312 if (!pPage)
313 return nullptr;
314 if (pPage->GetPDFPage()) { // for pdf annots.
Dan Sinclaircbf76e62018-03-28 21:00:35 +0000315 CPDFSDK_AnnotIterator ai(pSDKAnnot->GetPageView(),
316 pSDKAnnot->GetAnnotSubtype());
jaepark98e10192016-08-15 10:51:11 -0700317 CPDFSDK_Annot* pNext =
318 bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
319 return pNext;
320 }
321 // for xfa annots
322 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
323 pPage->GetXFAPageView()->CreateWidgetIterator(
324 XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible |
325 XFA_WidgetStatus_Viewable |
326 XFA_WidgetStatus_Focused));
327 if (!pWidgetIterator)
328 return nullptr;
329 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
330 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
331 CXFA_FFWidget* hNextFocus =
332 bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious();
333 if (!hNextFocus && pSDKAnnot)
334 hNextFocus = pWidgetIterator->MoveToFirst();
335
336 return pPageView->GetAnnotByXFAWidget(hNextFocus);
337#else // PDF_ENABLE_XFA
Dan Sinclaircbf76e62018-03-28 21:00:35 +0000338 CPDFSDK_AnnotIterator ai(pSDKAnnot->GetPageView(),
339 CPDF_Annot::Subtype::WIDGET);
jaepark98e10192016-08-15 10:51:11 -0700340 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
341#endif // PDF_ENABLE_XFA
342}