From d2b93dfa15dbb7fd42b7cf05fc248d7f5c87f1ef Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 26 May 2016 09:40:32 -0700 Subject: Remove one (of several) usages of SetPrivateData from IFWL_Widget Allow an upper layer to store an "event key" directly in the widget. Also fix some dubious logic in key allocation. Review-Url: https://codereview.chromium.org/2012143003 --- xfa/fwl/core/fwl_noteimp.cpp | 17 ++++---- xfa/fwl/core/fwl_widgetimp.cpp | 92 ++++++++++++++++++++++++------------------ xfa/fwl/core/fwl_widgetimp.h | 4 ++ xfa/fwl/core/ifwl_widget.h | 2 + 4 files changed, 65 insertions(+), 50 deletions(-) diff --git a/xfa/fwl/core/fwl_noteimp.cpp b/xfa/fwl/core/fwl_noteimp.cpp index 41201e6b6b..9518a08f00 100644 --- a/xfa/fwl/core/fwl_noteimp.cpp +++ b/xfa/fwl/core/fwl_noteimp.cpp @@ -7,6 +7,7 @@ #include "xfa/fwl/core/fwl_noteimp.h" #include "core/fxcrt/include/fx_ext.h" +#include "third_party/base/stl_util.h" #include "xfa/fwl/basewidget/fwl_tooltipctrlimp.h" #include "xfa/fwl/basewidget/ifwl_tooltip.h" #include "xfa/fwl/core/cfwl_message.h" @@ -101,18 +102,15 @@ void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) { } } -#define FWL_NoteDriver_EventKey 1100 FWL_Error CFWL_NoteDriver::RegisterEventTarget(IFWL_Widget* pListener, IFWL_Widget* pEventSource, uint32_t dwFilter) { - uint32_t key = (uint32_t)(uintptr_t)pListener->GetPrivateData( - (void*)(uintptr_t)FWL_NoteDriver_EventKey); + uint32_t key = pListener->GetEventKey(); if (key == 0) { - void* random = FX_Random_MT_Start(0); - key = rand(); - FX_Random_MT_Close(random); - pListener->SetPrivateData((void*)(uintptr_t)FWL_NoteDriver_EventKey, - (void*)(uintptr_t)key, NULL); + do { + key = rand(); + } while (key == 0 || pdfium::ContainsKey(m_eventTargets, key)); + pListener->SetEventKey(key); } if (!m_eventTargets[key]) m_eventTargets[key] = new CFWL_EventTarget(this, pListener); @@ -122,8 +120,7 @@ FWL_Error CFWL_NoteDriver::RegisterEventTarget(IFWL_Widget* pListener, } FWL_Error CFWL_NoteDriver::UnregisterEventTarget(IFWL_Widget* pListener) { - uint32_t key = (uint32_t)(uintptr_t)pListener->GetPrivateData( - (void*)(uintptr_t)FWL_NoteDriver_EventKey); + uint32_t key = pListener->GetEventKey(); if (key == 0) return FWL_Error::Indefinite; diff --git a/xfa/fwl/core/fwl_widgetimp.cpp b/xfa/fwl/core/fwl_widgetimp.cpp index adf548f24e..c6070b28e7 100644 --- a/xfa/fwl/core/fwl_widgetimp.cpp +++ b/xfa/fwl/core/fwl_widgetimp.cpp @@ -48,114 +48,116 @@ FWL_Error IFWL_Widget::Finalize() { } FWL_Error IFWL_Widget::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { - return static_cast(GetImpl()) - ->GetWidgetRect(rect, bAutoSize); + return GetImpl()->GetWidgetRect(rect, bAutoSize); } FWL_Error IFWL_Widget::GetGlobalRect(CFX_RectF& rect) { - return static_cast(GetImpl())->GetGlobalRect(rect); + return GetImpl()->GetGlobalRect(rect); } FWL_Error IFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { - return static_cast(GetImpl())->SetWidgetRect(rect); + return GetImpl()->SetWidgetRect(rect); } FWL_Error IFWL_Widget::GetClientRect(CFX_RectF& rect) { - return static_cast(GetImpl())->GetClientRect(rect); + return GetImpl()->GetClientRect(rect); } IFWL_Widget* IFWL_Widget::GetParent() { - return static_cast(GetImpl())->GetParent(); + return GetImpl()->GetParent(); } FWL_Error IFWL_Widget::SetParent(IFWL_Widget* pParent) { - return static_cast(GetImpl())->SetParent(pParent); + return GetImpl()->SetParent(pParent); } IFWL_Widget* IFWL_Widget::GetOwner() { - return static_cast(GetImpl())->GetOwner(); + return GetImpl()->GetOwner(); } FWL_Error IFWL_Widget::SetOwner(IFWL_Widget* pOwner) { - return static_cast(GetImpl())->SetOwner(pOwner); + return GetImpl()->SetOwner(pOwner); } IFWL_Widget* IFWL_Widget::GetOuter() { - return static_cast(GetImpl())->GetOuter(); + return GetImpl()->GetOuter(); } uint32_t IFWL_Widget::GetStyles() { - return static_cast(GetImpl())->GetStyles(); + return GetImpl()->GetStyles(); } FWL_Error IFWL_Widget::ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved) { - return static_cast(GetImpl()) - ->ModifyStyles(dwStylesAdded, dwStylesRemoved); + return GetImpl()->ModifyStyles(dwStylesAdded, dwStylesRemoved); } uint32_t IFWL_Widget::GetStylesEx() { - return static_cast(GetImpl())->GetStylesEx(); + return GetImpl()->GetStylesEx(); } FWL_Error IFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved) { - return static_cast(GetImpl()) - ->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); + return GetImpl()->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); } uint32_t IFWL_Widget::GetStates() { - return static_cast(GetImpl())->GetStates(); + return GetImpl()->GetStates(); } void IFWL_Widget::SetStates(uint32_t dwStates, FX_BOOL bSet) { - static_cast(GetImpl())->SetStates(dwStates, bSet); + GetImpl()->SetStates(dwStates, bSet); } + +uint32_t IFWL_Widget::GetEventKey() const { + return GetImpl()->GetEventKey(); +} + +void IFWL_Widget::SetEventKey(uint32_t key) { + GetImpl()->SetEventKey(key); +} + FWL_Error IFWL_Widget::SetPrivateData(void* module_id, void* pData, PD_CALLBACK_FREEDATA callback) { - return static_cast(GetImpl()) - ->SetPrivateData(module_id, pData, callback); + return GetImpl()->SetPrivateData(module_id, pData, callback); } void* IFWL_Widget::GetPrivateData(void* module_id) { - return static_cast(GetImpl())->GetPrivateData(module_id); + return GetImpl()->GetPrivateData(module_id); } FWL_Error IFWL_Widget::Update() { - return static_cast(GetImpl())->Update(); + return GetImpl()->Update(); } FWL_Error IFWL_Widget::LockUpdate() { - return static_cast(GetImpl())->LockUpdate(); + return GetImpl()->LockUpdate(); } FWL_Error IFWL_Widget::UnlockUpdate() { - return static_cast(GetImpl())->UnlockUpdate(); + return GetImpl()->UnlockUpdate(); } FWL_WidgetHit IFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - return static_cast(GetImpl())->HitTest(fx, fy); + return GetImpl()->HitTest(fx, fy); } FWL_Error IFWL_Widget::TransformTo(IFWL_Widget* pWidget, FX_FLOAT& fx, FX_FLOAT& fy) { - return static_cast(GetImpl())->TransformTo(pWidget, fx, fy); + return GetImpl()->TransformTo(pWidget, fx, fy); } FWL_Error IFWL_Widget::TransformTo(IFWL_Widget* pWidget, CFX_RectF& rt) { - return static_cast(GetImpl())->TransformTo(pWidget, rt); + return GetImpl()->TransformTo(pWidget, rt); } FWL_Error IFWL_Widget::GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal) { - return static_cast(GetImpl())->GetMatrix(matrix, bGlobal); + return GetImpl()->GetMatrix(matrix, bGlobal); } FWL_Error IFWL_Widget::SetMatrix(const CFX_Matrix& matrix) { - return static_cast(GetImpl())->SetMatrix(matrix); + return GetImpl()->SetMatrix(matrix); } FWL_Error IFWL_Widget::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { - return static_cast(GetImpl()) - ->DrawWidget(pGraphics, pMatrix); + return GetImpl()->DrawWidget(pGraphics, pMatrix); } IFWL_ThemeProvider* IFWL_Widget::GetThemeProvider() { - return static_cast(GetImpl())->GetThemeProvider(); + return GetImpl()->GetThemeProvider(); } FWL_Error IFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { - return static_cast(GetImpl()) - ->SetThemeProvider(pThemeProvider); + return GetImpl()->SetThemeProvider(pThemeProvider); } FWL_Error IFWL_Widget::SetDataProvider(IFWL_DataProvider* pDataProvider) { - return static_cast(GetImpl()) - ->SetDataProvider(pDataProvider); + return GetImpl()->SetDataProvider(pDataProvider); } IFWL_WidgetDelegate* IFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { - return static_cast(GetImpl())->SetDelegate(pDelegate); + return GetImpl()->SetDelegate(pDelegate); } IFWL_App* IFWL_Widget::GetOwnerApp() const { - return static_cast(GetImpl())->GetOwnerApp(); + return GetImpl()->GetOwnerApp(); } CFX_SizeF IFWL_Widget::GetOffsetFromParent(IFWL_Widget* pParent) { - return static_cast(GetImpl())->GetOffsetFromParent(pParent); + return GetImpl()->GetOffsetFromParent(pParent); } FWL_Error CFWL_WidgetImp::Initialize() { @@ -506,6 +508,15 @@ IFWL_Widget* CFWL_WidgetImp::GetInterface() const { void CFWL_WidgetImp::SetInterface(IFWL_Widget* pInterface) { m_pInterface = pInterface; } + +uint32_t CFWL_WidgetImp::GetEventKey() const { + return m_nEventKey; +} + +void CFWL_WidgetImp::SetEventKey(uint32_t key) { + m_nEventKey = key; +} + CFWL_WidgetImp::CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties, IFWL_Widget* pOuter) : m_pProperties(new CFWL_WidgetImpProperties), @@ -514,7 +525,8 @@ CFWL_WidgetImp::CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties, m_pCurDelegate(NULL), m_pOuter(pOuter), m_pInterface(NULL), - m_iLock(0) { + m_iLock(0), + m_nEventKey(0) { *m_pProperties = properties; m_pWidgetMgr = CFWL_WidgetMgr::GetInstance(); ASSERT(m_pWidgetMgr != NULL); diff --git a/xfa/fwl/core/fwl_widgetimp.h b/xfa/fwl/core/fwl_widgetimp.h index 1b1ccc4b74..3fdef9786c 100644 --- a/xfa/fwl/core/fwl_widgetimp.h +++ b/xfa/fwl/core/fwl_widgetimp.h @@ -73,10 +73,13 @@ class CFWL_WidgetImp { virtual FWL_Error SetDataProvider(IFWL_DataProvider* pDataProvider); virtual IFWL_WidgetDelegate* SetDelegate(IFWL_WidgetDelegate* pDelegate); virtual IFWL_App* GetOwnerApp() const; + FWL_Error SetOwnerApp(CFWL_AppImp* pOwnerApp); IFWL_Widget* GetInterface() const; void SetInterface(IFWL_Widget* pInterface); CFX_SizeF GetOffsetFromParent(IFWL_Widget* pParent); + uint32_t GetEventKey() const; + void SetEventKey(uint32_t key); protected: friend class CFWL_WidgetImpDelegate; @@ -160,6 +163,7 @@ class CFWL_WidgetImp { IFWL_Widget* m_pOuter; IFWL_Widget* m_pInterface; int32_t m_iLock; + uint32_t m_nEventKey; }; class CFWL_WidgetImpDelegate : public IFWL_WidgetDelegate { diff --git a/xfa/fwl/core/ifwl_widget.h b/xfa/fwl/core/ifwl_widget.h index 8bbf8da469..1c469b276c 100644 --- a/xfa/fwl/core/ifwl_widget.h +++ b/xfa/fwl/core/ifwl_widget.h @@ -75,6 +75,8 @@ class IFWL_Widget { uint32_t dwStylesExRemoved); uint32_t GetStates(); void SetStates(uint32_t dwStates, FX_BOOL bSet = TRUE); + uint32_t GetEventKey() const; + void SetEventKey(uint32_t key); FWL_Error SetPrivateData(void* module_id, void* pData, PD_CALLBACK_FREEDATA callback); -- cgit v1.2.3