From 8fba261fb6584169c5788326dd49e91bc9babda5 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 26 Oct 2018 21:27:41 +0000 Subject: Remove pParentWnd field entirely from CreateParams. Put it into CPWL_Wnd directly, and set/clear it when a child is added/removed from a parent. Change-Id: I7a8cd0cf22dbd6173e64bec5d844df56ad373722 Reviewed-on: https://pdfium-review.googlesource.com/c/44692 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fpdfsdk/formfiller/cffl_formfiller.cpp | 1 - fpdfsdk/pwl/cpwl_combo_box.cpp | 3 --- fpdfsdk/pwl/cpwl_edit_ctrl.cpp | 1 - fpdfsdk/pwl/cpwl_scroll_bar.cpp | 1 - fpdfsdk/pwl/cpwl_wnd.cpp | 10 ++++++---- fpdfsdk/pwl/cpwl_wnd.h | 6 ++---- 6 files changed, 8 insertions(+), 14 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index 76421368b2..91e16e8169 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -329,7 +329,6 @@ bool CFFL_FormFiller::IsValid() const { CPWL_Wnd::CreateParams CFFL_FormFiller::GetCreateParam() { CPWL_Wnd::CreateParams cp; - cp.pParentWnd = nullptr; cp.pProvider.Reset(this); cp.rcRectWnd = GetPDFWindowRect(); diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp index db1def0758..70893ca437 100644 --- a/fpdfsdk/pwl/cpwl_combo_box.cpp +++ b/fpdfsdk/pwl/cpwl_combo_box.cpp @@ -277,7 +277,6 @@ void CPWL_ComboBox::CreateEdit(const CreateParams& cp) { AddChild(m_pEdit.Get()); CreateParams ecp = cp; - ecp.pParentWnd = this; ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | PES_AUTOSCROLL | PES_UNDO; @@ -301,7 +300,6 @@ void CPWL_ComboBox::CreateButton(const CreateParams& cp) { AddChild(m_pButton.Get()); CreateParams bcp = cp; - bcp.pParentWnd = this; bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; bcp.sBackgroundColor = CFX_Color(CFX_Color::kRGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f); @@ -321,7 +319,6 @@ void CPWL_ComboBox::CreateListBox(const CreateParams& cp) { AddChild(m_pList.Get()); CreateParams lcp = cp; - lcp.pParentWnd = this; lcp.dwFlags = PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; lcp.nBorderStyle = BorderStyle::SOLID; diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp index ea48c45376..8bf13a73d0 100644 --- a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp +++ b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp @@ -93,7 +93,6 @@ void CPWL_EditCtrl::CreateEditCaret(const CreateParams& cp) { AddChild(m_pEditCaret); CreateParams ecp = cp; - ecp.pParentWnd = this; ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; ecp.dwBorderWidth = 0; ecp.nBorderStyle = BorderStyle::SOLID; diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/fpdfsdk/pwl/cpwl_scroll_bar.cpp index 3e52e0d81b..34154aaa98 100644 --- a/fpdfsdk/pwl/cpwl_scroll_bar.cpp +++ b/fpdfsdk/pwl/cpwl_scroll_bar.cpp @@ -535,7 +535,6 @@ void CPWL_ScrollBar::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) { void CPWL_ScrollBar::CreateButtons(const CreateParams& cp) { CreateParams scp = cp; - scp.pParentWnd = this; scp.dwBorderWidth = 2; scp.nBorderStyle = BorderStyle::BEVELED; scp.dwFlags = diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp index d5d2102997..66e5cfa0b6 100644 --- a/fpdfsdk/pwl/cpwl_wnd.cpp +++ b/fpdfsdk/pwl/cpwl_wnd.cpp @@ -173,9 +173,8 @@ void CPWL_Wnd::Destroy() { delete pChild; } } - if (m_CreationParams.pParentWnd) - m_CreationParams.pParentWnd->RemoveChild(this); - + if (m_pParent) + m_pParent->RemoveChild(this); m_bCreated = false; } DestroyMsgControl(); @@ -379,10 +378,14 @@ bool CPWL_Wnd::OnMouseWheel(short zDelta, } void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) { + ASSERT(!pWnd->m_pParent); + pWnd->m_pParent = this; m_Children.push_back(pWnd); } void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) { + ASSERT(pWnd->m_pParent == this); + pWnd->m_pParent = nullptr; for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { if (*it && *it == pWnd) { m_Children.erase(std::next(it).base()); @@ -492,7 +495,6 @@ void CPWL_Wnd::CreateVScrollBar(const CreateParams& cp) { scp.dwFlags = PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; - scp.pParentWnd = this; scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; scp.eCursorType = FXCT_ARROW; scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h index 8d7eebc5e9..3a4c9a5914 100644 --- a/fpdfsdk/pwl/cpwl_wnd.h +++ b/fpdfsdk/pwl/cpwl_wnd.h @@ -127,7 +127,6 @@ class CPWL_Wnd : public CPWL_TimerHandler, public Observable { int32_t nTransparency; // optional float fFontSize; // optional CPWL_Dash sDash; // optional - UnownedPtr pParentWnd; // ignore CPWL_MsgControl* pMsgControl; // ignore int32_t eCursorType; // ignore CFX_Matrix mtChild; // ignore @@ -215,9 +214,7 @@ class CPWL_Wnd : public CPWL_TimerHandler, public Observable { void SetClipRect(const CFX_FloatRect& rect); const CFX_FloatRect& GetClipRect() const; - CPWL_Wnd* GetParentWindow() const { - return m_CreationParams.pParentWnd.Get(); - } + CPWL_Wnd* GetParentWindow() const { return m_pParent.Get(); } const PrivateData* GetAttachedData() const { return m_pAttachedData.get(); } std::unique_ptr CloneAttachedData() const; @@ -308,6 +305,7 @@ class CPWL_Wnd : public CPWL_TimerHandler, public Observable { CreateParams m_CreationParams; std::unique_ptr m_pAttachedData; + UnownedPtr m_pParent; std::vector m_Children; UnownedPtr m_pVScrollBar; CFX_FloatRect m_rcWindow; -- cgit v1.2.3