summaryrefslogtreecommitdiff
path: root/xfa/fwl/core/fwl_noteimp.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-26 09:40:32 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-26 09:40:32 -0700
commitd2b93dfa15dbb7fd42b7cf05fc248d7f5c87f1ef (patch)
tree9b30522756508ff0a97a119a56260e0c36eb5fb7 /xfa/fwl/core/fwl_noteimp.cpp
parent7f2abcc015583e63cceb52acde757cb2111420bd (diff)
downloadpdfium-d2b93dfa15dbb7fd42b7cf05fc248d7f5c87f1ef.tar.xz
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
Diffstat (limited to 'xfa/fwl/core/fwl_noteimp.cpp')
-rw-r--r--xfa/fwl/core/fwl_noteimp.cpp17
1 files changed, 7 insertions, 10 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;