blob: d83dfbadc93603d5c30de79f664cc3ab49394e7d [file] [log] [blame]
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "fpdfsdk/cpdfsdk_baannothandler.h"
#include <memory>
#include <vector>
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfdoc/cpdf_interactiveform.h"
#include "fpdfsdk/cpdfsdk_annot.h"
#include "fpdfsdk/cpdfsdk_baannot.h"
#include "fpdfsdk/cpdfsdk_pageview.h"
#include "fpdfsdk/formfiller/cffl_formfiller.h"
namespace {
void UpdateAnnotRects(CPDFSDK_PageView* pPageView, CPDFSDK_BAAnnot* pBAAnnot) {
std::vector<CFX_FloatRect> rects;
rects.push_back(pBAAnnot->GetRect());
if (CPDF_Annot* pPopupAnnot = pBAAnnot->GetPDFPopupAnnot())
rects.push_back(pPopupAnnot->GetRect());
// Make the rects round up to avoid https://crbug.com/662804
for (CFX_FloatRect& rect : rects)
rect.Inflate(1, 1);
pPageView->UpdateRects(rects);
}
} // namespace
CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {}
CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {}
void CPDFSDK_BAAnnotHandler::SetFormFillEnvironment(
CPDFSDK_FormFillEnvironment* pFormFillEnv) {
// CPDFSDK_BAAnnotHandler does not need it.
}
bool CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
return false;
}
std::unique_ptr<CPDFSDK_Annot> CPDFSDK_BAAnnotHandler::NewAnnot(
CPDF_Annot* pAnnot,
CPDFSDK_PageView* pPageView) {
return pdfium::MakeUnique<CPDFSDK_BAAnnot>(pAnnot, pPageView);
}
void CPDFSDK_BAAnnotHandler::ReleaseAnnot(
std::unique_ptr<CPDFSDK_Annot> pAnnot) {
// pAnnot deleted by unique_ptr going out of scope.
}
void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot,
CFX_RenderDevice* pDevice,
const CFX_Matrix& mtUser2Device,
bool bDrawAnnots) {
if (pAnnot->AsXFAWidget())
return;
if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) {
pAnnot->AsBAAnnot()->DrawAppearance(pDevice, mtUser2Device,
CPDF_Annot::Normal, nullptr);
}
}
void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlag) {
CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot();
pBAAnnot->SetOpenState(true);
UpdateAnnotRects(pPageView, pBAAnnot);
}
void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlag) {
CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot();
pBAAnnot->SetOpenState(false);
UpdateAnnotRects(pPageView, pBAAnnot);
}
bool CPDFSDK_BAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlags,
short zDelta,
const CFX_PointF& point) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
uint32_t nChar,
uint32_t nFlags) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
int nKeyCode,
int nFlag) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
int nKeyCode,
int nFlag) {
return false;
}
void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
bool CPDFSDK_BAAnnotHandler::OnSetFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlag) {
return false;
}
bool CPDFSDK_BAAnnotHandler::OnKillFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot,
uint32_t nFlag) {
return false;
}
bool CPDFSDK_BAAnnotHandler::SetIndexSelected(
ObservedPtr<CPDFSDK_Annot>* pAnnot,
int index,
bool selected) {
return false;
}
bool CPDFSDK_BAAnnotHandler::IsIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot,
int index) {
return false;
}
CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot) {
return pAnnot->GetRect();
}
WideString CPDFSDK_BAAnnotHandler::GetText(CPDFSDK_Annot* pAnnot) {
return WideString();
}
WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) {
return WideString();
}
void CPDFSDK_BAAnnotHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot,
const WideString& text) {}
bool CPDFSDK_BAAnnotHandler::CanUndo(CPDFSDK_Annot* pAnnot) {
return false;
}
bool CPDFSDK_BAAnnotHandler::CanRedo(CPDFSDK_Annot* pAnnot) {
return false;
}
bool CPDFSDK_BAAnnotHandler::Undo(CPDFSDK_Annot* pAnnot) {
return false;
}
bool CPDFSDK_BAAnnotHandler::Redo(CPDFSDK_Annot* pAnnot) {
return false;
}
bool CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot,
const CFX_PointF& point) {
ASSERT(pPageView);
ASSERT(pAnnot);
return GetViewBBox(pPageView, pAnnot).Contains(point);
}