From d96fa3b42797332ab53c05b8e6b6357676838e55 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 3 Jul 2018 18:48:04 +0000 Subject: Use UnownedPtr<> in cfwl_notedriver.h Re-order owned/unowned references to obey lifetime constraint. Change-Id: I589746b3c2e7d8c45d26d63d09eef977b095226d Reviewed-on: https://pdfium-review.googlesource.com/36970 Commit-Queue: Tom Sepez Commit-Queue: dsinclair Reviewed-by: dsinclair --- xfa/fwl/cfwl_app.cpp | 2 +- xfa/fwl/cfwl_notedriver.cpp | 39 ++++++++++++++++++--------------------- xfa/fwl/cfwl_notedriver.h | 15 ++++++++------- 3 files changed, 27 insertions(+), 29 deletions(-) (limited to 'xfa') diff --git a/xfa/fwl/cfwl_app.cpp b/xfa/fwl/cfwl_app.cpp index 58ca93de61..666a91d209 100644 --- a/xfa/fwl/cfwl_app.cpp +++ b/xfa/fwl/cfwl_app.cpp @@ -19,4 +19,4 @@ CFWL_App::CFWL_App(CXFA_FFApp* pAdapter) ASSERT(m_pAdapterNative); } -CFWL_App::~CFWL_App() {} +CFWL_App::~CFWL_App() = default; diff --git a/xfa/fwl/cfwl_notedriver.cpp b/xfa/fwl/cfwl_notedriver.cpp index e33a423086..b1f21ece37 100644 --- a/xfa/fwl/cfwl_notedriver.cpp +++ b/xfa/fwl/cfwl_notedriver.cpp @@ -24,14 +24,11 @@ #include "xfa/fwl/cfwl_widgetmgr.h" CFWL_NoteDriver::CFWL_NoteDriver() - : m_pHover(nullptr), - m_pFocus(nullptr), - m_pGrab(nullptr), - m_pNoteLoop(pdfium::MakeUnique()) { + : m_pNoteLoop(pdfium::MakeUnique()) { PushNoteLoop(m_pNoteLoop.get()); } -CFWL_NoteDriver::~CFWL_NoteDriver() {} +CFWL_NoteDriver::~CFWL_NoteDriver() = default; void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) { for (const auto& pair : m_eventTargets) { @@ -66,14 +63,14 @@ void CFWL_NoteDriver::UnregisterEventTarget(CFWL_Widget* pListener) { } void CFWL_NoteDriver::PushNoteLoop(CFWL_NoteLoop* pNoteLoop) { - m_NoteLoopQueue.push_back(pNoteLoop); + m_NoteLoopQueue.emplace_back(pNoteLoop); } CFWL_NoteLoop* CFWL_NoteDriver::PopNoteLoop() { if (m_NoteLoopQueue.empty()) return nullptr; - CFWL_NoteLoop* p = m_NoteLoopQueue.back(); + CFWL_NoteLoop* p = m_NoteLoopQueue.back().Get(); m_NoteLoopQueue.pop_back(); return p; } @@ -82,7 +79,7 @@ bool CFWL_NoteDriver::SetFocus(CFWL_Widget* pFocus) { if (m_pFocus == pFocus) return true; - CFWL_Widget* pPrev = m_pFocus; + CFWL_Widget* pPrev = m_pFocus.Get(); m_pFocus = pFocus; if (pPrev) { if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate()) { @@ -135,8 +132,8 @@ void CFWL_NoteDriver::NotifyTargetDestroy(CFWL_Widget* pNoteTarget) { UnregisterEventTarget(pNoteTarget); - for (CFWL_Widget* pWidget : m_Forms) { - CFWL_Form* pForm = static_cast(pWidget); + for (const auto& pWidget : m_Forms) { + CFWL_Form* pForm = static_cast(pWidget.Get()); if (!pForm) continue; @@ -153,7 +150,7 @@ void CFWL_NoteDriver::RegisterForm(CFWL_Widget* pForm) { if (!pForm || pdfium::ContainsValue(m_Forms, pForm)) return; - m_Forms.push_back(pForm); + m_Forms.emplace_back(pForm); if (m_Forms.size() == 1 && !m_NoteLoopQueue.empty() && m_NoteLoopQueue[0]) m_NoteLoopQueue[0]->SetMainForm(pForm); } @@ -181,7 +178,7 @@ void CFWL_NoteDriver::UnqueueMessageAndProcess(CFWL_NoteLoop* pNoteLoop) { } CFWL_NoteLoop* CFWL_NoteDriver::GetTopLoop() const { - return !m_NoteLoopQueue.empty() ? m_NoteLoopQueue.back() : nullptr; + return !m_NoteLoopQueue.empty() ? m_NoteLoopQueue.back().Get() : nullptr; } void CFWL_NoteDriver::ProcessMessage(std::unique_ptr pMessage) { @@ -254,8 +251,8 @@ bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) { pMsg->m_dwKeyCode == FWL_VKEY_Tab) { CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); CFWL_Widget* pForm = GetMessageForm(pMsg->GetDstTarget()); - CFWL_Widget* pFocus = m_pFocus; - if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm) + CFWL_Widget* pFocus = m_pFocus.Get(); + if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus.Get()) != pForm) pFocus = nullptr; bool bFind = false; @@ -284,7 +281,7 @@ bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) { } return false; } - pMsg->SetDstTarget(m_pFocus); + pMsg->SetDstTarget(m_pFocus.Get()); return true; } @@ -326,7 +323,7 @@ bool CFWL_NoteDriver::DoMouseEx(CFWL_Message* pMessage, return false; CFWL_Widget* pTarget = nullptr; if (m_pGrab) - pTarget = m_pGrab; + pTarget = m_pGrab.Get(); CFWL_MessageMouse* pMsg = static_cast(pMessage); if (!pTarget) @@ -347,8 +344,8 @@ void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) { CFWL_MessageMouse* pMsg = static_cast(pMessage); if (m_pHover) { - CFWL_MessageMouse msLeave(nullptr, m_pHover); - msLeave.m_pos = pTarget->TransformTo(m_pHover, pMsg->m_pos); + CFWL_MessageMouse msLeave(nullptr, m_pHover.Get()); + msLeave.m_pos = pTarget->TransformTo(m_pHover.Get(), pMsg->m_pos); msLeave.m_dwFlags = 0; msLeave.m_dwCmd = FWL_MouseCommand::Leave; DispatchMessage(&msLeave, nullptr); @@ -367,13 +364,13 @@ void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) { } bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) { - for (CFWL_NoteLoop* pNoteLoop : m_NoteLoopQueue) { + for (const auto& pNoteLoop : m_NoteLoopQueue) { CFWL_Widget* pForm = pNoteLoop->GetForm(); if (pForm && pForm == pMessage->GetDstTarget()) return true; } - for (CFWL_Widget* pWidget : m_Forms) { - CFWL_Form* pForm = static_cast(pWidget); + for (const auto& pWidget : m_Forms) { + auto* pForm = static_cast(pWidget.Get()); if (pForm == pMessage->GetDstTarget()) return true; } diff --git a/xfa/fwl/cfwl_notedriver.h b/xfa/fwl/cfwl_notedriver.h index 0db482ecbc..f894fe33d8 100644 --- a/xfa/fwl/cfwl_notedriver.h +++ b/xfa/fwl/cfwl_notedriver.h @@ -12,6 +12,7 @@ #include #include +#include "core/fxcrt/unowned_ptr.h" #include "xfa/fwl/cfwl_event.h" #include "xfa/fwl/cfwl_widget.h" #include "xfa/fxgraphics/cxfa_graphics.h" @@ -36,7 +37,7 @@ class CFWL_NoteDriver { void PushNoteLoop(CFWL_NoteLoop* pNoteLoop); CFWL_NoteLoop* PopNoteLoop(); - CFWL_Widget* GetFocus() const { return m_pFocus; } + CFWL_Widget* GetFocus() const { return m_pFocus.Get(); } bool SetFocus(CFWL_Widget* pFocus); void SetGrab(CFWL_Widget* pGrab, bool bSet) { m_pGrab = bSet ? pGrab : nullptr; @@ -66,14 +67,14 @@ class CFWL_NoteDriver { bool IsValidMessage(CFWL_Message* pMessage); CFWL_Widget* GetMessageForm(CFWL_Widget* pDstTarget); - std::vector m_Forms; + std::vector> m_Forms; std::deque> m_NoteQueue; - std::vector m_NoteLoopQueue; - std::map> m_eventTargets; - CFWL_Widget* m_pHover; - CFWL_Widget* m_pFocus; - CFWL_Widget* m_pGrab; std::unique_ptr m_pNoteLoop; + std::vector> m_NoteLoopQueue; + std::map> m_eventTargets; + UnownedPtr m_pHover; + UnownedPtr m_pFocus; + UnownedPtr m_pGrab; }; #endif // XFA_FWL_CFWL_NOTEDRIVER_H_ -- cgit v1.2.3