blob: 6aa6de73ea3caf737f591564960f86d6b52409b2 [file] [log] [blame]
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -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
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 Huang49cc9302020-04-27 16:14:24 -070014#include "core/fpdfdoc/cpdf_interactiveform.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070015#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. Moltmann4d3acf42017-03-20 11:05:52 -070020namespace {
21
22void 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
37CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {}
38
39CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {}
40
Haibo Huang49cc9302020-04-27 16:14:24 -070041void CPDFSDK_BAAnnotHandler::SetFormFillEnvironment(
42 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
43 // CPDFSDK_BAAnnotHandler does not need it.
44}
45
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070046bool CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
47 return false;
48}
49
50CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
51 CPDFSDK_PageView* pPage) {
52 return new CPDFSDK_BAAnnot(pAnnot, pPage);
53}
54
Haibo Huang49cc9302020-04-27 16:14:24 -070055void CPDFSDK_BAAnnotHandler::ReleaseAnnot(
56 std::unique_ptr<CPDFSDK_Annot> pAnnot) {
57 // pAnnot deleted by unique_ptr going out of scope.
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070058}
59
60void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
61 CPDFSDK_Annot* pAnnot,
62 CFX_RenderDevice* pDevice,
Haibo Huang49cc9302020-04-27 16:14:24 -070063 const CFX_Matrix& mtUser2Device,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070064 bool bDrawAnnots) {
Haibo Huang49cc9302020-04-27 16:14:24 -070065 if (pAnnot->AsXFAWidget())
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070066 return;
Haibo Huang49cc9302020-04-27 16:14:24 -070067
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070068 if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) {
Haibo Huang49cc9302020-04-27 16:14:24 -070069 pAnnot->AsBAAnnot()->DrawAppearance(pDevice, mtUser2Device,
70 CPDF_Annot::Normal, nullptr);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070071 }
72}
73
74void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -070075 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070076 uint32_t nFlag) {
Haibo Huang49cc9302020-04-27 16:14:24 -070077 CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070078 pBAAnnot->SetOpenState(true);
79 UpdateAnnotRects(pPageView, pBAAnnot);
80}
81
82void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -070083 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070084 uint32_t nFlag) {
Haibo Huang49cc9302020-04-27 16:14:24 -070085 CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070086 pBAAnnot->SetOpenState(false);
87 UpdateAnnotRects(pPageView, pBAAnnot);
88}
89
90bool CPDFSDK_BAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -070091 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070092 uint32_t nFlags,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -070093 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070094 return false;
95}
96
97bool CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -070098 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070099 uint32_t nFlags,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700100 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700101 return false;
102}
103
104bool CPDFSDK_BAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -0700105 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700106 uint32_t nFlags,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700107 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700108 return false;
109}
110
111bool CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -0700112 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700113 uint32_t nFlags,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700114 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700115 return false;
116}
117
118bool CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -0700119 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700120 uint32_t nFlags,
121 short zDelta,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700122 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700123 return false;
124}
125
126bool CPDFSDK_BAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -0700127 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700128 uint32_t nFlags,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700129 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700130 return false;
131}
132
133bool CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -0700134 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700135 uint32_t nFlags,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700136 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700137 return false;
138}
139
140bool CPDFSDK_BAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -0700141 ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700142 uint32_t nFlags,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700143 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700144 return false;
145}
146
147bool CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
148 uint32_t nChar,
149 uint32_t nFlags) {
150 return false;
151}
152
153bool CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
154 int nKeyCode,
155 int nFlag) {
156 return false;
157}
158
159bool CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
160 int nKeyCode,
161 int nFlag) {
162 return false;
163}
164
165void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
166
Haibo Huang49cc9302020-04-27 16:14:24 -0700167bool CPDFSDK_BAAnnotHandler::OnSetFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700168 uint32_t nFlag) {
169 return false;
170}
171
Haibo Huang49cc9302020-04-27 16:14:24 -0700172bool CPDFSDK_BAAnnotHandler::OnKillFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700173 uint32_t nFlag) {
174 return false;
175}
176
Haibo Huang49cc9302020-04-27 16:14:24 -0700177bool CPDFSDK_BAAnnotHandler::SetIndexSelected(
178 ObservedPtr<CPDFSDK_Annot>* pAnnot,
179 int index,
180 bool selected) {
181 return false;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700182}
Haibo Huang49cc9302020-04-27 16:14:24 -0700183
184bool CPDFSDK_BAAnnotHandler::IsIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot,
185 int index) {
186 return false;
187}
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700188
189CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
190 CPDFSDK_Annot* pAnnot) {
191 return pAnnot->GetRect();
192}
193
Haibo Huang49cc9302020-04-27 16:14:24 -0700194WideString CPDFSDK_BAAnnotHandler::GetText(CPDFSDK_Annot* pAnnot) {
195 return WideString();
196}
197
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700198WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) {
199 return WideString();
200}
201
202void CPDFSDK_BAAnnotHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot,
203 const WideString& text) {}
204
Haibo Huang49cc9302020-04-27 16:14:24 -0700205bool CPDFSDK_BAAnnotHandler::CanUndo(CPDFSDK_Annot* pAnnot) {
206 return false;
207}
208
209bool CPDFSDK_BAAnnotHandler::CanRedo(CPDFSDK_Annot* pAnnot) {
210 return false;
211}
212
213bool CPDFSDK_BAAnnotHandler::Undo(CPDFSDK_Annot* pAnnot) {
214 return false;
215}
216
217bool CPDFSDK_BAAnnotHandler::Redo(CPDFSDK_Annot* pAnnot) {
218 return false;
219}
220
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700221bool CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
222 CPDFSDK_Annot* pAnnot,
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700223 const CFX_PointF& point) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700224 ASSERT(pPageView);
225 ASSERT(pAnnot);
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700226 return GetViewBBox(pPageView, pAnnot).Contains(point);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700227}