blob: c5d33d60a16a4c33a0697e4e8ee18ac89f174da8 [file] [log] [blame]
K. Moon832a6942022-10-31 20:11:31 +00001// Copyright 2016 The PDFium Authors
jaepark27362762016-08-11 13:10:39 -07002// 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_baannot.h"
jaepark27362762016-08-11 13:10:39 -07008
Lei Zhang76ef4c92022-04-08 19:03:51 +00009#include <vector>
10
Lei Zhang12885992019-02-02 00:29:49 +000011#include "constants/annotation_common.h"
Lei Zhang85549b42019-02-02 00:40:19 +000012#include "constants/annotation_flags.h"
Lei Zhang43705d72020-08-04 22:20:42 +000013#include "constants/form_fields.h"
dsinclair488b7ad2016-10-04 11:55:50 -070014#include "core/fpdfapi/parser/cpdf_array.h"
Lei Zhang81535612018-10-09 21:15:17 +000015#include "core/fpdfapi/parser/cpdf_dictionary.h"
tsepez0e606b52016-11-18 16:22:41 -080016#include "core/fpdfapi/parser/cpdf_name.h"
dsinclair488b7ad2016-10-04 11:55:50 -070017#include "core/fpdfapi/parser/cpdf_number.h"
tsepez0e606b52016-11-18 16:22:41 -080018#include "core/fpdfapi/parser/cpdf_reference.h"
dsinclair488b7ad2016-10-04 11:55:50 -070019#include "core/fpdfapi/parser/cpdf_stream.h"
tsepez0e606b52016-11-18 16:22:41 -080020#include "core/fpdfapi/parser/cpdf_string.h"
dsinclair488b7ad2016-10-04 11:55:50 -070021#include "core/fpdfapi/parser/fpdf_parser_decode.h"
Lei Zhangdeca6842022-03-17 01:50:07 +000022#include "core/fpdfapi/parser/fpdf_parser_utility.h"
Lei Zhang2ea512b2022-04-08 21:10:01 +000023#include "core/fxge/cfx_drawutils.h"
Lei Zhang2ea512b2022-04-08 21:10:01 +000024#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070025#include "fpdfsdk/cpdfsdk_pageview.h"
Tom Sepezaad1a842022-10-17 21:39:31 +000026#include "third_party/abseil-cpp/absl/types/optional.h"
Tom Sepez9c78c0d2021-01-27 20:13:14 +000027#include "third_party/base/check.h"
Lei Zhang2ea512b2022-04-08 21:10:01 +000028#include "third_party/base/containers/contains.h"
jaepark27362762016-08-11 13:10:39 -070029
30CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
31 CPDFSDK_PageView* pPageView)
32 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {}
33
Lei Zhang0e744a22020-06-02 00:44:28 +000034CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() = default;
jaepark27362762016-08-11 13:10:39 -070035
Tom Sepez522d77d2018-07-28 00:00:25 +000036CPDFSDK_BAAnnot* CPDFSDK_BAAnnot::AsBAAnnot() {
37 return this;
38}
39
Lei Zhang76ef4c92022-04-08 19:03:51 +000040CPDFSDK_Annot::UnsafeInputHandlers* CPDFSDK_BAAnnot::GetUnsafeInputHandlers() {
41 return this;
42}
43
jaepark27362762016-08-11 13:10:39 -070044CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
Tom Sepezc4acde52022-10-28 00:47:46 +000045 return m_pAnnot;
jaepark27362762016-08-11 13:10:39 -070046}
47
Tom Sepezb5649d92022-07-19 00:45:22 +000048const CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
jaepark27362762016-08-11 13:10:39 -070049 return m_pAnnot->GetAnnotDict();
50}
51
Tom Sepezb5649d92022-07-19 00:45:22 +000052RetainPtr<CPDF_Dictionary> CPDFSDK_BAAnnot::GetMutableAnnotDict() {
53 return m_pAnnot->GetMutableAnnotDict();
54}
55
56RetainPtr<CPDF_Dictionary> CPDFSDK_BAAnnot::GetAPDict() {
57 return GetMutableAnnotDict()->GetOrCreateDictFor(pdfium::annotation::kAP);
Dan Sinclaircb2ea422017-07-19 15:24:49 -040058}
59
Lei Zhang76ef4c92022-04-08 19:03:51 +000060void CPDFSDK_BAAnnot::ClearCachedAnnotAP() {
61 m_pAnnot->ClearCachedAP();
62}
63
Lei Zhang2ea512b2022-04-08 21:10:01 +000064bool CPDFSDK_BAAnnot::IsFocusableAnnot(
65 const CPDF_Annot::Subtype& annot_type) const {
66 return pdfium::Contains(
Tom Sepeza5af7872022-08-16 19:26:42 +000067 GetPageView()->GetFormFillEnv()->GetFocusableAnnotSubtypes(), annot_type);
Lei Zhang2ea512b2022-04-08 21:10:01 +000068}
69
jaepark27362762016-08-11 13:10:39 -070070CFX_FloatRect CPDFSDK_BAAnnot::GetRect() const {
jaeparka1d21112016-08-25 13:33:34 -070071 return m_pAnnot->GetRect();
jaepark27362762016-08-11 13:10:39 -070072}
73
jaepark956553e2016-08-31 06:49:27 -070074CPDF_Annot::Subtype CPDFSDK_BAAnnot::GetAnnotSubtype() const {
jaepark9ed91372016-08-26 16:16:10 -070075 return m_pAnnot->GetSubtype();
jaepark27362762016-08-11 13:10:39 -070076}
77
78void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
Lei Zhang8a449402017-08-17 15:07:47 -070079 const CFX_Matrix& mtUser2Device,
Tom Sepezaa0b2b92021-10-28 18:38:22 +000080 CPDF_Annot::AppearanceMode mode) {
Tom Sepeza5af7872022-08-16 19:26:42 +000081 m_pAnnot->DrawAppearance(GetPageView()->GetPDFPage(), pDevice, mtUser2Device,
Tom Sepezaa0b2b92021-10-28 18:38:22 +000082 mode);
jaepark27362762016-08-11 13:10:39 -070083}
84
tsepez4cf55152016-11-02 14:37:54 -070085bool CPDFSDK_BAAnnot::IsAppearanceValid() {
Lei Zhang12885992019-02-02 00:29:49 +000086 return !!GetAnnotDict()->GetDictFor(pdfium::annotation::kAP);
jaepark27362762016-08-11 13:10:39 -070087}
88
Ryan Harrison275e2602017-09-18 14:23:18 -040089void CPDFSDK_BAAnnot::SetAnnotName(const WideString& sName) {
Tom Sepezb5649d92022-07-19 00:45:22 +000090 RetainPtr<CPDF_Dictionary> pDict = GetMutableAnnotDict();
Tom Sepez9e802622022-03-18 20:44:15 +000091 if (sName.IsEmpty()) {
Tom Sepez84cce242019-05-06 19:32:59 +000092 pDict->RemoveFor(pdfium::annotation::kNM);
Tom Sepez9e802622022-03-18 20:44:15 +000093 return;
94 }
95 pDict->SetNewFor<CPDF_String>(pdfium::annotation::kNM, sName.AsStringView());
jaepark27362762016-08-11 13:10:39 -070096}
97
Ryan Harrison275e2602017-09-18 14:23:18 -040098WideString CPDFSDK_BAAnnot::GetAnnotName() const {
Lei Zhang12885992019-02-02 00:29:49 +000099 return GetAnnotDict()->GetUnicodeTextFor(pdfium::annotation::kNM);
jaepark27362762016-08-11 13:10:39 -0700100}
101
jaepark27362762016-08-11 13:10:39 -0700102void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) {
Tom Sepezb5649d92022-07-19 00:45:22 +0000103 GetMutableAnnotDict()->SetNewFor<CPDF_Number>(pdfium::annotation::kF,
104 static_cast<int>(nFlags));
jaepark27362762016-08-11 13:10:39 -0700105}
106
107uint32_t CPDFSDK_BAAnnot::GetFlags() const {
Lei Zhang12885992019-02-02 00:29:49 +0000108 return GetAnnotDict()->GetIntegerFor(pdfium::annotation::kF);
jaepark27362762016-08-11 13:10:39 -0700109}
110
Tom Sepeze45b8c72021-04-15 23:14:47 +0000111void CPDFSDK_BAAnnot::SetAppStateOff() {
Tom Sepezb5649d92022-07-19 00:45:22 +0000112 RetainPtr<CPDF_Dictionary> pDict = GetMutableAnnotDict();
Tom Sepeze45b8c72021-04-15 23:14:47 +0000113 pDict->SetNewFor<CPDF_String>(pdfium::annotation::kAS, "Off", false);
jaepark27362762016-08-11 13:10:39 -0700114}
115
Ryan Harrison275e2602017-09-18 14:23:18 -0400116ByteString CPDFSDK_BAAnnot::GetAppState() const {
Tom Sepez27151a62022-09-14 19:48:59 +0000117 return GetAnnotDict()->GetByteStringFor(pdfium::annotation::kAS);
jaepark27362762016-08-11 13:10:39 -0700118}
119
jaepark27362762016-08-11 13:10:39 -0700120void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
Tom Sepezb5649d92022-07-19 00:45:22 +0000121 RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDict();
Tom Sepez3d64afa2022-06-24 16:40:17 +0000122 RetainPtr<CPDF_Array> pBorder =
Tom Sepezc153a822022-06-30 21:37:02 +0000123 pAnnotDict->GetMutableArrayFor(pdfium::annotation::kBorder);
jaepark27362762016-08-11 13:10:39 -0700124 if (pBorder) {
tsepez8a3aa452016-11-16 12:26:06 -0800125 pBorder->SetNewAt<CPDF_Number>(2, nWidth);
Tom Sepezc153a822022-06-30 21:37:02 +0000126 return;
jaepark27362762016-08-11 13:10:39 -0700127 }
Tom Sepezc153a822022-06-30 21:37:02 +0000128 pAnnotDict->GetOrCreateDictFor("BS")->SetNewFor<CPDF_Number>("W", nWidth);
jaepark27362762016-08-11 13:10:39 -0700129}
130
131int CPDFSDK_BAAnnot::GetBorderWidth() const {
Tom Sepezc84dc1f2022-09-19 23:06:33 +0000132 RetainPtr<const CPDF_Array> pBorder =
Tom Sepez3d64afa2022-06-24 16:40:17 +0000133 GetAnnotDict()->GetArrayFor(pdfium::annotation::kBorder);
134 if (pBorder)
jaepark27362762016-08-11 13:10:39 -0700135 return pBorder->GetIntegerAt(2);
tsepez698c5712016-09-28 16:47:07 -0700136
Tom Sepez5313f922022-09-20 18:17:45 +0000137 RetainPtr<const CPDF_Dictionary> pBSDict = GetAnnotDict()->GetDictFor("BS");
Tom Sepez3d64afa2022-06-24 16:40:17 +0000138 if (pBSDict)
dsinclair38fd8442016-09-15 10:15:32 -0700139 return pBSDict->GetIntegerFor("W", 1);
tsepez698c5712016-09-28 16:47:07 -0700140
jaepark27362762016-08-11 13:10:39 -0700141 return 1;
142}
143
144void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) {
Tom Sepezb5649d92022-07-19 00:45:22 +0000145 RetainPtr<CPDF_Dictionary> pBSDict =
146 GetMutableAnnotDict()->GetOrCreateDictFor("BS");
Tom Sepez45348342018-11-15 22:22:00 +0000147 const char* name = nullptr;
jaepark27362762016-08-11 13:10:39 -0700148 switch (nStyle) {
Lei Zhang99f44ba2020-06-18 17:41:38 +0000149 case BorderStyle::kSolid:
Tom Sepez45348342018-11-15 22:22:00 +0000150 name = "S";
jaepark27362762016-08-11 13:10:39 -0700151 break;
Lei Zhang99f44ba2020-06-18 17:41:38 +0000152 case BorderStyle::kDash:
Tom Sepez45348342018-11-15 22:22:00 +0000153 name = "D";
jaepark27362762016-08-11 13:10:39 -0700154 break;
Lei Zhang99f44ba2020-06-18 17:41:38 +0000155 case BorderStyle::kBeveled:
Tom Sepez45348342018-11-15 22:22:00 +0000156 name = "B";
jaepark27362762016-08-11 13:10:39 -0700157 break;
Lei Zhang99f44ba2020-06-18 17:41:38 +0000158 case BorderStyle::kInset:
Tom Sepez45348342018-11-15 22:22:00 +0000159 name = "I";
jaepark27362762016-08-11 13:10:39 -0700160 break;
Lei Zhang99f44ba2020-06-18 17:41:38 +0000161 case BorderStyle::kUnderline:
Tom Sepez45348342018-11-15 22:22:00 +0000162 name = "U";
jaepark27362762016-08-11 13:10:39 -0700163 break;
jaepark27362762016-08-11 13:10:39 -0700164 }
Tom Sepez45348342018-11-15 22:22:00 +0000165 pBSDict->SetNewFor<CPDF_Name>("S", name);
jaepark27362762016-08-11 13:10:39 -0700166}
167
168BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
Tom Sepez5313f922022-09-20 18:17:45 +0000169 RetainPtr<const CPDF_Dictionary> pBSDict = GetAnnotDict()->GetDictFor("BS");
jaepark27362762016-08-11 13:10:39 -0700170 if (pBSDict) {
Tom Sepez27151a62022-09-14 19:48:59 +0000171 ByteString sBorderStyle = pBSDict->GetByteStringFor("S", "S");
jaepark27362762016-08-11 13:10:39 -0700172 if (sBorderStyle == "S")
Lei Zhang99f44ba2020-06-18 17:41:38 +0000173 return BorderStyle::kSolid;
jaepark27362762016-08-11 13:10:39 -0700174 if (sBorderStyle == "D")
Lei Zhang99f44ba2020-06-18 17:41:38 +0000175 return BorderStyle::kDash;
jaepark27362762016-08-11 13:10:39 -0700176 if (sBorderStyle == "B")
Lei Zhang99f44ba2020-06-18 17:41:38 +0000177 return BorderStyle::kBeveled;
jaepark27362762016-08-11 13:10:39 -0700178 if (sBorderStyle == "I")
Lei Zhang99f44ba2020-06-18 17:41:38 +0000179 return BorderStyle::kInset;
jaepark27362762016-08-11 13:10:39 -0700180 if (sBorderStyle == "U")
Lei Zhang99f44ba2020-06-18 17:41:38 +0000181 return BorderStyle::kUnderline;
jaepark27362762016-08-11 13:10:39 -0700182 }
183
Tom Sepezc84dc1f2022-09-19 23:06:33 +0000184 RetainPtr<const CPDF_Array> pBorder =
Lei Zhang12885992019-02-02 00:29:49 +0000185 GetAnnotDict()->GetArrayFor(pdfium::annotation::kBorder);
jaepark27362762016-08-11 13:10:39 -0700186 if (pBorder) {
Lei Zhangf40380f2018-10-12 18:31:51 +0000187 if (pBorder->size() >= 4) {
Tom Sepezcf282022022-09-07 01:09:52 +0000188 RetainPtr<const CPDF_Array> pDP = pBorder->GetArrayAt(3);
Lei Zhangf40380f2018-10-12 18:31:51 +0000189 if (pDP && pDP->size() > 0)
Lei Zhang99f44ba2020-06-18 17:41:38 +0000190 return BorderStyle::kDash;
jaepark27362762016-08-11 13:10:39 -0700191 }
192 }
193
Lei Zhang99f44ba2020-06-18 17:41:38 +0000194 return BorderStyle::kSolid;
jaepark27362762016-08-11 13:10:39 -0700195}
196
tsepez4cf55152016-11-02 14:37:54 -0700197bool CPDFSDK_BAAnnot::IsVisible() const {
jaepark27362762016-08-11 13:10:39 -0700198 uint32_t nFlags = GetFlags();
Lei Zhang85549b42019-02-02 00:40:19 +0000199 return !((nFlags & pdfium::annotation_flags::kInvisible) ||
200 (nFlags & pdfium::annotation_flags::kHidden) ||
201 (nFlags & pdfium::annotation_flags::kNoView));
jaepark27362762016-08-11 13:10:39 -0700202}
203
204CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
Tom Sepezaf0fcf12022-09-27 18:12:53 +0000205 return CPDF_Action(GetAnnotDict()->GetDictFor("A"));
jaepark27362762016-08-11 13:10:39 -0700206}
207
jaepark27362762016-08-11 13:10:39 -0700208CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
Tom Sepezb01b2cd2022-09-30 00:55:15 +0000209 return CPDF_AAction(GetAnnotDict()->GetDictFor(pdfium::form_fields::kAA));
jaepark27362762016-08-11 13:10:39 -0700210}
211
jaepark27362762016-08-11 13:10:39 -0700212CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
213 CPDF_AAction AAction = GetAAction();
jaepark27362762016-08-11 13:10:39 -0700214 if (AAction.ActionExist(eAAT))
215 return AAction.GetAction(eAAT);
216
Badhri Ravikumardacaac72020-04-23 18:00:38 +0000217 if (eAAT == CPDF_AAction::kButtonUp || eAAT == CPDF_AAction::kKeyStroke)
jaepark27362762016-08-11 13:10:39 -0700218 return GetAction();
219
Lei Zhang4ecf9a82017-12-11 14:34:58 +0000220 return CPDF_Action(nullptr);
jaepark27362762016-08-11 13:10:39 -0700221}
222
jaepark35512aa2016-08-29 17:15:08 -0700223void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) {
Tom Sepezaad1a842022-10-17 21:39:31 +0000224 m_pAnnot->SetPopupAnnotOpenState(bOpenState);
jaepark35512aa2016-08-29 17:15:08 -0700225}
Henrique Nakashima89bf9ce2017-09-19 16:45:10 -0400226
Lei Zhang76ef4c92022-04-08 19:03:51 +0000227void CPDFSDK_BAAnnot::UpdateAnnotRects() {
228 std::vector<CFX_FloatRect> rects;
229 rects.push_back(GetRect());
Tom Sepezaad1a842022-10-17 21:39:31 +0000230
231 absl::optional<CFX_FloatRect> annot_rect = m_pAnnot->GetPopupAnnotRect();
232 if (annot_rect.has_value())
233 rects.push_back(annot_rect.value());
Lei Zhang76ef4c92022-04-08 19:03:51 +0000234
235 // Make the rects round up to avoid https://crbug.com/662804
236 for (CFX_FloatRect& rect : rects)
237 rect.Inflate(1, 1);
238
239 GetPageView()->UpdateRects(rects);
240}
241
Lei Zhang2ea512b2022-04-08 21:10:01 +0000242void CPDFSDK_BAAnnot::InvalidateRect() {
243 CFX_FloatRect view_bounding_box = GetViewBBox();
244 if (view_bounding_box.IsEmpty())
245 return;
246
247 view_bounding_box.Inflate(1, 1);
248 view_bounding_box.Normalize();
249 FX_RECT rect = view_bounding_box.GetOuterRect();
Tom Sepeza5af7872022-08-16 19:26:42 +0000250 GetPageView()->GetFormFillEnv()->Invalidate(GetPage(), rect);
Lei Zhang2ea512b2022-04-08 21:10:01 +0000251}
252
Henrique Nakashima89bf9ce2017-09-19 16:45:10 -0400253int CPDFSDK_BAAnnot::GetLayoutOrder() const {
254 if (m_pAnnot->GetSubtype() == CPDF_Annot::Subtype::POPUP)
255 return 1;
256
257 return CPDFSDK_Annot::GetLayoutOrder();
258}
Badhri Ravikumarf5cc1ac2020-04-30 19:00:55 +0000259
Lei Zhang2ea512b2022-04-08 21:10:01 +0000260void CPDFSDK_BAAnnot::OnDraw(CFX_RenderDevice* pDevice,
261 const CFX_Matrix& mtUser2Device,
262 bool bDrawAnnots) {
263 if (!IsVisible())
264 return;
265
266 const CPDF_Annot::Subtype annot_type = GetAnnotSubtype();
267 if (bDrawAnnots && annot_type == CPDF_Annot::Subtype::POPUP) {
268 DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::AppearanceMode::kNormal);
269 return;
270 }
271
272 if (!is_focused_ || !IsFocusableAnnot(annot_type) ||
Tom Sepeza5af7872022-08-16 19:26:42 +0000273 this != GetPageView()->GetFormFillEnv()->GetFocusAnnot()) {
Lei Zhang2ea512b2022-04-08 21:10:01 +0000274 return;
275 }
276
277 CFX_FloatRect view_bounding_box = GetViewBBox();
278 if (view_bounding_box.IsEmpty())
279 return;
280
281 view_bounding_box.Normalize();
282 CFX_DrawUtils::DrawFocusRect(pDevice, mtUser2Device, view_bounding_box);
283}
284
Lei Zhang37cef932022-04-05 18:23:29 +0000285bool CPDFSDK_BAAnnot::DoHitTest(const CFX_PointF& point) {
286 return false;
287}
288
Lei Zhang23a042f2022-04-05 23:45:19 +0000289CFX_FloatRect CPDFSDK_BAAnnot::GetViewBBox() {
290 return GetRect();
291}
292
Lei Zhang76ef4c92022-04-08 19:03:51 +0000293void CPDFSDK_BAAnnot::OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) {
294 SetOpenState(true);
295 UpdateAnnotRects();
296}
297
298void CPDFSDK_BAAnnot::OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) {
299 SetOpenState(false);
300 UpdateAnnotRects();
301}
302
303bool CPDFSDK_BAAnnot::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
304 const CFX_PointF& point) {
305 return false;
306}
307
308bool CPDFSDK_BAAnnot::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
309 const CFX_PointF& point) {
310 return false;
311}
312
313bool CPDFSDK_BAAnnot::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
314 const CFX_PointF& point) {
315 return false;
316}
317
318bool CPDFSDK_BAAnnot::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
319 const CFX_PointF& point) {
320 return false;
321}
322
323bool CPDFSDK_BAAnnot::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
324 const CFX_PointF& point,
325 const CFX_Vector& delta) {
326 return false;
327}
328
329bool CPDFSDK_BAAnnot::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
330 const CFX_PointF& point) {
331 return false;
332}
333
334bool CPDFSDK_BAAnnot::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
335 const CFX_PointF& point) {
336 return false;
337}
338
Lei Zhang2ea512b2022-04-08 21:10:01 +0000339bool CPDFSDK_BAAnnot::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
340 return false;
341}
342
343bool CPDFSDK_BAAnnot::OnKeyDown(FWL_VKEYCODE nKeyCode,
344 Mask<FWL_EVENTFLAG> nFlags) {
345 // OnKeyDown() is implemented only for link annotations for now. As
346 // OnKeyDown() is implemented for other subtypes, following check should be
347 // modified.
348 if (nKeyCode != FWL_VKEY_Return ||
349 GetAnnotSubtype() != CPDF_Annot::Subtype::LINK) {
350 return false;
351 }
352
353 CPDF_Action action = GetAAction(CPDF_AAction::kKeyStroke);
Tom Sepeza5af7872022-08-16 19:26:42 +0000354 CPDFSDK_FormFillEnvironment* env = GetPageView()->GetFormFillEnv();
Tom Sepez05332a82022-10-05 21:37:45 +0000355 if (action.HasDict()) {
Tom Sepez946bf0f2022-04-08 22:06:41 +0000356 return env->DoActionLink(action, CPDF_AAction::kKeyStroke, nFlags);
Lei Zhang2ea512b2022-04-08 21:10:01 +0000357 }
358
Tom Sepez946bf0f2022-04-08 22:06:41 +0000359 return env->DoActionDestination(GetDestination());
Lei Zhang2ea512b2022-04-08 21:10:01 +0000360}
361
362bool CPDFSDK_BAAnnot::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) {
363 if (!IsFocusableAnnot(GetAnnotSubtype()))
364 return false;
365
366 is_focused_ = true;
367 InvalidateRect();
368 return true;
369}
370
371bool CPDFSDK_BAAnnot::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) {
372 if (!IsFocusableAnnot(GetAnnotSubtype()))
373 return false;
374
375 is_focused_ = false;
376 InvalidateRect();
377 return true;
378}
379
Lei Zhangf342da72022-04-06 23:54:50 +0000380bool CPDFSDK_BAAnnot::CanUndo() {
381 return false;
382}
383
384bool CPDFSDK_BAAnnot::CanRedo() {
385 return false;
386}
387
388bool CPDFSDK_BAAnnot::Undo() {
389 return false;
390}
391
392bool CPDFSDK_BAAnnot::Redo() {
393 return false;
394}
395
Lei Zhang889fce72022-04-08 21:13:51 +0000396WideString CPDFSDK_BAAnnot::GetText() {
397 return WideString();
398}
399
400WideString CPDFSDK_BAAnnot::GetSelectedText() {
401 return WideString();
402}
403
Keren Zhu74e7eb72023-01-19 19:21:41 +0000404void CPDFSDK_BAAnnot::ReplaceAndKeepSelection(const WideString& text) {}
405
Lei Zhang889fce72022-04-08 21:13:51 +0000406void CPDFSDK_BAAnnot::ReplaceSelection(const WideString& text) {}
407
408bool CPDFSDK_BAAnnot::SelectAllText() {
409 return false;
410}
411
412bool CPDFSDK_BAAnnot::SetIndexSelected(int index, bool selected) {
413 return false;
414}
415
416bool CPDFSDK_BAAnnot::IsIndexSelected(int index) {
417 return false;
418}
419
Badhri Ravikumarf5cc1ac2020-04-30 19:00:55 +0000420CPDF_Dest CPDFSDK_BAAnnot::GetDestination() const {
421 if (m_pAnnot->GetSubtype() != CPDF_Annot::Subtype::LINK)
Lei Zhange782e372020-05-11 21:47:38 +0000422 return CPDF_Dest(nullptr);
Badhri Ravikumarf5cc1ac2020-04-30 19:00:55 +0000423
424 // Link annotations can have "Dest" entry defined as an explicit array.
Lei Zhang87f35282021-10-18 05:03:08 +0000425 // See ISO 32000-1:2008 spec, section 12.3.2.1.
Tom Sepeza5af7872022-08-16 19:26:42 +0000426 return CPDF_Dest::Create(GetPageView()->GetPDFDocument(),
Badhri Ravikumarf5cc1ac2020-04-30 19:00:55 +0000427 GetAnnotDict()->GetDirectObjectFor("Dest"));
Lei Zhange782e372020-05-11 21:47:38 +0000428}