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 | |
Tom Sepez | 0f35a9e | 2019-04-23 00:32:37 +0000 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 11 | #include "core/fpdfapi/parser/cpdf_number.h" |
| 12 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 13 | #include "core/fpdfdoc/cpdf_annot.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/cpdfsdk_annot.h" |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 15 | #include "fpdfsdk/cpdfsdk_annotiterator.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 16 | #include "fpdfsdk/cpdfsdk_baannot.h" |
| 17 | #include "fpdfsdk/cpdfsdk_baannothandler.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 18 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 19 | #include "fpdfsdk/cpdfsdk_pageview.h" |
Tom Sepez | 11a6bec | 2018-07-25 23:25:55 +0000 | [diff] [blame] | 20 | #include "fpdfsdk/cpdfsdk_widget.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/cpdfsdk_widgethandler.h" |
Tom Sepez | 43f012f | 2019-08-02 16:16:46 +0000 | [diff] [blame^] | 22 | #include "fpdfsdk/pwl/cpwl_wnd.h" |
Lei Zhang | ac75664 | 2018-12-13 20:47:10 +0000 | [diff] [blame] | 23 | #include "public/fpdf_fwlevent.h" |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 24 | #include "third_party/base/ptr_util.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 25 | |
| 26 | #ifdef PDF_ENABLE_XFA |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 27 | #include "fpdfsdk/cpdfsdk_xfawidgethandler.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 28 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 29 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 30 | #include "xfa/fxfa/cxfa_ffwidget.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 31 | #endif // PDF_ENABLE_XFA |
| 32 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 33 | CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr( |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 34 | CPDFSDK_FormFillEnvironment* pFormFillEnv) |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 35 | : m_pBAAnnotHandler(pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>()), |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 36 | m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 37 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 38 | , |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 39 | m_pXFAWidgetHandler( |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 40 | pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 41 | #endif // PDF_ENABLE_XFA |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 42 | { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {} |
| 46 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 47 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, |
| 48 | CPDFSDK_PageView* pPageView) { |
| 49 | ASSERT(pPageView); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 50 | return GetAnnotHandler(pAnnot->GetSubtype())->NewAnnot(pAnnot, pPageView); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | #ifdef PDF_ENABLE_XFA |
| 54 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot, |
| 55 | CPDFSDK_PageView* pPageView) { |
| 56 | ASSERT(pAnnot); |
| 57 | ASSERT(pPageView); |
| 58 | |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 59 | return GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET) |
| 60 | ->NewAnnot(pAnnot, pPageView); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 61 | } |
| 62 | #endif // PDF_ENABLE_XFA |
| 63 | |
Tom Sepez | 0f35a9e | 2019-04-23 00:32:37 +0000 | [diff] [blame] | 64 | void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot( |
| 65 | std::unique_ptr<CPDFSDK_Annot> pAnnot) { |
| 66 | IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot.get()); |
| 67 | pAnnotHandler->ReleaseAnnot(std::move(pAnnot)); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 68 | } |
| 69 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 70 | void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) { |
| 71 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 72 | GetAnnotHandler(pAnnot)->OnLoad(pAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 75 | WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) { |
| 76 | return GetAnnotHandler(pAnnot)->GetText(pAnnot); |
| 77 | } |
| 78 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 79 | WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText( |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 80 | CPDFSDK_Annot* pAnnot) { |
| 81 | return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot); |
| 82 | } |
| 83 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 84 | void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot, |
| 85 | const WideString& text) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 86 | GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 89 | bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) { |
| 90 | return GetAnnotHandler(pAnnot)->CanUndo(pAnnot); |
| 91 | } |
| 92 | |
| 93 | bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) { |
| 94 | return GetAnnotHandler(pAnnot)->CanRedo(pAnnot); |
| 95 | } |
| 96 | |
| 97 | bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) { |
| 98 | return GetAnnotHandler(pAnnot)->Undo(pAnnot); |
| 99 | } |
| 100 | |
| 101 | bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) { |
| 102 | return GetAnnotHandler(pAnnot)->Redo(pAnnot); |
| 103 | } |
| 104 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 105 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
| 106 | CPDFSDK_Annot* pAnnot) const { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 107 | return GetAnnotHandler(pAnnot->GetAnnotSubtype()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 111 | CPDF_Annot::Subtype nAnnotSubtype) const { |
| 112 | if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 113 | return m_pWidgetHandler.get(); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 114 | |
| 115 | #ifdef PDF_ENABLE_XFA |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 116 | if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 117 | return m_pXFAWidgetHandler.get(); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 118 | #endif // PDF_ENABLE_XFA |
| 119 | |
| 120 | return m_pBAAnnotHandler.get(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, |
| 124 | CPDFSDK_Annot* pAnnot, |
| 125 | CFX_RenderDevice* pDevice, |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 126 | const CFX_Matrix& mtUser2Device, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 127 | bool bDrawAnnots) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 128 | ASSERT(pAnnot); |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 129 | GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 130 | bDrawAnnots); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 131 | } |
| 132 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 133 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 134 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 135 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 136 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 137 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 138 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 139 | return GetAnnotHandler(pAnnot->Get()) |
| 140 | ->OnLButtonDown(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 141 | } |
| 142 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 143 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 144 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 145 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 146 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 147 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 148 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 149 | return GetAnnotHandler(pAnnot->Get()) |
| 150 | ->OnLButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 153 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk( |
| 154 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 155 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 156 | uint32_t nFlags, |
| 157 | const CFX_PointF& point) { |
| 158 | ASSERT(pAnnot->HasObservable()); |
| 159 | return GetAnnotHandler(pAnnot->Get()) |
| 160 | ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); |
| 161 | } |
| 162 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 163 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 164 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 165 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 166 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 167 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 168 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 169 | return GetAnnotHandler(pAnnot->Get()) |
| 170 | ->OnMouseMove(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 171 | } |
| 172 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 173 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 174 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 175 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 176 | uint32_t nFlags, |
| 177 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 178 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 179 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 180 | return GetAnnotHandler(pAnnot->Get()) |
| 181 | ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 182 | } |
| 183 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 184 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 185 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 186 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 187 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 188 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 189 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 190 | return GetAnnotHandler(pAnnot->Get()) |
| 191 | ->OnRButtonDown(pPageView, pAnnot, nFlags, point); |
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_OnRButtonUp( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 195 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 196 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 197 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 198 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 199 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 200 | return GetAnnotHandler(pAnnot->Get()) |
| 201 | ->OnRButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 202 | } |
| 203 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 204 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter( |
| 205 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 206 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 207 | uint32_t nFlag) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 208 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 209 | GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 210 | } |
| 211 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 212 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit( |
| 213 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 214 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 215 | uint32_t nFlag) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 216 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 217 | GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, 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_OnChar(CPDFSDK_Annot* pAnnot, |
| 221 | uint32_t nChar, |
| 222 | uint32_t nFlags) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 223 | return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags); |
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_OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 227 | int nKeyCode, |
| 228 | int nFlag) { |
Tom Sepez | 43f012f | 2019-08-02 16:16:46 +0000 | [diff] [blame^] | 229 | if (CPWL_Wnd::IsCTRLKeyDown(nFlag) || CPWL_Wnd::IsALTKeyDown(nFlag)) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 230 | return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag); |
thestig | 7b3252f | 2016-11-08 21:30:11 -0800 | [diff] [blame] | 231 | } |
huyna | 6e3a406 | 2019-07-25 20:41:23 +0000 | [diff] [blame] | 232 | ObservedPtr<CPDFSDK_Annot> pObservedAnnot(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 233 | CPDFSDK_PageView* pPage = pAnnot->GetPageView(); |
| 234 | CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot(); |
| 235 | if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) { |
Tom Sepez | 43f012f | 2019-08-02 16:16:46 +0000 | [diff] [blame^] | 236 | ObservedPtr<CPDFSDK_Annot> pNext( |
| 237 | GetNextAnnot(pFocusAnnot, !CPWL_Wnd::IsSHIFTKeyDown(nFlag))); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 238 | if (pNext && pNext.Get() != pFocusAnnot) { |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 239 | pPage->GetFormFillEnv()->SetFocusAnnot(&pNext); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 240 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
huyna | 6e3a406 | 2019-07-25 20:41:23 +0000 | [diff] [blame] | 244 | // Check |pAnnot| again because JS may have destroyed it in |GetNextAnnot| |
| 245 | if (!pObservedAnnot) |
| 246 | return false; |
| 247 | |
thestig | 7b3252f | 2016-11-08 21:30:11 -0800 | [diff] [blame] | 248 | return GetAnnotHandler(pAnnot)->OnKeyDown(pAnnot, nKeyCode, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 249 | } |
| 250 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 251 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus( |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 252 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 253 | uint32_t nFlag) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 254 | ASSERT(pAnnot->HasObservable()); |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 255 | return GetAnnotHandler(pAnnot->Get())->OnSetFocus(pAnnot, nFlag); |
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_OnKillFocus( |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 259 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 260 | uint32_t nFlag) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 261 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 262 | return GetAnnotHandler(pAnnot->Get())->OnKillFocus(pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 263 | } |
| 264 | |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 265 | bool CPDFSDK_AnnotHandlerMgr::Annot_SetIndexSelected( |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 266 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 267 | int index, |
| 268 | bool selected) { |
| 269 | return GetAnnotHandler(pAnnot->Get()) |
| 270 | ->SetIndexSelected(pAnnot, index, selected); |
| 271 | } |
| 272 | |
| 273 | bool CPDFSDK_AnnotHandlerMgr::Annot_IsIndexSelected( |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 274 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 275 | int index) { |
| 276 | return GetAnnotHandler(pAnnot->Get())->IsIndexSelected(pAnnot, index); |
| 277 | } |
| 278 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 279 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 280 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus( |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 281 | ObservedPtr<CPDFSDK_Annot>* pSetAnnot, |
| 282 | ObservedPtr<CPDFSDK_Annot>* pKillAnnot) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 283 | bool bXFA = (*pSetAnnot && (*pSetAnnot)->GetXFAWidget()) || |
| 284 | (*pKillAnnot && (*pKillAnnot)->GetXFAWidget()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 285 | |
| 286 | if (bXFA) { |
| 287 | if (IPDFSDK_AnnotHandler* pXFAAnnotHandler = |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 288 | GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 289 | return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot); |
| 290 | } |
| 291 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 292 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 293 | } |
| 294 | #endif // PDF_ENABLE_XFA |
| 295 | |
| 296 | CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox( |
| 297 | CPDFSDK_PageView* pPageView, |
| 298 | CPDFSDK_Annot* pAnnot) { |
| 299 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 300 | return GetAnnotHandler(pAnnot)->GetViewBBox(pPageView, pAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 301 | } |
| 302 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 303 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView, |
| 304 | CPDFSDK_Annot* pAnnot, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 305 | const CFX_PointF& point) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 306 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 307 | IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot); |
| 308 | if (pAnnotHandler->CanAnswer(pAnnot)) |
| 309 | return pAnnotHandler->HitTest(pPageView, pAnnot, point); |
| 310 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 311 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 315 | bool bNext) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 316 | #ifdef PDF_ENABLE_XFA |
huyna | 6e3a406 | 2019-07-25 20:41:23 +0000 | [diff] [blame] | 317 | ObservedPtr<CPDFSDK_Annot> pObservedAnnot(pSDKAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 318 | CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); |
| 319 | CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); |
Tom Sepez | 8e63177 | 2018-06-13 21:26:56 +0000 | [diff] [blame] | 320 | if (pPage && !pPage->AsPDFPage()) { |
| 321 | // For xfa annots in XFA pages not backed by PDF pages. |
| 322 | std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( |
| 323 | pPage->GetXFAPageView()->CreateWidgetIterator( |
| 324 | XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible | |
| 325 | XFA_WidgetStatus_Viewable | |
| 326 | XFA_WidgetStatus_Focused)); |
huyna | 6e3a406 | 2019-07-25 20:41:23 +0000 | [diff] [blame] | 327 | |
| 328 | // Check |pSDKAnnot| again because JS may have destroyed it |
| 329 | if (!pObservedAnnot || !pWidgetIterator) |
Tom Sepez | 8e63177 | 2018-06-13 21:26:56 +0000 | [diff] [blame] | 330 | return nullptr; |
| 331 | if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) |
| 332 | pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); |
| 333 | CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext() |
| 334 | : pWidgetIterator->MoveToPrevious(); |
| 335 | if (!hNextFocus && pSDKAnnot) |
| 336 | hNextFocus = pWidgetIterator->MoveToFirst(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 337 | |
Tom Sepez | 8e63177 | 2018-06-13 21:26:56 +0000 | [diff] [blame] | 338 | return pPageView->GetAnnotByXFAWidget(hNextFocus); |
| 339 | } |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 340 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 8e63177 | 2018-06-13 21:26:56 +0000 | [diff] [blame] | 341 | |
| 342 | // For PDF annots. |
Tom Sepez | 11a6bec | 2018-07-25 23:25:55 +0000 | [diff] [blame] | 343 | CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot); |
| 344 | CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype()); |
| 345 | return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 346 | } |