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