Make CFWL_WidgetMgr{Delegate} inherit from IFWL_WidgetMgr{Delegate}.
C-style casting masked a fairly serious botch, where an
CFWL_ type would get cast to an IFWL_ type, and later we'd
invoke virtual methods against the IFWL_ type. Without the
proper inheritance, there's no reason to believe that the
vtables for each of these would line up with each other.
Fixing the inheritence allows us to remove the c-style casts.
I'm guessing these were added to make this compile without
having to understand the true nature of the flaw.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1439093003 .
diff --git a/xfa/src/fwl/src/core/fwl_appimp.cpp b/xfa/src/fwl/src/core/fwl_appimp.cpp
index d9d37e2..948001c 100644
--- a/xfa/src/fwl/src/core/fwl_appimp.cpp
+++ b/xfa/src/fwl/src/core/fwl_appimp.cpp
@@ -41,10 +41,8 @@
return FWL_ERR_Succeeded;
}
FWL_ERR CFWL_AppImp::Finalize() {
- if (m_pWidgetMgr) {
- delete m_pWidgetMgr;
- m_pWidgetMgr = NULL;
- }
+ delete m_pWidgetMgr;
+ m_pWidgetMgr = NULL;
return FWL_ERR_Succeeded;
}
IFWL_AdapterNative* CFWL_AppImp::GetAdapterNative() {
@@ -54,7 +52,7 @@
return ((CFWL_WidgetMgr*)FWL_GetWidgetMgr())->GetAdapterWidgetMgr();
}
IFWL_WidgetMgr* CFWL_AppImp::GetWidgetMgr() {
- return (IFWL_WidgetMgr*)m_pWidgetMgr;
+ return m_pWidgetMgr;
}
FWL_ERR CFWL_AppImp::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
m_pThemeProvider = pThemeProvider;
diff --git a/xfa/src/fwl/src/core/fwl_widgetmgrimp.cpp b/xfa/src/fwl/src/core/fwl_widgetmgrimp.cpp
index 5671ff6..00bebae 100644
--- a/xfa/src/fwl/src/core/fwl_widgetmgrimp.cpp
+++ b/xfa/src/fwl/src/core/fwl_widgetmgrimp.cpp
@@ -26,8 +26,7 @@
CFWL_WidgetMgr::CFWL_WidgetMgr(IFWL_AdapterNative* pAdapterNative)
: m_dwCapability(0) {
m_pDelegate = new CFWL_WidgetMgrDelegate(this);
- m_pAdapter =
- pAdapterNative->GetWidgetMgr((IFWL_WidgetMgrDelegate*)m_pDelegate);
+ m_pAdapter = pAdapterNative->GetWidgetMgr(m_pDelegate);
FXSYS_assert(m_pAdapter);
CFWL_WidgetMgrItem* pRoot = new CFWL_WidgetMgrItem;
m_mapWidgetItem.SetAt(NULL, pRoot);
diff --git a/xfa/src/fwl/src/core/include/fwl_widgetmgrimp.h b/xfa/src/fwl/src/core/include/fwl_widgetmgrimp.h
index 5cd8510..b5d59b9 100644
--- a/xfa/src/fwl/src/core/include/fwl_widgetmgrimp.h
+++ b/xfa/src/fwl/src/core/include/fwl_widgetmgrimp.h
@@ -49,20 +49,23 @@
#endif
};
-class CFWL_WidgetMgr {
+class CFWL_WidgetMgr : public IFWL_WidgetMgr {
public:
CFWL_WidgetMgr(IFWL_AdapterNative* pAdapterNative);
- virtual ~CFWL_WidgetMgr();
- virtual int32_t CountWidgets(IFWL_Widget* pParent = NULL);
- virtual IFWL_Widget* GetWidget(int32_t nIndex, IFWL_Widget* pParent = NULL);
- virtual IFWL_Widget* GetWidget(IFWL_Widget* pWidget,
- FWL_WGTRELATION eRelation);
- virtual int32_t GetWidgetIndex(IFWL_Widget* pWidget);
- virtual FX_BOOL SetWidgetIndex(IFWL_Widget* pWidget, int32_t nIndex);
- virtual FX_BOOL IsWidget(void* pObj);
- virtual FWL_ERR RepaintWidget(IFWL_Widget* pWidget,
- const CFX_RectF* pRect = NULL);
- virtual FX_DWORD GetCapability() { return m_dwCapability; }
+ ~CFWL_WidgetMgr() override;
+
+ // IFWL_WidgetMgr:
+ int32_t CountWidgets(IFWL_Widget* pParent = NULL) override;
+ IFWL_Widget* GetWidget(int32_t nIndex, IFWL_Widget* pParent = NULL) override;
+ IFWL_Widget* GetWidget(IFWL_Widget* pWidget,
+ FWL_WGTRELATION eRelation) override;
+ int32_t GetWidgetIndex(IFWL_Widget* pWidget) override;
+ FX_BOOL SetWidgetIndex(IFWL_Widget* pWidget, int32_t nIndex) override;
+ FX_BOOL IsWidget(void* pObj) override;
+ FWL_ERR RepaintWidget(IFWL_Widget* pWidget,
+ const CFX_RectF* pRect = NULL) override;
+ FX_DWORD GetCapability() override { return m_dwCapability; }
+
void AddWidget(IFWL_Widget* pWidget);
void InsertWidget(IFWL_Widget* pParent,
IFWL_Widget* pChild,
@@ -130,16 +133,19 @@
CFX_RectF m_rtScreen;
#endif
};
-class CFWL_WidgetMgrDelegate {
+
+class CFWL_WidgetMgrDelegate : public IFWL_WidgetMgrDelegate {
public:
CFWL_WidgetMgrDelegate(CFWL_WidgetMgr* pWidgetMgr);
- virtual ~CFWL_WidgetMgrDelegate() {}
- virtual FWL_ERR OnSetCapability(
- FX_DWORD dwCapability = FWL_WGTMGR_DisableThread);
- virtual int32_t OnProcessMessageToForm(CFWL_Message* pMessage);
- virtual FWL_ERR OnDrawWidget(IFWL_Widget* pWidget,
- CFX_Graphics* pGraphics,
- const CFX_Matrix* pMatrix);
+ ~CFWL_WidgetMgrDelegate() override {}
+
+ // IFWL_WidgetMgrDelegate:
+ FWL_ERR OnSetCapability(
+ FX_DWORD dwCapability = FWL_WGTMGR_DisableThread) override;
+ int32_t OnProcessMessageToForm(CFWL_Message* pMessage) override;
+ FWL_ERR OnDrawWidget(IFWL_Widget* pWidget,
+ CFX_Graphics* pGraphics,
+ const CFX_Matrix* pMatrix) override;
protected:
void DrawChild(IFWL_Widget* pParent,