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/cpdfsdk_annot.h" |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 13 | #include "fpdfsdk/cpdfsdk_annotiterator.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 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>()), |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 32 | m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 33 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 34 | , |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 35 | m_pXFAWidgetHandler( |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 36 | pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 37 | #endif // PDF_ENABLE_XFA |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 38 | { |
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 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 79 | WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) { |
| 80 | return GetAnnotHandler(pAnnot)->GetText(pAnnot); |
| 81 | } |
| 82 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 83 | WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText( |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 84 | CPDFSDK_Annot* pAnnot) { |
| 85 | return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot); |
| 86 | } |
| 87 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 88 | void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot, |
| 89 | const WideString& text) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 90 | GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 93 | bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) { |
| 94 | return GetAnnotHandler(pAnnot)->CanUndo(pAnnot); |
| 95 | } |
| 96 | |
| 97 | bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) { |
| 98 | return GetAnnotHandler(pAnnot)->CanRedo(pAnnot); |
| 99 | } |
| 100 | |
| 101 | bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) { |
| 102 | return GetAnnotHandler(pAnnot)->Undo(pAnnot); |
| 103 | } |
| 104 | |
| 105 | bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) { |
| 106 | return GetAnnotHandler(pAnnot)->Redo(pAnnot); |
| 107 | } |
| 108 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 109 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
| 110 | CPDFSDK_Annot* pAnnot) const { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 111 | return GetAnnotHandler(pAnnot->GetAnnotSubtype()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 115 | CPDF_Annot::Subtype nAnnotSubtype) const { |
| 116 | if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 117 | return m_pWidgetHandler.get(); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 118 | |
| 119 | #ifdef PDF_ENABLE_XFA |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 120 | if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 121 | return m_pXFAWidgetHandler.get(); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 122 | #endif // PDF_ENABLE_XFA |
| 123 | |
| 124 | return m_pBAAnnotHandler.get(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, |
| 128 | CPDFSDK_Annot* pAnnot, |
| 129 | CFX_RenderDevice* pDevice, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 130 | CFX_Matrix* pUser2Device, |
| 131 | bool bDrawAnnots) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 132 | ASSERT(pAnnot); |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 133 | GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, |
| 134 | bDrawAnnots); |
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_OnLButtonDown( |
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 | ->OnLButtonDown(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_OnLButtonUp( |
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, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 151 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 152 | ASSERT(*pAnnot); |
| 153 | return GetAnnotHandler(pAnnot->Get()) |
| 154 | ->OnLButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 155 | } |
| 156 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 157 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 158 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 159 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 160 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 161 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 162 | ASSERT(*pAnnot); |
| 163 | return GetAnnotHandler(pAnnot->Get()) |
| 164 | ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 165 | } |
| 166 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 167 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 168 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 169 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 170 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 171 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 172 | ASSERT(*pAnnot); |
| 173 | return GetAnnotHandler(pAnnot->Get()) |
| 174 | ->OnMouseMove(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 175 | } |
| 176 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 177 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 178 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 179 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 180 | uint32_t nFlags, |
| 181 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 182 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 183 | ASSERT(*pAnnot); |
| 184 | return GetAnnotHandler(pAnnot->Get()) |
| 185 | ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 186 | } |
| 187 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 188 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 189 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 190 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 191 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 192 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 193 | ASSERT(*pAnnot); |
| 194 | return GetAnnotHandler(pAnnot->Get()) |
| 195 | ->OnRButtonDown(pPageView, pAnnot, nFlags, point); |
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_OnRButtonUp( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 199 | CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 200 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 201 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 202 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 203 | ASSERT(*pAnnot); |
| 204 | return GetAnnotHandler(pAnnot->Get()) |
| 205 | ->OnRButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 206 | } |
| 207 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 208 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter( |
| 209 | CPDFSDK_PageView* pPageView, |
| 210 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 211 | uint32_t nFlag) { |
| 212 | ASSERT(*pAnnot); |
| 213 | GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 214 | } |
| 215 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 216 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit( |
| 217 | CPDFSDK_PageView* pPageView, |
| 218 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 219 | uint32_t nFlag) { |
| 220 | ASSERT(*pAnnot); |
| 221 | GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 222 | } |
| 223 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 224 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, |
| 225 | uint32_t nChar, |
| 226 | uint32_t nFlags) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 227 | return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 228 | } |
| 229 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 230 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 231 | int nKeyCode, |
| 232 | int nFlag) { |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 233 | if (CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag) || |
| 234 | CPDFSDK_FormFillEnvironment::IsALTKeyDown(nFlag)) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 235 | return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag); |
thestig | 7b3252f | 2016-11-08 21:30:11 -0800 | [diff] [blame] | 236 | } |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 237 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 238 | CPDFSDK_PageView* pPage = pAnnot->GetPageView(); |
| 239 | CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot(); |
| 240 | if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) { |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 241 | CPDFSDK_Annot::ObservedPtr pNext(GetNextAnnot( |
| 242 | pFocusAnnot, !CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag))); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 243 | if (pNext && pNext.Get() != pFocusAnnot) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 244 | pPage->GetFormFillEnv()->SetFocusAnnot(&pNext); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 245 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
thestig | 7b3252f | 2016-11-08 21:30:11 -0800 | [diff] [blame] | 249 | return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 250 | } |
| 251 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 252 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 253 | int nKeyCode, |
| 254 | int nFlag) { |
| 255 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 256 | } |
| 257 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 258 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 259 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 260 | uint32_t nFlag) { |
| 261 | ASSERT(*pAnnot); |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 262 | return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 263 | } |
| 264 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 265 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 266 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 267 | uint32_t nFlag) { |
| 268 | ASSERT(*pAnnot); |
| 269 | return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 273 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 274 | CPDFSDK_Annot::ObservedPtr* pSetAnnot, |
| 275 | CPDFSDK_Annot::ObservedPtr* pKillAnnot) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 276 | bool bXFA = (*pSetAnnot && (*pSetAnnot)->GetXFAWidget()) || |
| 277 | (*pKillAnnot && (*pKillAnnot)->GetXFAWidget()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 278 | |
| 279 | if (bXFA) { |
| 280 | if (IPDFSDK_AnnotHandler* pXFAAnnotHandler = |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 281 | GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 282 | return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot); |
| 283 | } |
| 284 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 285 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 286 | } |
| 287 | #endif // PDF_ENABLE_XFA |
| 288 | |
| 289 | CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox( |
| 290 | CPDFSDK_PageView* pPageView, |
| 291 | CPDFSDK_Annot* pAnnot) { |
| 292 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 293 | return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 294 | } |
| 295 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 296 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView, |
| 297 | CPDFSDK_Annot* pAnnot, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 298 | const CFX_PointF& point) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 299 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 300 | IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot); |
| 301 | if (pAnnotHandler->CanAnswer(pAnnot)) |
| 302 | return pAnnotHandler->HitTest(pPageView, pAnnot, point); |
| 303 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 304 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 308 | bool bNext) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 309 | #ifdef PDF_ENABLE_XFA |
| 310 | CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); |
| 311 | CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); |
Tom Sepez | 8e63177 | 2018-06-13 21:26:56 +0000 | [diff] [blame^] | 312 | if (pPage && !pPage->AsPDFPage()) { |
| 313 | // For xfa annots in XFA pages not backed by PDF pages. |
| 314 | std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( |
| 315 | pPage->GetXFAPageView()->CreateWidgetIterator( |
| 316 | XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible | |
| 317 | XFA_WidgetStatus_Viewable | |
| 318 | XFA_WidgetStatus_Focused)); |
| 319 | if (!pWidgetIterator) |
| 320 | return nullptr; |
| 321 | if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) |
| 322 | pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); |
| 323 | CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext() |
| 324 | : pWidgetIterator->MoveToPrevious(); |
| 325 | if (!hNextFocus && pSDKAnnot) |
| 326 | hNextFocus = pWidgetIterator->MoveToFirst(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 327 | |
Tom Sepez | 8e63177 | 2018-06-13 21:26:56 +0000 | [diff] [blame^] | 328 | return pPageView->GetAnnotByXFAWidget(hNextFocus); |
| 329 | } |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 330 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 8e63177 | 2018-06-13 21:26:56 +0000 | [diff] [blame^] | 331 | |
| 332 | // For PDF annots. |
| 333 | ASSERT(pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET); |
| 334 | CPDFSDK_AnnotIterator ai(pSDKAnnot->GetPageView(), |
| 335 | pSDKAnnot->GetAnnotSubtype()); |
| 336 | return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 337 | } |