jaepark | 35512aa | 2016-08-29 17:15:08 -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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_baannothandler.h" |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 8 | |
| 9 | #include <memory> |
| 10 | #include <vector> |
| 11 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/cpdfsdk_annot.h" |
| 16 | #include "fpdfsdk/cpdfsdk_baannot.h" |
| 17 | #include "fpdfsdk/cpdfsdk_pageview.h" |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 18 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 19 | |
| 20 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 22 | #endif // PDF_ENABLE_XFA |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | void UpdateAnnotRects(CPDFSDK_PageView* pPageView, CPDFSDK_BAAnnot* pBAAnnot) { |
| 27 | std::vector<CFX_FloatRect> rects; |
| 28 | rects.push_back(pBAAnnot->GetRect()); |
| 29 | if (CPDF_Annot* pPopupAnnot = pBAAnnot->GetPDFPopupAnnot()) |
| 30 | rects.push_back(pPopupAnnot->GetRect()); |
thestig | c75dcd2 | 2016-11-14 13:15:47 -0800 | [diff] [blame] | 31 | |
| 32 | // Make the rects round up to avoid https://crbug.com/662804 |
| 33 | for (CFX_FloatRect& rect : rects) |
| 34 | rect.Inflate(1, 1); |
| 35 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 36 | pPageView->UpdateRects(rects); |
| 37 | } |
| 38 | |
| 39 | } // namespace |
| 40 | |
| 41 | CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {} |
| 42 | |
| 43 | CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {} |
| 44 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 45 | bool CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
| 46 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, |
| 50 | CPDFSDK_PageView* pPage) { |
| 51 | return new CPDFSDK_BAAnnot(pAnnot, pPage); |
| 52 | } |
| 53 | |
| 54 | #ifdef PDF_ENABLE_XFA |
| 55 | CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget, |
| 56 | CPDFSDK_PageView* pPage) { |
| 57 | return nullptr; |
| 58 | } |
| 59 | #endif // PDF_ENABLE_XFA |
| 60 | |
| 61 | void CPDFSDK_BAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
| 62 | delete pAnnot; |
| 63 | } |
| 64 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 65 | void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, |
| 66 | CPDFSDK_Annot* pAnnot, |
| 67 | CFX_RenderDevice* pDevice, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 68 | CFX_Matrix* pUser2Device, |
| 69 | bool bDrawAnnots) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 70 | #ifdef PDF_ENABLE_XFA |
| 71 | if (pAnnot->IsXFAField()) |
| 72 | return; |
| 73 | #endif // PDF_ENABLE_XFA |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 74 | if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) { |
| 75 | static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance( |
| 76 | pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); |
| 77 | } |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 78 | } |
| 79 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 80 | void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 81 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 82 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 83 | CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get()); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 84 | pBAAnnot->SetOpenState(true); |
| 85 | UpdateAnnotRects(pPageView, pBAAnnot); |
| 86 | } |
| 87 | |
| 88 | void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 89 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 90 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 91 | CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get()); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 92 | pBAAnnot->SetOpenState(false); |
| 93 | UpdateAnnotRects(pPageView, pBAAnnot); |
| 94 | } |
| 95 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 96 | bool CPDFSDK_BAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 97 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 98 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 99 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 100 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 101 | } |
| 102 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 103 | bool CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 104 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 105 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 106 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 107 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 108 | } |
| 109 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 110 | bool CPDFSDK_BAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 111 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 112 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 113 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 114 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 115 | } |
| 116 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 117 | bool CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
| 118 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 119 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 120 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 121 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 122 | } |
| 123 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 124 | bool CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
| 125 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 126 | uint32_t nFlags, |
| 127 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 128 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 129 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 130 | } |
| 131 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 132 | bool CPDFSDK_BAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, |
| 133 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 134 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 135 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 136 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 137 | } |
| 138 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 139 | bool CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
| 140 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 141 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 142 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 143 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 144 | } |
| 145 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 146 | bool CPDFSDK_BAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, |
| 147 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 148 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 149 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 150 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 151 | } |
| 152 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 153 | bool CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 154 | uint32_t nChar, |
| 155 | uint32_t nFlags) { |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | bool CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 160 | int nKeyCode, |
| 161 | int nFlag) { |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | bool CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 166 | int nKeyCode, |
| 167 | int nFlag) { |
| 168 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 169 | } |
| 170 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 171 | void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {} |
| 172 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 173 | bool CPDFSDK_BAAnnotHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 174 | uint32_t nFlag) { |
| 175 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 176 | } |
| 177 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 178 | bool CPDFSDK_BAAnnotHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 179 | uint32_t nFlag) { |
| 180 | return false; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 184 | bool CPDFSDK_BAAnnotHandler::OnXFAChangedFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 185 | CPDFSDK_Annot::ObservedPtr* pOldAnnot, |
| 186 | CPDFSDK_Annot::ObservedPtr* pNewAnnot) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 187 | return true; |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 188 | } |
| 189 | #endif // PDF_ENABLE_XFA |
| 190 | |
| 191 | CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 192 | CPDFSDK_Annot* pAnnot) { |
| 193 | return pAnnot->GetRect(); |
| 194 | } |
| 195 | |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 196 | CFX_WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) { |
| 197 | return CFX_WideString(); |
| 198 | } |
| 199 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 200 | void CPDFSDK_BAAnnotHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, |
| 201 | const CFX_WideString& text) {} |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 202 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 203 | bool CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 204 | CPDFSDK_Annot* pAnnot, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 205 | const CFX_PointF& point) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 206 | ASSERT(pPageView); |
| 207 | ASSERT(pAnnot); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 208 | return GetViewBBox(pPageView, pAnnot).Contains(point); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 209 | } |