summaryrefslogtreecommitdiff
path: root/xfa/fwl/lightwidget/cfwl_widget.cpp
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-08 17:30:37 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-08 17:30:37 -0700
commit5d8e5aa882fe8d37d32b71137f039165581ddb82 (patch)
treea0a2b0efa1ee6f8fd06c964f4b9cda5f551c74ae /xfa/fwl/lightwidget/cfwl_widget.cpp
parentb6befb2ed2485a3805cddea86dc7574510178ea9 (diff)
downloadpdfium-5d8e5aa882fe8d37d32b71137f039165581ddb82.tar.xz
Use virtual function to retrieve interface pointer
Use virtual function to return the actual interface type instead of the base interface type to avoid a lot of casts. Also tidy up CFWL_Widget by encapsulating variables, and use smart pointers for class owned member variables. Review-Url: https://codereview.chromium.org/2209153002
Diffstat (limited to 'xfa/fwl/lightwidget/cfwl_widget.cpp')
-rw-r--r--xfa/fwl/lightwidget/cfwl_widget.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/xfa/fwl/lightwidget/cfwl_widget.cpp b/xfa/fwl/lightwidget/cfwl_widget.cpp
index 8022f0afb0..3a5478a433 100644
--- a/xfa/fwl/lightwidget/cfwl_widget.cpp
+++ b/xfa/fwl/lightwidget/cfwl_widget.cpp
@@ -20,7 +20,11 @@
#define FWL_WGT_CalcMultiLineDefWidth 120.0f
IFWL_Widget* CFWL_Widget::GetWidget() {
- return m_pIface;
+ return m_pIface.get();
+}
+
+const IFWL_Widget* CFWL_Widget::GetWidget() const {
+ return m_pIface.get();
}
FWL_Error CFWL_Widget::GetClassName(CFX_WideString& wsClass) const {
@@ -208,18 +212,15 @@ IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) {
}
CFWL_Widget::CFWL_Widget()
- : m_pIface(nullptr), m_pDelegate(nullptr), m_pProperties(nullptr) {
- m_pProperties = new CFWL_WidgetProperties;
- m_pWidgetMgr = CFWL_WidgetMgr::GetInstance();
+ : m_pDelegate(nullptr),
+ m_pWidgetMgr(CFWL_WidgetMgr::GetInstance()),
+ m_pProperties(new CFWL_WidgetProperties) {
ASSERT(m_pWidgetMgr);
}
CFWL_Widget::~CFWL_Widget() {
- delete m_pProperties;
- if (m_pIface) {
+ if (m_pIface)
m_pIface->Finalize();
- delete m_pIface;
- }
}
FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) {
@@ -233,7 +234,7 @@ FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) {
m_pIface->GetWidgetRect(rect);
rect.left = rect.top = 0;
}
- return m_pWidgetMgr->RepaintWidget(m_pIface, &rect);
+ return m_pWidgetMgr->RepaintWidget(m_pIface.get(), &rect);
}
FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) {
@@ -249,9 +250,9 @@ FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) {
return FWL_Error::Indefinite;
if (bFocus) {
- pDriver->SetFocus(m_pIface);
+ pDriver->SetFocus(m_pIface.get());
} else {
- if (pDriver->GetFocus() == m_pIface) {
+ if (pDriver->GetFocus() == m_pIface.get()) {
pDriver->SetFocus(nullptr);
}
}
@@ -270,7 +271,7 @@ FWL_Error CFWL_Widget::SetGrab(FX_BOOL bSet) {
if (!pDriver)
return FWL_Error::Indefinite;
- pDriver->SetGrab(m_pIface, bSet);
+ pDriver->SetGrab(m_pIface.get(), bSet);
return FWL_Error::Succeeded;
}
@@ -320,7 +321,7 @@ CFX_SizeF CFWL_Widget::CalcTextSize(const CFX_WideString& wsText,
return CFX_SizeF();
CFWL_ThemeText calPart;
- calPart.m_pWidget = m_pIface;
+ calPart.m_pWidget = m_pIface.get();
calPart.m_wsText = wsText;
calPart.m_dwTTOStyles =
bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine;