Make CFWL_WidgetProperties::m_pParent a const member.
It is only changed after creation by SetParent(), but that is right
after creation and can be worked around in the one place it is called.
Change-Id: Ic3bf5d012bddd3401b5fe9793617410bd3aa12de
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72611
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp
index 31a3051..e9a89b4 100644
--- a/xfa/fwl/cfwl_barcode.cpp
+++ b/xfa/fwl/cfwl_barcode.cpp
@@ -16,7 +16,9 @@
#include "xfa/fwl/theme/cfwl_utils.h"
CFWL_Barcode::CFWL_Barcode(const CFWL_App* app)
- : CFWL_Edit(app, std::make_unique<CFWL_WidgetProperties>(), nullptr) {}
+ : CFWL_Edit(app,
+ std::make_unique<CFWL_WidgetProperties>(nullptr),
+ nullptr) {}
CFWL_Barcode::~CFWL_Barcode() = default;
diff --git a/xfa/fwl/cfwl_checkbox.cpp b/xfa/fwl/cfwl_checkbox.cpp
index baf7133..8ff0e13 100644
--- a/xfa/fwl/cfwl_checkbox.cpp
+++ b/xfa/fwl/cfwl_checkbox.cpp
@@ -29,7 +29,9 @@
} // namespace
CFWL_CheckBox::CFWL_CheckBox(const CFWL_App* app)
- : CFWL_Widget(app, std::make_unique<CFWL_WidgetProperties>(), nullptr) {
+ : CFWL_Widget(app,
+ std::make_unique<CFWL_WidgetProperties>(nullptr),
+ nullptr) {
m_TTOStyles.single_line_ = true;
}
diff --git a/xfa/fwl/cfwl_combobox.cpp b/xfa/fwl/cfwl_combobox.cpp
index 920fbd4..707739b 100644
--- a/xfa/fwl/cfwl_combobox.cpp
+++ b/xfa/fwl/cfwl_combobox.cpp
@@ -29,7 +29,9 @@
#include "xfa/fwl/ifwl_themeprovider.h"
CFWL_ComboBox::CFWL_ComboBox(const CFWL_App* app)
- : CFWL_Widget(app, std::make_unique<CFWL_WidgetProperties>(), nullptr) {
+ : CFWL_Widget(app,
+ std::make_unique<CFWL_WidgetProperties>(nullptr),
+ nullptr) {
InitComboList();
InitComboEdit();
}
@@ -405,8 +407,7 @@
if (m_pListBox)
return;
- auto prop = std::make_unique<CFWL_WidgetProperties>();
- prop->m_pParent = this;
+ auto prop = std::make_unique<CFWL_WidgetProperties>(this);
prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll;
prop->m_dwStates = FWL_WGTSTATE_Invisible;
prop->m_pThemeProvider = GetProperties()->m_pThemeProvider;
@@ -418,8 +419,7 @@
if (m_pEdit)
return;
- auto prop = std::make_unique<CFWL_WidgetProperties>();
- prop->m_pParent = this;
+ auto prop = std::make_unique<CFWL_WidgetProperties>(this);
prop->m_pThemeProvider = GetProperties()->m_pThemeProvider;
m_pEdit =
diff --git a/xfa/fwl/cfwl_datetimepicker.cpp b/xfa/fwl/cfwl_datetimepicker.cpp
index 047e5c6..3f5a3b9 100644
--- a/xfa/fwl/cfwl_datetimepicker.cpp
+++ b/xfa/fwl/cfwl_datetimepicker.cpp
@@ -24,13 +24,14 @@
} // namespace
CFWL_DateTimePicker::CFWL_DateTimePicker(const CFWL_App* app)
- : CFWL_Widget(app, std::make_unique<CFWL_WidgetProperties>(), nullptr) {
+ : CFWL_Widget(app,
+ std::make_unique<CFWL_WidgetProperties>(nullptr),
+ nullptr) {
GetProperties()->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat;
- auto monthProp = std::make_unique<CFWL_WidgetProperties>();
+ auto monthProp = std::make_unique<CFWL_WidgetProperties>(this);
monthProp->m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border;
monthProp->m_dwStates = FWL_WGTSTATE_Invisible;
- monthProp->m_pParent = this;
monthProp->m_pThemeProvider = GetProperties()->m_pThemeProvider;
m_pMonthCal = std::make_unique<CFWL_MonthCalendar>(
GetOwnerApp(), std::move(monthProp), this);
@@ -38,8 +39,7 @@
m_pMonthCal->SetWidgetRect(
CFX_RectF(0, 0, m_pMonthCal->GetAutosizedWidgetRect().Size()));
- auto editProp = std::make_unique<CFWL_WidgetProperties>();
- editProp->m_pParent = this;
+ auto editProp = std::make_unique<CFWL_WidgetProperties>(this);
editProp->m_pThemeProvider = GetProperties()->m_pThemeProvider;
m_pEdit = std::make_unique<CFWL_DateTimeEdit>(GetOwnerApp(),
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 3c9552d..9806248 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -870,10 +870,9 @@
if (m_pVertScrollBar)
return;
- auto prop = std::make_unique<CFWL_WidgetProperties>();
+ auto prop = std::make_unique<CFWL_WidgetProperties>(this);
prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert;
prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible;
- prop->m_pParent = this;
prop->m_pThemeProvider = GetProperties()->m_pThemeProvider;
m_pVertScrollBar =
std::make_unique<CFWL_ScrollBar>(GetOwnerApp(), std::move(prop), this);
@@ -883,10 +882,9 @@
if (m_pHorzScrollBar)
return;
- auto prop = std::make_unique<CFWL_WidgetProperties>();
+ auto prop = std::make_unique<CFWL_WidgetProperties>(this);
prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz;
prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible;
- prop->m_pParent = this;
prop->m_pThemeProvider = GetProperties()->m_pThemeProvider;
m_pHorzScrollBar =
std::make_unique<CFWL_ScrollBar>(GetOwnerApp(), std::move(prop), this);
@@ -962,8 +960,8 @@
return;
m_pCaret = std::make_unique<CFWL_Caret>(
- GetOwnerApp(), std::make_unique<CFWL_WidgetProperties>(), this);
- m_pCaret->SetParent(this);
+ GetOwnerApp(), std::make_unique<CFWL_WidgetProperties>(this), this);
+ GetWidgetMgr()->SetParent(this, m_pCaret.get());
m_pCaret->SetStates(GetProperties()->m_dwStates);
UpdateCursorRect();
}
diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp
index 51da1b3..9586cfa 100644
--- a/xfa/fwl/cfwl_listbox.cpp
+++ b/xfa/fwl/cfwl_listbox.cpp
@@ -615,10 +615,9 @@
if (m_pVertScrollBar)
return;
- auto prop = std::make_unique<CFWL_WidgetProperties>();
+ auto prop = std::make_unique<CFWL_WidgetProperties>(this);
prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert;
prop->m_dwStates = FWL_WGTSTATE_Invisible;
- prop->m_pParent = this;
prop->m_pThemeProvider = m_pScrollBarTP;
m_pVertScrollBar =
std::make_unique<CFWL_ScrollBar>(GetOwnerApp(), std::move(prop), this);
@@ -628,10 +627,9 @@
if (m_pHorzScrollBar)
return;
- auto prop = std::make_unique<CFWL_WidgetProperties>();
+ auto prop = std::make_unique<CFWL_WidgetProperties>(this);
prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz;
prop->m_dwStates = FWL_WGTSTATE_Invisible;
- prop->m_pParent = this;
prop->m_pThemeProvider = m_pScrollBarTP;
m_pHorzScrollBar =
std::make_unique<CFWL_ScrollBar>(GetOwnerApp(), std::move(prop), this);
diff --git a/xfa/fwl/cfwl_picturebox.cpp b/xfa/fwl/cfwl_picturebox.cpp
index 6746042..07062aa 100644
--- a/xfa/fwl/cfwl_picturebox.cpp
+++ b/xfa/fwl/cfwl_picturebox.cpp
@@ -9,7 +9,9 @@
#include <memory>
CFWL_PictureBox::CFWL_PictureBox(const CFWL_App* app)
- : CFWL_Widget(app, std::make_unique<CFWL_WidgetProperties>(), nullptr) {}
+ : CFWL_Widget(app,
+ std::make_unique<CFWL_WidgetProperties>(nullptr),
+ nullptr) {}
CFWL_PictureBox::~CFWL_PictureBox() = default;
diff --git a/xfa/fwl/cfwl_pushbutton.cpp b/xfa/fwl/cfwl_pushbutton.cpp
index 2e5c962..df68393 100644
--- a/xfa/fwl/cfwl_pushbutton.cpp
+++ b/xfa/fwl/cfwl_pushbutton.cpp
@@ -21,7 +21,9 @@
#include "xfa/fwl/ifwl_themeprovider.h"
CFWL_PushButton::CFWL_PushButton(const CFWL_App* app)
- : CFWL_Widget(app, std::make_unique<CFWL_WidgetProperties>(), nullptr) {}
+ : CFWL_Widget(app,
+ std::make_unique<CFWL_WidgetProperties>(nullptr),
+ nullptr) {}
CFWL_PushButton::~CFWL_PushButton() = default;
diff --git a/xfa/fwl/cfwl_widget.cpp b/xfa/fwl/cfwl_widget.cpp
index c62d658..89853c2 100644
--- a/xfa/fwl/cfwl_widget.cpp
+++ b/xfa/fwl/cfwl_widget.cpp
@@ -78,11 +78,6 @@
return GetEdgeRect();
}
-void CFWL_Widget::SetParent(CFWL_Widget* pParent) {
- m_pProperties->m_pParent = pParent;
- m_pWidgetMgr->SetParent(pParent, this);
-}
-
void CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded,
uint32_t dwStylesRemoved) {
m_pProperties->m_dwStyles =
diff --git a/xfa/fwl/cfwl_widget.h b/xfa/fwl/cfwl_widget.h
index c1111d2..f6a85da 100644
--- a/xfa/fwl/cfwl_widget.h
+++ b/xfa/fwl/cfwl_widget.h
@@ -94,8 +94,6 @@
void InflateWidgetRect(CFX_RectF& rect);
void SetWidgetRect(const CFX_RectF& rect);
- void SetParent(CFWL_Widget* pParent);
-
bool IsVisible() const;
bool IsOverLapper() const;
bool IsPopup() const;
diff --git a/xfa/fwl/cfwl_widgetproperties.cpp b/xfa/fwl/cfwl_widgetproperties.cpp
index 4dc3cd5..7437919 100644
--- a/xfa/fwl/cfwl_widgetproperties.cpp
+++ b/xfa/fwl/cfwl_widgetproperties.cpp
@@ -6,6 +6,7 @@
#include "xfa/fwl/cfwl_widgetproperties.h"
-CFWL_WidgetProperties::CFWL_WidgetProperties() = default;
+CFWL_WidgetProperties::CFWL_WidgetProperties(CFWL_Widget* pParent)
+ : m_pParent(pParent) {}
CFWL_WidgetProperties::~CFWL_WidgetProperties() = default;
diff --git a/xfa/fwl/cfwl_widgetproperties.h b/xfa/fwl/cfwl_widgetproperties.h
index 977f846..59e9070 100644
--- a/xfa/fwl/cfwl_widgetproperties.h
+++ b/xfa/fwl/cfwl_widgetproperties.h
@@ -17,7 +17,7 @@
class CFWL_WidgetProperties {
public:
- CFWL_WidgetProperties();
+ explicit CFWL_WidgetProperties(CFWL_Widget* pParent);
~CFWL_WidgetProperties();
uint32_t m_dwStyles = FWL_WGTSTYLE_Child;
@@ -25,7 +25,7 @@
uint32_t m_dwStates = 0;
CFX_RectF m_WidgetRect;
UnownedPtr<IFWL_ThemeProvider> m_pThemeProvider;
- CFWL_Widget* m_pParent = nullptr; // Raw, this class owned by node in tree.
+ CFWL_Widget* const m_pParent; // Raw, this class owned by node in tree.
};
#endif // XFA_FWL_CFWL_WIDGETPROPERTIES_H_
diff --git a/xfa/fxfa/cxfa_fflistbox.cpp b/xfa/fxfa/cxfa_fflistbox.cpp
index 76a28c6..5a81efe 100644
--- a/xfa/fxfa/cxfa_fflistbox.cpp
+++ b/xfa/fxfa/cxfa_fflistbox.cpp
@@ -44,7 +44,7 @@
RetainPtr<CXFA_ContentLayoutItem> retain_layout(m_pLayoutItem.Get());
auto pNew = std::make_unique<CFWL_ListBox>(
- GetFWLApp(), std::make_unique<CFWL_WidgetProperties>(), nullptr);
+ GetFWLApp(), std::make_unique<CFWL_WidgetProperties>(nullptr), nullptr);
CFWL_ListBox* pListBox = pNew.get();
pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground,
0xFFFFFFFF);
diff --git a/xfa/fxfa/cxfa_ffnumericedit.cpp b/xfa/fxfa/cxfa_ffnumericedit.cpp
index dae089c..21248db 100644
--- a/xfa/fxfa/cxfa_ffnumericedit.cpp
+++ b/xfa/fxfa/cxfa_ffnumericedit.cpp
@@ -29,7 +29,7 @@
RetainPtr<CXFA_ContentLayoutItem> retain_layout(m_pLayoutItem.Get());
auto pNewEdit = std::make_unique<CFWL_Edit>(
- GetFWLApp(), std::make_unique<CFWL_WidgetProperties>(), nullptr);
+ GetFWLApp(), std::make_unique<CFWL_WidgetProperties>(nullptr), nullptr);
CFWL_Edit* pWidget = pNewEdit.get();
SetNormalWidget(std::move(pNewEdit));
pWidget->SetAdapterIface(this);
diff --git a/xfa/fxfa/cxfa_ffpasswordedit.cpp b/xfa/fxfa/cxfa_ffpasswordedit.cpp
index b0ece33..10ab7d5 100644
--- a/xfa/fxfa/cxfa_ffpasswordedit.cpp
+++ b/xfa/fxfa/cxfa_ffpasswordedit.cpp
@@ -28,7 +28,7 @@
RetainPtr<CXFA_ContentLayoutItem> retain_layout(m_pLayoutItem.Get());
auto pNewEdit = std::make_unique<CFWL_Edit>(
- GetFWLApp(), std::make_unique<CFWL_WidgetProperties>(), nullptr);
+ GetFWLApp(), std::make_unique<CFWL_WidgetProperties>(nullptr), nullptr);
CFWL_Edit* pWidget = pNewEdit.get();
SetNormalWidget(std::move(pNewEdit));
pWidget->SetAdapterIface(this);
diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp
index c2833b8..072c3fd 100644
--- a/xfa/fxfa/cxfa_fftextedit.cpp
+++ b/xfa/fxfa/cxfa_fftextedit.cpp
@@ -49,7 +49,7 @@
RetainPtr<CXFA_ContentLayoutItem> retain_layout(m_pLayoutItem.Get());
auto pNewWidget = std::make_unique<CFWL_Edit>(
- GetFWLApp(), std::make_unique<CFWL_WidgetProperties>(), nullptr);
+ GetFWLApp(), std::make_unique<CFWL_WidgetProperties>(nullptr), nullptr);
CFWL_Edit* pFWLEdit = pNewWidget.get();
SetNormalWidget(std::move(pNewWidget));
pFWLEdit->SetAdapterIface(this);