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