blob: 027527ec5f20b90f807e74290a0e8bf400054d53 [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
dsinclair41872fa2016-10-04 11:29:35 -070012#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070013#include "core/fpdfapi/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
dsinclair521b7502016-11-02 13:02:28 -070021#include "fpdfsdk/fpdfxfa/cpdfxfa_context.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());
thestigc75dcd22016-11-14 13:15:47 -080031
32 // Make the rects round up to avoid https://crbug.com/662804
33 for (CFX_FloatRect& rect : rects)
34 rect.Inflate(1, 1);
35
jaepark35512aa2016-08-29 17:15:08 -070036 pPageView->UpdateRects(rects);
37}
38
39} // namespace
40
41CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {}
42
43CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {}
44
tsepez4cf55152016-11-02 14:37:54 -070045bool CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
46 return false;
jaepark35512aa2016-08-29 17:15:08 -070047}
48
49CPDFSDK_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
55CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
56 CPDFSDK_PageView* pPage) {
57 return nullptr;
58}
59#endif // PDF_ENABLE_XFA
60
61void CPDFSDK_BAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
62 delete pAnnot;
63}
64
jaepark35512aa2016-08-29 17:15:08 -070065void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
66 CPDFSDK_Annot* pAnnot,
67 CFX_RenderDevice* pDevice,
jaepark75f84a52016-09-09 15:39:09 -070068 CFX_Matrix* pUser2Device,
69 bool bDrawAnnots) {
jaepark35512aa2016-08-29 17:15:08 -070070#ifdef PDF_ENABLE_XFA
71 if (pAnnot->IsXFAField())
72 return;
73#endif // PDF_ENABLE_XFA
jaepark75f84a52016-09-09 15:39:09 -070074 if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) {
75 static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
Lei Zhang8a449402017-08-17 15:07:47 -070076 pDevice, *pUser2Device, CPDF_Annot::Normal, nullptr);
jaepark75f84a52016-09-09 15:39:09 -070077 }
jaepark35512aa2016-08-29 17:15:08 -070078}
79
jaepark35512aa2016-08-29 17:15:08 -070080void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -070081 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -070082 uint32_t nFlag) {
tsepezf8074ce2016-09-27 14:29:57 -070083 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get());
jaepark35512aa2016-08-29 17:15:08 -070084 pBAAnnot->SetOpenState(true);
85 UpdateAnnotRects(pPageView, pBAAnnot);
86}
87
88void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -070089 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -070090 uint32_t nFlag) {
tsepezf8074ce2016-09-27 14:29:57 -070091 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot->Get());
jaepark35512aa2016-08-29 17:15:08 -070092 pBAAnnot->SetOpenState(false);
93 UpdateAnnotRects(pPageView, pBAAnnot);
94}
95
tsepez4cf55152016-11-02 14:37:54 -070096bool CPDFSDK_BAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
97 CPDFSDK_Annot::ObservedPtr* pAnnot,
98 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -050099 const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700100 return false;
jaepark35512aa2016-08-29 17:15:08 -0700101}
102
tsepez4cf55152016-11-02 14:37:54 -0700103bool CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
104 CPDFSDK_Annot::ObservedPtr* pAnnot,
105 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500106 const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700107 return false;
jaepark35512aa2016-08-29 17:15:08 -0700108}
109
tsepez4cf55152016-11-02 14:37:54 -0700110bool CPDFSDK_BAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700111 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark35512aa2016-08-29 17:15:08 -0700112 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500113 const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700114 return false;
jaepark35512aa2016-08-29 17:15:08 -0700115}
116
tsepez4cf55152016-11-02 14:37:54 -0700117bool CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
118 CPDFSDK_Annot::ObservedPtr* pAnnot,
119 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500120 const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700121 return false;
jaepark35512aa2016-08-29 17:15:08 -0700122}
123
tsepez4cf55152016-11-02 14:37:54 -0700124bool CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
125 CPDFSDK_Annot::ObservedPtr* pAnnot,
126 uint32_t nFlags,
127 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500128 const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700129 return false;
jaepark35512aa2016-08-29 17:15:08 -0700130}
131
tsepez4cf55152016-11-02 14:37:54 -0700132bool CPDFSDK_BAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
133 CPDFSDK_Annot::ObservedPtr* pAnnot,
134 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500135 const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700136 return false;
jaepark35512aa2016-08-29 17:15:08 -0700137}
138
tsepez4cf55152016-11-02 14:37:54 -0700139bool CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
140 CPDFSDK_Annot::ObservedPtr* pAnnot,
141 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500142 const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700143 return false;
jaepark35512aa2016-08-29 17:15:08 -0700144}
145
tsepez4cf55152016-11-02 14:37:54 -0700146bool CPDFSDK_BAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
147 CPDFSDK_Annot::ObservedPtr* pAnnot,
148 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500149 const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700150 return false;
jaepark35512aa2016-08-29 17:15:08 -0700151}
152
tsepez4cf55152016-11-02 14:37:54 -0700153bool CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
154 uint32_t nChar,
155 uint32_t nFlags) {
156 return false;
157}
158
159bool CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
160 int nKeyCode,
161 int nFlag) {
162 return false;
163}
164
165bool CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
166 int nKeyCode,
167 int nFlag) {
168 return false;
jaepark35512aa2016-08-29 17:15:08 -0700169}
170
jaepark35512aa2016-08-29 17:15:08 -0700171void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
172
tsepez4cf55152016-11-02 14:37:54 -0700173bool CPDFSDK_BAAnnotHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
174 uint32_t nFlag) {
175 return false;
jaepark35512aa2016-08-29 17:15:08 -0700176}
177
tsepez4cf55152016-11-02 14:37:54 -0700178bool CPDFSDK_BAAnnotHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
179 uint32_t nFlag) {
180 return false;
jaepark35512aa2016-08-29 17:15:08 -0700181}
182
183#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700184bool CPDFSDK_BAAnnotHandler::OnXFAChangedFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700185 CPDFSDK_Annot::ObservedPtr* pOldAnnot,
186 CPDFSDK_Annot::ObservedPtr* pNewAnnot) {
tsepez4cf55152016-11-02 14:37:54 -0700187 return true;
jaepark35512aa2016-08-29 17:15:08 -0700188}
189#endif // PDF_ENABLE_XFA
190
191CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
192 CPDFSDK_Annot* pAnnot) {
193 return pAnnot->GetRect();
194}
195
Ryan Harrison275e2602017-09-18 14:23:18 -0400196WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) {
197 return WideString();
Diana Gagedce2d722017-06-20 11:17:11 -0700198}
199
Diana Gageab390972017-07-28 17:07:39 -0700200void CPDFSDK_BAAnnotHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot,
Ryan Harrison275e2602017-09-18 14:23:18 -0400201 const WideString& text) {}
Diana Gage1c7f1422017-07-24 11:19:52 -0700202
tsepez4cf55152016-11-02 14:37:54 -0700203bool CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
204 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500205 const CFX_PointF& point) {
jaepark35512aa2016-08-29 17:15:08 -0700206 ASSERT(pPageView);
207 ASSERT(pAnnot);
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500208 return GetViewBBox(pPageView, pAnnot).Contains(point);
jaepark35512aa2016-08-29 17:15:08 -0700209}