Stop transfering ownership of |this| as CPWL_Wnd::Create() side-effect Instead, make it an explicit method called on the parent outside of create. Rename Create() to Realize() to be sure to catch all usages, and add the new required call. Attachment to the parent now takes place a little earlier on in the life-cycle as a result but should be ok. Precursor to converting to smart pointers. Change-Id: I45c459fcd28b5d03c428ce5809d0432506cf4ec6 Reviewed-on: https://pdfium-review.googlesource.com/c/44690 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp index 3dbac1a..d9add78 100644 --- a/fpdfsdk/formfiller/cffl_checkbox.cpp +++ b/fpdfsdk/formfiller/cffl_checkbox.cpp
@@ -25,7 +25,9 @@ const CPWL_Wnd::CreateParams& cp, std::unique_ptr<CPWL_Wnd::PrivateData> pAttachedData) { auto pWnd = pdfium::MakeUnique<CPWL_CheckBox>(std::move(pAttachedData)); - pWnd->Create(cp); + if (cp.pParentWnd) + cp.pParentWnd->AddChild(pWnd.get()); + pWnd->Realize(cp); pWnd->SetCheck(m_pWidget->IsChecked()); return std::move(pWnd); }
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index b068171..7d2124c 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -48,8 +48,10 @@ const CPWL_Wnd::CreateParams& cp, std::unique_ptr<CPWL_Wnd::PrivateData> pAttachedData) { auto pWnd = pdfium::MakeUnique<CPWL_ComboBox>(std::move(pAttachedData)); + if (cp.pParentWnd) + cp.pParentWnd->AddChild(pWnd.get()); pWnd->AttachFFLData(this); - pWnd->Create(cp); + pWnd->Realize(cp); CFFL_InteractiveFormFiller* pFormFiller = m_pFormFillEnv->GetInteractiveFormFiller();
diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index 4eb3a71..3350732 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp
@@ -43,8 +43,10 @@ const CPWL_Wnd::CreateParams& cp, std::unique_ptr<CPWL_Wnd::PrivateData> pAttachedData) { auto pWnd = pdfium::MakeUnique<CPWL_ListBox>(std::move(pAttachedData)); + if (cp.pParentWnd) + cp.pParentWnd->AddChild(pWnd.get()); pWnd->AttachFFLData(this); - pWnd->Create(cp); + pWnd->Realize(cp); pWnd->SetFillerNotify(m_pFormFillEnv->GetInteractiveFormFiller()); for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++)
diff --git a/fpdfsdk/formfiller/cffl_pushbutton.cpp b/fpdfsdk/formfiller/cffl_pushbutton.cpp index 04db191..4c9a1ed 100644 --- a/fpdfsdk/formfiller/cffl_pushbutton.cpp +++ b/fpdfsdk/formfiller/cffl_pushbutton.cpp
@@ -21,6 +21,8 @@ const CPWL_Wnd::CreateParams& cp, std::unique_ptr<CPWL_Wnd::PrivateData> pAttachedData) { auto pWnd = pdfium::MakeUnique<CPWL_PushButton>(std::move(pAttachedData)); - pWnd->Create(cp); + if (cp.pParentWnd) + cp.pParentWnd->AddChild(pWnd.get()); + pWnd->Realize(cp); return std::move(pWnd); }
diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp index c8103d4..f987d76 100644 --- a/fpdfsdk/formfiller/cffl_radiobutton.cpp +++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp
@@ -24,7 +24,9 @@ const CPWL_Wnd::CreateParams& cp, std::unique_ptr<CPWL_Wnd::PrivateData> pAttachedData) { auto pWnd = pdfium::MakeUnique<CPWL_RadioButton>(std::move(pAttachedData)); - pWnd->Create(cp); + if (cp.pParentWnd) + cp.pParentWnd->AddChild(pWnd.get()); + pWnd->Realize(cp); pWnd->SetCheck(m_pWidget->IsChecked()); return std::move(pWnd); }
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index a549396..fbbc637 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -74,7 +74,9 @@ std::unique_ptr<CPWL_Wnd::PrivateData> pAttachedData) { auto pWnd = pdfium::MakeUnique<CPWL_Edit>(std::move(pAttachedData)); pWnd->AttachFFLData(this); - pWnd->Create(cp); + if (cp.pParentWnd) + cp.pParentWnd->AddChild(pWnd.get()); + pWnd->Realize(cp); pWnd->SetFillerNotify(m_pFormFillEnv->GetInteractiveFormFiller()); int32_t nMaxLen = m_pWidget->GetMaxLen();
diff --git a/fpdfsdk/pwl/cpwl_appstream.cpp b/fpdfsdk/pwl/cpwl_appstream.cpp index ebd47be..02541aa3 100644 --- a/fpdfsdk/pwl/cpwl_appstream.cpp +++ b/fpdfsdk/pwl/cpwl_appstream.cpp
@@ -684,9 +684,9 @@ return ByteString(); CPWL_Icon icon(nullptr); - CPWL_Wnd::CreateParams cp; + CPWL_Wnd::CreateParams cp; // No parent. cp.dwFlags = PWS_VISIBLE; - icon.Create(cp); + icon.Realize(cp); icon.SetIconFit(&fit); icon.SetPDFStream(pIconStream); if (!icon.Move(rcIcon, false, false))
diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp index bb5890b..db1def0 100644 --- a/fpdfsdk/pwl/cpwl_combo_box.cpp +++ b/fpdfsdk/pwl/cpwl_combo_box.cpp
@@ -274,6 +274,7 @@ m_pEdit = new CPWL_Edit(CloneAttachedData()); m_pEdit->AttachFFLData(m_pFormFiller.Get()); + AddChild(m_pEdit.Get()); CreateParams ecp = cp; ecp.pParentWnd = this; @@ -289,7 +290,7 @@ ecp.rcRectWnd = CFX_FloatRect(); ecp.dwBorderWidth = 0; ecp.nBorderStyle = BorderStyle::SOLID; - m_pEdit->Create(ecp); + m_pEdit->Realize(ecp); } void CPWL_ComboBox::CreateButton(const CreateParams& cp) { @@ -297,6 +298,7 @@ return; m_pButton = new CPWL_CBButton(CloneAttachedData()); + AddChild(m_pButton.Get()); CreateParams bcp = cp; bcp.pParentWnd = this; @@ -307,7 +309,7 @@ bcp.dwBorderWidth = 2; bcp.nBorderStyle = BorderStyle::BEVELED; bcp.eCursorType = FXCT_ARROW; - m_pButton->Create(bcp); + m_pButton->Realize(bcp); } void CPWL_ComboBox::CreateListBox(const CreateParams& cp) { @@ -316,6 +318,7 @@ m_pList = new CPWL_CBListBox(CloneAttachedData()); m_pList->AttachFFLData(m_pFormFiller.Get()); + AddChild(m_pList.Get()); CreateParams lcp = cp; lcp.pParentWnd = this; @@ -335,7 +338,7 @@ if (cp.sBackgroundColor.nColorType == CFX_Color::kTransparent) lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; - m_pList->Create(lcp); + m_pList->Realize(lcp); } bool CPWL_ComboBox::RePosChildWnd() {
diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp index d27c6cd..ea48c45 100644 --- a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp +++ b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
@@ -90,6 +90,7 @@ m_pEditCaret = new CPWL_Caret(CloneAttachedData()); m_pEditCaret->SetInvalidRect(GetClientRect()); + AddChild(m_pEditCaret); CreateParams ecp = cp; ecp.pParentWnd = this; @@ -97,7 +98,7 @@ ecp.dwBorderWidth = 0; ecp.nBorderStyle = BorderStyle::SOLID; ecp.rcRectWnd = CFX_FloatRect(); - m_pEditCaret->Create(ecp); + m_pEditCaret->Realize(ecp); } void CPWL_EditCtrl::SetFontSize(float fFontSize) {
diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/fpdfsdk/pwl/cpwl_scroll_bar.cpp index 4051d7b..3e52e0d8 100644 --- a/fpdfsdk/pwl/cpwl_scroll_bar.cpp +++ b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
@@ -543,19 +543,23 @@ if (!m_pMinButton) { m_pMinButton = new CPWL_SBButton(CloneAttachedData(), m_sbType, PSBT_MIN); - m_pMinButton->Create(scp); + AddChild(m_pMinButton.Get()); + m_pMinButton->Realize(scp); } if (!m_pMaxButton) { m_pMaxButton = new CPWL_SBButton(CloneAttachedData(), m_sbType, PSBT_MAX); - m_pMaxButton->Create(scp); + AddChild(m_pMaxButton.Get()); + m_pMaxButton->Realize(scp); } if (!m_pPosButton) { m_pPosButton = new CPWL_SBButton(CloneAttachedData(), m_sbType, PSBT_POS); ObservedPtr thisObserved(this); - if (m_pPosButton->SetVisible(false) && thisObserved) - m_pPosButton->Create(scp); + if (m_pPosButton->SetVisible(false) && thisObserved) { + AddChild(m_pPosButton.Get()); + m_pPosButton->Realize(scp); + } } }
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp index 6767164..d5d2102 100644 --- a/fpdfsdk/pwl/cpwl_wnd.cpp +++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -118,9 +118,8 @@ ASSERT(!m_bCreated); } -void CPWL_Wnd::Create(const CreateParams& cp) { - if (IsValid()) - return; +void CPWL_Wnd::Realize(const CreateParams& cp) { + ASSERT(!m_bCreated); m_CreationParams = cp; OnCreate(&m_CreationParams); @@ -132,8 +131,6 @@ m_rcClip.Normalize(); } CreateMsgControl(); - if (m_CreationParams.pParentWnd) - m_CreationParams.pParentWnd->AddChild(this); CreateParams ccp = m_CreationParams; ccp.dwFlags &= 0xFFFF0000L; // remove sub styles @@ -501,7 +498,8 @@ scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; m_pVScrollBar = new CPWL_ScrollBar(CloneAttachedData(), SBT_VSCROLL); - m_pVScrollBar->Create(scp); + AddChild(m_pVScrollBar.Get()); + m_pVScrollBar->Realize(scp); } void CPWL_Wnd::SetCapture() {
diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h index 921693f..8d7eebc 100644 --- a/fpdfsdk/pwl/cpwl_wnd.h +++ b/fpdfsdk/pwl/cpwl_wnd.h
@@ -177,15 +177,16 @@ virtual CFX_FloatRect GetFocusRect() const; virtual CFX_FloatRect GetClientRect() const; - void InvalidateFocusHandler(FocusHandlerIface* handler); - void InvalidateProvider(ProviderIface* provider); - void Create(const CreateParams& cp); + void AddChild(CPWL_Wnd* pWnd); + void RemoveChild(CPWL_Wnd* pWnd); + void Realize(const CreateParams& cp); void Destroy(); bool Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh); + void InvalidateFocusHandler(FocusHandlerIface* handler); + void InvalidateProvider(ProviderIface* provider); void SetCapture(); void ReleaseCapture(); - void DrawAppearance(CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device); @@ -296,9 +297,6 @@ CFX_FloatRect PWLtoWnd(const CFX_FloatRect& rect) const; - void AddChild(CPWL_Wnd* pWnd); - void RemoveChild(CPWL_Wnd* pWnd); - void CreateScrollBar(const CreateParams& cp); void CreateVScrollBar(const CreateParams& cp);