Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 1 | // 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 | |
| 7 | #include "fpdfsdk/cpdfsdk_baannothandler.h" |
| 8 | |
| 9 | #include <memory> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "core/fpdfapi/page/cpdf_page.h" |
| 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 14 | #include "core/fpdfdoc/cpdf_interactiveform.h" |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/cpdfsdk_annot.h" |
| 16 | #include "fpdfsdk/cpdfsdk_baannot.h" |
| 17 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 18 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
| 19 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 20 | namespace { |
| 21 | |
| 22 | void UpdateAnnotRects(CPDFSDK_PageView* pPageView, CPDFSDK_BAAnnot* pBAAnnot) { |
| 23 | std::vector<CFX_FloatRect> rects; |
| 24 | rects.push_back(pBAAnnot->GetRect()); |
| 25 | if (CPDF_Annot* pPopupAnnot = pBAAnnot->GetPDFPopupAnnot()) |
| 26 | rects.push_back(pPopupAnnot->GetRect()); |
| 27 | |
| 28 | // Make the rects round up to avoid https://crbug.com/662804 |
| 29 | for (CFX_FloatRect& rect : rects) |
| 30 | rect.Inflate(1, 1); |
| 31 | |
| 32 | pPageView->UpdateRects(rects); |
| 33 | } |
| 34 | |
| 35 | } // namespace |
| 36 | |
| 37 | CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {} |
| 38 | |
| 39 | CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {} |
| 40 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 41 | void CPDFSDK_BAAnnotHandler::SetFormFillEnvironment( |
| 42 | CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 43 | // CPDFSDK_BAAnnotHandler does not need it. |
| 44 | } |
| 45 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 46 | bool CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, |
| 51 | CPDFSDK_PageView* pPage) { |
| 52 | return new CPDFSDK_BAAnnot(pAnnot, pPage); |
| 53 | } |
| 54 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 55 | void CPDFSDK_BAAnnotHandler::ReleaseAnnot( |
| 56 | std::unique_ptr<CPDFSDK_Annot> pAnnot) { |
| 57 | // pAnnot deleted by unique_ptr going out of scope. |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, |
| 61 | CPDFSDK_Annot* pAnnot, |
| 62 | CFX_RenderDevice* pDevice, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 63 | const CFX_Matrix& mtUser2Device, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 64 | bool bDrawAnnots) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 65 | if (pAnnot->AsXFAWidget()) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 66 | return; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 67 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 68 | if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 69 | pAnnot->AsBAAnnot()->DrawAppearance(pDevice, mtUser2Device, |
| 70 | CPDF_Annot::Normal, nullptr); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 75 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 76 | uint32_t nFlag) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 77 | CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 78 | pBAAnnot->SetOpenState(true); |
| 79 | UpdateAnnotRects(pPageView, pBAAnnot); |
| 80 | } |
| 81 | |
| 82 | void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 83 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 84 | uint32_t nFlag) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 85 | CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 86 | pBAAnnot->SetOpenState(false); |
| 87 | UpdateAnnotRects(pPageView, pBAAnnot); |
| 88 | } |
| 89 | |
| 90 | bool CPDFSDK_BAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 91 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 92 | uint32_t nFlags, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 93 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 94 | return false; |
| 95 | } |
| 96 | |
| 97 | bool CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 98 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 99 | uint32_t nFlags, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 100 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 101 | return false; |
| 102 | } |
| 103 | |
| 104 | bool CPDFSDK_BAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 105 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 106 | uint32_t nFlags, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 107 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 108 | return false; |
| 109 | } |
| 110 | |
| 111 | bool CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 112 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 113 | uint32_t nFlags, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 114 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 115 | return false; |
| 116 | } |
| 117 | |
| 118 | bool CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 119 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 120 | uint32_t nFlags, |
| 121 | short zDelta, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 122 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 123 | return false; |
| 124 | } |
| 125 | |
| 126 | bool CPDFSDK_BAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 127 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 128 | uint32_t nFlags, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 129 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 130 | return false; |
| 131 | } |
| 132 | |
| 133 | bool CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 134 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 135 | uint32_t nFlags, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 136 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 137 | return false; |
| 138 | } |
| 139 | |
| 140 | bool CPDFSDK_BAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 141 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 142 | uint32_t nFlags, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 143 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 144 | return false; |
| 145 | } |
| 146 | |
| 147 | bool CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 148 | uint32_t nChar, |
| 149 | uint32_t nFlags) { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | bool CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 154 | int nKeyCode, |
| 155 | int nFlag) { |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | bool CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 160 | int nKeyCode, |
| 161 | int nFlag) { |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {} |
| 166 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 167 | bool CPDFSDK_BAAnnotHandler::OnSetFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 168 | uint32_t nFlag) { |
| 169 | return false; |
| 170 | } |
| 171 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 172 | bool CPDFSDK_BAAnnotHandler::OnKillFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 173 | uint32_t nFlag) { |
| 174 | return false; |
| 175 | } |
| 176 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 177 | bool CPDFSDK_BAAnnotHandler::SetIndexSelected( |
| 178 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
| 179 | int index, |
| 180 | bool selected) { |
| 181 | return false; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 182 | } |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 183 | |
| 184 | bool CPDFSDK_BAAnnotHandler::IsIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot, |
| 185 | int index) { |
| 186 | return false; |
| 187 | } |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 188 | |
| 189 | CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 190 | CPDFSDK_Annot* pAnnot) { |
| 191 | return pAnnot->GetRect(); |
| 192 | } |
| 193 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 194 | WideString CPDFSDK_BAAnnotHandler::GetText(CPDFSDK_Annot* pAnnot) { |
| 195 | return WideString(); |
| 196 | } |
| 197 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 198 | WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) { |
| 199 | return WideString(); |
| 200 | } |
| 201 | |
| 202 | void CPDFSDK_BAAnnotHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, |
| 203 | const WideString& text) {} |
| 204 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 205 | bool CPDFSDK_BAAnnotHandler::CanUndo(CPDFSDK_Annot* pAnnot) { |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | bool CPDFSDK_BAAnnotHandler::CanRedo(CPDFSDK_Annot* pAnnot) { |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | bool CPDFSDK_BAAnnotHandler::Undo(CPDFSDK_Annot* pAnnot) { |
| 214 | return false; |
| 215 | } |
| 216 | |
| 217 | bool CPDFSDK_BAAnnotHandler::Redo(CPDFSDK_Annot* pAnnot) { |
| 218 | return false; |
| 219 | } |
| 220 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 221 | bool CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 222 | CPDFSDK_Annot* pAnnot, |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 223 | const CFX_PointF& point) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 224 | ASSERT(pPageView); |
| 225 | ASSERT(pAnnot); |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 226 | return GetViewBBox(pPageView, pAnnot).Contains(point); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 227 | } |