xref: /aosp_15_r20/external/pdfium/xfa/fxfa/cxfa_fffield.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2014 The PDFium Authors
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 XFA_FXFA_CXFA_FFFIELD_H_
8 #define XFA_FXFA_CXFA_FFFIELD_H_
9 
10 #include "xfa/fwl/cfwl_widget.h"
11 #include "xfa/fwl/ifwl_widgetdelegate.h"
12 #include "xfa/fxfa/cxfa_ffpageview.h"
13 #include "xfa/fxfa/cxfa_ffwidget.h"
14 
15 class CXFA_FFDropDown;
16 class CXFA_Node;
17 
18 class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate {
19  public:
20   enum ShapeOption { kSquareShape = 0, kRoundShape };
21 
22   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
23   ~CXFA_FFField() override;
24 
25   virtual CXFA_FFDropDown* AsDropDown();
26 
27   // CXFA_FFWidget:
28   void Trace(cppgc::Visitor* visitor) const override;
29   CXFA_FFField* AsField() override;
30   CFX_RectF GetBBox(FocusOption focus) override;
31   void RenderWidget(CFGAS_GEGraphics* pGS,
32                     const CFX_Matrix& matrix,
33                     HighlightOption highlight) override;
34   bool IsLoaded() override;
35   bool LoadWidget() override;
36   bool PerformLayout() override;
37   bool AcceptsFocusOnButtonDown(
38       Mask<XFA_FWL_KeyFlag> dwFlags,
39       const CFX_PointF& point,
40       CFWL_MessageMouse::MouseCommand command) override;
41   bool OnMouseEnter() override;
42   bool OnMouseExit() override;
43   bool OnLButtonDown(Mask<XFA_FWL_KeyFlag> dwFlags,
44                      const CFX_PointF& point) override;
45   bool OnLButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
46                    const CFX_PointF& point) override;
47   bool OnLButtonDblClk(Mask<XFA_FWL_KeyFlag> dwFlags,
48                        const CFX_PointF& point) override;
49   bool OnMouseMove(Mask<XFA_FWL_KeyFlag> dwFlags,
50                    const CFX_PointF& point) override;
51   bool OnMouseWheel(Mask<XFA_FWL_KeyFlag> dwFlags,
52                     const CFX_PointF& point,
53                     const CFX_Vector& delta) override;
54   bool OnRButtonDown(Mask<XFA_FWL_KeyFlag> dwFlags,
55                      const CFX_PointF& point) override;
56   bool OnRButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
57                    const CFX_PointF& point) override;
58   bool OnRButtonDblClk(Mask<XFA_FWL_KeyFlag> dwFlags,
59                        const CFX_PointF& point) override;
60   [[nodiscard]] bool OnSetFocus(CXFA_FFWidget* pOldWidget) override;
61   [[nodiscard]] bool OnKillFocus(CXFA_FFWidget* pNewWidget) override;
62   bool OnKeyDown(XFA_FWL_VKEYCODE dwKeyCode,
63                  Mask<XFA_FWL_KeyFlag> dwFlags) override;
64   bool OnChar(uint32_t dwChar, Mask<XFA_FWL_KeyFlag> dwFlags) override;
65   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
66 
67   // IFWL_WidgetDelegate:
68   void OnProcessMessage(CFWL_Message* pMessage) override;
69   void OnProcessEvent(CFWL_Event* pEvent) override;
70   void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
71                     const CFX_Matrix& matrix) override;
72 
73   void UpdateFWL();
74   uint32_t UpdateUIProperty();
75 
76  protected:
77   explicit CXFA_FFField(CXFA_Node* pNode);
78 
79   bool PtInActiveRect(const CFX_PointF& point) override;
80 
81   virtual void SetFWLRect();
82   virtual bool CommitData();
83   virtual bool IsDataChanged();
84 
85   CFWL_Widget* GetNormalWidget();
86   const CFWL_Widget* GetNormalWidget() const;
87   void SetNormalWidget(CFWL_Widget* widget);
88   CFX_PointF FWLToClient(const CFX_PointF& point);
89   void LayoutCaption();
90   void RenderCaption(CFGAS_GEGraphics* pGS, const CFX_Matrix& pMatrix);
91 
92   int32_t CalculateOverride();
93   int32_t CalculateNode(CXFA_Node* pNode);
94   bool ProcessCommittedData();
95   void DrawHighlight(CFGAS_GEGraphics* pGS,
96                      const CFX_Matrix& pMatrix,
97                      HighlightOption highlight,
98                      ShapeOption shape);
99   void SendMessageToFWLWidget(CFWL_Message* pMessage);
100   void CapPlacement();
101   void CapTopBottomPlacement(const CXFA_Margin* margin,
102                              const CFX_RectF& rtWidget,
103                              XFA_AttributeValue iCapPlacement);
104   void CapLeftRightPlacement(const CXFA_Margin* margin,
105                              const CFX_RectF& rtWidget,
106                              XFA_AttributeValue iCapPlacement);
107   void SetEditScrollOffset();
108 
109   CFX_RectF m_UIRect;
110   CFX_RectF m_CaptionRect;
111 
112  private:
113   cppgc::Member<CFWL_Widget> m_pNormalWidget;
114 };
115 
ToDropDown(CXFA_FFField * field)116 inline CXFA_FFDropDown* ToDropDown(CXFA_FFField* field) {
117   return field ? field->AsDropDown() : nullptr;
118 }
119 
120 #endif  // XFA_FXFA_CXFA_FFFIELD_H_
121