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