jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 1 | // 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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_annothandlermgr.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 8 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 9 | #include "core/fpdfapi/parser/cpdf_number.h" |
| 10 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 11 | #include "core/fpdfdoc/cpdf_annot.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 12 | #include "fpdfsdk/cba_annotiterator.h" |
| 13 | #include "fpdfsdk/cpdfsdk_annot.h" |
| 14 | #include "fpdfsdk/cpdfsdk_baannot.h" |
| 15 | #include "fpdfsdk/cpdfsdk_baannothandler.h" |
| 16 | #include "fpdfsdk/cpdfsdk_datetime.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 17 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 18 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 19 | #include "fpdfsdk/cpdfsdk_widgethandler.h" |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 20 | #include "third_party/base/ptr_util.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 21 | |
| 22 | #ifdef PDF_ENABLE_XFA |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 23 | #include "fpdfsdk/cpdfsdk_xfawidgethandler.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 24 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 25 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 26 | #include "xfa/fxfa/cxfa_ffwidget.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 27 | #endif // PDF_ENABLE_XFA |
| 28 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 29 | CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr( |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 30 | CPDFSDK_FormFillEnvironment* pFormFillEnv) |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 31 | : m_pBAAnnotHandler(pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>()), |
| 32 | m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv)), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 33 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 34 | m_pXFAWidgetHandler( |
| 35 | pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv)), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 36 | #endif // PDF_ENABLE_XFA |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 37 | m_pFormFillEnv(pFormFillEnv) { |
| 38 | m_pWidgetHandler->SetFormFiller(m_pFormFillEnv->GetInteractiveFormFiller()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {} |
| 42 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 43 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, |
| 44 | CPDFSDK_PageView* pPageView) { |
| 45 | ASSERT(pPageView); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 46 | return GetAnnotHandler(pAnnot->GetSubtype())->NewAnnot(pAnnot, pPageView); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | #ifdef PDF_ENABLE_XFA |
| 50 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot, |
| 51 | CPDFSDK_PageView* pPageView) { |
| 52 | ASSERT(pAnnot); |
| 53 | ASSERT(pPageView); |
| 54 | |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 55 | return GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET) |
| 56 | ->NewAnnot(pAnnot, pPageView); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 57 | } |
| 58 | #endif // PDF_ENABLE_XFA |
| 59 | |
| 60 | void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 61 | IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 62 | pAnnotHandler->ReleaseAnnot(pAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) { |
| 66 | CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); |
| 67 | |
| 68 | CPDFSDK_DateTime curTime; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 69 | pPDFAnnot->GetAnnotDict()->SetNewFor<CPDF_String>( |
| 70 | "M", curTime.ToPDFDateTimeString(), false); |
| 71 | pPDFAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F", 0); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) { |
| 75 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 76 | GetAnnotHandler(pAnnot)->OnLoad(pAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
| 80 | CPDFSDK_Annot* pAnnot) const { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 81 | return GetAnnotHandler(pAnnot->GetAnnotSubtype()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 85 | CPDF_Annot::Subtype nAnnotSubtype) const { |
| 86 | if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 87 | return m_pWidgetHandler.get(); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 88 | |
| 89 | #ifdef PDF_ENABLE_XFA |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 90 | if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 91 | return m_pXFAWidgetHandler.get(); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 92 | #endif // PDF_ENABLE_XFA |
| 93 | |
| 94 | return m_pBAAnnotHandler.get(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, |
| 98 | CPDFSDK_Annot* pAnnot, |
| 99 | CFX_RenderDevice* pDevice, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 100 | CFX_Matrix* pUser2Device, |
| 101 | bool bDrawAnnots) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 102 | ASSERT(pAnnot); |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 103 | GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, |
| 104 | bDrawAnnots); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 105 | } |
| 106 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 107 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 108 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 109 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 110 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 111 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 112 | ASSERT(*pAnnot); |
| 113 | return GetAnnotHandler(pAnnot->Get()) |
| 114 | ->OnLButtonDown(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 115 | } |
| 116 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 117 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 118 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 119 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 120 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 121 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 122 | ASSERT(*pAnnot); |
| 123 | return GetAnnotHandler(pAnnot->Get()) |
| 124 | ->OnLButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 125 | } |
| 126 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 127 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 128 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 129 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 130 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 131 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 132 | ASSERT(*pAnnot); |
| 133 | return GetAnnotHandler(pAnnot->Get()) |
| 134 | ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 135 | } |
| 136 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 137 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 138 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 139 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 140 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 141 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 142 | ASSERT(*pAnnot); |
| 143 | return GetAnnotHandler(pAnnot->Get()) |
| 144 | ->OnMouseMove(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 145 | } |
| 146 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 147 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 148 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 149 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 150 | uint32_t nFlags, |
| 151 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 152 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 153 | ASSERT(*pAnnot); |
| 154 | return GetAnnotHandler(pAnnot->Get()) |
| 155 | ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 156 | } |
| 157 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 158 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 159 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 160 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 161 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 162 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 163 | ASSERT(*pAnnot); |
| 164 | return GetAnnotHandler(pAnnot->Get()) |
| 165 | ->OnRButtonDown(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 166 | } |
| 167 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 168 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 169 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 170 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 171 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 172 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 173 | ASSERT(*pAnnot); |
| 174 | return GetAnnotHandler(pAnnot->Get()) |
| 175 | ->OnRButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 176 | } |
| 177 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 178 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter( |
| 179 | CPDFSDK_PageView* pPageView, |
| 180 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 181 | uint32_t nFlag) { |
| 182 | ASSERT(*pAnnot); |
| 183 | GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 184 | } |
| 185 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 186 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit( |
| 187 | CPDFSDK_PageView* pPageView, |
| 188 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 189 | uint32_t nFlag) { |
| 190 | ASSERT(*pAnnot); |
| 191 | GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 192 | } |
| 193 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 194 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, |
| 195 | uint32_t nChar, |
| 196 | uint32_t nFlags) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 197 | return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 198 | } |
| 199 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 200 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 201 | int nKeyCode, |
| 202 | int nFlag) { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 203 | if (m_pFormFillEnv->IsCTRLKeyDown(nFlag) || |
thestig | 7b3252f | 2016-11-08 21:30:11 -0800 | [diff] [blame] | 204 | m_pFormFillEnv->IsALTKeyDown(nFlag)) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 205 | return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag); |
thestig | 7b3252f | 2016-11-08 21:30:11 -0800 | [diff] [blame] | 206 | } |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 207 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 208 | CPDFSDK_PageView* pPage = pAnnot->GetPageView(); |
| 209 | CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot(); |
| 210 | if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 211 | CPDFSDK_Annot::ObservedPtr pNext( |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 212 | GetNextAnnot(pFocusAnnot, !m_pFormFillEnv->IsSHIFTKeyDown(nFlag))); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 213 | if (pNext && pNext.Get() != pFocusAnnot) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 214 | pPage->GetFormFillEnv()->SetFocusAnnot(&pNext); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 215 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
thestig | 7b3252f | 2016-11-08 21:30:11 -0800 | [diff] [blame] | 219 | return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 220 | } |
| 221 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 222 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 223 | int nKeyCode, |
| 224 | int nFlag) { |
| 225 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 226 | } |
| 227 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 228 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 229 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 230 | uint32_t nFlag) { |
| 231 | ASSERT(*pAnnot); |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 232 | return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 233 | } |
| 234 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 235 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 236 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 237 | uint32_t nFlag) { |
| 238 | ASSERT(*pAnnot); |
| 239 | return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 243 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 244 | CPDFSDK_Annot::ObservedPtr* pSetAnnot, |
| 245 | CPDFSDK_Annot::ObservedPtr* pKillAnnot) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 246 | bool bXFA = (*pSetAnnot && (*pSetAnnot)->GetXFAWidget()) || |
| 247 | (*pKillAnnot && (*pKillAnnot)->GetXFAWidget()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 248 | |
| 249 | if (bXFA) { |
| 250 | if (IPDFSDK_AnnotHandler* pXFAAnnotHandler = |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 251 | GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 252 | return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot); |
| 253 | } |
| 254 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 255 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 256 | } |
| 257 | #endif // PDF_ENABLE_XFA |
| 258 | |
| 259 | CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox( |
| 260 | CPDFSDK_PageView* pPageView, |
| 261 | CPDFSDK_Annot* pAnnot) { |
| 262 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 263 | return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 264 | } |
| 265 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 266 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView, |
| 267 | CPDFSDK_Annot* pAnnot, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 268 | const CFX_PointF& point) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 269 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 270 | IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot); |
| 271 | if (pAnnotHandler->CanAnswer(pAnnot)) |
| 272 | return pAnnotHandler->HitTest(pPageView, pAnnot, point); |
| 273 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 274 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 278 | bool bNext) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 279 | #ifdef PDF_ENABLE_XFA |
| 280 | CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); |
| 281 | CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); |
| 282 | if (!pPage) |
| 283 | return nullptr; |
| 284 | if (pPage->GetPDFPage()) { // for pdf annots. |
jaepark | 9ed9137 | 2016-08-26 16:16:10 -0700 | [diff] [blame] | 285 | CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), |
| 286 | pSDKAnnot->GetAnnotSubtype()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 287 | CPDFSDK_Annot* pNext = |
| 288 | bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); |
| 289 | return pNext; |
| 290 | } |
| 291 | // for xfa annots |
| 292 | std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( |
| 293 | pPage->GetXFAPageView()->CreateWidgetIterator( |
| 294 | XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible | |
| 295 | XFA_WidgetStatus_Viewable | |
| 296 | XFA_WidgetStatus_Focused)); |
| 297 | if (!pWidgetIterator) |
| 298 | return nullptr; |
| 299 | if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) |
| 300 | pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); |
| 301 | CXFA_FFWidget* hNextFocus = |
| 302 | bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious(); |
| 303 | if (!hNextFocus && pSDKAnnot) |
| 304 | hNextFocus = pWidgetIterator->MoveToFirst(); |
| 305 | |
| 306 | return pPageView->GetAnnotByXFAWidget(hNextFocus); |
| 307 | #else // PDF_ENABLE_XFA |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 308 | CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), CPDF_Annot::Subtype::WIDGET); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 309 | return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); |
| 310 | #endif // PDF_ENABLE_XFA |
| 311 | } |