blob: b40014d8da652b4515c359d9ba3276f09c1f36e7 [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
Tom Sepez0f35a9e2019-04-23 00:32:37 +00009#include <utility>
10
tsepez0e606b52016-11-18 16:22:41 -080011#include "core/fpdfapi/parser/cpdf_number.h"
12#include "core/fpdfapi/parser/cpdf_string.h"
dsinclair1727aee2016-09-29 13:12:56 -070013#include "core/fpdfdoc/cpdf_annot.h"
dsinclair114e46a2016-09-29 17:18:21 -070014#include "fpdfsdk/cpdfsdk_annot.h"
Dan Sinclaircbf76e62018-03-28 21:00:35 +000015#include "fpdfsdk/cpdfsdk_annotiterator.h"
dsinclair114e46a2016-09-29 17:18:21 -070016#include "fpdfsdk/cpdfsdk_baannot.h"
17#include "fpdfsdk/cpdfsdk_baannothandler.h"
dsinclair735606d2016-10-05 15:47:02 -070018#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#include "fpdfsdk/cpdfsdk_pageview.h"
Tom Sepez11a6bec2018-07-25 23:25:55 +000020#include "fpdfsdk/cpdfsdk_widget.h"
dsinclair114e46a2016-09-29 17:18:21 -070021#include "fpdfsdk/cpdfsdk_widgethandler.h"
Lei Zhangac756642018-12-13 20:47:10 +000022#include "public/fpdf_fwlevent.h"
Tom Sepezfe91c6c2017-05-16 15:33:20 -070023#include "third_party/base/ptr_util.h"
jaepark98e10192016-08-15 10:51:11 -070024
25#ifdef PDF_ENABLE_XFA
dsinclair114e46a2016-09-29 17:18:21 -070026#include "fpdfsdk/cpdfsdk_xfawidgethandler.h"
dsinclair4d29e782016-10-04 14:02:47 -070027#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040028#include "xfa/fxfa/cxfa_ffpageview.h"
29#include "xfa/fxfa/cxfa_ffwidget.h"
jaepark98e10192016-08-15 10:51:11 -070030#endif // PDF_ENABLE_XFA
31
dsinclair735606d2016-10-05 15:47:02 -070032CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(
dsinclair8779fa82016-10-12 12:05:44 -070033 CPDFSDK_FormFillEnvironment* pFormFillEnv)
Tom Sepezfe91c6c2017-05-16 15:33:20 -070034 : m_pBAAnnotHandler(pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>()),
Lei Zhang60fa2fc2017-07-21 17:42:19 -070035 m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv))
jaepark98e10192016-08-15 10:51:11 -070036#ifdef PDF_ENABLE_XFA
Lei Zhang60fa2fc2017-07-21 17:42:19 -070037 ,
Tom Sepezfe91c6c2017-05-16 15:33:20 -070038 m_pXFAWidgetHandler(
Lei Zhang60fa2fc2017-07-21 17:42:19 -070039 pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv))
jaepark98e10192016-08-15 10:51:11 -070040#endif // PDF_ENABLE_XFA
Lei Zhang60fa2fc2017-07-21 17:42:19 -070041{
jaepark98e10192016-08-15 10:51:11 -070042}
43
44CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {}
45
jaepark98e10192016-08-15 10:51:11 -070046CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
47 CPDFSDK_PageView* pPageView) {
48 ASSERT(pPageView);
jaepark35512aa2016-08-29 17:15:08 -070049 return GetAnnotHandler(pAnnot->GetSubtype())->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070050}
51
52#ifdef PDF_ENABLE_XFA
53CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot,
54 CPDFSDK_PageView* pPageView) {
55 ASSERT(pAnnot);
56 ASSERT(pPageView);
57
jaepark956553e2016-08-31 06:49:27 -070058 return GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET)
59 ->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070060}
61#endif // PDF_ENABLE_XFA
62
Tom Sepez0f35a9e2019-04-23 00:32:37 +000063void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(
64 std::unique_ptr<CPDFSDK_Annot> pAnnot) {
65 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot.get());
66 pAnnotHandler->ReleaseAnnot(std::move(pAnnot));
jaepark98e10192016-08-15 10:51:11 -070067}
68
jaepark98e10192016-08-15 10:51:11 -070069void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
70 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070071 GetAnnotHandler(pAnnot)->OnLoad(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070072}
73
Lei Zhanga4c7ac42018-04-17 15:12:58 +000074WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) {
75 return GetAnnotHandler(pAnnot)->GetText(pAnnot);
76}
77
Ryan Harrison275e2602017-09-18 14:23:18 -040078WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText(
Diana Gagedce2d722017-06-20 11:17:11 -070079 CPDFSDK_Annot* pAnnot) {
80 return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot);
81}
82
Ryan Harrison275e2602017-09-18 14:23:18 -040083void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot,
84 const WideString& text) {
Diana Gageab390972017-07-28 17:07:39 -070085 GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text);
Diana Gage1c7f1422017-07-24 11:19:52 -070086}
87
Lei Zhangee967722018-04-19 20:55:54 +000088bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) {
89 return GetAnnotHandler(pAnnot)->CanUndo(pAnnot);
90}
91
92bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) {
93 return GetAnnotHandler(pAnnot)->CanRedo(pAnnot);
94}
95
96bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) {
97 return GetAnnotHandler(pAnnot)->Undo(pAnnot);
98}
99
100bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) {
101 return GetAnnotHandler(pAnnot)->Redo(pAnnot);
102}
103
jaepark98e10192016-08-15 10:51:11 -0700104IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
105 CPDFSDK_Annot* pAnnot) const {
jaepark35512aa2016-08-29 17:15:08 -0700106 return GetAnnotHandler(pAnnot->GetAnnotSubtype());
jaepark98e10192016-08-15 10:51:11 -0700107}
108
109IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
jaepark956553e2016-08-31 06:49:27 -0700110 CPDF_Annot::Subtype nAnnotSubtype) const {
111 if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET)
jaepark8c541822016-08-30 13:43:05 -0700112 return m_pWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700113
114#ifdef PDF_ENABLE_XFA
jaepark956553e2016-08-31 06:49:27 -0700115 if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET)
jaepark8c541822016-08-30 13:43:05 -0700116 return m_pXFAWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700117#endif // PDF_ENABLE_XFA
118
119 return m_pBAAnnotHandler.get();
jaepark98e10192016-08-15 10:51:11 -0700120}
121
122void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
123 CPDFSDK_Annot* pAnnot,
124 CFX_RenderDevice* pDevice,
Lei Zhang09ee0872018-10-09 19:13:55 +0000125 const CFX_Matrix& mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700126 bool bDrawAnnots) {
jaepark98e10192016-08-15 10:51:11 -0700127 ASSERT(pAnnot);
Lei Zhang09ee0872018-10-09 19:13:55 +0000128 GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700129 bDrawAnnots);
jaepark98e10192016-08-15 10:51:11 -0700130}
131
tsepez4cf55152016-11-02 14:37:54 -0700132bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700133 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700134 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700135 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500136 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000137 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700138 return GetAnnotHandler(pAnnot->Get())
139 ->OnLButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700140}
141
tsepez4cf55152016-11-02 14:37:54 -0700142bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700143 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700144 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700145 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500146 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000147 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700148 return GetAnnotHandler(pAnnot->Get())
149 ->OnLButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700150}
151
Lei Zhanga37989f2018-10-17 20:32:41 +0000152bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
153 CPDFSDK_PageView* pPageView,
154 CPDFSDK_Annot::ObservedPtr* pAnnot,
155 uint32_t nFlags,
156 const CFX_PointF& point) {
157 ASSERT(pAnnot->HasObservable());
158 return GetAnnotHandler(pAnnot->Get())
159 ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
160}
161
tsepez4cf55152016-11-02 14:37:54 -0700162bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
jaepark98e10192016-08-15 10:51:11 -0700163 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700164 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700165 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500166 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000167 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700168 return GetAnnotHandler(pAnnot->Get())
169 ->OnMouseMove(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700170}
171
tsepez4cf55152016-11-02 14:37:54 -0700172bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
jaepark98e10192016-08-15 10:51:11 -0700173 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700174 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700175 uint32_t nFlags,
176 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500177 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000178 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700179 return GetAnnotHandler(pAnnot->Get())
180 ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700181}
182
tsepez4cf55152016-11-02 14:37:54 -0700183bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700184 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700185 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700186 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500187 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000188 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700189 return GetAnnotHandler(pAnnot->Get())
190 ->OnRButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700191}
192
tsepez4cf55152016-11-02 14:37:54 -0700193bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700194 CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700195 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700196 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500197 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000198 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700199 return GetAnnotHandler(pAnnot->Get())
200 ->OnRButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700201}
202
tsepezf8074ce2016-09-27 14:29:57 -0700203void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(
204 CPDFSDK_PageView* pPageView,
205 CPDFSDK_Annot::ObservedPtr* pAnnot,
206 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000207 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700208 GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700209}
210
tsepezf8074ce2016-09-27 14:29:57 -0700211void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(
212 CPDFSDK_PageView* pPageView,
213 CPDFSDK_Annot::ObservedPtr* pAnnot,
214 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000215 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700216 GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700217}
218
tsepez4cf55152016-11-02 14:37:54 -0700219bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
220 uint32_t nChar,
221 uint32_t nFlags) {
jaepark35512aa2016-08-29 17:15:08 -0700222 return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
jaepark98e10192016-08-15 10:51:11 -0700223}
224
tsepez4cf55152016-11-02 14:37:54 -0700225bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
226 int nKeyCode,
227 int nFlag) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700228 if (CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag) ||
229 CPDFSDK_FormFillEnvironment::IsALTKeyDown(nFlag)) {
jaepark35512aa2016-08-29 17:15:08 -0700230 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
thestig7b3252f2016-11-08 21:30:11 -0800231 }
jaepark98e10192016-08-15 10:51:11 -0700232
jaepark35512aa2016-08-29 17:15:08 -0700233 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
234 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
235 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
Lei Zhang60fa2fc2017-07-21 17:42:19 -0700236 CPDFSDK_Annot::ObservedPtr pNext(GetNextAnnot(
237 pFocusAnnot, !CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag)));
tsepezf8074ce2016-09-27 14:29:57 -0700238 if (pNext && pNext.Get() != pFocusAnnot) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700239 pPage->GetFormFillEnv()->SetFocusAnnot(&pNext);
tsepez4cf55152016-11-02 14:37:54 -0700240 return true;
jaepark98e10192016-08-15 10:51:11 -0700241 }
242 }
243
thestig7b3252f2016-11-08 21:30:11 -0800244 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700245}
246
tsepez4cf55152016-11-02 14:37:54 -0700247bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700248 CPDFSDK_Annot::ObservedPtr* pAnnot,
249 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000250 ASSERT(pAnnot->HasObservable());
dsinclairb402b172016-10-11 09:26:32 -0700251 return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700252}
253
tsepez4cf55152016-11-02 14:37:54 -0700254bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700255 CPDFSDK_Annot::ObservedPtr* pAnnot,
256 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000257 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700258 return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700259}
260
rycsmitha5230e22019-02-21 17:33:03 +0000261bool CPDFSDK_AnnotHandlerMgr::Annot_SetIndexSelected(
262 CPDFSDK_Annot::ObservedPtr* pAnnot,
263 int index,
264 bool selected) {
265 return GetAnnotHandler(pAnnot->Get())
266 ->SetIndexSelected(pAnnot, index, selected);
267}
268
269bool CPDFSDK_AnnotHandlerMgr::Annot_IsIndexSelected(
270 CPDFSDK_Annot::ObservedPtr* pAnnot,
271 int index) {
272 return GetAnnotHandler(pAnnot->Get())->IsIndexSelected(pAnnot, index);
273}
274
jaepark98e10192016-08-15 10:51:11 -0700275#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700276bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700277 CPDFSDK_Annot::ObservedPtr* pSetAnnot,
278 CPDFSDK_Annot::ObservedPtr* pKillAnnot) {
tsepez4cf55152016-11-02 14:37:54 -0700279 bool bXFA = (*pSetAnnot && (*pSetAnnot)->GetXFAWidget()) ||
280 (*pKillAnnot && (*pKillAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700281
282 if (bXFA) {
283 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
jaepark956553e2016-08-31 06:49:27 -0700284 GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET))
jaepark98e10192016-08-15 10:51:11 -0700285 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
286 }
287
tsepez4cf55152016-11-02 14:37:54 -0700288 return true;
jaepark98e10192016-08-15 10:51:11 -0700289}
290#endif // PDF_ENABLE_XFA
291
292CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
293 CPDFSDK_PageView* pPageView,
294 CPDFSDK_Annot* pAnnot) {
295 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700296 return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot);
jaepark98e10192016-08-15 10:51:11 -0700297}
298
tsepez4cf55152016-11-02 14:37:54 -0700299bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
300 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500301 const CFX_PointF& point) {
jaepark98e10192016-08-15 10:51:11 -0700302 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700303 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
304 if (pAnnotHandler->CanAnswer(pAnnot))
305 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
306
tsepez4cf55152016-11-02 14:37:54 -0700307 return false;
jaepark98e10192016-08-15 10:51:11 -0700308}
309
310CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
tsepez4cf55152016-11-02 14:37:54 -0700311 bool bNext) {
jaepark98e10192016-08-15 10:51:11 -0700312#ifdef PDF_ENABLE_XFA
313 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
314 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
Tom Sepez8e631772018-06-13 21:26:56 +0000315 if (pPage && !pPage->AsPDFPage()) {
316 // For xfa annots in XFA pages not backed by PDF pages.
317 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
318 pPage->GetXFAPageView()->CreateWidgetIterator(
319 XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible |
320 XFA_WidgetStatus_Viewable |
321 XFA_WidgetStatus_Focused));
322 if (!pWidgetIterator)
323 return nullptr;
324 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
325 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
326 CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext()
327 : pWidgetIterator->MoveToPrevious();
328 if (!hNextFocus && pSDKAnnot)
329 hNextFocus = pWidgetIterator->MoveToFirst();
jaepark98e10192016-08-15 10:51:11 -0700330
Tom Sepez8e631772018-06-13 21:26:56 +0000331 return pPageView->GetAnnotByXFAWidget(hNextFocus);
332 }
jaepark98e10192016-08-15 10:51:11 -0700333#endif // PDF_ENABLE_XFA
Tom Sepez8e631772018-06-13 21:26:56 +0000334
335 // For PDF annots.
Tom Sepez11a6bec2018-07-25 23:25:55 +0000336 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot);
337 CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype());
338 return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget);
jaepark98e10192016-08-15 10:51:11 -0700339}