blob: f4807b65c787570acd734a39ccad9ddc4d431e20 [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"
Tom Sepez43f012f2019-08-02 16:16:46 +000022#include "fpdfsdk/pwl/cpwl_wnd.h"
Lei Zhangac756642018-12-13 20:47:10 +000023#include "public/fpdf_fwlevent.h"
Tom Sepezfe91c6c2017-05-16 15:33:20 -070024#include "third_party/base/ptr_util.h"
jaepark98e10192016-08-15 10:51:11 -070025
26#ifdef PDF_ENABLE_XFA
dsinclair114e46a2016-09-29 17:18:21 -070027#include "fpdfsdk/cpdfsdk_xfawidgethandler.h"
dsinclair4d29e782016-10-04 14:02:47 -070028#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040029#include "xfa/fxfa/cxfa_ffpageview.h"
30#include "xfa/fxfa/cxfa_ffwidget.h"
jaepark98e10192016-08-15 10:51:11 -070031#endif // PDF_ENABLE_XFA
32
dsinclair735606d2016-10-05 15:47:02 -070033CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(
dsinclair8779fa82016-10-12 12:05:44 -070034 CPDFSDK_FormFillEnvironment* pFormFillEnv)
Tom Sepezfe91c6c2017-05-16 15:33:20 -070035 : m_pBAAnnotHandler(pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>()),
Lei Zhang60fa2fc2017-07-21 17:42:19 -070036 m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv))
jaepark98e10192016-08-15 10:51:11 -070037#ifdef PDF_ENABLE_XFA
Lei Zhang60fa2fc2017-07-21 17:42:19 -070038 ,
Tom Sepezfe91c6c2017-05-16 15:33:20 -070039 m_pXFAWidgetHandler(
Lei Zhang60fa2fc2017-07-21 17:42:19 -070040 pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv))
jaepark98e10192016-08-15 10:51:11 -070041#endif // PDF_ENABLE_XFA
Lei Zhang60fa2fc2017-07-21 17:42:19 -070042{
jaepark98e10192016-08-15 10:51:11 -070043}
44
45CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {}
46
jaepark98e10192016-08-15 10:51:11 -070047CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
48 CPDFSDK_PageView* pPageView) {
49 ASSERT(pPageView);
jaepark35512aa2016-08-29 17:15:08 -070050 return GetAnnotHandler(pAnnot->GetSubtype())->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070051}
52
53#ifdef PDF_ENABLE_XFA
54CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot,
55 CPDFSDK_PageView* pPageView) {
56 ASSERT(pAnnot);
57 ASSERT(pPageView);
58
jaepark956553e2016-08-31 06:49:27 -070059 return GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET)
60 ->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070061}
62#endif // PDF_ENABLE_XFA
63
Tom Sepez0f35a9e2019-04-23 00:32:37 +000064void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(
65 std::unique_ptr<CPDFSDK_Annot> pAnnot) {
66 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot.get());
67 pAnnotHandler->ReleaseAnnot(std::move(pAnnot));
jaepark98e10192016-08-15 10:51:11 -070068}
69
jaepark98e10192016-08-15 10:51:11 -070070void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
71 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070072 GetAnnotHandler(pAnnot)->OnLoad(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070073}
74
Lei Zhanga4c7ac42018-04-17 15:12:58 +000075WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) {
76 return GetAnnotHandler(pAnnot)->GetText(pAnnot);
77}
78
Ryan Harrison275e2602017-09-18 14:23:18 -040079WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText(
Diana Gagedce2d722017-06-20 11:17:11 -070080 CPDFSDK_Annot* pAnnot) {
81 return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot);
82}
83
Ryan Harrison275e2602017-09-18 14:23:18 -040084void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot,
85 const WideString& text) {
Diana Gageab390972017-07-28 17:07:39 -070086 GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text);
Diana Gage1c7f1422017-07-24 11:19:52 -070087}
88
Lei Zhangee967722018-04-19 20:55:54 +000089bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) {
90 return GetAnnotHandler(pAnnot)->CanUndo(pAnnot);
91}
92
93bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) {
94 return GetAnnotHandler(pAnnot)->CanRedo(pAnnot);
95}
96
97bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) {
98 return GetAnnotHandler(pAnnot)->Undo(pAnnot);
99}
100
101bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) {
102 return GetAnnotHandler(pAnnot)->Redo(pAnnot);
103}
104
jaepark98e10192016-08-15 10:51:11 -0700105IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
106 CPDFSDK_Annot* pAnnot) const {
jaepark35512aa2016-08-29 17:15:08 -0700107 return GetAnnotHandler(pAnnot->GetAnnotSubtype());
jaepark98e10192016-08-15 10:51:11 -0700108}
109
110IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
jaepark956553e2016-08-31 06:49:27 -0700111 CPDF_Annot::Subtype nAnnotSubtype) const {
112 if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET)
jaepark8c541822016-08-30 13:43:05 -0700113 return m_pWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700114
115#ifdef PDF_ENABLE_XFA
jaepark956553e2016-08-31 06:49:27 -0700116 if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET)
jaepark8c541822016-08-30 13:43:05 -0700117 return m_pXFAWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700118#endif // PDF_ENABLE_XFA
119
120 return m_pBAAnnotHandler.get();
jaepark98e10192016-08-15 10:51:11 -0700121}
122
123void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
124 CPDFSDK_Annot* pAnnot,
125 CFX_RenderDevice* pDevice,
Lei Zhang09ee0872018-10-09 19:13:55 +0000126 const CFX_Matrix& mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700127 bool bDrawAnnots) {
jaepark98e10192016-08-15 10:51:11 -0700128 ASSERT(pAnnot);
Lei Zhang09ee0872018-10-09 19:13:55 +0000129 GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700130 bDrawAnnots);
jaepark98e10192016-08-15 10:51:11 -0700131}
132
tsepez4cf55152016-11-02 14:37:54 -0700133bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700134 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000135 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700136 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500137 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000138 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700139 return GetAnnotHandler(pAnnot->Get())
140 ->OnLButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700141}
142
tsepez4cf55152016-11-02 14:37:54 -0700143bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700144 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000145 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700146 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500147 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000148 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700149 return GetAnnotHandler(pAnnot->Get())
150 ->OnLButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700151}
152
Lei Zhanga37989f2018-10-17 20:32:41 +0000153bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
154 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000155 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Lei Zhanga37989f2018-10-17 20:32:41 +0000156 uint32_t nFlags,
157 const CFX_PointF& point) {
158 ASSERT(pAnnot->HasObservable());
159 return GetAnnotHandler(pAnnot->Get())
160 ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
161}
162
tsepez4cf55152016-11-02 14:37:54 -0700163bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
jaepark98e10192016-08-15 10:51:11 -0700164 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000165 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700166 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500167 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000168 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700169 return GetAnnotHandler(pAnnot->Get())
170 ->OnMouseMove(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700171}
172
tsepez4cf55152016-11-02 14:37:54 -0700173bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
jaepark98e10192016-08-15 10:51:11 -0700174 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000175 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700176 uint32_t nFlags,
177 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500178 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000179 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700180 return GetAnnotHandler(pAnnot->Get())
181 ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700182}
183
tsepez4cf55152016-11-02 14:37:54 -0700184bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700185 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000186 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700187 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500188 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000189 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700190 return GetAnnotHandler(pAnnot->Get())
191 ->OnRButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700192}
193
tsepez4cf55152016-11-02 14:37:54 -0700194bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700195 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000196 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700197 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500198 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000199 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700200 return GetAnnotHandler(pAnnot->Get())
201 ->OnRButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700202}
203
tsepezf8074ce2016-09-27 14:29:57 -0700204void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(
205 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000206 ObservedPtr<CPDFSDK_Annot>* pAnnot,
tsepezf8074ce2016-09-27 14:29:57 -0700207 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000208 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700209 GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700210}
211
tsepezf8074ce2016-09-27 14:29:57 -0700212void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(
213 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000214 ObservedPtr<CPDFSDK_Annot>* pAnnot,
tsepezf8074ce2016-09-27 14:29:57 -0700215 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000216 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700217 GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700218}
219
tsepez4cf55152016-11-02 14:37:54 -0700220bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
221 uint32_t nChar,
222 uint32_t nFlags) {
jaepark35512aa2016-08-29 17:15:08 -0700223 return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
jaepark98e10192016-08-15 10:51:11 -0700224}
225
tsepez4cf55152016-11-02 14:37:54 -0700226bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
227 int nKeyCode,
228 int nFlag) {
Tom Sepez43f012f2019-08-02 16:16:46 +0000229 if (CPWL_Wnd::IsCTRLKeyDown(nFlag) || CPWL_Wnd::IsALTKeyDown(nFlag)) {
jaepark35512aa2016-08-29 17:15:08 -0700230 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
thestig7b3252f2016-11-08 21:30:11 -0800231 }
huyna6e3a4062019-07-25 20:41:23 +0000232 ObservedPtr<CPDFSDK_Annot> pObservedAnnot(pAnnot);
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)) {
Tom Sepez43f012f2019-08-02 16:16:46 +0000236 ObservedPtr<CPDFSDK_Annot> pNext(
237 GetNextAnnot(pFocusAnnot, !CPWL_Wnd::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
huyna6e3a4062019-07-25 20:41:23 +0000244 // Check |pAnnot| again because JS may have destroyed it in |GetNextAnnot|
245 if (!pObservedAnnot)
246 return false;
247
thestig7b3252f2016-11-08 21:30:11 -0800248 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700249}
250
tsepez4cf55152016-11-02 14:37:54 -0700251bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000252 ObservedPtr<CPDFSDK_Annot>* pAnnot,
tsepezf8074ce2016-09-27 14:29:57 -0700253 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000254 ASSERT(pAnnot->HasObservable());
dsinclairb402b172016-10-11 09:26:32 -0700255 return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700256}
257
tsepez4cf55152016-11-02 14:37:54 -0700258bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000259 ObservedPtr<CPDFSDK_Annot>* pAnnot,
tsepezf8074ce2016-09-27 14:29:57 -0700260 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000261 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700262 return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700263}
264
rycsmitha5230e22019-02-21 17:33:03 +0000265bool CPDFSDK_AnnotHandlerMgr::Annot_SetIndexSelected(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000266 ObservedPtr<CPDFSDK_Annot>* pAnnot,
rycsmitha5230e22019-02-21 17:33:03 +0000267 int index,
268 bool selected) {
269 return GetAnnotHandler(pAnnot->Get())
270 ->SetIndexSelected(pAnnot, index, selected);
271}
272
273bool CPDFSDK_AnnotHandlerMgr::Annot_IsIndexSelected(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000274 ObservedPtr<CPDFSDK_Annot>* pAnnot,
rycsmitha5230e22019-02-21 17:33:03 +0000275 int index) {
276 return GetAnnotHandler(pAnnot->Get())->IsIndexSelected(pAnnot, index);
277}
278
jaepark98e10192016-08-15 10:51:11 -0700279#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700280bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000281 ObservedPtr<CPDFSDK_Annot>* pSetAnnot,
282 ObservedPtr<CPDFSDK_Annot>* pKillAnnot) {
tsepez4cf55152016-11-02 14:37:54 -0700283 bool bXFA = (*pSetAnnot && (*pSetAnnot)->GetXFAWidget()) ||
284 (*pKillAnnot && (*pKillAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700285
286 if (bXFA) {
287 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
jaepark956553e2016-08-31 06:49:27 -0700288 GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET))
jaepark98e10192016-08-15 10:51:11 -0700289 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
290 }
291
tsepez4cf55152016-11-02 14:37:54 -0700292 return true;
jaepark98e10192016-08-15 10:51:11 -0700293}
294#endif // PDF_ENABLE_XFA
295
296CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
297 CPDFSDK_PageView* pPageView,
298 CPDFSDK_Annot* pAnnot) {
299 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700300 return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot);
jaepark98e10192016-08-15 10:51:11 -0700301}
302
tsepez4cf55152016-11-02 14:37:54 -0700303bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
304 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500305 const CFX_PointF& point) {
jaepark98e10192016-08-15 10:51:11 -0700306 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700307 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
308 if (pAnnotHandler->CanAnswer(pAnnot))
309 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
310
tsepez4cf55152016-11-02 14:37:54 -0700311 return false;
jaepark98e10192016-08-15 10:51:11 -0700312}
313
314CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
tsepez4cf55152016-11-02 14:37:54 -0700315 bool bNext) {
jaepark98e10192016-08-15 10:51:11 -0700316#ifdef PDF_ENABLE_XFA
huyna6e3a4062019-07-25 20:41:23 +0000317 ObservedPtr<CPDFSDK_Annot> pObservedAnnot(pSDKAnnot);
jaepark98e10192016-08-15 10:51:11 -0700318 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
319 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
Tom Sepez8e631772018-06-13 21:26:56 +0000320 if (pPage && !pPage->AsPDFPage()) {
321 // For xfa annots in XFA pages not backed by PDF pages.
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));
huyna6e3a4062019-07-25 20:41:23 +0000327
328 // Check |pSDKAnnot| again because JS may have destroyed it
329 if (!pObservedAnnot || !pWidgetIterator)
Tom Sepez8e631772018-06-13 21:26:56 +0000330 return nullptr;
331 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
332 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
333 CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext()
334 : pWidgetIterator->MoveToPrevious();
335 if (!hNextFocus && pSDKAnnot)
336 hNextFocus = pWidgetIterator->MoveToFirst();
jaepark98e10192016-08-15 10:51:11 -0700337
Tom Sepez8e631772018-06-13 21:26:56 +0000338 return pPageView->GetAnnotByXFAWidget(hNextFocus);
339 }
jaepark98e10192016-08-15 10:51:11 -0700340#endif // PDF_ENABLE_XFA
Tom Sepez8e631772018-06-13 21:26:56 +0000341
342 // For PDF annots.
Tom Sepez11a6bec2018-07-25 23:25:55 +0000343 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot);
344 CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype());
345 return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget);
jaepark98e10192016-08-15 10:51:11 -0700346}