blob: 02ffff4265a2061f7154df956dd9b4b952718139 [file] [log] [blame]
jaepark35512aa2016-08-29 17:15:08 -07001// 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
dsinclair114e46a2016-09-29 17:18:21 -07007#include "fpdfsdk/cpdfsdk_baannothandler.h"
jaepark35512aa2016-08-29 17:15:08 -07008
9#include <memory>
10#include <vector>
11
dsinclair8a752ab2016-09-29 11:59:54 -070012#include "core/fpdfapi/fpdf_page/cpdf_page.h"
dsinclairc6c425a2016-09-29 12:01:30 -070013#include "core/fpdfapi/fpdf_parser/cpdf_document.h"
dsinclair1727aee2016-09-29 13:12:56 -070014#include "core/fpdfdoc/cpdf_interform.h"
dsinclair114e46a2016-09-29 17:18:21 -070015#include "fpdfsdk/cpdfsdk_annot.h"
16#include "fpdfsdk/cpdfsdk_baannot.h"
17#include "fpdfsdk/cpdfsdk_pageview.h"
jaepark35512aa2016-08-29 17:15:08 -070018#include "fpdfsdk/formfiller/cffl_formfiller.h"
jaepark35512aa2016-08-29 17:15:08 -070019
20#ifdef PDF_ENABLE_XFA
dsinclairbec76922016-09-29 16:52:30 -070021#include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h"
jaepark35512aa2016-08-29 17:15:08 -070022#endif // PDF_ENABLE_XFA
23
24namespace {
25
26void 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
36CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {}
37
38CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {}
39
jaepark35512aa2016-08-29 17:15:08 -070040FX_BOOL CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
41 return FALSE;
42}
43
44CPDFSDK_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
50CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
51 CPDFSDK_PageView* pPage) {
52 return nullptr;
53}
54#endif // PDF_ENABLE_XFA
55
56void CPDFSDK_BAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
57 delete pAnnot;
58}
59
60void CPDFSDK_BAAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
61
62void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
63 CPDFSDK_Annot* pAnnot,
64 CFX_RenderDevice* pDevice,
jaepark75f84a52016-09-09 15:39:09 -070065 CFX_Matrix* pUser2Device,
66 bool bDrawAnnots) {
jaepark35512aa2016-08-29 17:15:08 -070067#ifdef PDF_ENABLE_XFA
68 if (pAnnot->IsXFAField())
69 return;
70#endif // PDF_ENABLE_XFA
jaepark75f84a52016-09-09 15:39:09 -070071 if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) {
72 static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
73 pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
74 }
jaepark35512aa2016-08-29 17:15:08 -070075}
76
jaepark35512aa2016-08-29 17:15:08 -070077void CPDFSDK_BAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
78
79void CPDFSDK_BAAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
80
81void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -070082 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -070083 uint32_t nFlag) {
tsepezf8074ce2016-09-27 14:29:57 -070084 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get());
jaepark35512aa2016-08-29 17:15:08 -070085 pBAAnnot->SetOpenState(true);
86 UpdateAnnotRects(pPageView, pBAAnnot);
87}
88
89void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -070090 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -070091 uint32_t nFlag) {
tsepezf8074ce2016-09-27 14:29:57 -070092 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get());
jaepark35512aa2016-08-29 17:15:08 -070093 pBAAnnot->SetOpenState(false);
94 UpdateAnnotRects(pPageView, pBAAnnot);
95}
96
tsepezf8074ce2016-09-27 14:29:57 -070097FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonDown(
98 CPDFSDK_PageView* pPageView,
99 CPDFSDK_Annot::ObservedPtr* pAnnot,
100 uint32_t nFlags,
101 const CFX_FloatPoint& point) {
jaepark35512aa2016-08-29 17:15:08 -0700102 return FALSE;
103}
104
105FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700106 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -0700107 uint32_t nFlags,
108 const CFX_FloatPoint& point) {
109 return FALSE;
110}
111
tsepezf8074ce2016-09-27 14:29:57 -0700112FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonDblClk(
113 CPDFSDK_PageView* pPageView,
114 CPDFSDK_Annot::ObservedPtr* pAnnot,
115 uint32_t nFlags,
116 const CFX_FloatPoint& point) {
jaepark35512aa2016-08-29 17:15:08 -0700117 return FALSE;
118}
119
120FX_BOOL CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700121 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -0700122 uint32_t nFlags,
123 const CFX_FloatPoint& point) {
124 return FALSE;
125}
126
127FX_BOOL CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700128 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -0700129 uint32_t nFlags,
130 short zDelta,
131 const CFX_FloatPoint& point) {
132 return FALSE;
133}
134
tsepezf8074ce2016-09-27 14:29:57 -0700135FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonDown(
136 CPDFSDK_PageView* pPageView,
137 CPDFSDK_Annot::ObservedPtr* pAnnot,
138 uint32_t nFlags,
139 const CFX_FloatPoint& point) {
jaepark35512aa2016-08-29 17:15:08 -0700140 return FALSE;
141}
142
143FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700144 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -0700145 uint32_t nFlags,
146 const CFX_FloatPoint& point) {
147 return FALSE;
148}
149
tsepezf8074ce2016-09-27 14:29:57 -0700150FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonDblClk(
151 CPDFSDK_PageView* pPageView,
152 CPDFSDK_Annot::ObservedPtr* pAnnot,
153 uint32_t nFlags,
154 const CFX_FloatPoint& point) {
jaepark35512aa2016-08-29 17:15:08 -0700155 return FALSE;
156}
157
158FX_BOOL CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
159 uint32_t nChar,
160 uint32_t nFlags) {
161 return FALSE;
162}
163
164FX_BOOL CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
165 int nKeyCode,
166 int nFlag) {
167 return FALSE;
168}
169
170FX_BOOL CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
171 int nKeyCode,
172 int nFlag) {
173 return FALSE;
174}
175
176void CPDFSDK_BAAnnotHandler::OnDeSelected(CPDFSDK_Annot* pAnnot) {}
177
178void CPDFSDK_BAAnnotHandler::OnSelected(CPDFSDK_Annot* pAnnot) {}
179
180void CPDFSDK_BAAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {}
181
182void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
183
tsepezf8074ce2016-09-27 14:29:57 -0700184FX_BOOL CPDFSDK_BAAnnotHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -0700185 uint32_t nFlag) {
186 return FALSE;
187}
188
tsepezf8074ce2016-09-27 14:29:57 -0700189FX_BOOL CPDFSDK_BAAnnotHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -0700190 uint32_t nFlag) {
191 return FALSE;
192}
193
194#ifdef PDF_ENABLE_XFA
tsepezf8074ce2016-09-27 14:29:57 -0700195FX_BOOL CPDFSDK_BAAnnotHandler::OnXFAChangedFocus(
196 CPDFSDK_Annot::ObservedPtr* pOldAnnot,
197 CPDFSDK_Annot::ObservedPtr* pNewAnnot) {
jaepark35512aa2016-08-29 17:15:08 -0700198 return TRUE;
199}
200#endif // PDF_ENABLE_XFA
201
202CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
203 CPDFSDK_Annot* pAnnot) {
204 return pAnnot->GetRect();
205}
206
207FX_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}