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" |
Lei Zhang | ac75664 | 2018-12-13 20:47:10 +0000 | [diff] [blame] | 22 | #include "public/fpdf_fwlevent.h" |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 23 | #include "third_party/base/ptr_util.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 24 | |
| 25 | #ifdef PDF_ENABLE_XFA |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 26 | #include "fpdfsdk/cpdfsdk_xfawidgethandler.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 27 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 28 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 29 | #include "xfa/fxfa/cxfa_ffwidget.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 30 | #endif // PDF_ENABLE_XFA |
| 31 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 32 | CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr( |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 33 | CPDFSDK_FormFillEnvironment* pFormFillEnv) |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 34 | : m_pBAAnnotHandler(pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>()), |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 35 | m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 36 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 37 | , |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 38 | m_pXFAWidgetHandler( |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 39 | pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 40 | #endif // PDF_ENABLE_XFA |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 41 | { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {} |
| 45 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 46 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, |
| 47 | CPDFSDK_PageView* pPageView) { |
| 48 | ASSERT(pPageView); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 49 | return GetAnnotHandler(pAnnot->GetSubtype())->NewAnnot(pAnnot, pPageView); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | #ifdef PDF_ENABLE_XFA |
| 53 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot, |
| 54 | CPDFSDK_PageView* pPageView) { |
| 55 | ASSERT(pAnnot); |
| 56 | ASSERT(pPageView); |
| 57 | |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 58 | return GetAnnotHandler(CPDF_Annot::Subtype::XFAWIDGET) |
| 59 | ->NewAnnot(pAnnot, pPageView); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 60 | } |
| 61 | #endif // PDF_ENABLE_XFA |
| 62 | |
Tom Sepez | 0f35a9e | 2019-04-23 00:32:37 +0000 | [diff] [blame] | 63 | void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot( |
| 64 | std::unique_ptr<CPDFSDK_Annot> pAnnot) { |
| 65 | IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot.get()); |
| 66 | pAnnotHandler->ReleaseAnnot(std::move(pAnnot)); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 67 | } |
| 68 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 69 | void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) { |
| 70 | ASSERT(pAnnot); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 71 | GetAnnotHandler(pAnnot)->OnLoad(pAnnot); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 74 | WideString CPDFSDK_AnnotHandlerMgr::Annot_GetText(CPDFSDK_Annot* pAnnot) { |
| 75 | return GetAnnotHandler(pAnnot)->GetText(pAnnot); |
| 76 | } |
| 77 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 78 | WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText( |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 79 | CPDFSDK_Annot* pAnnot) { |
| 80 | return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot); |
| 81 | } |
| 82 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 83 | void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot, |
| 84 | const WideString& text) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 85 | GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 88 | bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) { |
| 89 | return GetAnnotHandler(pAnnot)->CanUndo(pAnnot); |
| 90 | } |
| 91 | |
| 92 | bool CPDFSDK_AnnotHandlerMgr::Annot_CanRedo(CPDFSDK_Annot* pAnnot) { |
| 93 | return GetAnnotHandler(pAnnot)->CanRedo(pAnnot); |
| 94 | } |
| 95 | |
| 96 | bool CPDFSDK_AnnotHandlerMgr::Annot_Undo(CPDFSDK_Annot* pAnnot) { |
| 97 | return GetAnnotHandler(pAnnot)->Undo(pAnnot); |
| 98 | } |
| 99 | |
| 100 | bool CPDFSDK_AnnotHandlerMgr::Annot_Redo(CPDFSDK_Annot* pAnnot) { |
| 101 | return GetAnnotHandler(pAnnot)->Redo(pAnnot); |
| 102 | } |
| 103 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 104 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
| 105 | CPDFSDK_Annot* pAnnot) const { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 106 | return GetAnnotHandler(pAnnot->GetAnnotSubtype()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 110 | CPDF_Annot::Subtype nAnnotSubtype) const { |
| 111 | if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 112 | return m_pWidgetHandler.get(); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 113 | |
| 114 | #ifdef PDF_ENABLE_XFA |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 115 | if (nAnnotSubtype == CPDF_Annot::Subtype::XFAWIDGET) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 116 | return m_pXFAWidgetHandler.get(); |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 117 | #endif // PDF_ENABLE_XFA |
| 118 | |
| 119 | return m_pBAAnnotHandler.get(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, |
| 123 | CPDFSDK_Annot* pAnnot, |
| 124 | CFX_RenderDevice* pDevice, |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 125 | const CFX_Matrix& mtUser2Device, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 126 | bool bDrawAnnots) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 127 | ASSERT(pAnnot); |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 128 | GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 129 | bDrawAnnots); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 130 | } |
| 131 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 132 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 133 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 134 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 135 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 136 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 137 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 138 | return GetAnnotHandler(pAnnot->Get()) |
| 139 | ->OnLButtonDown(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 140 | } |
| 141 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 142 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 143 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 144 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 145 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 146 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 147 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 148 | return GetAnnotHandler(pAnnot->Get()) |
| 149 | ->OnLButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 152 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk( |
| 153 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 154 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
Lei Zhang | a37989f | 2018-10-17 20:32:41 +0000 | [diff] [blame] | 155 | uint32_t nFlags, |
| 156 | const CFX_PointF& point) { |
| 157 | ASSERT(pAnnot->HasObservable()); |
| 158 | return GetAnnotHandler(pAnnot->Get()) |
| 159 | ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); |
| 160 | } |
| 161 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 162 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 163 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 164 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 165 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 166 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 167 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 168 | return GetAnnotHandler(pAnnot->Get()) |
| 169 | ->OnMouseMove(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 170 | } |
| 171 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 172 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 173 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 174 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 175 | uint32_t nFlags, |
| 176 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 177 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 178 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 179 | return GetAnnotHandler(pAnnot->Get()) |
| 180 | ->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 181 | } |
| 182 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 183 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 184 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 185 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 186 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 187 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 188 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 189 | return GetAnnotHandler(pAnnot->Get()) |
| 190 | ->OnRButtonDown(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 191 | } |
| 192 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 193 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 194 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 195 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 196 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 197 | const CFX_PointF& point) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 198 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 199 | return GetAnnotHandler(pAnnot->Get()) |
| 200 | ->OnRButtonUp(pPageView, pAnnot, nFlags, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 201 | } |
| 202 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 203 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter( |
| 204 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 205 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 206 | uint32_t nFlag) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 207 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 208 | GetAnnotHandler(pAnnot->Get())->OnMouseEnter(pPageView, pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 209 | } |
| 210 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 211 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit( |
| 212 | CPDFSDK_PageView* pPageView, |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 213 | ObservedPtr<CPDFSDK_Annot>* pAnnot, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 214 | uint32_t nFlag) { |
Lei Zhang | f0b7d59 | 2018-10-10 18:54:24 +0000 | [diff] [blame] | 215 | ASSERT(pAnnot->HasObservable()); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 216 | GetAnnotHandler(pAnnot->Get())->OnMouseExit(pPageView, pAnnot, nFlag); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 217 | } |
| 218 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 219 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, |
| 220 | uint32_t nChar, |
| 221 | uint32_t nFlags) { |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 222 | return GetAnnotHandler(pAnnot)->OnChar(pAnnot, nChar, nFlags); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 223 | } |
| 224 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 225 | bool CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 226 | int nKeyCode, |
| 227 | int nFlag) { |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 228 | if (CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag) || |
| 229 | CPDFSDK_FormFillEnvironment::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 | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 236 | ObservedPtr<CPDFSDK_Annot> pNext(GetNextAnnot( |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 237 | pFocusAnnot, !CPDFSDK_FormFillEnvironment::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 | } |