From 3b3ce1a242f8445848d3f23d6c35ba01d7c645f4 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 2 Nov 2016 14:51:25 -0700 Subject: Merge delegates into IFWL_* classes. This Cl removes ownership of the delgates from IFWL_Widget and puts it in the hand of the creating classes. In doing so, merge the delegates back into the IFWL_* classes to simplify logic. Review-Url: https://codereview.chromium.org/2467993003 --- xfa/fwl/core/ifwl_widget.h | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'xfa/fwl/core/ifwl_widget.h') diff --git a/xfa/fwl/core/ifwl_widget.h b/xfa/fwl/core/ifwl_widget.h index 264ff67513..0c8cef1adc 100644 --- a/xfa/fwl/core/ifwl_widget.h +++ b/xfa/fwl/core/ifwl_widget.h @@ -62,9 +62,9 @@ class IFWL_ThemeProvider; class IFWL_Widget; enum class FWL_Type; -class IFWL_Widget { +class IFWL_Widget : public IFWL_WidgetDelegate { public: - virtual ~IFWL_Widget(); + ~IFWL_Widget() override; virtual FWL_Type GetClassID() const = 0; virtual FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const; @@ -112,8 +112,19 @@ class IFWL_Widget { virtual IFWL_ThemeProvider* GetThemeProvider(); virtual FWL_Error SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); - IFWL_WidgetDelegate* GetCurrentDelegate(); - void SetCurrentDelegate(IFWL_WidgetDelegate* pDelegate); + void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } + IFWL_WidgetDelegate* GetDelegate() { + return m_pDelegate ? m_pDelegate : this; + } + const IFWL_WidgetDelegate* GetDelegate() const { + return m_pDelegate ? m_pDelegate : this; + } + + // IFWL_WidgetDelegate. + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; const IFWL_App* GetOwnerApp() const; @@ -127,6 +138,9 @@ class IFWL_Widget { void SetAssociateWidget(CFWL_Widget* pAssociate); + void SetFocus(FX_BOOL bFocus); + void Repaint(const CFX_RectF* pRect = nullptr); + protected: friend class CFWL_WidgetImpDelegate; @@ -160,7 +174,6 @@ class IFWL_Widget { uint32_t dwTTOStyles, int32_t iTTOAlign, CFX_RectF& rect); - void SetFocus(FX_BOOL bFocus); void SetGrab(FX_BOOL bSet); FX_BOOL GetPopupPos(FX_FLOAT fMinHeight, FX_FLOAT fMaxHeight, @@ -184,7 +197,6 @@ class IFWL_Widget { void UnregisterEventTarget(); void DispatchKeyEvent(CFWL_MsgKey* pNote); void DispatchEvent(CFWL_Event* pEvent); - void Repaint(const CFX_RectF* pRect = nullptr); void DrawBackground(CFX_Graphics* pGraphics, CFWL_Part iPartBk, IFWL_ThemeProvider* pTheme, @@ -201,15 +213,9 @@ class IFWL_Widget { FX_BOOL IsParent(IFWL_Widget* pParent); - void SetDelegate(std::unique_ptr delegate) { - m_pDelegate = std::move(delegate); - } - IFWL_WidgetDelegate* GetDelegate() const { return m_pDelegate.get(); } - const IFWL_App* const m_pOwnerApp; CFWL_WidgetMgr* const m_pWidgetMgr; std::unique_ptr m_pProperties; - IFWL_WidgetDelegate* m_pCurDelegate; // Not owned. IFWL_Widget* m_pOuter; void* m_pLayoutItem; CFWL_Widget* m_pAssociate; @@ -217,17 +223,7 @@ class IFWL_Widget { uint32_t m_nEventKey; private: - std::unique_ptr m_pDelegate; -}; - -class CFWL_WidgetImpDelegate : public IFWL_WidgetDelegate { - public: - CFWL_WidgetImpDelegate(); - ~CFWL_WidgetImpDelegate() override {} - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; + IFWL_WidgetDelegate* m_pDelegate; // Not owned. }; #endif // XFA_FWL_CORE_IFWL_WIDGET_H_ -- cgit v1.2.3