John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 8 | |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
Lei Zhang | a676aca | 2019-02-02 00:41:09 +0000 | [diff] [blame] | 11 | #include "constants/form_flags.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/page/cpdf_page.h" |
Tom Sepez | 3609c98 | 2019-06-04 21:35:25 +0000 | [diff] [blame] | 13 | #include "core/fpdfdoc/cba_fontmap.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 14 | #include "core/fxge/cfx_renderdevice.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 16 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 17 | #include "fpdfsdk/cpdfsdk_widget.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 18 | |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 19 | CFFL_FormFiller::CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Lei Zhang | 4f34c64 | 2017-06-02 00:45:14 -0700 | [diff] [blame] | 20 | CPDFSDK_Widget* pWidget) |
Tom Sepez | 333165a | 2018-10-24 23:56:43 +0000 | [diff] [blame] | 21 | : m_pFormFillEnv(pFormFillEnv), m_pWidget(pWidget) { |
Lei Zhang | 4f34c64 | 2017-06-02 00:45:14 -0700 | [diff] [blame] | 22 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | CFFL_FormFiller::~CFFL_FormFiller() { |
dsinclair | 28a4a24 | 2016-08-22 13:36:02 -0700 | [diff] [blame] | 26 | DestroyWindows(); |
| 27 | } |
| 28 | |
| 29 | void CFFL_FormFiller::DestroyWindows() { |
Tom Sepez | 333165a | 2018-10-24 23:56:43 +0000 | [diff] [blame] | 30 | while (!m_Maps.empty()) { |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 31 | auto it = m_Maps.begin(); |
| 32 | std::unique_ptr<CPWL_Wnd> pWnd = std::move(it->second); |
| 33 | m_Maps.erase(it); |
| 34 | pWnd->InvalidateProvider(this); |
| 35 | pWnd->Destroy(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 39 | FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 40 | ASSERT(pPageView); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 42 | CFX_FloatRect rcAnnot = m_pWidget->GetRect(); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 43 | if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) |
| 44 | rcAnnot = PWLtoFFL(pWnd->GetWindowRect()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 46 | CFX_FloatRect rcWin = rcAnnot; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 47 | CFX_FloatRect rcFocus = GetFocusBox(pPageView); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | if (!rcFocus.IsEmpty()) |
| 49 | rcWin.Union(rcFocus); |
| 50 | |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame] | 51 | if (!rcWin.IsEmpty()) { |
| 52 | rcWin.Inflate(1, 1); |
| 53 | rcWin.Normalize(); |
| 54 | } |
| 55 | return rcWin.GetOuterRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, |
| 59 | CPDFSDK_Annot* pAnnot, |
| 60 | CFX_RenderDevice* pDevice, |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 61 | const CFX_Matrix& mtUser2Device) { |
Lei Zhang | a1f94aa | 2018-12-20 01:56:06 +0000 | [diff] [blame] | 62 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 63 | if (pWnd) { |
| 64 | pWnd->DrawAppearance(pDevice, GetCurMatrix() * mtUser2Device); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 65 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | } |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 67 | |
Tom Sepez | 11a6bec | 2018-07-25 23:25:55 +0000 | [diff] [blame] | 68 | CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 69 | if (!CFFL_InteractiveFormFiller::IsVisible(pWidget)) |
| 70 | return; |
| 71 | |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 72 | pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView, |
| 76 | CPDFSDK_Annot* pAnnot, |
| 77 | CFX_RenderDevice* pDevice, |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 78 | const CFX_Matrix& mtUser2Device) { |
Tom Sepez | 11a6bec | 2018-07-25 23:25:55 +0000 | [diff] [blame] | 79 | ToCPDFSDKWidget(pAnnot)->DrawAppearance(pDevice, mtUser2Device, |
| 80 | CPDF_Annot::Normal, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 83 | void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 85 | void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | EndTimer(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 87 | ASSERT(m_pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | } |
| 89 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 90 | bool CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 91 | CPDFSDK_Annot* pAnnot, |
| 92 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 93 | const CFX_PointF& point) { |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 94 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); |
| 95 | if (!pWnd) |
| 96 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 98 | m_bValid = true; |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 99 | FX_RECT rect = GetViewBBox(pPageView); |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 100 | InvalidateRect(rect); |
| 101 | if (!rect.Contains(static_cast<int>(point.x), static_cast<int>(point.y))) |
| 102 | return false; |
| 103 | return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | } |
| 105 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 106 | bool CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 107 | CPDFSDK_Annot* pAnnot, |
| 108 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 109 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 110 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 111 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 112 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 114 | InvalidateRect(GetViewBBox(pPageView)); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 115 | pWnd->OnLButtonUp(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 116 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 117 | } |
| 118 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 119 | bool CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 120 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 121 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 122 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 123 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 124 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 126 | pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 127 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | } |
| 129 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 130 | bool CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -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 | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 133 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 134 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 135 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 136 | |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 137 | pWnd->OnMouseMove(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 138 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 139 | } |
| 140 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 141 | bool CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 142 | uint32_t nFlags, |
| 143 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 144 | const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | if (!IsValid()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 146 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 148 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 149 | return pWnd && pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point), nFlags); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 150 | } |
| 151 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 152 | bool CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 153 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 154 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 155 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 156 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 157 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 158 | |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 159 | pWnd->OnRButtonDown(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 160 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | } |
| 162 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 163 | bool CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 164 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 165 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 166 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 167 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 168 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 170 | pWnd->OnRButtonUp(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 171 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 174 | bool CFFL_FormFiller::OnKeyDown(uint32_t nKeyCode, uint32_t nFlags) { |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 175 | if (!IsValid()) |
| 176 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 177 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 178 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 179 | ASSERT(pPageView); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 180 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 181 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 182 | return pWnd && pWnd->OnKeyDown(nKeyCode, nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | bool CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, |
| 186 | uint32_t nChar, |
| 187 | uint32_t nFlags) { |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 188 | if (!IsValid()) |
| 189 | return false; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 190 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 191 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 192 | ASSERT(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 193 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 194 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 195 | return pWnd && pWnd->OnChar(nChar, nFlags); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 196 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 197 | |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 198 | bool CFFL_FormFiller::SetIndexSelected(int index, bool selected) { |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | bool CFFL_FormFiller::IsIndexSelected(int index) { |
| 203 | return false; |
| 204 | } |
| 205 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 206 | WideString CFFL_FormFiller::GetText() { |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 207 | if (!IsValid()) |
| 208 | return WideString(); |
| 209 | |
| 210 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 211 | ASSERT(pPageView); |
| 212 | |
| 213 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 214 | return pWnd ? pWnd->GetText() : WideString(); |
| 215 | } |
| 216 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 217 | WideString CFFL_FormFiller::GetSelectedText() { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 218 | if (!IsValid()) |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 219 | return WideString(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 220 | |
| 221 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 222 | ASSERT(pPageView); |
| 223 | |
| 224 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 225 | return pWnd ? pWnd->GetSelectedText() : WideString(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 228 | void CFFL_FormFiller::ReplaceSelection(const WideString& text) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 229 | if (!IsValid()) |
| 230 | return; |
| 231 | |
| 232 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 233 | ASSERT(pPageView); |
| 234 | |
| 235 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 236 | if (!pWnd) |
| 237 | return; |
| 238 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 239 | pWnd->ReplaceSelection(text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 242 | bool CFFL_FormFiller::CanUndo() { |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 243 | if (!IsValid()) |
| 244 | return false; |
| 245 | |
| 246 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 247 | ASSERT(pPageView); |
| 248 | |
| 249 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 250 | return pWnd && pWnd->CanUndo(); |
| 251 | } |
| 252 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 253 | bool CFFL_FormFiller::CanRedo() { |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 254 | if (!IsValid()) |
| 255 | return false; |
| 256 | |
| 257 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 258 | ASSERT(pPageView); |
| 259 | |
| 260 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 261 | return pWnd && pWnd->CanRedo(); |
| 262 | } |
| 263 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 264 | bool CFFL_FormFiller::Undo() { |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 265 | if (!IsValid()) |
| 266 | return false; |
| 267 | |
| 268 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 269 | ASSERT(pPageView); |
| 270 | |
| 271 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 272 | return pWnd && pWnd->Undo(); |
| 273 | } |
| 274 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 275 | bool CFFL_FormFiller::Redo() { |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 276 | if (!IsValid()) |
| 277 | return false; |
| 278 | |
| 279 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 280 | ASSERT(pPageView); |
| 281 | |
| 282 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 283 | return pWnd && pWnd->Redo(); |
| 284 | } |
| 285 | |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 286 | void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { |
Tom Sepez | 4ef943b | 2018-07-26 19:06:06 +0000 | [diff] [blame] | 287 | CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 288 | IPDF_Page* pPage = pWidget->GetPage(); |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 289 | CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 290 | if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 291 | pWnd->SetFocus(); |
| 292 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 293 | m_bValid = true; |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 294 | InvalidateRect(GetViewBBox(pPageView)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 297 | void CFFL_FormFiller::KillFocusForAnnot(uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | if (!IsValid()) |
Lei Zhang | 8c217c5 | 2015-10-03 23:26:09 -0700 | [diff] [blame] | 299 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 300 | |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 301 | CPDFSDK_PageView* pPageView = GetCurPageView(false); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 302 | if (!pPageView || !CommitData(pPageView, nFlag)) |
Lei Zhang | 8c217c5 | 2015-10-03 23:26:09 -0700 | [diff] [blame] | 303 | return; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 304 | if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 305 | pWnd->KillFocus(); |
| 306 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 307 | bool bDestroyPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 308 | switch (m_pWidget->GetFieldType()) { |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 309 | case FormFieldType::kPushButton: |
| 310 | case FormFieldType::kCheckBox: |
| 311 | case FormFieldType::kRadioButton: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 312 | bDestroyPDFWindow = true; |
Lei Zhang | d77f03f | 2015-12-28 13:12:26 -0800 | [diff] [blame] | 313 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 314 | default: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 315 | bDestroyPDFWindow = false; |
Lei Zhang | d77f03f | 2015-12-28 13:12:26 -0800 | [diff] [blame] | 316 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | } |
Lei Zhang | 8c217c5 | 2015-10-03 23:26:09 -0700 | [diff] [blame] | 318 | EscapeFiller(pPageView, bDestroyPDFWindow); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | } |
| 320 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 321 | bool CFFL_FormFiller::IsValid() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 322 | return m_bValid; |
| 323 | } |
| 324 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 325 | CPWL_Wnd::CreateParams CFFL_FormFiller::GetCreateParam() { |
| 326 | CPWL_Wnd::CreateParams cp; |
Dan Sinclair | bc8dcc3 | 2017-01-19 13:53:02 -0500 | [diff] [blame] | 327 | cp.pProvider.Reset(this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | cp.rcRectWnd = GetPDFWindowRect(); |
| 329 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 330 | uint32_t dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; |
| 331 | uint32_t dwFieldFlag = m_pWidget->GetFieldFlags(); |
Lei Zhang | a676aca | 2019-02-02 00:41:09 +0000 | [diff] [blame] | 332 | if (dwFieldFlag & pdfium::form_flags::kReadOnly) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 333 | dwCreateFlags |= PWS_READONLY; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 334 | |
Lei Zhang | b353f8c | 2018-10-10 18:39:14 +0000 | [diff] [blame] | 335 | Optional<FX_COLORREF> color = m_pWidget->GetFillColor(); |
| 336 | if (color.has_value()) |
| 337 | cp.sBackgroundColor = CFX_Color(color.value()); |
| 338 | color = m_pWidget->GetBorderColor(); |
| 339 | if (color.has_value()) |
| 340 | cp.sBorderColor = CFX_Color(color.value()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 341 | |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 342 | cp.sTextColor = CFX_Color(CFX_Color::kGray, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 343 | |
Lei Zhang | b353f8c | 2018-10-10 18:39:14 +0000 | [diff] [blame] | 344 | color = m_pWidget->GetTextColor(); |
| 345 | if (color.has_value()) |
| 346 | cp.sTextColor = CFX_Color(color.value()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | |
| 348 | cp.fFontSize = m_pWidget->GetFontSize(); |
| 349 | cp.dwBorderWidth = m_pWidget->GetBorderWidth(); |
| 350 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 351 | cp.nBorderStyle = m_pWidget->GetBorderStyle(); |
| 352 | switch (cp.nBorderStyle) { |
| 353 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | cp.sDash = CPWL_Dash(3, 3, 0); |
| 355 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 356 | case BorderStyle::BEVELED: |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 357 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 358 | cp.dwBorderWidth *= 2; |
| 359 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 360 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 361 | break; |
| 362 | } |
| 363 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 364 | if (cp.fFontSize <= 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 365 | dwCreateFlags |= PWS_AUTOFONTSIZE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | |
| 367 | cp.dwFlags = dwCreateFlags; |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 368 | cp.pSystemHandler = m_pFormFillEnv->GetSysHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 369 | return cp; |
| 370 | } |
| 371 | |
| 372 | CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 373 | bool bNew) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | ASSERT(pPageView); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 375 | auto it = m_Maps.find(pPageView); |
Tom Sepez | 333165a | 2018-10-24 23:56:43 +0000 | [diff] [blame] | 376 | if (it == m_Maps.end()) { |
| 377 | if (!bNew) |
| 378 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 379 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 380 | CPWL_Wnd::CreateParams cp = GetCreateParam(); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 381 | cp.pAttachedWidget.Reset(m_pWidget.Get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 382 | |
Tom Sepez | 333165a | 2018-10-24 23:56:43 +0000 | [diff] [blame] | 383 | auto pPrivateData = pdfium::MakeUnique<CFFL_PrivateData>(); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 384 | pPrivateData->pWidget = m_pWidget.Get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | pPrivateData->pPageView = pPageView; |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 386 | pPrivateData->nWidgetAppearanceAge = m_pWidget->GetAppearanceAge(); |
| 387 | pPrivateData->nWidgetValueAge = 0; |
Tom Sepez | 385bf2e | 2018-10-26 17:37:17 +0000 | [diff] [blame] | 388 | m_Maps[pPageView] = NewPWLWindow(cp, std::move(pPrivateData)); |
Tom Sepez | 333165a | 2018-10-24 23:56:43 +0000 | [diff] [blame] | 389 | return m_Maps[pPageView].get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Tom Sepez | 333165a | 2018-10-24 23:56:43 +0000 | [diff] [blame] | 392 | CPWL_Wnd* pWnd = it->second.get(); |
| 393 | if (!bNew) |
| 394 | return pWnd; |
| 395 | |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 396 | const auto* pPrivateData = |
| 397 | static_cast<const CFFL_PrivateData*>(pWnd->GetAttachedData()); |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 398 | if (pPrivateData->nWidgetAppearanceAge == m_pWidget->GetAppearanceAge()) |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 399 | return pWnd; |
| 400 | |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 401 | return ResetPDFWindow( |
| 402 | pPageView, pPrivateData->nWidgetValueAge == m_pWidget->GetValueAge()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { |
| 406 | auto it = m_Maps.find(pPageView); |
| 407 | if (it == m_Maps.end()) |
| 408 | return; |
| 409 | |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 410 | std::unique_ptr<CPWL_Wnd> pWnd = std::move(it->second); |
| 411 | m_Maps.erase(it); |
| 412 | pWnd->Destroy(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 415 | CFX_Matrix CFFL_FormFiller::GetWindowMatrix( |
| 416 | const CPWL_Wnd::PrivateData* pAttached) { |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 417 | const auto* pPrivateData = static_cast<const CFFL_PrivateData*>(pAttached); |
Tom Sepez | 134ac91 | 2017-09-15 15:32:01 -0700 | [diff] [blame] | 418 | if (!pPrivateData || !pPrivateData->pPageView) |
Lei Zhang | a1f94aa | 2018-12-20 01:56:06 +0000 | [diff] [blame] | 419 | return CFX_Matrix(); |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 420 | |
Lei Zhang | a1f94aa | 2018-12-20 01:56:06 +0000 | [diff] [blame] | 421 | return GetCurMatrix() * pPrivateData->pPageView->GetCurrentMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 424 | CFX_Matrix CFFL_FormFiller::GetCurMatrix() { |
| 425 | CFX_Matrix mt; |
jaepark | a1d2111 | 2016-08-25 13:33:34 -0700 | [diff] [blame] | 426 | CFX_FloatRect rcDA = m_pWidget->GetPDFAnnot()->GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 427 | switch (m_pWidget->GetRotate()) { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 428 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 429 | mt = CFX_Matrix(0, 1, -1, 0, rcDA.right - rcDA.left, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 430 | break; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 431 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 432 | mt = CFX_Matrix(-1, 0, 0, -1, rcDA.right - rcDA.left, |
| 433 | rcDA.top - rcDA.bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 434 | break; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 435 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 436 | mt = CFX_Matrix(0, -1, 1, 0, 0, rcDA.top - rcDA.bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 437 | break; |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 438 | case 0: |
| 439 | default: |
| 440 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 441 | } |
| 442 | mt.e += rcDA.left; |
| 443 | mt.f += rcDA.bottom; |
| 444 | |
| 445 | return mt; |
| 446 | } |
| 447 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 448 | CFX_FloatRect CFFL_FormFiller::GetPDFWindowRect() const { |
jaepark | a1d2111 | 2016-08-25 13:33:34 -0700 | [diff] [blame] | 449 | CFX_FloatRect rectAnnot = m_pWidget->GetPDFAnnot()->GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 450 | |
Lei Zhang | 9875889 | 2018-03-15 15:02:22 +0000 | [diff] [blame] | 451 | float fWidth = rectAnnot.Width(); |
| 452 | float fHeight = rectAnnot.Height(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | if ((m_pWidget->GetRotate() / 90) & 0x01) |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 454 | std::swap(fWidth, fHeight); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 455 | return CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | } |
| 457 | |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 458 | CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView(bool renew) { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 459 | IPDF_Page* pPage = m_pWidget->GetPage(); |
Lei Zhang | 4f34c64 | 2017-06-02 00:45:14 -0700 | [diff] [blame] | 460 | return m_pFormFillEnv->GetPageView(pPage, renew); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 463 | CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 464 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 465 | if (!pWnd) |
| 466 | return CFX_FloatRect(); |
| 467 | |
| 468 | CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); |
Tom Sepez | 778e59e | 2018-06-05 19:24:42 +0000 | [diff] [blame] | 469 | return pPageView->GetPDFPage()->GetBBox().Contains(rcFocus) ? rcFocus |
| 470 | : CFX_FloatRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 473 | CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) { |
Jane Liu | 878b27d | 2017-08-22 10:50:06 -0400 | [diff] [blame] | 474 | return GetCurMatrix().GetInverse().TransformRect(rect); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 477 | CFX_FloatRect CFFL_FormFiller::PWLtoFFL(const CFX_FloatRect& rect) { |
Jane Liu | 878b27d | 2017-08-22 10:50:06 -0400 | [diff] [blame] | 478 | return GetCurMatrix().TransformRect(rect); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 481 | CFX_PointF CFFL_FormFiller::FFLtoPWL(const CFX_PointF& point) { |
Nicolas Pena | b21f174 | 2017-06-29 12:02:06 -0400 | [diff] [blame] | 482 | return GetCurMatrix().GetInverse().Transform(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 485 | CFX_PointF CFFL_FormFiller::PWLtoFFL(const CFX_PointF& point) { |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 486 | return GetCurMatrix().Transform(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 489 | CFX_PointF CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, |
| 490 | const CFX_PointF& pt) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 491 | return FFLtoPWL(pt); |
| 492 | } |
| 493 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 494 | CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, |
| 495 | const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | return rect; |
| 497 | } |
| 498 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 499 | bool CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, uint32_t nFlag) { |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 500 | if (!IsDataChanged(pPageView)) |
| 501 | return true; |
Lei Zhang | 6a3fc45 | 2017-06-13 14:04:02 -0700 | [diff] [blame] | 502 | |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 503 | CFFL_InteractiveFormFiller* pFormFiller = |
| 504 | m_pFormFillEnv->GetInteractiveFormFiller(); |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame^] | 505 | ObservedPtr<CPDFSDK_Annot> pObserved(m_pWidget.Get()); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 506 | |
| 507 | if (!pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, nFlag)) { |
Dan Sinclair | bdb9653 | 2017-07-06 10:40:51 -0400 | [diff] [blame] | 508 | if (!pObserved) |
| 509 | return false; |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 510 | ResetPDFWindow(pPageView, false); |
| 511 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 512 | } |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 513 | if (!pObserved) |
| 514 | return false; |
| 515 | |
| 516 | if (!pFormFiller->OnValidate(&pObserved, pPageView, nFlag)) { |
| 517 | if (!pObserved) |
| 518 | return false; |
| 519 | ResetPDFWindow(pPageView, false); |
| 520 | return true; |
| 521 | } |
| 522 | if (!pObserved) |
| 523 | return false; |
| 524 | |
Lei Zhang | dd92aa5 | 2018-09-20 12:56:04 +0000 | [diff] [blame] | 525 | SaveData(pPageView); // may invoking JS to delete this widget. |
Luật Nguyễn | 1886471 | 2017-10-10 12:39:22 +0800 | [diff] [blame] | 526 | if (!pObserved) |
| 527 | return false; |
| 528 | |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 529 | pFormFiller->OnCalculate(&pObserved, pPageView, nFlag); |
| 530 | if (!pObserved) |
| 531 | return false; |
| 532 | |
| 533 | pFormFiller->OnFormat(&pObserved, pPageView, nFlag); |
| 534 | if (!pObserved) |
| 535 | return false; |
| 536 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 537 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 538 | } |
| 539 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 540 | bool CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { |
| 541 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {} |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 545 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 546 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 547 | bool CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { |
| 548 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 549 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 550 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 551 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | void CFFL_FormFiller::SetChangeMark() { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 553 | m_pFormFillEnv->OnChange(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 556 | void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, |
| 557 | CPDF_AAction::AActionType type, |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 558 | CPDFSDK_FieldAction& fa) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | fa.sValue = m_pWidget->GetValue(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 562 | void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, |
| 563 | CPDF_AAction::AActionType type, |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 564 | const CPDFSDK_FieldAction& fa) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 566 | bool CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 567 | const CPDFSDK_FieldAction& faOld, |
| 568 | const CPDFSDK_FieldAction& faNew) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 569 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 572 | void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) {} |
| 573 | |
| 574 | void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) {} |
| 575 | |
| 576 | CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 577 | bool bRestoreValue) { |
| 578 | return GetPDFWindow(pPageView, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 581 | void CFFL_FormFiller::TimerProc() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 582 | |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 583 | CFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 584 | return m_pFormFillEnv->GetSysHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 587 | void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 588 | bool bDestroyPDFWindow) { |
| 589 | m_bValid = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 590 | |
Lei Zhang | d6b7287 | 2019-02-21 21:33:53 +0000 | [diff] [blame] | 591 | InvalidateRect(GetViewBBox(pPageView)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 592 | if (bDestroyPDFWindow) |
| 593 | DestroyPDFWindow(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Dan Sinclair | 6eec1c4 | 2017-02-21 17:20:43 -0500 | [diff] [blame] | 596 | void CFFL_FormFiller::InvalidateRect(const FX_RECT& rect) { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 597 | m_pFormFillEnv->Invalidate(m_pWidget->GetPage(), rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 598 | } |