blob: 2a45b0d4eb43a2cc1e9700fd27c9032ee20df353 [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
dsinclair4d29e782016-10-04 14:02:47 -070027#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Tom Sepez451ed2d2019-08-19 22:55:31 +000028#include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h"
Tom Sepezf89a43f2019-08-09 19:55:49 +000029#include "fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h"
jaepark98e10192016-08-15 10:51:11 -070030#endif // PDF_ENABLE_XFA
31
dsinclair735606d2016-10-05 15:47:02 -070032CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(
Tom Sepez49357702019-08-19 17:17:18 +000033 std::unique_ptr<CPDFSDK_BAAnnotHandler> pBAAnnotHandler,
34 std::unique_ptr<CPDFSDK_WidgetHandler> pWidgetHandler,
35 std::unique_ptr<IPDFSDK_AnnotHandler> pXFAWidgetHandler)
36 : m_pBAAnnotHandler(std::move(pBAAnnotHandler)),
37 m_pWidgetHandler(std::move(pWidgetHandler)),
38 m_pXFAWidgetHandler(std::move(pXFAWidgetHandler)) {
39 ASSERT(m_pBAAnnotHandler);
40 ASSERT(m_pWidgetHandler);
jaepark98e10192016-08-15 10:51:11 -070041}
42
Lei Zhang2ffc6282019-08-16 16:59:23 +000043CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() = default;
jaepark98e10192016-08-15 10:51:11 -070044
Tom Sepez49357702019-08-19 17:17:18 +000045void CPDFSDK_AnnotHandlerMgr::SetFormFillEnv(
46 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
47 m_pBAAnnotHandler->SetFormFillEnvironment(pFormFillEnv);
48 m_pWidgetHandler->SetFormFillEnvironment(pFormFillEnv);
49 if (m_pXFAWidgetHandler)
50 m_pXFAWidgetHandler->SetFormFillEnvironment(pFormFillEnv);
51}
52
jaepark98e10192016-08-15 10:51:11 -070053CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
54 CPDFSDK_PageView* pPageView) {
55 ASSERT(pPageView);
Lei Zhang2ffc6282019-08-16 16:59:23 +000056 return GetAnnotHandlerOfType(pAnnot->GetSubtype())
57 ->NewAnnot(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070058}
59
60#ifdef PDF_ENABLE_XFA
Lei Zhang51d02662019-10-31 18:28:51 +000061std::unique_ptr<CPDFSDK_Annot> CPDFSDK_AnnotHandlerMgr::NewXFAAnnot(
Lei Zhang2ffc6282019-08-16 16:59:23 +000062 CXFA_FFWidget* pAnnot,
63 CPDFSDK_PageView* pPageView) {
jaepark98e10192016-08-15 10:51:11 -070064 ASSERT(pAnnot);
65 ASSERT(pPageView);
Tom Sepez49357702019-08-19 17:17:18 +000066 return static_cast<CPDFXFA_WidgetHandler*>(m_pXFAWidgetHandler.get())
67 ->NewAnnotForXFA(pAnnot, pPageView);
jaepark98e10192016-08-15 10:51:11 -070068}
69#endif // PDF_ENABLE_XFA
70
Tom Sepez0f35a9e2019-04-23 00:32:37 +000071void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(
72 std::unique_ptr<CPDFSDK_Annot> pAnnot) {
73 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot.get());
74 pAnnotHandler->ReleaseAnnot(std::move(pAnnot));
jaepark98e10192016-08-15 10:51:11 -070075}
76
jaepark98e10192016-08-15 10:51:11 -070077void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
78 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -070079 GetAnnotHandler(pAnnot)->OnLoad(pAnnot);
jaepark98e10192016-08-15 10:51:11 -070080}
81
Lei Zhanga4c7ac42018-04-17 15:12:58 +000082WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) {
83 return GetAnnotHandler(pAnnot)->GetText(pAnnot);
84}
85
Ryan Harrison275e2602017-09-18 14:23:18 -040086WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText(
Diana Gagedce2d722017-06-20 11:17:11 -070087 CPDFSDK_Annot* pAnnot) {
88 return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot);
89}
90
Ryan Harrison275e2602017-09-18 14:23:18 -040091void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot,
92 const WideString& text) {
Diana Gageab390972017-07-28 17:07:39 -070093 GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text);
Diana Gage1c7f1422017-07-24 11:19:52 -070094}
95
Lei Zhangee967722018-04-19 20:55:54 +000096bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) {
97 return GetAnnotHandler(pAnnot)->CanUndo(pAnnot);
98}
99
100bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) {
101 return GetAnnotHandler(pAnnot)->CanRedo(pAnnot);
102}
103
104bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) {
105 return GetAnnotHandler(pAnnot)->Undo(pAnnot);
106}
107
108bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) {
109 return GetAnnotHandler(pAnnot)->Redo(pAnnot);
110}
111
jaepark98e10192016-08-15 10:51:11 -0700112IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
113 CPDFSDK_Annot* pAnnot) const {
Lei Zhang2ffc6282019-08-16 16:59:23 +0000114 return GetAnnotHandlerOfType(pAnnot->GetAnnotSubtype());
jaepark98e10192016-08-15 10:51:11 -0700115}
116
Lei Zhang2ffc6282019-08-16 16:59:23 +0000117IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandlerOfType(
jaepark956553e2016-08-31 06:49:27 -0700118 CPDF_Annot::Subtype nAnnotSubtype) const {
119 if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET)
jaepark8c541822016-08-30 13:43:05 -0700120 return m_pWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700121
122#ifdef PDF_ENABLE_XFA
jaepark956553e2016-08-31 06:49:27 -0700123 if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET)
jaepark8c541822016-08-30 13:43:05 -0700124 return m_pXFAWidgetHandler.get();
jaepark35512aa2016-08-29 17:15:08 -0700125#endif // PDF_ENABLE_XFA
126
127 return m_pBAAnnotHandler.get();
jaepark98e10192016-08-15 10:51:11 -0700128}
129
130void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
131 CPDFSDK_Annot* pAnnot,
132 CFX_RenderDevice* pDevice,
Lei Zhang09ee0872018-10-09 19:13:55 +0000133 const CFX_Matrix& mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700134 bool bDrawAnnots) {
jaepark98e10192016-08-15 10:51:11 -0700135 ASSERT(pAnnot);
Lei Zhang09ee0872018-10-09 19:13:55 +0000136 GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device,
jaepark75f84a52016-09-09 15:39:09 -0700137 bDrawAnnots);
jaepark98e10192016-08-15 10:51:11 -0700138}
139
tsepez4cf55152016-11-02 14:37:54 -0700140bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700141 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000142 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700143 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500144 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000145 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700146 return GetAnnotHandler(pAnnot->Get())
147 ->OnLButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700148}
149
tsepez4cf55152016-11-02 14:37:54 -0700150bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700151 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000152 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700153 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500154 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000155 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700156 return GetAnnotHandler(pAnnot->Get())
157 ->OnLButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700158}
159
Lei Zhanga37989f2018-10-17 20:32:41 +0000160bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
161 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000162 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Lei Zhanga37989f2018-10-17 20:32:41 +0000163 uint32_t nFlags,
164 const CFX_PointF& point) {
165 ASSERT(pAnnot->HasObservable());
166 return GetAnnotHandler(pAnnot->Get())
167 ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
168}
169
tsepez4cf55152016-11-02 14:37:54 -0700170bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
jaepark98e10192016-08-15 10:51:11 -0700171 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000172 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700173 uint32_t nFlags,
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 ->OnMouseMove(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700178}
179
tsepez4cf55152016-11-02 14:37:54 -0700180bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
jaepark98e10192016-08-15 10:51:11 -0700181 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000182 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700183 uint32_t nFlags,
184 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500185 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000186 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700187 return GetAnnotHandler(pAnnot->Get())
188 ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700189}
190
tsepez4cf55152016-11-02 14:37:54 -0700191bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
jaepark98e10192016-08-15 10:51:11 -0700192 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000193 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700194 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500195 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000196 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700197 return GetAnnotHandler(pAnnot->Get())
198 ->OnRButtonDown(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700199}
200
tsepez4cf55152016-11-02 14:37:54 -0700201bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
jaepark98e10192016-08-15 10:51:11 -0700202 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000203 ObservedPtr<CPDFSDK_Annot>* pAnnot,
jaepark98e10192016-08-15 10:51:11 -0700204 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500205 const CFX_PointF& point) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000206 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700207 return GetAnnotHandler(pAnnot->Get())
208 ->OnRButtonUp(pPageView, pAnnot, nFlags, point);
jaepark98e10192016-08-15 10:51:11 -0700209}
210
tsepezf8074ce2016-09-27 14:29:57 -0700211void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(
212 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000213 ObservedPtr<CPDFSDK_Annot>* pAnnot,
tsepezf8074ce2016-09-27 14:29:57 -0700214 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000215 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700216 GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700217}
218
tsepezf8074ce2016-09-27 14:29:57 -0700219void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(
220 CPDFSDK_PageView* pPageView,
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000221 ObservedPtr<CPDFSDK_Annot>* pAnnot,
tsepezf8074ce2016-09-27 14:29:57 -0700222 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000223 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700224 GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700225}
226
tsepez4cf55152016-11-02 14:37:54 -0700227bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
228 uint32_t nChar,
229 uint32_t nFlags) {
jaepark35512aa2016-08-29 17:15:08 -0700230 return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
jaepark98e10192016-08-15 10:51:11 -0700231}
232
tsepez4cf55152016-11-02 14:37:54 -0700233bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
234 int nKeyCode,
235 int nFlag) {
Tom Sepez43f012f2019-08-02 16:16:46 +0000236 if (CPWL_Wnd::IsCTRLKeyDown(nFlag) || CPWL_Wnd::IsALTKeyDown(nFlag)) {
jaepark35512aa2016-08-29 17:15:08 -0700237 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
thestig7b3252f2016-11-08 21:30:11 -0800238 }
huyna6e3a4062019-07-25 20:41:23 +0000239 ObservedPtr<CPDFSDK_Annot> pObservedAnnot(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700240 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
241 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
242 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
Tom Sepez43f012f2019-08-02 16:16:46 +0000243 ObservedPtr<CPDFSDK_Annot> pNext(
244 GetNextAnnot(pFocusAnnot, !CPWL_Wnd::IsSHIFTKeyDown(nFlag)));
tsepezf8074ce2016-09-27 14:29:57 -0700245 if (pNext && pNext.Get() != pFocusAnnot) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700246 pPage->GetFormFillEnv()->SetFocusAnnot(&pNext);
tsepez4cf55152016-11-02 14:37:54 -0700247 return true;
jaepark98e10192016-08-15 10:51:11 -0700248 }
249 }
250
huyna6e3a4062019-07-25 20:41:23 +0000251 // Check |pAnnot| again because JS may have destroyed it in |GetNextAnnot|
252 if (!pObservedAnnot)
253 return false;
254
thestig7b3252f2016-11-08 21:30:11 -0800255 return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700256}
257
tsepez4cf55152016-11-02 14:37:54 -0700258bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(
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());
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(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000266 ObservedPtr<CPDFSDK_Annot>* pAnnot,
tsepezf8074ce2016-09-27 14:29:57 -0700267 uint32_t nFlag) {
Lei Zhangf0b7d592018-10-10 18:54:24 +0000268 ASSERT(pAnnot->HasObservable());
tsepezf8074ce2016-09-27 14:29:57 -0700269 return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag);
jaepark98e10192016-08-15 10:51:11 -0700270}
271
rycsmitha5230e22019-02-21 17:33:03 +0000272bool CPDFSDK_AnnotHandlerMgr::Annot_SetIndexSelected(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000273 ObservedPtr<CPDFSDK_Annot>* pAnnot,
rycsmitha5230e22019-02-21 17:33:03 +0000274 int index,
275 bool selected) {
276 return GetAnnotHandler(pAnnot->Get())
277 ->SetIndexSelected(pAnnot, index, selected);
278}
279
280bool CPDFSDK_AnnotHandlerMgr::Annot_IsIndexSelected(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000281 ObservedPtr<CPDFSDK_Annot>* pAnnot,
rycsmitha5230e22019-02-21 17:33:03 +0000282 int index) {
283 return GetAnnotHandler(pAnnot->Get())->IsIndexSelected(pAnnot, index);
284}
285
jaepark98e10192016-08-15 10:51:11 -0700286#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700287bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000288 ObservedPtr<CPDFSDK_Annot>* pSetAnnot,
289 ObservedPtr<CPDFSDK_Annot>* pKillAnnot) {
Tom Sepez451ed2d2019-08-19 22:55:31 +0000290 CPDFXFA_Widget* pSetXFAWidget = ToXFAWidget(pSetAnnot->Get());
291 CPDFXFA_Widget* pKillXFAWidget = ToXFAWidget(pKillAnnot->Get());
292 bool bXFA = (pSetXFAWidget && pSetXFAWidget->GetXFAFFWidget()) ||
293 (pKillXFAWidget && pKillXFAWidget->GetXFAFFWidget());
Tom Sepez49357702019-08-19 17:17:18 +0000294
295 return !bXFA || static_cast<CPDFXFA_WidgetHandler*>(m_pXFAWidgetHandler.get())
296 ->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
jaepark98e10192016-08-15 10:51:11 -0700297}
298#endif // PDF_ENABLE_XFA
299
300CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
301 CPDFSDK_PageView* pPageView,
302 CPDFSDK_Annot* pAnnot) {
303 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700304 return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot);
jaepark98e10192016-08-15 10:51:11 -0700305}
306
tsepez4cf55152016-11-02 14:37:54 -0700307bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
308 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500309 const CFX_PointF& point) {
jaepark98e10192016-08-15 10:51:11 -0700310 ASSERT(pAnnot);
jaepark35512aa2016-08-29 17:15:08 -0700311 IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
312 if (pAnnotHandler->CanAnswer(pAnnot))
313 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
314
tsepez4cf55152016-11-02 14:37:54 -0700315 return false;
jaepark98e10192016-08-15 10:51:11 -0700316}
317
318CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
tsepez4cf55152016-11-02 14:37:54 -0700319 bool bNext) {
jaepark98e10192016-08-15 10:51:11 -0700320#ifdef PDF_ENABLE_XFA
Tom Sepez9bf01812019-08-19 18:59:27 +0000321 IPDF_Page* pPage = pSDKAnnot->GetPageView()->GetXFAPage();
Tom Sepez8e631772018-06-13 21:26:56 +0000322 if (pPage && !pPage->AsPDFPage()) {
323 // For xfa annots in XFA pages not backed by PDF pages.
Tom Sepez9bf01812019-08-19 18:59:27 +0000324 return static_cast<CPDFXFA_Page*>(pPage)->GetNextXFAAnnot(pSDKAnnot, bNext);
Tom Sepez8e631772018-06-13 21:26:56 +0000325 }
jaepark98e10192016-08-15 10:51:11 -0700326#endif // PDF_ENABLE_XFA
Tom Sepez8e631772018-06-13 21:26:56 +0000327
328 // For PDF annots.
Tom Sepez11a6bec2018-07-25 23:25:55 +0000329 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot);
330 CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype());
331 return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget);
jaepark98e10192016-08-15 10:51:11 -0700332}