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. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_ 8 #define FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_ 9 10 #include <map> 11 #include <memory> 12 #include <utility> 13 14 #include "core/fxcrt/observed_ptr.h" 15 #include "core/fxcrt/unowned_ptr.h" 16 #include "fpdfsdk/cpdfsdk_annot.h" 17 #include "fpdfsdk/pwl/cpwl_edit.h" 18 #include "fpdfsdk/pwl/cpwl_wnd.h" 19 #include "fpdfsdk/pwl/ipwl_systemhandler.h" 20 21 class CFFL_FormFiller; 22 class CPDFSDK_FormFillEnvironment; 23 class CPDFSDK_PageView; 24 class CPDFSDK_Widget; 25 26 class CFFL_InteractiveFormFiller final : public IPWL_Filler_Notify { 27 public: 28 explicit CFFL_InteractiveFormFiller( 29 CPDFSDK_FormFillEnvironment* pFormFillEnv); 30 ~CFFL_InteractiveFormFiller() override; 31 32 bool Annot_HitTest(CPDFSDK_PageView* pPageView, 33 CPDFSDK_Annot* pAnnot, 34 const CFX_PointF& point); 35 FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot); 36 void OnDraw(CPDFSDK_PageView* pPageView, 37 CPDFSDK_Annot* pAnnot, 38 CFX_RenderDevice* pDevice, 39 const CFX_Matrix& mtUser2Device); 40 41 void OnDelete(CPDFSDK_Annot* pAnnot); 42 43 void OnMouseEnter(CPDFSDK_PageView* pPageView, 44 ObservedPtr<CPDFSDK_Annot>* pAnnot, 45 uint32_t nFlag); 46 void OnMouseExit(CPDFSDK_PageView* pPageView, 47 ObservedPtr<CPDFSDK_Annot>* pAnnot, 48 uint32_t nFlag); 49 bool OnLButtonDown(CPDFSDK_PageView* pPageView, 50 ObservedPtr<CPDFSDK_Annot>* pAnnot, 51 uint32_t nFlags, 52 const CFX_PointF& point); 53 bool OnLButtonUp(CPDFSDK_PageView* pPageView, 54 ObservedPtr<CPDFSDK_Annot>* pAnnot, 55 uint32_t nFlags, 56 const CFX_PointF& point); 57 bool OnLButtonDblClk(CPDFSDK_PageView* pPageView, 58 ObservedPtr<CPDFSDK_Annot>* pAnnot, 59 uint32_t nFlags, 60 const CFX_PointF& point); 61 bool OnMouseMove(CPDFSDK_PageView* pPageView, 62 ObservedPtr<CPDFSDK_Annot>* pAnnot, 63 uint32_t nFlags, 64 const CFX_PointF& point); 65 bool OnMouseWheel(CPDFSDK_PageView* pPageView, 66 ObservedPtr<CPDFSDK_Annot>* pAnnot, 67 uint32_t nFlags, 68 short zDelta, 69 const CFX_PointF& point); 70 bool OnRButtonDown(CPDFSDK_PageView* pPageView, 71 ObservedPtr<CPDFSDK_Annot>* pAnnot, 72 uint32_t nFlags, 73 const CFX_PointF& point); 74 bool OnRButtonUp(CPDFSDK_PageView* pPageView, 75 ObservedPtr<CPDFSDK_Annot>* pAnnot, 76 uint32_t nFlags, 77 const CFX_PointF& point); 78 79 bool OnKeyDown(CPDFSDK_Annot* pAnnot, uint32_t nKeyCode, uint32_t nFlags); 80 bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags); 81 82 bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, uint32_t nFlag); 83 bool OnKillFocus(ObservedPtr<CPDFSDK_Annot>* pAnnot, uint32_t nFlag); 84 GetFormFillerForTesting(CPDFSDK_Annot * pAnnot)85 CFFL_FormFiller* GetFormFillerForTesting(CPDFSDK_Annot* pAnnot) { 86 return GetFormFiller(pAnnot); 87 } 88 89 WideString GetText(CPDFSDK_Annot* pAnnot); 90 WideString GetSelectedText(CPDFSDK_Annot* pAnnot); 91 void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text); 92 93 bool CanUndo(CPDFSDK_Annot* pAnnot); 94 bool CanRedo(CPDFSDK_Annot* pAnnot); 95 bool Undo(CPDFSDK_Annot* pAnnot); 96 bool Redo(CPDFSDK_Annot* pAnnot); 97 98 static bool IsVisible(CPDFSDK_Widget* pWidget); 99 static bool IsReadOnly(CPDFSDK_Widget* pWidget); 100 static bool IsValidAnnot(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot); 101 102 bool OnKeyStrokeCommit(ObservedPtr<CPDFSDK_Annot>* pAnnot, 103 CPDFSDK_PageView* pPageView, 104 uint32_t nFlag); 105 bool OnValidate(ObservedPtr<CPDFSDK_Annot>* pAnnot, 106 CPDFSDK_PageView* pPageView, 107 uint32_t nFlag); 108 void OnCalculate(ObservedPtr<CPDFSDK_Annot>* pAnnot, 109 CPDFSDK_PageView* pPageView, 110 uint32_t nFlag); 111 void OnFormat(ObservedPtr<CPDFSDK_Annot>* pAnnot, 112 CPDFSDK_PageView* pPageView, 113 uint32_t nFlag); 114 bool OnButtonUp(ObservedPtr<CPDFSDK_Annot>* pAnnot, 115 CPDFSDK_PageView* pPageView, 116 uint32_t nFlag); 117 118 bool SetIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot, 119 int index, 120 bool selected); 121 bool IsIndexSelected(ObservedPtr<CPDFSDK_Annot>* pAnnot, int index); 122 123 private: 124 using WidgetToFormFillerMap = 125 std::map<CPDFSDK_Annot*, std::unique_ptr<CFFL_FormFiller>>; 126 127 // IPWL_Filler_Notify: 128 void QueryWherePopup(const IPWL_SystemHandler::PerWindowData* pAttached, 129 float fPopupMin, 130 float fPopupMax, 131 bool* bBottom, 132 float* fPopupRet) override; 133 // Returns {bRC, bExit}. 134 std::pair<bool, bool> OnBeforeKeyStroke( 135 const IPWL_SystemHandler::PerWindowData* pAttached, 136 WideString& strChange, 137 const WideString& strChangeEx, 138 int nSelStart, 139 int nSelEnd, 140 bool bKeyDown, 141 uint32_t nFlag) override; 142 bool OnPopupPreOpen(const IPWL_SystemHandler::PerWindowData* pAttached, 143 uint32_t nFlag) override; 144 bool OnPopupPostOpen(const IPWL_SystemHandler::PerWindowData* pAttached, 145 uint32_t nFlag) override; 146 147 #ifdef PDF_ENABLE_XFA 148 void SetFocusAnnotTab(CPDFSDK_Annot* pWidget, bool bSameField, bool bNext); 149 bool OnClick(ObservedPtr<CPDFSDK_Annot>* pAnnot, 150 CPDFSDK_PageView* pPageView, 151 uint32_t nFlag); 152 bool OnFull(ObservedPtr<CPDFSDK_Annot>* pAnnot, 153 CPDFSDK_PageView* pPageView, 154 uint32_t nFlag); 155 bool OnPreOpen(ObservedPtr<CPDFSDK_Annot>* pAnnot, 156 CPDFSDK_PageView* pPageView, 157 uint32_t nFlag); 158 bool OnPostOpen(ObservedPtr<CPDFSDK_Annot>* pAnnot, 159 CPDFSDK_PageView* pPageView, 160 uint32_t nFlag); 161 #endif // PDF_ENABLE_XFA 162 163 bool IsFillingAllowed(CPDFSDK_Widget* pWidget) const; 164 CFFL_FormFiller* GetFormFiller(CPDFSDK_Annot* pAnnot); 165 CFFL_FormFiller* GetOrCreateFormFiller(CPDFSDK_Annot* pAnnot); 166 void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot); 167 168 UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; 169 WidgetToFormFillerMap m_Map; 170 bool m_bNotifying = false; 171 }; 172 173 class CFFL_PrivateData final : public IPWL_SystemHandler::PerWindowData { 174 public: 175 CFFL_PrivateData(); 176 CFFL_PrivateData(const CFFL_PrivateData& that); 177 ~CFFL_PrivateData() override; 178 179 // CPWL_Wnd::PrivateData: 180 std::unique_ptr<IPWL_SystemHandler::PerWindowData> Clone() const override; 181 GetWidget()182 CPDFSDK_Widget* GetWidget() const { return pWidget.Get(); } 183 184 ObservedPtr<CPDFSDK_Widget> pWidget; 185 CPDFSDK_PageView* pPageView = nullptr; 186 uint32_t nWidgetAppearanceAge = 0; 187 uint32_t nWidgetValueAge = 0; 188 }; 189 190 #endif // FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_ 191