blob: 0061eb5a20b283e2bd628971b5bd39ec47a5fe12 [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"
Lei Zhangac756642018-12-13 20:47:10 +000020#include "public/fpdf_fwlevent.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
jaepark98e10192016-08-15 10:51:11 -070066void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
67 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070068 GetAnnotHandler(pAnnot)->OnLoad(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070069}
70
Lei Zhanga4c7ac42018-04-17 15:12:58 +000071WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) {
72 return GetAnnotHandler(pAnnot)->GetText(pAnnot);
73}
74
Ryan Harrison275e2602017-09-18 14:23:18 -040075WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText(
Diana Gagedce2d722017-06-20 11:17:11 -070076 CPDFSDK_Annot* pAnnot) {
77 return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot);
78}
79
Ryan Harrison275e2602017-09-18 14:23:18 -040080void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot,
81 const WideString& text) {
Diana Gageab390972017-07-28 17:07:39 -070082 GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text);
Diana Gage1c7f1422017-07-24 11:19:52 -070083}
84
Lei Zhangee967722018-04-19 20:55:54 +000085bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) {
86 return GetAnnotHandler(pAnnot)->CanUndo(pAnnot);
87}
88
89bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) {
90 return GetAnnotHandler(pAnnot)->CanRedo(pAnnot);
91}
92
93bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) {
94 return GetAnnotHandler(pAnnot)->Undo(pAnnot);
95}
96
97bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) {
98 return GetAnnotHandler(pAnnot)->Redo(pAnnot);
99}
100
jaepark98e10192016-08-15 10:51:11 -0700101IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
102 CPDFSDK_Annot* pAnnot) const {
jaepark35512aa2016-08-29 17:15:08 -0700103 return GetAnnotHandler(pAnnot->GetAnnotSubtype());
jaepark98e10192016-08-15 10:51:11 -0700104}
105
106IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
jaepark956553e2016-08-31 06:49:27 -0700107 CPDF_Annot::Subtype nAnnotSubtype) const {
108 if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET)
jaepark8c541822016-08-30 13:43:05 -0700109 return m_pWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700110
111#ifdef PDF_ENABLE_XFA
jaepark956553e2016-08-31 06:49:27 -0700112 if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET)
jaepark8c541822016-08-30 13:43:05 -0700113 return m_pXFAWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700114#endif // PDF_ENABLE_XFA
115
116 return m_pBAAnnotHandler.get();
jaepark98e10192016-08-15 10:51:11 -0700117}
118
119void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
120 CPDFSDK_Annot* pAnnot,
121 CFX_RenderDevice* pDevice,
Lei Zhang09ee0872018-10-09 19:13:55 +0000122 const CFX_Matrix& mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700123 bool bDrawAnnots) {
jaepark98e10192016-08-15 10:51:11 -0700124 ASSERT(pAnnot);
Lei Zhang09ee0872018-10-09 19:13:55 +0000125 GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700126 bDrawAnnots);
jaepark98e10192016-08-15 10:51:11 -0700127}
128
tsepez4cf55152016-11-02 14:37:54 -0700129bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700130 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700131 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700132 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500133 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000134 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700135 return GetAnnotHandler(pAnnot->Get())
136 ->OnLButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700137}
138
tsepez4cf55152016-11-02 14:37:54 -0700139bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700140 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700141 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700142 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500143 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000144 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700145 return GetAnnotHandler(pAnnot->Get())
146 ->OnLButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700147}
148
Lei Zhanga37989f2018-10-17 20:32:41 +0000149bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
150 CPDFSDK_PageView* pPageView,
151 CPDFSDK_Annot::ObservedPtr* pAnnot,
152 uint32_t nFlags,
153 const CFX_PointF& point) {
154 ASSERT(pAnnot->HasObservable());
155 return GetAnnotHandler(pAnnot->Get())
156 ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
157}
158
tsepez4cf55152016-11-02 14:37:54 -0700159bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
jaepark98e10192016-08-15 10:51:11 -0700160 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700161 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700162 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500163 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000164 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700165 return GetAnnotHandler(pAnnot->Get())
166 ->OnMouseMove(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700167}
168
tsepez4cf55152016-11-02 14:37:54 -0700169bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
jaepark98e10192016-08-15 10:51:11 -0700170 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700171 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700172 uint32_t nFlags,
173 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500174 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000175 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700176 return GetAnnotHandler(pAnnot->Get())
177 ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700178}
179
tsepez4cf55152016-11-02 14:37:54 -0700180bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700181 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700182 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700183 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500184 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000185 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700186 return GetAnnotHandler(pAnnot->Get())
187 ->OnRButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700188}
189
tsepez4cf55152016-11-02 14:37:54 -0700190bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700191 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700192 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700193 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500194 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000195 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700196 return GetAnnotHandler(pAnnot->Get())
197 ->OnRButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700198}
199
tsepezf8074ce2016-09-27 14:29:57 -0700200void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(
201 CPDFSDK_PageView* pPageView,
202 CPDFSDK_Annot::ObservedPtr* pAnnot,
203 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000204 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700205 GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700206}
207
tsepezf8074ce2016-09-27 14:29:57 -0700208void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(
209 CPDFSDK_PageView* pPageView,
210 CPDFSDK_Annot::ObservedPtr* pAnnot,
211 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000212 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700213 GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700214}
215
tsepez4cf55152016-11-02 14:37:54 -0700216bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
217 uint32_t nChar,
218 uint32_t nFlags) {
jaepark35512aa2016-08-29 17:15:08 -0700219 return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
jaepark98e10192016-08-15 10:51:11 -0700220}
221
tsepez4cf55152016-11-02 14:37:54 -0700222bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
223 int nKeyCode,
224 int nFlag) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700225 if (CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag) ||
226 CPDFSDK_FormFillEnvironment::IsALTKeyDown(nFlag)) {
jaepark35512aa2016-08-29 17:15:08 -0700227 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
thestig7b3252f2016-11-08 21:30:11 -0800228 }
jaepark98e10192016-08-15 10:51:11 -0700229
jaepark35512aa2016-08-29 17:15:08 -0700230 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
231 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
232 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700233 CPDFSDK_Annot::ObservedPtr pNext(GetNextAnnot(
234 pFocusAnnot, !CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag)));
tsepezf8074ce2016-09-27 14:29:57 -0700235 if (pNext && pNext.Get() != pFocusAnnot) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700236 pPage->GetFormFillEnv()->SetFocusAnnot(&pNext);
tsepez4cf55152016-11-02 14:37:54 -0700237 return true;
jaepark98e10192016-08-15 10:51:11 -0700238 }
239 }
240
thestig7b3252f2016-11-08 21:30:11 -0800241 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700242}
243
tsepez4cf55152016-11-02 14:37:54 -0700244bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700245 CPDFSDK_Annot::ObservedPtr* pAnnot,
246 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000247 ASSERT(pAnnot->HasObservable());
dsinclairb402b172016-10-11 09:26:32 -0700248 return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700249}
250
tsepez4cf55152016-11-02 14:37:54 -0700251bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700252 CPDFSDK_Annot::ObservedPtr* pAnnot,
253 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000254 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700255 return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700256}
257
rycsmitha5230e22019-02-21 17:33:03 +0000258bool CPDFSDK_AnnotHandlerMgr::Annot_SetIndexSelected(
259 CPDFSDK_Annot::ObservedPtr* pAnnot,
260 int index,
261 bool selected) {
262 return GetAnnotHandler(pAnnot->Get())
263 ->SetIndexSelected(pAnnot, index, selected);
264}
265
266bool CPDFSDK_AnnotHandlerMgr::Annot_IsIndexSelected(
267 CPDFSDK_Annot::ObservedPtr* pAnnot,
268 int index) {
269 return GetAnnotHandler(pAnnot->Get())->IsIndexSelected(pAnnot, index);
270}
271
jaepark98e10192016-08-15 10:51:11 -0700272#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();
Tom Sepez8e631772018-06-13 21:26:56 +0000312 if (pPage && !pPage->AsPDFPage()) {
313 // For xfa annots in XFA pages not backed by PDF pages.
314 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
315 pPage->GetXFAPageView()->CreateWidgetIterator(
316 XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible |
317 XFA_WidgetStatus_Viewable |
318 XFA_WidgetStatus_Focused));
319 if (!pWidgetIterator)
320 return nullptr;
321 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
322 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
323 CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext()
324 : pWidgetIterator->MoveToPrevious();
325 if (!hNextFocus && pSDKAnnot)
326 hNextFocus = pWidgetIterator->MoveToFirst();
jaepark98e10192016-08-15 10:51:11 -0700327
Tom Sepez8e631772018-06-13 21:26:56 +0000328 return pPageView->GetAnnotByXFAWidget(hNextFocus);
329 }
jaepark98e10192016-08-15 10:51:11 -0700330#endif // PDF_ENABLE_XFA
Tom Sepez8e631772018-06-13 21:26:56 +0000331
332 // For PDF annots.
Tom Sepez11a6bec2018-07-25 23:25:55 +0000333 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot);
334 CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype());
335 return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget);
jaepark98e10192016-08-15 10:51:11 -0700336}