K. Moon | 832a694 | 2022-10-31 20:11:31 +0000 | [diff] [blame] | 1 | // Copyright 2016 The PDFium Authors |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_baannot.h" |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 8 | |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Lei Zhang | 1288599 | 2019-02-02 00:29:49 +0000 | [diff] [blame] | 11 | #include "constants/annotation_common.h" |
Lei Zhang | 85549b4 | 2019-02-02 00:40:19 +0000 | [diff] [blame] | 12 | #include "constants/annotation_flags.h" |
Lei Zhang | 43705d7 | 2020-08-04 22:20:42 +0000 | [diff] [blame] | 13 | #include "constants/form_fields.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_array.h" |
Lei Zhang | 8153561 | 2018-10-09 21:15:17 +0000 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_name.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 17 | #include "core/fpdfapi/parser/cpdf_number.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 18 | #include "core/fpdfapi/parser/cpdf_reference.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 19 | #include "core/fpdfapi/parser/cpdf_stream.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 20 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 21 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
Lei Zhang | deca684 | 2022-03-17 01:50:07 +0000 | [diff] [blame] | 22 | #include "core/fpdfapi/parser/fpdf_parser_utility.h" |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 23 | #include "core/fxge/cfx_drawutils.h" |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 24 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 25 | #include "fpdfsdk/cpdfsdk_pageview.h" |
Tom Sepez | aad1a84 | 2022-10-17 21:39:31 +0000 | [diff] [blame] | 26 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Tom Sepez | 9c78c0d | 2021-01-27 20:13:14 +0000 | [diff] [blame] | 27 | #include "third_party/base/check.h" |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 28 | #include "third_party/base/containers/contains.h" |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 29 | |
| 30 | CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, |
| 31 | CPDFSDK_PageView* pPageView) |
| 32 | : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {} |
| 33 | |
Lei Zhang | 0e744a2 | 2020-06-02 00:44:28 +0000 | [diff] [blame] | 34 | CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() = default; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 35 | |
Tom Sepez | 522d77d | 2018-07-28 00:00:25 +0000 | [diff] [blame] | 36 | CPDFSDK_BAAnnot* CPDFSDK_BAAnnot::AsBAAnnot() { |
| 37 | return this; |
| 38 | } |
| 39 | |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 40 | CPDFSDK_Annot::UnsafeInputHandlers* CPDFSDK_BAAnnot::GetUnsafeInputHandlers() { |
| 41 | return this; |
| 42 | } |
| 43 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 44 | CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const { |
Tom Sepez | c4acde5 | 2022-10-28 00:47:46 +0000 | [diff] [blame] | 45 | return m_pAnnot; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Tom Sepez | b5649d9 | 2022-07-19 00:45:22 +0000 | [diff] [blame] | 48 | const CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 49 | return m_pAnnot->GetAnnotDict(); |
| 50 | } |
| 51 | |
Tom Sepez | b5649d9 | 2022-07-19 00:45:22 +0000 | [diff] [blame] | 52 | RetainPtr<CPDF_Dictionary> CPDFSDK_BAAnnot::GetMutableAnnotDict() { |
| 53 | return m_pAnnot->GetMutableAnnotDict(); |
| 54 | } |
| 55 | |
| 56 | RetainPtr<CPDF_Dictionary> CPDFSDK_BAAnnot::GetAPDict() { |
| 57 | return GetMutableAnnotDict()->GetOrCreateDictFor(pdfium::annotation::kAP); |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 60 | void CPDFSDK_BAAnnot::ClearCachedAnnotAP() { |
| 61 | m_pAnnot->ClearCachedAP(); |
| 62 | } |
| 63 | |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 64 | bool CPDFSDK_BAAnnot::IsFocusableAnnot( |
| 65 | const CPDF_Annot::Subtype& annot_type) const { |
| 66 | return pdfium::Contains( |
Tom Sepez | a5af787 | 2022-08-16 19:26:42 +0000 | [diff] [blame] | 67 | GetPageView()->GetFormFillEnv()->GetFocusableAnnotSubtypes(), annot_type); |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 68 | } |
| 69 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 70 | CFX_FloatRect CPDFSDK_BAAnnot::GetRect() const { |
jaepark | a1d2111 | 2016-08-25 13:33:34 -0700 | [diff] [blame] | 71 | return m_pAnnot->GetRect(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 72 | } |
| 73 | |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 74 | CPDF_Annot::Subtype CPDFSDK_BAAnnot::GetAnnotSubtype() const { |
jaepark | 9ed9137 | 2016-08-26 16:16:10 -0700 | [diff] [blame] | 75 | return m_pAnnot->GetSubtype(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 79 | const CFX_Matrix& mtUser2Device, |
Tom Sepez | aa0b2b9 | 2021-10-28 18:38:22 +0000 | [diff] [blame] | 80 | CPDF_Annot::AppearanceMode mode) { |
Tom Sepez | a5af787 | 2022-08-16 19:26:42 +0000 | [diff] [blame] | 81 | m_pAnnot->DrawAppearance(GetPageView()->GetPDFPage(), pDevice, mtUser2Device, |
Tom Sepez | aa0b2b9 | 2021-10-28 18:38:22 +0000 | [diff] [blame] | 82 | mode); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 83 | } |
| 84 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 85 | bool CPDFSDK_BAAnnot::IsAppearanceValid() { |
Lei Zhang | 1288599 | 2019-02-02 00:29:49 +0000 | [diff] [blame] | 86 | return !!GetAnnotDict()->GetDictFor(pdfium::annotation::kAP); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 89 | void CPDFSDK_BAAnnot::SetAnnotName(const WideString& sName) { |
Tom Sepez | b5649d9 | 2022-07-19 00:45:22 +0000 | [diff] [blame] | 90 | RetainPtr<CPDF_Dictionary> pDict = GetMutableAnnotDict(); |
Tom Sepez | 9e80262 | 2022-03-18 20:44:15 +0000 | [diff] [blame] | 91 | if (sName.IsEmpty()) { |
Tom Sepez | 84cce24 | 2019-05-06 19:32:59 +0000 | [diff] [blame] | 92 | pDict->RemoveFor(pdfium::annotation::kNM); |
Tom Sepez | 9e80262 | 2022-03-18 20:44:15 +0000 | [diff] [blame] | 93 | return; |
| 94 | } |
| 95 | pDict->SetNewFor<CPDF_String>(pdfium::annotation::kNM, sName.AsStringView()); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 98 | WideString CPDFSDK_BAAnnot::GetAnnotName() const { |
Lei Zhang | 1288599 | 2019-02-02 00:29:49 +0000 | [diff] [blame] | 99 | return GetAnnotDict()->GetUnicodeTextFor(pdfium::annotation::kNM); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 100 | } |
| 101 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 102 | void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) { |
Tom Sepez | b5649d9 | 2022-07-19 00:45:22 +0000 | [diff] [blame] | 103 | GetMutableAnnotDict()->SetNewFor<CPDF_Number>(pdfium::annotation::kF, |
| 104 | static_cast<int>(nFlags)); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | uint32_t CPDFSDK_BAAnnot::GetFlags() const { |
Lei Zhang | 1288599 | 2019-02-02 00:29:49 +0000 | [diff] [blame] | 108 | return GetAnnotDict()->GetIntegerFor(pdfium::annotation::kF); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Tom Sepez | e45b8c7 | 2021-04-15 23:14:47 +0000 | [diff] [blame] | 111 | void CPDFSDK_BAAnnot::SetAppStateOff() { |
Tom Sepez | b5649d9 | 2022-07-19 00:45:22 +0000 | [diff] [blame] | 112 | RetainPtr<CPDF_Dictionary> pDict = GetMutableAnnotDict(); |
Tom Sepez | e45b8c7 | 2021-04-15 23:14:47 +0000 | [diff] [blame] | 113 | pDict->SetNewFor<CPDF_String>(pdfium::annotation::kAS, "Off", false); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 116 | ByteString CPDFSDK_BAAnnot::GetAppState() const { |
Tom Sepez | 27151a6 | 2022-09-14 19:48:59 +0000 | [diff] [blame] | 117 | return GetAnnotDict()->GetByteStringFor(pdfium::annotation::kAS); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 118 | } |
| 119 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 120 | void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) { |
Tom Sepez | b5649d9 | 2022-07-19 00:45:22 +0000 | [diff] [blame] | 121 | RetainPtr<CPDF_Dictionary> pAnnotDict = GetMutableAnnotDict(); |
Tom Sepez | 3d64afa | 2022-06-24 16:40:17 +0000 | [diff] [blame] | 122 | RetainPtr<CPDF_Array> pBorder = |
Tom Sepez | c153a82 | 2022-06-30 21:37:02 +0000 | [diff] [blame] | 123 | pAnnotDict->GetMutableArrayFor(pdfium::annotation::kBorder); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 124 | if (pBorder) { |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 125 | pBorder->SetNewAt<CPDF_Number>(2, nWidth); |
Tom Sepez | c153a82 | 2022-06-30 21:37:02 +0000 | [diff] [blame] | 126 | return; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 127 | } |
Tom Sepez | c153a82 | 2022-06-30 21:37:02 +0000 | [diff] [blame] | 128 | pAnnotDict->GetOrCreateDictFor("BS")->SetNewFor<CPDF_Number>("W", nWidth); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | int CPDFSDK_BAAnnot::GetBorderWidth() const { |
Tom Sepez | c84dc1f | 2022-09-19 23:06:33 +0000 | [diff] [blame] | 132 | RetainPtr<const CPDF_Array> pBorder = |
Tom Sepez | 3d64afa | 2022-06-24 16:40:17 +0000 | [diff] [blame] | 133 | GetAnnotDict()->GetArrayFor(pdfium::annotation::kBorder); |
| 134 | if (pBorder) |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 135 | return pBorder->GetIntegerAt(2); |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 136 | |
Tom Sepez | 5313f92 | 2022-09-20 18:17:45 +0000 | [diff] [blame] | 137 | RetainPtr<const CPDF_Dictionary> pBSDict = GetAnnotDict()->GetDictFor("BS"); |
Tom Sepez | 3d64afa | 2022-06-24 16:40:17 +0000 | [diff] [blame] | 138 | if (pBSDict) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 139 | return pBSDict->GetIntegerFor("W", 1); |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 140 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 141 | return 1; |
| 142 | } |
| 143 | |
| 144 | void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) { |
Tom Sepez | b5649d9 | 2022-07-19 00:45:22 +0000 | [diff] [blame] | 145 | RetainPtr<CPDF_Dictionary> pBSDict = |
| 146 | GetMutableAnnotDict()->GetOrCreateDictFor("BS"); |
Tom Sepez | 4534834 | 2018-11-15 22:22:00 +0000 | [diff] [blame] | 147 | const char* name = nullptr; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 148 | switch (nStyle) { |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 149 | case BorderStyle::kSolid: |
Tom Sepez | 4534834 | 2018-11-15 22:22:00 +0000 | [diff] [blame] | 150 | name = "S"; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 151 | break; |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 152 | case BorderStyle::kDash: |
Tom Sepez | 4534834 | 2018-11-15 22:22:00 +0000 | [diff] [blame] | 153 | name = "D"; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 154 | break; |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 155 | case BorderStyle::kBeveled: |
Tom Sepez | 4534834 | 2018-11-15 22:22:00 +0000 | [diff] [blame] | 156 | name = "B"; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 157 | break; |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 158 | case BorderStyle::kInset: |
Tom Sepez | 4534834 | 2018-11-15 22:22:00 +0000 | [diff] [blame] | 159 | name = "I"; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 160 | break; |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 161 | case BorderStyle::kUnderline: |
Tom Sepez | 4534834 | 2018-11-15 22:22:00 +0000 | [diff] [blame] | 162 | name = "U"; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 163 | break; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 164 | } |
Tom Sepez | 4534834 | 2018-11-15 22:22:00 +0000 | [diff] [blame] | 165 | pBSDict->SetNewFor<CPDF_Name>("S", name); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const { |
Tom Sepez | 5313f92 | 2022-09-20 18:17:45 +0000 | [diff] [blame] | 169 | RetainPtr<const CPDF_Dictionary> pBSDict = GetAnnotDict()->GetDictFor("BS"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 170 | if (pBSDict) { |
Tom Sepez | 27151a6 | 2022-09-14 19:48:59 +0000 | [diff] [blame] | 171 | ByteString sBorderStyle = pBSDict->GetByteStringFor("S", "S"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 172 | if (sBorderStyle == "S") |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 173 | return BorderStyle::kSolid; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 174 | if (sBorderStyle == "D") |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 175 | return BorderStyle::kDash; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 176 | if (sBorderStyle == "B") |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 177 | return BorderStyle::kBeveled; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 178 | if (sBorderStyle == "I") |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 179 | return BorderStyle::kInset; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 180 | if (sBorderStyle == "U") |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 181 | return BorderStyle::kUnderline; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Tom Sepez | c84dc1f | 2022-09-19 23:06:33 +0000 | [diff] [blame] | 184 | RetainPtr<const CPDF_Array> pBorder = |
Lei Zhang | 1288599 | 2019-02-02 00:29:49 +0000 | [diff] [blame] | 185 | GetAnnotDict()->GetArrayFor(pdfium::annotation::kBorder); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 186 | if (pBorder) { |
Lei Zhang | f40380f | 2018-10-12 18:31:51 +0000 | [diff] [blame] | 187 | if (pBorder->size() >= 4) { |
Tom Sepez | cf28202 | 2022-09-07 01:09:52 +0000 | [diff] [blame] | 188 | RetainPtr<const CPDF_Array> pDP = pBorder->GetArrayAt(3); |
Lei Zhang | f40380f | 2018-10-12 18:31:51 +0000 | [diff] [blame] | 189 | if (pDP && pDP->size() > 0) |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 190 | return BorderStyle::kDash; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Lei Zhang | 99f44ba | 2020-06-18 17:41:38 +0000 | [diff] [blame] | 194 | return BorderStyle::kSolid; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 195 | } |
| 196 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 197 | bool CPDFSDK_BAAnnot::IsVisible() const { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 198 | uint32_t nFlags = GetFlags(); |
Lei Zhang | 85549b4 | 2019-02-02 00:40:19 +0000 | [diff] [blame] | 199 | return !((nFlags & pdfium::annotation_flags::kInvisible) || |
| 200 | (nFlags & pdfium::annotation_flags::kHidden) || |
| 201 | (nFlags & pdfium::annotation_flags::kNoView)); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | CPDF_Action CPDFSDK_BAAnnot::GetAction() const { |
Tom Sepez | af0fcf1 | 2022-09-27 18:12:53 +0000 | [diff] [blame] | 205 | return CPDF_Action(GetAnnotDict()->GetDictFor("A")); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 206 | } |
| 207 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 208 | CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const { |
Tom Sepez | b01b2cd | 2022-09-30 00:55:15 +0000 | [diff] [blame] | 209 | return CPDF_AAction(GetAnnotDict()->GetDictFor(pdfium::form_fields::kAA)); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 210 | } |
| 211 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 212 | CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 213 | CPDF_AAction AAction = GetAAction(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 214 | if (AAction.ActionExist(eAAT)) |
| 215 | return AAction.GetAction(eAAT); |
| 216 | |
Badhri Ravikumar | dacaac7 | 2020-04-23 18:00:38 +0000 | [diff] [blame] | 217 | if (eAAT == CPDF_AAction::kButtonUp || eAAT == CPDF_AAction::kKeyStroke) |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 218 | return GetAction(); |
| 219 | |
Lei Zhang | 4ecf9a8 | 2017-12-11 14:34:58 +0000 | [diff] [blame] | 220 | return CPDF_Action(nullptr); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 221 | } |
| 222 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 223 | void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { |
Tom Sepez | aad1a84 | 2022-10-17 21:39:31 +0000 | [diff] [blame] | 224 | m_pAnnot->SetPopupAnnotOpenState(bOpenState); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 225 | } |
Henrique Nakashima | 89bf9ce | 2017-09-19 16:45:10 -0400 | [diff] [blame] | 226 | |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 227 | void CPDFSDK_BAAnnot::UpdateAnnotRects() { |
| 228 | std::vector<CFX_FloatRect> rects; |
| 229 | rects.push_back(GetRect()); |
Tom Sepez | aad1a84 | 2022-10-17 21:39:31 +0000 | [diff] [blame] | 230 | |
| 231 | absl::optional<CFX_FloatRect> annot_rect = m_pAnnot->GetPopupAnnotRect(); |
| 232 | if (annot_rect.has_value()) |
| 233 | rects.push_back(annot_rect.value()); |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 234 | |
| 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 Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 242 | void 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 Sepez | a5af787 | 2022-08-16 19:26:42 +0000 | [diff] [blame] | 250 | GetPageView()->GetFormFillEnv()->Invalidate(GetPage(), rect); |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Henrique Nakashima | 89bf9ce | 2017-09-19 16:45:10 -0400 | [diff] [blame] | 253 | int CPDFSDK_BAAnnot::GetLayoutOrder() const { |
| 254 | if (m_pAnnot->GetSubtype() == CPDF_Annot::Subtype::POPUP) |
| 255 | return 1; |
| 256 | |
| 257 | return CPDFSDK_Annot::GetLayoutOrder(); |
| 258 | } |
Badhri Ravikumar | f5cc1ac | 2020-04-30 19:00:55 +0000 | [diff] [blame] | 259 | |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 260 | void 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 Sepez | a5af787 | 2022-08-16 19:26:42 +0000 | [diff] [blame] | 273 | this != GetPageView()->GetFormFillEnv()->GetFocusAnnot()) { |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 274 | 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 Zhang | 37cef93 | 2022-04-05 18:23:29 +0000 | [diff] [blame] | 285 | bool CPDFSDK_BAAnnot::DoHitTest(const CFX_PointF& point) { |
| 286 | return false; |
| 287 | } |
| 288 | |
Lei Zhang | 23a042f | 2022-04-05 23:45:19 +0000 | [diff] [blame] | 289 | CFX_FloatRect CPDFSDK_BAAnnot::GetViewBBox() { |
| 290 | return GetRect(); |
| 291 | } |
| 292 | |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 293 | void CPDFSDK_BAAnnot::OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) { |
| 294 | SetOpenState(true); |
| 295 | UpdateAnnotRects(); |
| 296 | } |
| 297 | |
| 298 | void CPDFSDK_BAAnnot::OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) { |
| 299 | SetOpenState(false); |
| 300 | UpdateAnnotRects(); |
| 301 | } |
| 302 | |
| 303 | bool CPDFSDK_BAAnnot::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, |
| 304 | const CFX_PointF& point) { |
| 305 | return false; |
| 306 | } |
| 307 | |
| 308 | bool CPDFSDK_BAAnnot::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags, |
| 309 | const CFX_PointF& point) { |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | bool CPDFSDK_BAAnnot::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags, |
| 314 | const CFX_PointF& point) { |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | bool CPDFSDK_BAAnnot::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags, |
| 319 | const CFX_PointF& point) { |
| 320 | return false; |
| 321 | } |
| 322 | |
| 323 | bool CPDFSDK_BAAnnot::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags, |
| 324 | const CFX_PointF& point, |
| 325 | const CFX_Vector& delta) { |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | bool CPDFSDK_BAAnnot::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, |
| 330 | const CFX_PointF& point) { |
| 331 | return false; |
| 332 | } |
| 333 | |
| 334 | bool CPDFSDK_BAAnnot::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, |
| 335 | const CFX_PointF& point) { |
| 336 | return false; |
| 337 | } |
| 338 | |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 339 | bool CPDFSDK_BAAnnot::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) { |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | bool 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 Sepez | a5af787 | 2022-08-16 19:26:42 +0000 | [diff] [blame] | 354 | CPDFSDK_FormFillEnvironment* env = GetPageView()->GetFormFillEnv(); |
Tom Sepez | 05332a8 | 2022-10-05 21:37:45 +0000 | [diff] [blame] | 355 | if (action.HasDict()) { |
Tom Sepez | 946bf0f | 2022-04-08 22:06:41 +0000 | [diff] [blame] | 356 | return env->DoActionLink(action, CPDF_AAction::kKeyStroke, nFlags); |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Tom Sepez | 946bf0f | 2022-04-08 22:06:41 +0000 | [diff] [blame] | 359 | return env->DoActionDestination(GetDestination()); |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | bool 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 | |
| 371 | bool 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 Zhang | f342da7 | 2022-04-06 23:54:50 +0000 | [diff] [blame] | 380 | bool CPDFSDK_BAAnnot::CanUndo() { |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | bool CPDFSDK_BAAnnot::CanRedo() { |
| 385 | return false; |
| 386 | } |
| 387 | |
| 388 | bool CPDFSDK_BAAnnot::Undo() { |
| 389 | return false; |
| 390 | } |
| 391 | |
| 392 | bool CPDFSDK_BAAnnot::Redo() { |
| 393 | return false; |
| 394 | } |
| 395 | |
Lei Zhang | 889fce7 | 2022-04-08 21:13:51 +0000 | [diff] [blame] | 396 | WideString CPDFSDK_BAAnnot::GetText() { |
| 397 | return WideString(); |
| 398 | } |
| 399 | |
| 400 | WideString CPDFSDK_BAAnnot::GetSelectedText() { |
| 401 | return WideString(); |
| 402 | } |
| 403 | |
Keren Zhu | 74e7eb7 | 2023-01-19 19:21:41 +0000 | [diff] [blame] | 404 | void CPDFSDK_BAAnnot::ReplaceAndKeepSelection(const WideString& text) {} |
| 405 | |
Lei Zhang | 889fce7 | 2022-04-08 21:13:51 +0000 | [diff] [blame] | 406 | void CPDFSDK_BAAnnot::ReplaceSelection(const WideString& text) {} |
| 407 | |
| 408 | bool CPDFSDK_BAAnnot::SelectAllText() { |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | bool CPDFSDK_BAAnnot::SetIndexSelected(int index, bool selected) { |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | bool CPDFSDK_BAAnnot::IsIndexSelected(int index) { |
| 417 | return false; |
| 418 | } |
| 419 | |
Badhri Ravikumar | f5cc1ac | 2020-04-30 19:00:55 +0000 | [diff] [blame] | 420 | CPDF_Dest CPDFSDK_BAAnnot::GetDestination() const { |
| 421 | if (m_pAnnot->GetSubtype() != CPDF_Annot::Subtype::LINK) |
Lei Zhang | e782e37 | 2020-05-11 21:47:38 +0000 | [diff] [blame] | 422 | return CPDF_Dest(nullptr); |
Badhri Ravikumar | f5cc1ac | 2020-04-30 19:00:55 +0000 | [diff] [blame] | 423 | |
| 424 | // Link annotations can have "Dest" entry defined as an explicit array. |
Lei Zhang | 87f3528 | 2021-10-18 05:03:08 +0000 | [diff] [blame] | 425 | // See ISO 32000-1:2008 spec, section 12.3.2.1. |
Tom Sepez | a5af787 | 2022-08-16 19:26:42 +0000 | [diff] [blame] | 426 | return CPDF_Dest::Create(GetPageView()->GetPDFDocument(), |
Badhri Ravikumar | f5cc1ac | 2020-04-30 19:00:55 +0000 | [diff] [blame] | 427 | GetAnnotDict()->GetDirectObjectFor("Dest")); |
Lei Zhang | e782e37 | 2020-05-11 21:47:38 +0000 | [diff] [blame] | 428 | } |