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_FWL_CFWL_WIDGET_H_ 8 #define XFA_FWL_CFWL_WIDGET_H_ 9 10 #include <stdint.h> 11 12 #include "core/fxcrt/fx_coordinates.h" 13 #include "core/fxcrt/unowned_ptr.h" 14 #include "core/fxcrt/widestring.h" 15 #include "core/fxge/dib/fx_dib.h" 16 #include "fxjs/gc/heap.h" 17 #include "v8/include/cppgc/garbage-collected.h" 18 #include "v8/include/cppgc/macros.h" 19 #include "v8/include/cppgc/member.h" 20 #include "v8/include/cppgc/prefinalizer.h" 21 #include "xfa/fde/cfde_data.h" 22 #include "xfa/fwl/cfwl_themepart.h" 23 #include "xfa/fwl/cfwl_widgetmgr.h" 24 #include "xfa/fwl/fwl_widgethit.h" 25 #include "xfa/fwl/ifwl_widgetdelegate.h" 26 27 class CFWL_App; 28 class CFWL_Event; 29 class CFWL_Widget; 30 class IFWL_ThemeProvider; 31 32 #define FWL_STYLE_WGT_OverLapper 0 33 #define FWL_STYLE_WGT_Popup (1L << 0) 34 #define FWL_STYLE_WGT_Child (2L << 0) 35 #define FWL_STYLE_WGT_WindowTypeMask (3L << 0) 36 #define FWL_STYLE_WGT_Border (1L << 2) 37 #define FWL_STYLE_WGT_VScroll (1L << 11) 38 #define FWL_STYLE_WGT_Group (1L << 22) 39 #define FWL_STYLE_WGT_NoBackground (1L << 28) 40 41 #define FWL_STATE_WGT_Disabled (1L << 2) 42 #define FWL_STATE_WGT_Focused (1L << 4) 43 #define FWL_STATE_WGT_Invisible (1L << 5) 44 #define FWL_STATE_WGT_MAX 6 45 46 enum class FWL_Type { 47 Unknown = 0, 48 49 Barcode, 50 Caret, 51 CheckBox, 52 ComboBox, 53 DateTimePicker, 54 Edit, 55 Form, 56 FormProxy, 57 ListBox, 58 MonthCalendar, 59 PictureBox, 60 PushButton, 61 ScrollBar, 62 SpinButton, 63 ToolTip 64 }; 65 66 // NOTE: CFWL_Widget serves as its own delegate until replaced at runtime. 67 class CFWL_Widget : public cppgc::GarbageCollected<CFWL_Widget>, 68 public IFWL_WidgetDelegate { 69 CPPGC_USING_PRE_FINALIZER(CFWL_Widget, PreFinalize); 70 71 public: 72 class AdapterIface : public cppgc::GarbageCollectedMixin { 73 public: 74 virtual ~AdapterIface() = default; 75 virtual CFX_Matrix GetRotateMatrix() = 0; 76 virtual void DisplayCaret(bool bVisible, const CFX_RectF* pRtAnchor) = 0; 77 virtual void GetBorderColorAndThickness(FX_ARGB* cr, float* fWidth) = 0; 78 }; 79 80 class Properties { 81 public: 82 uint32_t m_dwStyles = FWL_STYLE_WGT_Child; // Mask of FWL_STYLE_*_*. 83 uint32_t m_dwStyleExts = 0; // Mask of FWL_STYLEEXT_*_*. 84 uint32_t m_dwStates = 0; // Mask of FWL_STATE_*_*. 85 }; 86 87 class ScopedUpdateLock { 88 CPPGC_STACK_ALLOCATED(); // Allow raw/unowned pointers. 89 90 public: 91 explicit ScopedUpdateLock(CFWL_Widget* widget); 92 ~ScopedUpdateLock(); 93 94 private: 95 UnownedPtr<CFWL_Widget> const widget_; // Ok, stack-only. 96 }; 97 98 CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED; 99 ~CFWL_Widget() override; 100 101 virtual void PreFinalize(); 102 void Trace(cppgc::Visitor* visitor) const override; 103 104 virtual FWL_Type GetClassID() const = 0; 105 virtual bool IsForm() const; 106 virtual CFX_RectF GetAutosizedWidgetRect(); 107 virtual CFX_RectF GetWidgetRect(); 108 virtual CFX_RectF GetClientRect(); 109 virtual void ModifyStyleExts(uint32_t dwStyleExtsAdded, 110 uint32_t dwStyleExtsRemoved); 111 virtual void SetStates(uint32_t dwStates); 112 virtual void RemoveStates(uint32_t dwStates); 113 virtual void Update() = 0; 114 virtual FWL_WidgetHit HitTest(const CFX_PointF& point); 115 virtual void DrawWidget(CFGAS_GEGraphics* pGraphics, 116 const CFX_Matrix& matrix) = 0; 117 118 // IFWL_WidgetDelegate: 119 void OnProcessMessage(CFWL_Message* pMessage) override; 120 void OnProcessEvent(CFWL_Event* pEvent) override; 121 122 void InflateWidgetRect(CFX_RectF& rect); 123 void SetWidgetRect(const CFX_RectF& rect); 124 125 bool IsVisible() const; 126 bool IsOverLapper() const; 127 bool IsPopup() const; 128 bool IsChild() const; 129 GetWidgetMgr()130 CFWL_WidgetMgr* GetWidgetMgr() const { return m_pWidgetMgr; } GetOuter()131 CFWL_Widget* GetOuter() const { return m_pOuter; } 132 CFWL_Widget* GetOutmost() const; 133 134 void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved); GetStyleExts()135 uint32_t GetStyleExts() const { return m_Properties.m_dwStyleExts; } GetStates()136 uint32_t GetStates() const { return m_Properties.m_dwStates; } 137 138 CFX_PointF TransformTo(CFWL_Widget* pWidget, const CFX_PointF& point); 139 CFX_Matrix GetMatrix() const; 140 IFWL_ThemeProvider* GetThemeProvider() const; SetDelegate(IFWL_WidgetDelegate * delegate)141 void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } GetDelegate()142 IFWL_WidgetDelegate* GetDelegate() { 143 return m_pDelegate ? m_pDelegate.Get() : this; 144 } GetDelegate()145 const IFWL_WidgetDelegate* GetDelegate() const { 146 return m_pDelegate ? m_pDelegate.Get() : this; 147 } 148 GetFWLApp()149 CFWL_App* GetFWLApp() const { return m_pFWLApp; } GetEventKey()150 uint64_t GetEventKey() const { return m_nEventKey; } SetEventKey(uint64_t key)151 void SetEventKey(uint64_t key) { m_nEventKey = key; } 152 GetAdapterIface()153 AdapterIface* GetAdapterIface() const { return m_pAdapterIface; } SetAdapterIface(AdapterIface * pItem)154 void SetAdapterIface(AdapterIface* pItem) { m_pAdapterIface = pItem; } 155 void RepaintRect(const CFX_RectF& pRect); 156 157 protected: 158 CFWL_Widget(CFWL_App* app, const Properties& properties, CFWL_Widget* pOuter); 159 160 bool IsEnabled() const; IsLocked()161 bool IsLocked() const { return m_iLock > 0; } 162 bool HasBorder() const; 163 CFX_RectF GetEdgeRect() const; 164 float GetCXBorderSize() const; 165 float GetCYBorderSize() const; 166 CFX_RectF GetRelativeRect() const; 167 CFX_SizeF CalcTextSize(const WideString& wsText, bool bMultiLine); 168 void CalcTextRect(const WideString& wsText, 169 const FDE_TextStyle& dwTTOStyles, 170 FDE_TextAlignment iTTOAlign, 171 CFX_RectF* pRect); 172 void SetGrab(bool bSet); 173 void UnregisterEventTarget(); 174 void DispatchEvent(CFWL_Event* pEvent); 175 void DrawBorder(CFGAS_GEGraphics* pGraphics, 176 CFWL_ThemePart::Part iPartBorder, 177 const CFX_Matrix& pMatrix); 178 179 Properties m_Properties; 180 CFX_RectF m_WidgetRect; 181 182 private: LockUpdate()183 void LockUpdate() { m_iLock++; } UnlockUpdate()184 void UnlockUpdate() { 185 if (IsLocked()) 186 m_iLock--; 187 } 188 GetParent()189 CFWL_Widget* GetParent() const { return m_pWidgetMgr->GetParentWidget(this); } 190 CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent); 191 void DrawBackground(CFGAS_GEGraphics* pGraphics, 192 CFWL_ThemePart::Part iPartBk, 193 const CFX_Matrix& mtMatrix); 194 void NotifyDriver(); 195 bool IsParent(CFWL_Widget* pParent); 196 197 int32_t m_iLock = 0; 198 uint64_t m_nEventKey = 0; 199 cppgc::Member<AdapterIface> m_pAdapterIface; 200 cppgc::Member<CFWL_App> const m_pFWLApp; 201 cppgc::Member<CFWL_WidgetMgr> const m_pWidgetMgr; 202 cppgc::Member<IFWL_WidgetDelegate> m_pDelegate; 203 cppgc::Member<CFWL_Widget> const m_pOuter; 204 }; 205 206 #endif // XFA_FWL_CFWL_WIDGET_H_ 207