summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorjaepark <jaepark@google.com>2016-08-29 17:15:08 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-29 17:15:08 -0700
commit35512aa7e4acc3ceb9c6aef5d61eebfb4ae802af (patch)
tree18ad1447ba8a7d06f304e1418616d919eadbbf8c /fpdfsdk
parent07f5fd57682700bcbba20f01d52a806676fd02ff (diff)
downloadpdfium-35512aa7e4acc3ceb9c6aef5d61eebfb4ae802af.tar.xz
Display content of the annotation when mouse hover.
Each annotation has its contents, and users should be able to see the contents. In this patch, PDFium creates a Popup annotation for each annotation and stores the author and the content. When a user mouse hover on the annotation, PDFium draws the corresponding Popup annotation and displays the content. Also, roll DEPS for testing/corpus to 5867fa6. BUG=62625 Review-Url: https://codereview.chromium.org/2273893002
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_annothandlermgr.cpp213
-rw-r--r--fpdfsdk/cpdfsdk_baannot.cpp9
-rw-r--r--fpdfsdk/cpdfsdk_baannothandler.cpp219
-rw-r--r--fpdfsdk/fsdk_mgr.cpp6
-rw-r--r--fpdfsdk/include/cpdfsdk_annothandlermgr.h14
-rw-r--r--fpdfsdk/include/cpdfsdk_baannot.h3
-rw-r--r--fpdfsdk/include/cpdfsdk_baannothandler.h114
-rw-r--r--fpdfsdk/include/fsdk_mgr.h4
8 files changed, 424 insertions, 158 deletions
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index e7744bfa46..33c1ca95a9 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
@@ -10,6 +10,7 @@
#include "fpdfsdk/include/cba_annotiterator.h"
#include "fpdfsdk/include/cpdfsdk_annot.h"
#include "fpdfsdk/include/cpdfsdk_baannot.h"
+#include "fpdfsdk/include/cpdfsdk_baannothandler.h"
#include "fpdfsdk/include/cpdfsdk_bfannothandler.h"
#include "fpdfsdk/include/cpdfsdk_datetime.h"
#include "fpdfsdk/include/fsdk_mgr.h"
@@ -21,43 +22,22 @@
#include "xfa/fxfa/include/xfa_ffwidget.h"
#endif // PDF_ENABLE_XFA
-CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
- m_pApp = pApp;
-
- CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
- pHandler->SetFormFiller(m_pApp->GetIFormFiller());
- RegisterAnnotHandler(pHandler);
+CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp)
+ : m_pBAAnnotHandler(new CPDFSDK_BAAnnotHandler()),
+ m_pBFAnnotHandler(new CPDFSDK_BFAnnotHandler(pApp)),
#ifdef PDF_ENABLE_XFA
- CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler =
- new CPDFSDK_XFAAnnotHandler(m_pApp);
- RegisterAnnotHandler(pXFAAnnotHandler);
+ m_pXFAAnnotHandler(new CPDFSDK_XFAAnnotHandler(pApp)),
#endif // PDF_ENABLE_XFA
+ m_pApp(pApp) {
+ m_pBFAnnotHandler->SetFormFiller(m_pApp->GetIFormFiller());
}
CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {}
-void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(
- IPDFSDK_AnnotHandler* pAnnotHandler) {
- ASSERT(!GetAnnotHandler(pAnnotHandler->GetType()));
-
- m_mapType2Handler[pAnnotHandler->GetType()].reset(pAnnotHandler);
-}
-
-void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(
- IPDFSDK_AnnotHandler* pAnnotHandler) {
- m_mapType2Handler.erase(pAnnotHandler->GetType());
-}
-
CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
CPDFSDK_PageView* pPageView) {
ASSERT(pPageView);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler =
- GetAnnotHandler(pAnnot->GetSubtype())) {
- return pAnnotHandler->NewAnnot(pAnnot, pPageView);
- }
-
- return new CPDFSDK_BAAnnot(pAnnot, pPageView);
+ return GetAnnotHandler(pAnnot->GetSubtype())->NewAnnot(pAnnot, pPageView);
}
#ifdef PDF_ENABLE_XFA
@@ -66,22 +46,14 @@ CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot,
ASSERT(pAnnot);
ASSERT(pPageView);
- if (IPDFSDK_AnnotHandler* pAnnotHandler =
- GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) {
- return pAnnotHandler->NewAnnot(pAnnot, pPageView);
- }
-
- return nullptr;
+ return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)->NewAnnot(pAnnot, pPageView);
}
#endif // PDF_ENABLE_XFA
void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
- pAnnotHandler->OnRelease(pAnnot);
- pAnnotHandler->ReleaseAnnot(pAnnot);
- } else {
- delete pAnnot;
- }
+ IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
+ pAnnotHandler->OnRelease(pAnnot);
+ pAnnotHandler->ReleaseAnnot(pAnnot);
}
void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
@@ -91,33 +63,30 @@ void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString());
pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0);
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- pAnnotHandler->OnCreate(pAnnot);
+ GetAnnotHandler(pAnnot)->OnCreate(pAnnot);
}
void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- pAnnotHandler->OnLoad(pAnnot);
+ GetAnnotHandler(pAnnot)->OnLoad(pAnnot);
}
IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
CPDFSDK_Annot* pAnnot) const {
- CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
- if (pPDFAnnot)
- return GetAnnotHandler(pPDFAnnot->GetSubtype());
-#ifdef PDF_ENABLE_XFA
- if (pAnnot->GetXFAWidget())
- return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
-#endif // PDF_ENABLE_XFA
- return nullptr;
+ return GetAnnotHandler(pAnnot->GetAnnotSubtype());
}
IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
const CFX_ByteString& sType) const {
- auto it = m_mapType2Handler.find(sType);
- return it != m_mapType2Handler.end() ? it->second.get() : nullptr;
+ if (sType == "Widget")
+ return m_pBFAnnotHandler.get();
+
+#ifdef PDF_ENABLE_XFA
+ if (sType == FSDK_XFAWIDGET_TYPENAME)
+ return m_pXFAAnnotHandler.get();
+#endif // PDF_ENABLE_XFA
+
+ return m_pBAAnnotHandler.get();
}
void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
@@ -126,17 +95,8 @@ void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
CFX_Matrix* pUser2Device,
uint32_t dwFlags) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
- pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
- } else {
-#ifdef PDF_ENABLE_XFA
- if (pAnnot->IsXFAField())
- return;
-#endif // PDF_ENABLE_XFA
- static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
- pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
- }
+ GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device,
+ dwFlags);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
@@ -145,11 +105,8 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
uint32_t nFlags,
const CFX_FloatPoint& point) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
-
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnLButtonDown(pPageView, pAnnot, nFlags,
+ point);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
@@ -158,11 +115,7 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
uint32_t nFlags,
const CFX_FloatPoint& point) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
-
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnLButtonUp(pPageView, pAnnot, nFlags, point);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
@@ -171,11 +124,8 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
uint32_t nFlags,
const CFX_FloatPoint& point) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
-
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnLButtonDblClk(pPageView, pAnnot, nFlags,
+ point);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
@@ -184,11 +134,7 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
uint32_t nFlags,
const CFX_FloatPoint& point) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
-
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnMouseMove(pPageView, pAnnot, nFlags, point);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
@@ -198,12 +144,8 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
short zDelta,
const CFX_FloatPoint& point) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
- return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
- point);
- }
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnMouseWheel(pPageView, pAnnot, nFlags,
+ zDelta, point);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
@@ -212,11 +154,8 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
uint32_t nFlags,
const CFX_FloatPoint& point) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
-
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnRButtonDown(pPageView, pAnnot, nFlags,
+ point);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
@@ -225,61 +164,48 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
uint32_t nFlags,
const CFX_FloatPoint& point) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
-
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnRButtonUp(pPageView, pAnnot, nFlags, point);
}
void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot,
uint32_t nFlag) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
+ GetAnnotHandler(pAnnot)->OnMouseEnter(pPageView, pAnnot, nFlag);
}
void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot,
uint32_t nFlag) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
+ GetAnnotHandler(pAnnot)->OnMouseExit(pPageView, pAnnot, nFlag);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
uint32_t nChar,
uint32_t nFlags) {
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnChar(pAnnot, nChar, nFlags);
-
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
int nKeyCode,
int nFlag) {
- if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) {
- CPDFSDK_PageView* pPage = pAnnot->GetPageView();
- CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
- if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
- CPDFSDK_Annot* pNext =
- GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
-
- if (pNext && pNext != pFocusAnnot) {
- CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
- pDocument->SetFocusAnnot(pNext);
- return TRUE;
- }
+ if (m_pApp->FFI_IsCTRLKeyDown(nFlag) || m_pApp->FFI_IsALTKeyDown(nFlag))
+ return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag);
+
+ CPDFSDK_PageView* pPage = pAnnot->GetPageView();
+ CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
+ if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
+ CPDFSDK_Annot* pNext =
+ GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
+
+ if (pNext && pNext != pFocusAnnot) {
+ CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
+ pDocument->SetFocusAnnot(pNext);
+ return TRUE;
}
}
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag);
-
return FALSE;
}
@@ -293,24 +219,18 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot,
uint32_t nFlag) {
ASSERT(pAnnot);
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
- if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) {
- CPDFSDK_PageView* pPage = pAnnot->GetPageView();
- pPage->GetSDKDocument();
- return TRUE;
- }
- }
- return FALSE;
+ if (!GetAnnotHandler(pAnnot)->OnSetFocus(pAnnot, nFlag))
+ return FALSE;
+
+ CPDFSDK_PageView* pPage = pAnnot->GetPageView();
+ pPage->GetSDKDocument();
+ return TRUE;
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
uint32_t nFlag) {
ASSERT(pAnnot);
-
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
-
- return FALSE;
+ return GetAnnotHandler(pAnnot)->OnKillFocus(pAnnot, nFlag);
}
#ifdef PDF_ENABLE_XFA
@@ -334,20 +254,17 @@ CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot) {
ASSERT(pAnnot);
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
- return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
-
- return pAnnot->GetRect();
+ return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot);
}
FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot,
const CFX_FloatPoint& point) {
ASSERT(pAnnot);
- if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
- if (pAnnotHandler->CanAnswer(pAnnot))
- return pAnnotHandler->HitTest(pPageView, pAnnot, point);
- }
+ IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot);
+ if (pAnnotHandler->CanAnswer(pAnnot))
+ return pAnnotHandler->HitTest(pPageView, pAnnot, point);
+
return FALSE;
}
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index d1d3a0f63a..5e3e14572c 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -23,6 +23,10 @@ CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
return m_pAnnot;
}
+CPDF_Annot* CPDFSDK_BAAnnot::GetPDFPopupAnnot() const {
+ return m_pAnnot->GetPopupAnnot();
+}
+
CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
return m_pAnnot->GetAnnotDict();
}
@@ -396,3 +400,8 @@ void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
CPDF_Annot::Normal, nullptr);
}
+
+void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) {
+ if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot())
+ pAnnot->SetOpenState(bOpenState);
+}
diff --git a/fpdfsdk/cpdfsdk_baannothandler.cpp b/fpdfsdk/cpdfsdk_baannothandler.cpp
new file mode 100644
index 0000000000..2fe3623099
--- /dev/null
+++ b/fpdfsdk/cpdfsdk_baannothandler.cpp
@@ -0,0 +1,219 @@
+// 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/include/cpdfsdk_baannothandler.h"
+
+#include <memory>
+#include <vector>
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+#include "core/fpdfdoc/include/cpdf_interform.h"
+#include "fpdfsdk/formfiller/cffl_formfiller.h"
+#include "fpdfsdk/include/cpdfsdk_annot.h"
+#include "fpdfsdk/include/cpdfsdk_baannot.h"
+#include "fpdfsdk/include/fsdk_mgr.h"
+
+#ifdef PDF_ENABLE_XFA
+#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
+#endif // PDF_ENABLE_XFA
+
+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());
+ pPageView->UpdateRects(rects);
+}
+
+} // namespace
+
+CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {}
+
+CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {}
+
+CFX_ByteString CPDFSDK_BAAnnotHandler::GetType() {
+ return CFX_ByteString("");
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
+ return FALSE;
+}
+
+CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
+ CPDFSDK_PageView* pPage) {
+ return new CPDFSDK_BAAnnot(pAnnot, pPage);
+}
+
+#ifdef PDF_ENABLE_XFA
+CPDFSDK_Annot* CPDFSDK_BAAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
+ CPDFSDK_PageView* pPage) {
+ return nullptr;
+}
+#endif // PDF_ENABLE_XFA
+
+void CPDFSDK_BAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
+ delete pAnnot;
+}
+
+void CPDFSDK_BAAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
+
+void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice,
+ CFX_Matrix* pUser2Device,
+ uint32_t dwFlags) {
+#ifdef PDF_ENABLE_XFA
+ if (pAnnot->IsXFAField())
+ return;
+#endif // PDF_ENABLE_XFA
+ static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
+ pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
+}
+
+void CPDFSDK_BAAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice,
+ CFX_Matrix* pUser2Device,
+ const CFX_FloatRect& rcWindow,
+ uint32_t dwFlags) {}
+
+void CPDFSDK_BAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
+
+void CPDFSDK_BAAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
+
+void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlag) {
+ CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot);
+ pBAAnnot->SetOpenState(true);
+ UpdateAnnotRects(pPageView, pBAAnnot);
+}
+
+void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlag) {
+ CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pAnnot);
+ pBAAnnot->SetOpenState(false);
+ UpdateAnnotRects(pPageView, pBAAnnot);
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ short zDelta,
+ const CFX_FloatPoint& point) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
+ uint32_t nChar,
+ uint32_t nFlags) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
+ int nKeyCode,
+ int nFlag) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
+ int nKeyCode,
+ int nFlag) {
+ return FALSE;
+}
+
+void CPDFSDK_BAAnnotHandler::OnDeSelected(CPDFSDK_Annot* pAnnot) {}
+
+void CPDFSDK_BAAnnotHandler::OnSelected(CPDFSDK_Annot* pAnnot) {}
+
+void CPDFSDK_BAAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {}
+
+void CPDFSDK_BAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
+ uint32_t nFlag) {
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
+ uint32_t nFlag) {
+ return FALSE;
+}
+
+#ifdef PDF_ENABLE_XFA
+FX_BOOL CPDFSDK_BAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
+ CPDFSDK_Annot* pNewAnnot) {
+ return TRUE;
+}
+#endif // PDF_ENABLE_XFA
+
+CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot) {
+ return pAnnot->GetRect();
+}
+
+FX_BOOL CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ const CFX_FloatPoint& point) {
+ ASSERT(pPageView);
+ ASSERT(pAnnot);
+
+ CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot);
+ return rect.Contains(point.x, point.y);
+}
diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp
index 9f16098e12..fda00e0e6e 100644
--- a/fpdfsdk/fsdk_mgr.cpp
+++ b/fpdfsdk/fsdk_mgr.cpp
@@ -602,6 +602,8 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX,
CPDFSDK_AnnotIterator annotIterator(this, false);
while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
CFX_FloatRect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
+ if (pSDKAnnot->GetAnnotSubtype() == "Popup")
+ continue;
if (rc.Contains(pageX, pageY))
return pSDKAnnot;
}
@@ -833,13 +835,13 @@ FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point,
FX_BOOL CPDFSDK_PageView::OnMouseMove(const CFX_FloatPoint& point, int nFlag) {
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- if (CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y)) {
+ if (CPDFSDK_Annot* pFXAnnot = GetFXAnnotAtPoint(point.x, point.y)) {
if (m_CaptureWidget && m_CaptureWidget != pFXAnnot) {
m_bExitWidget = TRUE;
m_bEnterWidget = FALSE;
pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
}
- m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
+ m_CaptureWidget = pFXAnnot;
m_bOnWidget = TRUE;
if (!m_bEnterWidget) {
m_bEnterWidget = TRUE;
diff --git a/fpdfsdk/include/cpdfsdk_annothandlermgr.h b/fpdfsdk/include/cpdfsdk_annothandlermgr.h
index 2d09326e68..2ff35f83be 100644
--- a/fpdfsdk/include/cpdfsdk_annothandlermgr.h
+++ b/fpdfsdk/include/cpdfsdk_annothandlermgr.h
@@ -18,10 +18,13 @@ class CFX_RenderDevice;
class CPDF_Annot;
class CPDFDoc_Environment;
class CPDFSDK_Annot;
+class CPDFSDK_BAAnnotHandler;
+class CPDFSDK_BFAnnotHandler;
class CPDFSDK_PageView;
class IPDFSDK_AnnotHandler;
#ifdef PDF_ENABLE_XFA
+class CPDFSDK_XFAAnnotHandler;
class CXFA_FFWidget;
#endif // PDF_ENABLE_XFA
@@ -30,9 +33,6 @@ class CPDFSDK_AnnotHandlerMgr {
explicit CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp);
virtual ~CPDFSDK_AnnotHandlerMgr();
- void RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler);
- void UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler);
-
virtual CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot,
CPDFSDK_PageView* pPageView);
#ifdef PDF_ENABLE_XFA
@@ -112,8 +112,12 @@ class CPDFSDK_AnnotHandlerMgr {
IPDFSDK_AnnotHandler* GetAnnotHandler(const CFX_ByteString& sType) const;
CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, FX_BOOL bNext);
- std::map<CFX_ByteString, std::unique_ptr<IPDFSDK_AnnotHandler>>
- m_mapType2Handler;
+ std::unique_ptr<CPDFSDK_BAAnnotHandler> m_pBAAnnotHandler;
+ std::unique_ptr<CPDFSDK_BFAnnotHandler> m_pBFAnnotHandler;
+#ifdef PDF_ENABLE_XFA
+ std::unique_ptr<CPDFSDK_XFAAnnotHandler> m_pXFAAnnotHandler;
+#endif // PDF_ENABLE_XFA
+
CPDFDoc_Environment* m_pApp;
};
diff --git a/fpdfsdk/include/cpdfsdk_baannot.h b/fpdfsdk/include/cpdfsdk_baannot.h
index e83cb0fe45..0f417383c2 100644
--- a/fpdfsdk/include/cpdfsdk_baannot.h
+++ b/fpdfsdk/include/cpdfsdk_baannot.h
@@ -37,6 +37,7 @@ class CPDFSDK_BAAnnot : public CPDFSDK_Annot {
CPDF_RenderOptions* pOptions) override;
CPDF_Dictionary* GetAnnotDict() const;
+ CPDF_Annot* GetPDFPopupAnnot() const;
void SetContents(const CFX_WideString& sContents);
CFX_WideString GetContents() const;
@@ -96,6 +97,8 @@ class CPDFSDK_BAAnnot : public CPDFSDK_Annot {
const CFX_ByteString& sContents,
const CFX_ByteString& sAPState = "");
+ void SetOpenState(bool bState);
+
protected:
CPDF_Annot* m_pAnnot;
};
diff --git a/fpdfsdk/include/cpdfsdk_baannothandler.h b/fpdfsdk/include/cpdfsdk_baannothandler.h
new file mode 100644
index 0000000000..c1936a798e
--- /dev/null
+++ b/fpdfsdk/include/cpdfsdk_baannothandler.h
@@ -0,0 +1,114 @@
+// 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
+
+#ifndef FPDFSDK_INCLUDE_CPDFSDK_BAANNOTHANDLER_H_
+#define FPDFSDK_INCLUDE_CPDFSDK_BAANNOTHANDLER_H_
+
+#include "core/fxcrt/include/fx_basic.h"
+#include "core/fxcrt/include/fx_coordinates.h"
+#include "fpdfsdk/include/ipdfsdk_annothandler.h"
+
+class CFFL_IFormFiller;
+class CFX_Matrix;
+class CFX_RenderDevice;
+class CPDF_Annot;
+class CPDFDoc_Environment;
+class CPDFSDK_Annot;
+class CPDFSDK_PageView;
+
+#ifdef PDF_ENABLE_XFA
+class CXFA_FFWidget;
+#endif // PDF_ENABLE_XFA
+
+class CPDFSDK_BAAnnotHandler : public IPDFSDK_AnnotHandler {
+ public:
+ CPDFSDK_BAAnnotHandler();
+ ~CPDFSDK_BAAnnotHandler() override;
+
+ CFX_ByteString GetType() override;
+ FX_BOOL CanAnswer(CPDFSDK_Annot* pAnnot) override;
+ CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override;
+#ifdef PDF_ENABLE_XFA
+ CPDFSDK_Annot* NewAnnot(CXFA_FFWidget* hWidget,
+ CPDFSDK_PageView* pPage) override;
+#endif // PDF_ENABLE_XFA
+ void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override;
+ void DeleteAnnot(CPDFSDK_Annot* pAnnot) override;
+ CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot) override;
+ FX_BOOL HitTest(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ const CFX_FloatPoint& point) override;
+ void OnDraw(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice,
+ CFX_Matrix* pUser2Device,
+ uint32_t dwFlags) override;
+ void OnDrawSleep(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ CFX_RenderDevice* pDevice,
+ CFX_Matrix* pUser2Device,
+ const CFX_FloatRect& rcWindow,
+ uint32_t dwFlags) override;
+ void OnCreate(CPDFSDK_Annot* pAnnot) override;
+ void OnLoad(CPDFSDK_Annot* pAnnot) override;
+ void OnDelete(CPDFSDK_Annot* pAnnot) override;
+ void OnRelease(CPDFSDK_Annot* pAnnot) override;
+ void OnMouseEnter(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlag) override;
+ void OnMouseExit(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlag) override;
+ FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) override;
+ FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) override;
+ FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) override;
+ FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) override;
+ FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ short zDelta,
+ const CFX_FloatPoint& point) override;
+ FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) override;
+ FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) override;
+ FX_BOOL OnRButtonDblClk(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot* pAnnot,
+ uint32_t nFlags,
+ const CFX_FloatPoint& point) override;
+ FX_BOOL OnChar(CPDFSDK_Annot* pAnnot,
+ uint32_t nChar,
+ uint32_t nFlags) override;
+ FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override;
+ FX_BOOL OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) override;
+ void OnDeSelected(CPDFSDK_Annot* pAnnot) override;
+ void OnSelected(CPDFSDK_Annot* pAnnot) override;
+ FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override;
+ FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, uint32_t nFlag) override;
+#ifdef PDF_ENABLE_XFA
+ FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
+ CPDFSDK_Annot* pNewAnnot) override;
+#endif // PDF_ENABLE_XFA
+};
+
+#endif // FPDFSDK_INCLUDE_CPDFSDK_BAANNOTHANDLER_H_
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index 2892407f3f..924cd444e0 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -616,10 +616,8 @@ class CPDFSDK_PageView final : public CPDF_Page::View {
std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
CPDFSDK_Document* const m_pSDKDoc;
-#ifdef PDF_ENABLE_XFA
CPDFSDK_Annot* m_CaptureWidget;
-#else // PDF_ENABLE_XFA
- CPDFSDK_Widget* m_CaptureWidget;
+#ifndef PDF_ENABLE_XFA
FX_BOOL m_bTakeOverPage;
#endif // PDF_ENABLE_XFA
FX_BOOL m_bEnterWidget;