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