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 | 8a752ab | 2016-09-29 11:59:54 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/fpdf_page/cpdf_page.h" |
dsinclair | c6c425a | 2016-09-29 12:01:30 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/fpdf_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 | bec7692 | 2016-09-29 16:52:30 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/fpdfxfa/fpdfxfa_doc.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()); |
| 31 | pPageView->UpdateRects(rects); |
| 32 | } |
| 33 | |
| 34 | } // namespace |
| 35 | |
| 36 | CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {} |
| 37 | |
| 38 | CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {} |
| 39 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 40 | FX_BOOL CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
| 41 | return FALSE; |
| 42 | } |
| 43 | |
| 44 | CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, |
| 45 | CPDFSDK_PageView* pPage) { |
| 46 | return new CPDFSDK_BAAnnot(pAnnot, pPage); |
| 47 | } |
| 48 | |
| 49 | #ifdef PDF_ENABLE_XFA |
| 50 | CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget, |
| 51 | CPDFSDK_PageView* pPage) { |
| 52 | return nullptr; |
| 53 | } |
| 54 | #endif // PDF_ENABLE_XFA |
| 55 | |
| 56 | void CPDFSDK_BAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
| 57 | delete pAnnot; |
| 58 | } |
| 59 | |
| 60 | void CPDFSDK_BAAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {} |
| 61 | |
| 62 | void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, |
| 63 | CPDFSDK_Annot* pAnnot, |
| 64 | CFX_RenderDevice* pDevice, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 65 | CFX_Matrix* pUser2Device, |
| 66 | bool bDrawAnnots) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 67 | #ifdef PDF_ENABLE_XFA |
| 68 | if (pAnnot->IsXFAField()) |
| 69 | return; |
| 70 | #endif // PDF_ENABLE_XFA |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 71 | if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) { |
| 72 | static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance( |
| 73 | pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); |
| 74 | } |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 75 | } |
| 76 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 77 | void CPDFSDK_BAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {} |
| 78 | |
| 79 | void CPDFSDK_BAAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {} |
| 80 | |
| 81 | void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 82 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 83 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 84 | CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get()); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 85 | pBAAnnot->SetOpenState(true); |
| 86 | UpdateAnnotRects(pPageView, pBAAnnot); |
| 87 | } |
| 88 | |
| 89 | void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 90 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 91 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 92 | CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get()); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 93 | pBAAnnot->SetOpenState(false); |
| 94 | UpdateAnnotRects(pPageView, pBAAnnot); |
| 95 | } |
| 96 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 97 | FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonDown( |
| 98 | CPDFSDK_PageView* pPageView, |
| 99 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 100 | uint32_t nFlags, |
| 101 | const CFX_FloatPoint& point) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 102 | return FALSE; |
| 103 | } |
| 104 | |
| 105 | FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 106 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 107 | uint32_t nFlags, |
| 108 | const CFX_FloatPoint& point) { |
| 109 | return FALSE; |
| 110 | } |
| 111 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 112 | FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonDblClk( |
| 113 | CPDFSDK_PageView* pPageView, |
| 114 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 115 | uint32_t nFlags, |
| 116 | const CFX_FloatPoint& point) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 117 | return FALSE; |
| 118 | } |
| 119 | |
| 120 | FX_BOOL CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 121 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 122 | uint32_t nFlags, |
| 123 | const CFX_FloatPoint& point) { |
| 124 | return FALSE; |
| 125 | } |
| 126 | |
| 127 | FX_BOOL CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 128 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 129 | uint32_t nFlags, |
| 130 | short zDelta, |
| 131 | const CFX_FloatPoint& point) { |
| 132 | return FALSE; |
| 133 | } |
| 134 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 135 | FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonDown( |
| 136 | CPDFSDK_PageView* pPageView, |
| 137 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 138 | uint32_t nFlags, |
| 139 | const CFX_FloatPoint& point) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 140 | return FALSE; |
| 141 | } |
| 142 | |
| 143 | FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 144 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 145 | uint32_t nFlags, |
| 146 | const CFX_FloatPoint& point) { |
| 147 | return FALSE; |
| 148 | } |
| 149 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 150 | FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonDblClk( |
| 151 | CPDFSDK_PageView* pPageView, |
| 152 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 153 | uint32_t nFlags, |
| 154 | const CFX_FloatPoint& point) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 155 | return FALSE; |
| 156 | } |
| 157 | |
| 158 | FX_BOOL CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 159 | uint32_t nChar, |
| 160 | uint32_t nFlags) { |
| 161 | return FALSE; |
| 162 | } |
| 163 | |
| 164 | FX_BOOL CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 165 | int nKeyCode, |
| 166 | int nFlag) { |
| 167 | return FALSE; |
| 168 | } |
| 169 | |
| 170 | FX_BOOL CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 171 | int nKeyCode, |
| 172 | int nFlag) { |
| 173 | return FALSE; |
| 174 | } |
| 175 | |
| 176 | void CPDFSDK_BAAnnotHandler::OnDeSelected(CPDFSDK_Annot* pAnnot) {} |
| 177 | |
| 178 | void CPDFSDK_BAAnnotHandler::OnSelected(CPDFSDK_Annot* pAnnot) {} |
| 179 | |
| 180 | void CPDFSDK_BAAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {} |
| 181 | |
| 182 | void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {} |
| 183 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 184 | FX_BOOL CPDFSDK_BAAnnotHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 185 | uint32_t nFlag) { |
| 186 | return FALSE; |
| 187 | } |
| 188 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 189 | FX_BOOL CPDFSDK_BAAnnotHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 190 | uint32_t nFlag) { |
| 191 | return FALSE; |
| 192 | } |
| 193 | |
| 194 | #ifdef PDF_ENABLE_XFA |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 195 | FX_BOOL CPDFSDK_BAAnnotHandler::OnXFAChangedFocus( |
| 196 | CPDFSDK_Annot::ObservedPtr* pOldAnnot, |
| 197 | CPDFSDK_Annot::ObservedPtr* pNewAnnot) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 198 | return TRUE; |
| 199 | } |
| 200 | #endif // PDF_ENABLE_XFA |
| 201 | |
| 202 | CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 203 | CPDFSDK_Annot* pAnnot) { |
| 204 | return pAnnot->GetRect(); |
| 205 | } |
| 206 | |
| 207 | FX_BOOL CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 208 | CPDFSDK_Annot* pAnnot, |
| 209 | const CFX_FloatPoint& point) { |
| 210 | ASSERT(pPageView); |
| 211 | ASSERT(pAnnot); |
| 212 | |
| 213 | CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot); |
| 214 | return rect.Contains(point.x, point.y); |
| 215 | } |