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 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'xfa/fwl/core/fwl_noteimp.cpp') 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; -- cgit v1.2.3