Chromium Code Reviews| Index: xfa/fwl/core/cfwl_event.h |
| diff --git a/xfa/fwl/core/cfwl_event.h b/xfa/fwl/core/cfwl_event.h |
| index d9decac33414425f204a5c771488d4177a7ecf14..485f5812cd82ca265f43a0578ec0a8dba343c6ae 100644 |
| --- a/xfa/fwl/core/cfwl_event.h |
| +++ b/xfa/fwl/core/cfwl_event.h |
| @@ -66,22 +66,13 @@ class IFWL_Widget; |
| class CFWL_Event { |
| public: |
| - CFWL_Event() |
| - : m_pSrcTarget(nullptr), m_pDstTarget(nullptr), m_dwRefCount(1) {} |
| - virtual ~CFWL_Event() {} |
| - |
| - virtual FWL_Error GetClassName(CFX_WideString& wsClass) const { |
| - return FWL_Error::Succeeded; |
| - } |
| - virtual CFWL_EventType GetClassID() const { return CFWL_EventType::None; } |
| - |
| - uint32_t Release() { |
| - m_dwRefCount--; |
| - uint32_t dwRefCount = m_dwRefCount; |
| - if (!m_dwRefCount) |
| - delete this; |
| - return dwRefCount; |
| - } |
| + CFWL_Event(); |
| + virtual ~CFWL_Event(); |
| + |
| + virtual FWL_Error GetClassName(CFX_WideString& wsClass) const; |
| + virtual CFWL_EventType GetClassID() const; |
| + |
| + uint32_t Release(); |
| IFWL_Widget* m_pSrcTarget; |
| IFWL_Widget* m_pDstTarget; |
| @@ -90,84 +81,110 @@ class CFWL_Event { |
| uint32_t m_dwRefCount; |
| }; |
| -#define BEGIN_FWL_EVENT_DEF(classname, eventType) \ |
| +inline CFWL_Event::CFWL_Event() |
| + : m_pSrcTarget(nullptr), m_pDstTarget(nullptr), m_dwRefCount(1) {} |
| + |
| +inline CFWL_Event::~CFWL_Event() {} |
| + |
| +inline FWL_Error CFWL_Event::GetClassName(CFX_WideString& wsClass) const { |
| + return FWL_Error::Succeeded; |
| +} |
| + |
| +inline CFWL_EventType CFWL_Event::GetClassID() const { |
| + return CFWL_EventType::None; |
| +} |
| + |
| +inline uint32_t CFWL_Event::Release() { |
| + m_dwRefCount--; |
| + uint32_t dwRefCount = m_dwRefCount; |
| + if (!m_dwRefCount) |
| + delete this; |
| + return dwRefCount; |
| +} |
| + |
| +#define FWL_EVENT_DEF(classname, eventType, ...) \ |
| class classname : public CFWL_Event { \ |
| public: \ |
| - classname() : CFWL_Event() {} \ |
| - virtual FWL_Error GetClassName(CFX_WideString& wsClass) const { \ |
| - wsClass = L## #classname; \ |
| - return FWL_Error::Succeeded; \ |
| - } \ |
| - virtual CFWL_EventType GetClassID() const { return eventType; } |
| - |
| -#define END_FWL_EVENT_DEF \ |
| - } \ |
| - ; // NOLINT |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtMouse, CFWL_EventType::Mouse) |
| -FX_FLOAT m_fx; |
| -FX_FLOAT m_fy; |
| -uint32_t m_dwFlags; |
| -FWL_MouseCommand m_dwCmd; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtMouseWheel, CFWL_EventType::MouseWheel) |
| -FX_FLOAT m_fx; |
| -FX_FLOAT m_fy; |
| -FX_FLOAT m_fDeltaX; |
| -FX_FLOAT m_fDeltaY; |
| -uint32_t m_dwFlags; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtKey, CFWL_EventType::Key) |
| -uint32_t m_dwKeyCode; |
| -uint32_t m_dwFlags; |
| -FWL_KeyCommand m_dwCmd; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtSetFocus, CFWL_EventType::SetFocus) |
| -IFWL_Widget* m_pSetFocus; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtKillFocus, CFWL_EventType::KillFocus) |
| -IFWL_Widget* m_pKillFocus; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtDraw, CFWL_EventType::Draw) |
| -CFX_Graphics* m_pGraphics; |
| -IFWL_Widget* m_pWidget; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtClick, CFWL_EventType::Click) |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtScroll, CFWL_EventType::Scroll) |
| -uint32_t m_iScrollCode; |
| -FX_FLOAT m_fPos; |
| -FX_BOOL* m_pRet; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtClose, CFWL_EventType::Close) |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtContextMenu, CFWL_EventType::ContextMenu) |
| -FX_FLOAT m_fPosX; |
| -FX_FLOAT m_fPosY; |
| -IFWL_Widget* m_pOwner; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtMenuCommand, CFWL_EventType::MenuCommand) |
| -int32_t m_iCommand; |
| -void* m_pData; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtSizeChanged, CFWL_EventType::SizeChanged) |
| -IFWL_Widget* m_pWidget; |
| -CFX_RectF m_rtOld; |
| -CFX_RectF m_rtNew; |
| -END_FWL_EVENT_DEF |
| - |
| -BEGIN_FWL_EVENT_DEF(CFWL_EvtIdle, CFWL_EventType::Idle) |
| -END_FWL_EVENT_DEF |
| + classname(); \ |
| + ~classname() override; \ |
| + FWL_Error GetClassName(CFX_WideString& wsClass) const override; \ |
| + CFWL_EventType GetClassID() const override; \ |
| + __VA_ARGS__ \ |
|
dsinclair
2016/06/16 17:35:19
That's frighteningly awesome.
Wei Li
2016/06/16 18:16:33
thanks :)
|
| + }; // NOLINT |
|
dsinclair
2016/06/16 17:35:20
Does this need a nolint? It was there before becau
Wei Li
2016/06/16 18:16:33
Done.
|
| + |
| +#define FWL_EVENT_FUNCTION_DEF(classname, eventType) \ |
|
dsinclair
2016/06/16 17:35:19
Do we ever doe the above without doing this macro?
Wei Li
2016/06/16 18:16:33
This is the price we have to pay for using clang_u
dsinclair
2016/06/16 18:21:13
Right, but could the macro be:
#define FWL_EVENT_
Wei Li
2016/06/17 18:11:18
oh, since customized function implementation is no
|
| + inline classname::classname() {} \ |
| + inline classname::~classname() {} \ |
| + inline FWL_Error classname::GetClassName(CFX_WideString& wsClass) const { \ |
| + wsClass = L## #classname; \ |
| + return FWL_Error::Succeeded; \ |
| + } \ |
| + inline CFWL_EventType classname::GetClassID() const { return eventType; } |
| + |
| +FWL_EVENT_DEF(CFWL_EvtMouse, CFWL_EventType::Mouse, FX_FLOAT m_fx; |
| + FX_FLOAT m_fy; |
| + uint32_t m_dwFlags; |
| + FWL_MouseCommand m_dwCmd;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtMouse, CFWL_EventType::Mouse) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtMouseWheel, CFWL_EventType::MouseWheel, FX_FLOAT m_fx; |
| + FX_FLOAT m_fy; |
| + FX_FLOAT m_fDeltaX; |
| + FX_FLOAT m_fDeltaY; |
| + uint32_t m_dwFlags;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtMouseWheel, CFWL_EventType::MouseWheel) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtKey, CFWL_EventType::Key, uint32_t m_dwKeyCode; |
| + uint32_t m_dwFlags; |
| + FWL_KeyCommand m_dwCmd;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtKey, CFWL_EventType::Key) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtSetFocus, |
| + CFWL_EventType::SetFocus, |
| + IFWL_Widget* m_pSetFocus;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtSetFocus, CFWL_EventType::SetFocus) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtKillFocus, |
| + CFWL_EventType::KillFocus, |
| + IFWL_Widget* m_pKillFocus;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtKillFocus, CFWL_EventType::KillFocus) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtDraw, CFWL_EventType::Draw, CFX_Graphics* m_pGraphics; |
| + IFWL_Widget * m_pWidget;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtDraw, CFWL_EventType::Draw) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtClick, CFWL_EventType::Click) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtClick, CFWL_EventType::Click) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtScroll, CFWL_EventType::Scroll, uint32_t m_iScrollCode; |
| + FX_FLOAT m_fPos; |
| + FX_BOOL * m_pRet;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtScroll, CFWL_EventType::Scroll) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtClose, CFWL_EventType::Close) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtClose, CFWL_EventType::Close) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtContextMenu, |
| + CFWL_EventType::ContextMenu, |
| + FX_FLOAT m_fPosX; |
| + FX_FLOAT m_fPosY; |
| + IFWL_Widget * m_pOwner;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtContextMenu, CFWL_EventType::ContextMenu) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtMenuCommand, |
| + CFWL_EventType::MenuCommand, |
| + int32_t m_iCommand; |
| + void* m_pData;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtMenuCommand, CFWL_EventType::MenuCommand) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtSizeChanged, |
| + CFWL_EventType::SizeChanged, |
| + IFWL_Widget* m_pWidget; |
| + CFX_RectF m_rtOld; |
| + CFX_RectF m_rtNew;) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtSizeChanged, CFWL_EventType::SizeChanged) |
| + |
| +FWL_EVENT_DEF(CFWL_EvtIdle, CFWL_EventType::Idle) |
| +FWL_EVENT_FUNCTION_DEF(CFWL_EvtIdle, CFWL_EventType::Idle) |
| #endif // XFA_FWL_CORE_CFWL_EVENT_H_ |