From 1d52d1e5fb0b14782dd6b97eeee8c90106839452 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 18 Apr 2017 11:45:36 -0700 Subject: Use unique_ptr in CFWL_NoteDriver::m_eventTargets map Invert CFWL_EventTarget::m_bInvalid for the sake of positive logic. Change-Id: I9ccc512ab2ff553e1033698f36bf3a297c4ee7c9 Reviewed-on: https://pdfium-review.googlesource.com/4251 Commit-Queue: dsinclair Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- xfa/fwl/cfwl_eventtarget.cpp | 2 +- xfa/fwl/cfwl_eventtarget.h | 6 +++--- xfa/fwl/cfwl_notedriver.cpp | 20 ++++++-------------- xfa/fwl/cfwl_notedriver.h | 5 +++-- xfa/fxfa/cxfa_ffapp.cpp | 2 +- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/xfa/fwl/cfwl_eventtarget.cpp b/xfa/fwl/cfwl_eventtarget.cpp index 55f8e1fc78..8a3b78799b 100644 --- a/xfa/fwl/cfwl_eventtarget.cpp +++ b/xfa/fwl/cfwl_eventtarget.cpp @@ -10,7 +10,7 @@ #include "xfa/fwl/ifwl_widgetdelegate.h" CFWL_EventTarget::CFWL_EventTarget(CFWL_Widget* pListener) - : m_pListener(pListener), m_bInvalid(false) {} + : m_pListener(pListener), m_bValid(true) {} CFWL_EventTarget::~CFWL_EventTarget() {} diff --git a/xfa/fwl/cfwl_eventtarget.h b/xfa/fwl/cfwl_eventtarget.h index 1bca97232c..36d301df27 100644 --- a/xfa/fwl/cfwl_eventtarget.h +++ b/xfa/fwl/cfwl_eventtarget.h @@ -23,13 +23,13 @@ class CFWL_EventTarget { void SetEventSource(CFWL_Widget* pSource); bool ProcessEvent(CFWL_Event* pEvent); - bool IsInvalid() const { return m_bInvalid; } - void FlagInvalid() { m_bInvalid = true; } + bool IsValid() const { return m_bValid; } + void FlagInvalid() { m_bValid = false; } private: std::set m_widgets; CFWL_Widget* m_pListener; - bool m_bInvalid; + bool m_bValid; }; #endif // XFA_FWL_CFWL_EVENTTARGET_H_ diff --git a/xfa/fwl/cfwl_notedriver.cpp b/xfa/fwl/cfwl_notedriver.cpp index 8feb0fb4e5..9012100c32 100644 --- a/xfa/fwl/cfwl_notedriver.cpp +++ b/xfa/fwl/cfwl_notedriver.cpp @@ -31,18 +31,12 @@ CFWL_NoteDriver::CFWL_NoteDriver() PushNoteLoop(m_pNoteLoop.get()); } -CFWL_NoteDriver::~CFWL_NoteDriver() { - ClearEventTargets(true); -} +CFWL_NoteDriver::~CFWL_NoteDriver() {} void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) { - if (m_eventTargets.empty()) - return; - for (const auto& pair : m_eventTargets) { - CFWL_EventTarget* pEventTarget = pair.second; - if (pEventTarget && !pEventTarget->IsInvalid()) - pEventTarget->ProcessEvent(pNote); + if (pair.second->IsValid()) + pair.second->ProcessEvent(pNote); } } @@ -56,7 +50,7 @@ void CFWL_NoteDriver::RegisterEventTarget(CFWL_Widget* pListener, pListener->SetEventKey(key); } if (!m_eventTargets[key]) - m_eventTargets[key] = new CFWL_EventTarget(pListener); + m_eventTargets[key] = pdfium::MakeUnique(pListener); m_eventTargets[key]->SetEventSource(pEventSource); } @@ -445,13 +439,11 @@ CFWL_Widget* CFWL_NoteDriver::GetMessageForm(CFWL_Widget* pDstTarget) { return pMessageForm; } -void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { +void CFWL_NoteDriver::ClearEventTargets() { auto it = m_eventTargets.begin(); while (it != m_eventTargets.end()) { auto old = it++; - if (old->second && (bRemoveAll || old->second->IsInvalid())) { - delete old->second; + if (!old->second->IsValid()) m_eventTargets.erase(old); - } } } diff --git a/xfa/fwl/cfwl_notedriver.h b/xfa/fwl/cfwl_notedriver.h index e177494ff1..2ea3f97cc0 100644 --- a/xfa/fwl/cfwl_notedriver.h +++ b/xfa/fwl/cfwl_notedriver.h @@ -30,7 +30,7 @@ class CFWL_NoteDriver { void RegisterEventTarget(CFWL_Widget* pListener, CFWL_Widget* pEventSource); void UnregisterEventTarget(CFWL_Widget* pListener); - void ClearEventTargets(bool bRemoveAll); + void ClearEventTargets(); CFWL_NoteLoop* GetTopLoop() const; void PushNoteLoop(CFWL_NoteLoop* pNoteLoop); @@ -69,7 +69,8 @@ class CFWL_NoteDriver { std::vector m_Forms; std::deque> m_NoteQueue; std::vector m_NoteLoopQueue; - std::unordered_map m_eventTargets; + std::unordered_map> + m_eventTargets; CFWL_Widget* m_pHover; CFWL_Widget* m_pFocus; CFWL_Widget* m_pGrab; diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp index c02fd30e86..a71112c93e 100644 --- a/xfa/fxfa/cxfa_ffapp.cpp +++ b/xfa/fxfa/cxfa_ffapp.cpp @@ -92,5 +92,5 @@ IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() const { } void CXFA_FFApp::ClearEventTargets() { - m_pFWLApp->GetNoteDriver()->ClearEventTargets(false); + m_pFWLApp->GetNoteDriver()->ClearEventTargets(); } -- cgit v1.2.3