blob: 7d253c8709e88dbb7eb56f8721346ec1751a3191 [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"
dsinclair735606d2016-10-05 15:47:02 -070016#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070017#include "fpdfsdk/cpdfsdk_pageview.h"
Tom Sepez11a6bec2018-07-25 23:25:55 +000018#include "fpdfsdk/cpdfsdk_widget.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#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
jaepark98e10192016-08-15 10:51:11 -070065void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
66 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070067 GetAnnotHandler(pAnnot)->OnLoad(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070068}
69
Lei Zhanga4c7ac42018-04-17 15:12:58 +000070WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) {
71 return GetAnnotHandler(pAnnot)->GetText(pAnnot);
72}
73
Ryan Harrison275e2602017-09-18 14:23:18 -040074WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText(
Diana Gagedce2d722017-06-20 11:17:11 -070075 CPDFSDK_Annot* pAnnot) {
76 return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot);
77}
78
Ryan Harrison275e2602017-09-18 14:23:18 -040079void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot,
80 const WideString& text) {
Diana Gageab390972017-07-28 17:07:39 -070081 GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text);
Diana Gage1c7f1422017-07-24 11:19:52 -070082}
83
Lei Zhangee967722018-04-19 20:55:54 +000084bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) {
85 return GetAnnotHandler(pAnnot)->CanUndo(pAnnot);
86}
87
88bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) {
89 return GetAnnotHandler(pAnnot)->CanRedo(pAnnot);
90}
91
92bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) {
93 return GetAnnotHandler(pAnnot)->Undo(pAnnot);
94}
95
96bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) {
97 return GetAnnotHandler(pAnnot)->Redo(pAnnot);
98}
99
jaepark98e10192016-08-15 10:51:11 -0700100IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
101 CPDFSDK_Annot* pAnnot) const {
jaepark35512aa2016-08-29 17:15:08 -0700102 return GetAnnotHandler(pAnnot->GetAnnotSubtype());
jaepark98e10192016-08-15 10:51:11 -0700103}
104
105IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
jaepark956553e2016-08-31 06:49:27 -0700106 CPDF_Annot::Subtype nAnnotSubtype) const {
107 if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET)
jaepark8c541822016-08-30 13:43:05 -0700108 return m_pWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700109
110#ifdef PDF_ENABLE_XFA
jaepark956553e2016-08-31 06:49:27 -0700111 if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET)
jaepark8c541822016-08-30 13:43:05 -0700112 return m_pXFAWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700113#endif // PDF_ENABLE_XFA
114
115 return m_pBAAnnotHandler.get();
jaepark98e10192016-08-15 10:51:11 -0700116}
117
118void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
119 CPDFSDK_Annot* pAnnot,
120 CFX_RenderDevice* pDevice,
Lei Zhang09ee0872018-10-09 19:13:55 +0000121 const CFX_Matrix& mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700122 bool bDrawAnnots) {
jaepark98e10192016-08-15 10:51:11 -0700123 ASSERT(pAnnot);
Lei Zhang09ee0872018-10-09 19:13:55 +0000124 GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700125 bDrawAnnots);
jaepark98e10192016-08-15 10:51:11 -0700126}
127
tsepez4cf55152016-11-02 14:37:54 -0700128bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700129 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700130 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700131 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500132 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000133 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700134 return GetAnnotHandler(pAnnot->Get())
135 ->OnLButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700136}
137
tsepez4cf55152016-11-02 14:37:54 -0700138bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
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) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000143 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700144 return GetAnnotHandler(pAnnot->Get())
145 ->OnLButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700146}
147
Lei Zhanga37989f2018-10-17 20:32:41 +0000148bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
149 CPDFSDK_PageView* pPageView,
150 CPDFSDK_Annot::ObservedPtr* pAnnot,
151 uint32_t nFlags,
152 const CFX_PointF& point) {
153 ASSERT(pAnnot->HasObservable());
154 return GetAnnotHandler(pAnnot->Get())
155 ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
156}
157
tsepez4cf55152016-11-02 14:37:54 -0700158bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
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) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000163 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700164 return GetAnnotHandler(pAnnot->Get())
165 ->OnMouseMove(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700166}
167
tsepez4cf55152016-11-02 14:37:54 -0700168bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
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,
172 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500173 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000174 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700175 return GetAnnotHandler(pAnnot->Get())
176 ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700177}
178
tsepez4cf55152016-11-02 14:37:54 -0700179bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700180 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700181 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700182 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500183 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000184 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700185 return GetAnnotHandler(pAnnot->Get())
186 ->OnRButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700187}
188
tsepez4cf55152016-11-02 14:37:54 -0700189bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
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) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000194 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700195 return GetAnnotHandler(pAnnot->Get())
196 ->OnRButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700197}
198
tsepezf8074ce2016-09-27 14:29:57 -0700199void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(
200 CPDFSDK_PageView* pPageView,
201 CPDFSDK_Annot::ObservedPtr* pAnnot,
202 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000203 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700204 GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700205}
206
tsepezf8074ce2016-09-27 14:29:57 -0700207void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(
208 CPDFSDK_PageView* pPageView,
209 CPDFSDK_Annot::ObservedPtr* pAnnot,
210 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000211 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700212 GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700213}
214
tsepez4cf55152016-11-02 14:37:54 -0700215bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
216 uint32_t nChar,
217 uint32_t nFlags) {
jaepark35512aa2016-08-29 17:15:08 -0700218 return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
jaepark98e10192016-08-15 10:51:11 -0700219}
220
tsepez4cf55152016-11-02 14:37:54 -0700221bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
222 int nKeyCode,
223 int nFlag) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700224 if (CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag) ||
225 CPDFSDK_FormFillEnvironment::IsALTKeyDown(nFlag)) {
jaepark35512aa2016-08-29 17:15:08 -0700226 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
thestig7b3252f2016-11-08 21:30:11 -0800227 }
jaepark98e10192016-08-15 10:51:11 -0700228
jaepark35512aa2016-08-29 17:15:08 -0700229 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
230 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
231 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700232 CPDFSDK_Annot::ObservedPtr pNext(GetNextAnnot(
233 pFocusAnnot, !CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag)));
tsepezf8074ce2016-09-27 14:29:57 -0700234 if (pNext && pNext.Get() != pFocusAnnot) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700235 pPage->GetFormFillEnv()->SetFocusAnnot(&pNext);
tsepez4cf55152016-11-02 14:37:54 -0700236 return true;
jaepark98e10192016-08-15 10:51:11 -0700237 }
238 }
239
thestig7b3252f2016-11-08 21:30:11 -0800240 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700241}
242
tsepez4cf55152016-11-02 14:37:54 -0700243bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700244 CPDFSDK_Annot::ObservedPtr* pAnnot,
245 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000246 ASSERT(pAnnot->HasObservable());
dsinclairb402b172016-10-11 09:26:32 -0700247 return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700248}
249
tsepez4cf55152016-11-02 14:37:54 -0700250bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700251 CPDFSDK_Annot::ObservedPtr* pAnnot,
252 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000253 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700254 return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700255}
256
257#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700258bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700259 CPDFSDK_Annot::ObservedPtr* pSetAnnot,
260 CPDFSDK_Annot::ObservedPtr* pKillAnnot) {
tsepez4cf55152016-11-02 14:37:54 -0700261 bool bXFA = (*pSetAnnot && (*pSetAnnot)->GetXFAWidget()) ||
262 (*pKillAnnot && (*pKillAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700263
264 if (bXFA) {
265 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
jaepark956553e2016-08-31 06:49:27 -0700266 GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET))
jaepark98e10192016-08-15 10:51:11 -0700267 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
268 }
269
tsepez4cf55152016-11-02 14:37:54 -0700270 return true;
jaepark98e10192016-08-15 10:51:11 -0700271}
272#endif // PDF_ENABLE_XFA
273
274CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
275 CPDFSDK_PageView* pPageView,
276 CPDFSDK_Annot* pAnnot) {
277 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700278 return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot);
jaepark98e10192016-08-15 10:51:11 -0700279}
280
tsepez4cf55152016-11-02 14:37:54 -0700281bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
282 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500283 const CFX_PointF& point) {
jaepark98e10192016-08-15 10:51:11 -0700284 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700285 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
286 if (pAnnotHandler->CanAnswer(pAnnot))
287 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
288
tsepez4cf55152016-11-02 14:37:54 -0700289 return false;
jaepark98e10192016-08-15 10:51:11 -0700290}
291
292CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
tsepez4cf55152016-11-02 14:37:54 -0700293 bool bNext) {
jaepark98e10192016-08-15 10:51:11 -0700294#ifdef PDF_ENABLE_XFA
295 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
296 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
Tom Sepez8e631772018-06-13 21:26:56 +0000297 if (pPage && !pPage->AsPDFPage()) {
298 // For xfa annots in XFA pages not backed by PDF pages.
299 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
300 pPage->GetXFAPageView()->CreateWidgetIterator(
301 XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible |
302 XFA_WidgetStatus_Viewable |
303 XFA_WidgetStatus_Focused));
304 if (!pWidgetIterator)
305 return nullptr;
306 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
307 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
308 CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext()
309 : pWidgetIterator->MoveToPrevious();
310 if (!hNextFocus && pSDKAnnot)
311 hNextFocus = pWidgetIterator->MoveToFirst();
jaepark98e10192016-08-15 10:51:11 -0700312
Tom Sepez8e631772018-06-13 21:26:56 +0000313 return pPageView->GetAnnotByXFAWidget(hNextFocus);
314 }
jaepark98e10192016-08-15 10:51:11 -0700315#endif // PDF_ENABLE_XFA
Tom Sepez8e631772018-06-13 21:26:56 +0000316
317 // For PDF annots.
Tom Sepez11a6bec2018-07-25 23:25:55 +0000318 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot);
319 CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype());
320 return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget);
jaepark98e10192016-08-15 10:51:11 -0700321}