From 4e903136cf0f02578c0e47c6738b633c96814b62 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Tue, 18 Oct 2016 16:48:16 -0700 Subject: Merge IFWL_App and FWL_AppImp together The IFWL_App class just acts as a proxy to the FWL_AppImp code. This Cl removes FWL_AppImp and merges the code back up to IFWL_App, simplifying the object hierarchy. Review-Url: https://codereview.chromium.org/2430563003 --- xfa/fwl/basewidget/fwl_comboboximp.cpp | 1 - xfa/fwl/basewidget/fwl_editimp.cpp | 1 - xfa/fwl/core/cfwl_widgetmgr.cpp | 1 - xfa/fwl/core/fwl_appimp.cpp | 117 --------------------------------- xfa/fwl/core/fwl_appimp.h | 44 ------------- xfa/fwl/core/fwl_formimp.cpp | 1 - xfa/fwl/core/fwl_noteimp.cpp | 1 - xfa/fwl/core/fwl_timerimp.cpp | 1 - xfa/fwl/core/fwl_widgetimp.cpp | 9 ++- xfa/fwl/core/fwl_widgetimp.h | 4 +- xfa/fwl/core/ifwl_app.cpp | 50 ++++++++++++++ xfa/fwl/core/ifwl_app.h | 38 ++--------- xfa/fxfa/app/xfa_ffapp.cpp | 8 +-- xfa/fxfa/app/xfa_fftext.cpp | 1 + xfa/fxfa/app/xfa_ffwidget.cpp | 1 + 15 files changed, 65 insertions(+), 213 deletions(-) delete mode 100644 xfa/fwl/core/fwl_appimp.cpp delete mode 100644 xfa/fwl/core/fwl_appimp.h create mode 100644 xfa/fwl/core/ifwl_app.cpp (limited to 'xfa') diff --git a/xfa/fwl/basewidget/fwl_comboboximp.cpp b/xfa/fwl/basewidget/fwl_comboboximp.cpp index 17c5bf80d4..e586055c3b 100644 --- a/xfa/fwl/basewidget/fwl_comboboximp.cpp +++ b/xfa/fwl/basewidget/fwl_comboboximp.cpp @@ -17,7 +17,6 @@ #include "xfa/fwl/core/cfwl_themepart.h" #include "xfa/fwl/core/cfwl_themetext.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/fwl_appimp.h" #include "xfa/fwl/core/fwl_formimp.h" #include "xfa/fwl/core/fwl_noteimp.h" #include "xfa/fwl/core/fwl_widgetimp.h" diff --git a/xfa/fwl/basewidget/fwl_editimp.cpp b/xfa/fwl/basewidget/fwl_editimp.cpp index 8377daf628..0f939f1145 100644 --- a/xfa/fwl/basewidget/fwl_editimp.cpp +++ b/xfa/fwl/basewidget/fwl_editimp.cpp @@ -24,7 +24,6 @@ #include "xfa/fwl/core/cfwl_themebackground.h" #include "xfa/fwl/core/cfwl_themepart.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/fwl_appimp.h" #include "xfa/fwl/core/fwl_widgetimp.h" #include "xfa/fwl/core/ifwl_app.h" #include "xfa/fwl/core/ifwl_themeprovider.h" diff --git a/xfa/fwl/core/cfwl_widgetmgr.cpp b/xfa/fwl/core/cfwl_widgetmgr.cpp index db1035005f..30571c9aed 100644 --- a/xfa/fwl/core/cfwl_widgetmgr.cpp +++ b/xfa/fwl/core/cfwl_widgetmgr.cpp @@ -7,7 +7,6 @@ #include "xfa/fwl/core/cfwl_widgetmgr.h" #include "xfa/fwl/core/cfwl_message.h" -#include "xfa/fwl/core/fwl_appimp.h" #include "xfa/fwl/core/fwl_noteimp.h" #include "xfa/fwl/core/fwl_widgetimp.h" #include "xfa/fwl/core/ifwl_app.h" diff --git a/xfa/fwl/core/fwl_appimp.cpp b/xfa/fwl/core/fwl_appimp.cpp deleted file mode 100644 index 2df579ca38..0000000000 --- a/xfa/fwl/core/fwl_appimp.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/fwl_appimp.h" - -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/fwl_noteimp.h" -#include "xfa/fwl/core/ifwl_app.h" -#include "xfa/fwl/core/ifwl_widget.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" - -IFWL_App* IFWL_App::Create(CXFA_FFApp* pAdapter) { - IFWL_App* pApp = new IFWL_App; - pApp->SetImpl(new CFWL_AppImp(pApp, pAdapter)); - return pApp; -} - -IFWL_App::IFWL_App() {} - -IFWL_App::~IFWL_App() {} - -void IFWL_App::Release() {} - -FWL_Error IFWL_App::Initialize() { - return static_cast(GetImpl())->Initialize(); -} - -FWL_Error IFWL_App::Finalize() { - return static_cast(GetImpl())->Finalize(); -} - -CXFA_FFApp* IFWL_App::GetAdapterNative() { - return static_cast(GetImpl())->GetAdapterNative(); -} - -CFWL_WidgetMgr* IFWL_App::GetWidgetMgr() { - return static_cast(GetImpl())->GetWidgetMgr(); -} - -IFWL_ThemeProvider* IFWL_App::GetThemeProvider() { - return static_cast(GetImpl())->GetThemeProvider(); -} - -void IFWL_App::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { - static_cast(GetImpl())->SetThemeProvider(pThemeProvider); -} - -void IFWL_App::Exit(int32_t iExitCode) { - static_cast(GetImpl())->Exit(iExitCode); -} - -CFWL_NoteDriver* IFWL_App::GetNoteDriver() const { - return static_cast(GetImpl())->GetNoteDriver(); -} - -CFWL_AppImp::CFWL_AppImp(IFWL_App* pIface, CXFA_FFApp* pAdapter) - : m_pAdapterNative(pAdapter), - m_pThemeProvider(nullptr), - m_pNoteDriver(new CFWL_NoteDriver), - m_pIface(pIface) {} - -CFWL_AppImp::~CFWL_AppImp() { - CFWL_ToolTipContainer::DeleteInstance(); -} - -FWL_Error CFWL_AppImp::Initialize() { - if (!m_pWidgetMgr) { - m_pWidgetMgr.reset(new CFWL_WidgetMgr(m_pAdapterNative)); - } - return FWL_Error::Succeeded; -} -FWL_Error CFWL_AppImp::Finalize() { - m_pWidgetMgr.reset(); - return FWL_Error::Succeeded; -} -CXFA_FFApp* CFWL_AppImp::GetAdapterNative() const { - return m_pAdapterNative; -} -CXFA_FWLAdapterWidgetMgr* FWL_GetAdapterWidgetMgr() { - return CFWL_WidgetMgr::GetInstance()->GetAdapterWidgetMgr(); -} -CFWL_WidgetMgr* CFWL_AppImp::GetWidgetMgr() const { - return m_pWidgetMgr.get(); -} - -void CFWL_AppImp::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { - m_pThemeProvider = pThemeProvider; -} - -void CFWL_AppImp::Exit(int32_t iExitCode) { - while (m_pNoteDriver->PopNoteLoop()) { - continue; - } -} - -IFWL_ThemeProvider* CFWL_AppImp::GetThemeProvider() const { - return m_pThemeProvider; -} - -CXFA_FFApp* FWL_GetAdapterNative() { - IFWL_App* pApp = FWL_GetApp(); - if (!pApp) - return nullptr; - return pApp->GetAdapterNative(); -} - -static IFWL_App* g_theApp = nullptr; -IFWL_App* FWL_GetApp() { - return g_theApp; -} - -void FWL_SetApp(IFWL_App* pApp) { - g_theApp = pApp; -} diff --git a/xfa/fwl/core/fwl_appimp.h b/xfa/fwl/core/fwl_appimp.h deleted file mode 100644 index f3377048fc..0000000000 --- a/xfa/fwl/core/fwl_appimp.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_FWL_APPIMP_H_ -#define XFA_FWL_CORE_FWL_APPIMP_H_ - -#include - -#include "xfa/fwl/core/fwl_noteimp.h" - -class CFWL_WidgetMgr; -class CXFA_FFApp; -class IFWL_App; -class IFWL_NoteThread; -class IFWL_ThemeProvider; - -class CFWL_AppImp { - public: - CFWL_AppImp(IFWL_App* pIface, CXFA_FFApp* pAdapter); - ~CFWL_AppImp(); - - IFWL_App* GetInterface() const { return m_pIface; } - CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver.get(); } - - FWL_Error Initialize(); - FWL_Error Finalize(); - CXFA_FFApp* GetAdapterNative() const; - CFWL_WidgetMgr* GetWidgetMgr() const; - IFWL_ThemeProvider* GetThemeProvider() const; - void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); - void Exit(int32_t iExitCode); - - private: - CXFA_FFApp* const m_pAdapterNative; - std::unique_ptr m_pWidgetMgr; - IFWL_ThemeProvider* m_pThemeProvider; - std::unique_ptr m_pNoteDriver; - IFWL_App* const m_pIface; -}; - -#endif // XFA_FWL_CORE_FWL_APPIMP_H_ diff --git a/xfa/fwl/core/fwl_formimp.cpp b/xfa/fwl/core/fwl_formimp.cpp index 4dcedf67f9..747e5e83dc 100644 --- a/xfa/fwl/core/fwl_formimp.cpp +++ b/xfa/fwl/core/fwl_formimp.cpp @@ -13,7 +13,6 @@ #include "xfa/fwl/core/cfwl_themepart.h" #include "xfa/fwl/core/cfwl_themetext.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/fwl_appimp.h" #include "xfa/fwl/core/fwl_noteimp.h" #include "xfa/fwl/core/fwl_widgetimp.h" #include "xfa/fwl/core/ifwl_app.h" diff --git a/xfa/fwl/core/fwl_noteimp.cpp b/xfa/fwl/core/fwl_noteimp.cpp index 3173f3e4db..848cb772ba 100644 --- a/xfa/fwl/core/fwl_noteimp.cpp +++ b/xfa/fwl/core/fwl_noteimp.cpp @@ -12,7 +12,6 @@ #include "xfa/fwl/basewidget/ifwl_tooltip.h" #include "xfa/fwl/core/cfwl_message.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/fwl_appimp.h" #include "xfa/fwl/core/fwl_formimp.h" #include "xfa/fwl/core/fwl_widgetimp.h" #include "xfa/fwl/core/ifwl_app.h" diff --git a/xfa/fwl/core/fwl_timerimp.cpp b/xfa/fwl/core/fwl_timerimp.cpp index a46469391d..941113e7ca 100644 --- a/xfa/fwl/core/fwl_timerimp.cpp +++ b/xfa/fwl/core/fwl_timerimp.cpp @@ -4,7 +4,6 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fwl/core/fwl_appimp.h" #include "xfa/fwl/core/ifwl_adaptertimermgr.h" #include "xfa/fwl/core/ifwl_app.h" #include "xfa/fwl/core/ifwl_timer.h" diff --git a/xfa/fwl/core/fwl_widgetimp.cpp b/xfa/fwl/core/fwl_widgetimp.cpp index 6e8ec09243..b59fd27713 100644 --- a/xfa/fwl/core/fwl_widgetimp.cpp +++ b/xfa/fwl/core/fwl_widgetimp.cpp @@ -15,7 +15,6 @@ #include "xfa/fwl/core/cfwl_themepart.h" #include "xfa/fwl/core/cfwl_themetext.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/fwl_appimp.h" #include "xfa/fwl/core/fwl_noteimp.h" #include "xfa/fwl/core/ifwl_app.h" #include "xfa/fwl/core/ifwl_form.h" @@ -179,7 +178,7 @@ FWL_Error CFWL_WidgetImp::Initialize() { if (!pAdapter) return FWL_Error::Indefinite; - SetOwnerApp(static_cast(FWL_GetApp()->GetImpl())); + SetOwnerApp(FWL_GetApp()); IFWL_Widget* pParent = m_pProperties->m_pParent; m_pWidgetMgr->InsertWidget(pParent, m_pInterface); @@ -492,9 +491,9 @@ IFWL_WidgetDelegate* CFWL_WidgetImp::SetDelegate( return pOldDelegate; } IFWL_App* CFWL_WidgetImp::GetOwnerApp() const { - return static_cast(m_pOwnerApp->GetInterface()); + return m_pOwnerApp; } -FWL_Error CFWL_WidgetImp::SetOwnerApp(CFWL_AppImp* pOwnerApp) { +FWL_Error CFWL_WidgetImp::SetOwnerApp(IFWL_App* pOwnerApp) { m_pOwnerApp = pOwnerApp; return FWL_Error::Succeeded; } @@ -642,7 +641,7 @@ IFWL_ThemeProvider* CFWL_WidgetImp::GetAvailableTheme() { return pRet; } } while (pUp); - return FWL_GetApp()->GetThemeProvider(); + return nullptr; } CFWL_WidgetImp* CFWL_WidgetImp::GetRootOuter() { IFWL_Widget* pRet = m_pOuter; diff --git a/xfa/fwl/core/fwl_widgetimp.h b/xfa/fwl/core/fwl_widgetimp.h index 57970a87eb..dfbfc5bf4b 100644 --- a/xfa/fwl/core/fwl_widgetimp.h +++ b/xfa/fwl/core/fwl_widgetimp.h @@ -72,7 +72,7 @@ class CFWL_WidgetImp { virtual IFWL_WidgetDelegate* SetDelegate(IFWL_WidgetDelegate* pDelegate); virtual IFWL_App* GetOwnerApp() const; - FWL_Error SetOwnerApp(CFWL_AppImp* pOwnerApp); + FWL_Error SetOwnerApp(IFWL_App* pOwnerApp); IFWL_Widget* GetInterface() const; void SetInterface(IFWL_Widget* pInterface); CFX_SizeF GetOffsetFromParent(IFWL_Widget* pParent); @@ -157,7 +157,7 @@ class CFWL_WidgetImp { FX_BOOL IsParent(IFWL_Widget* pParent); CFWL_WidgetMgr* const m_pWidgetMgr; - CFWL_AppImp* m_pOwnerApp; + IFWL_App* m_pOwnerApp; std::unique_ptr m_pProperties; IFWL_WidgetDelegate* m_pDelegate; IFWL_WidgetDelegate* m_pCurDelegate; diff --git a/xfa/fwl/core/ifwl_app.cpp b/xfa/fwl/core/ifwl_app.cpp new file mode 100644 index 0000000000..a47a76e4c0 --- /dev/null +++ b/xfa/fwl/core/ifwl_app.cpp @@ -0,0 +1,50 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/ifwl_app.h" + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/core/cfwl_widgetmgr.h" +#include "xfa/fwl/core/fwl_noteimp.h" +#include "xfa/fwl/core/ifwl_widget.h" +#include "xfa/fxfa/app/xfa_fwladapter.h" + +CXFA_FWLAdapterWidgetMgr* FWL_GetAdapterWidgetMgr() { + return CFWL_WidgetMgr::GetInstance()->GetAdapterWidgetMgr(); +} + +CXFA_FFApp* FWL_GetAdapterNative() { + IFWL_App* pApp = FWL_GetApp(); + if (!pApp) + return nullptr; + return pApp->GetAdapterNative(); +} + +static IFWL_App* g_theApp = nullptr; +IFWL_App* FWL_GetApp() { + return g_theApp; +} + +void FWL_SetApp(IFWL_App* pApp) { + g_theApp = pApp; +} + +IFWL_App::IFWL_App(CXFA_FFApp* pAdapter) + : m_pAdapterNative(pAdapter), + m_pWidgetMgr(pdfium::MakeUnique(pAdapter)), + m_pNoteDriver(pdfium::MakeUnique()) {} + +IFWL_App::~IFWL_App() { + CFWL_ToolTipContainer::DeleteInstance(); +} + +CXFA_FFApp* IFWL_App::GetAdapterNative() { + return m_pAdapterNative; +} + +CFWL_WidgetMgr* IFWL_App::GetWidgetMgr() { + return m_pWidgetMgr.get(); +} diff --git a/xfa/fwl/core/ifwl_app.h b/xfa/fwl/core/ifwl_app.h index c030e26b2e..35cbbe2ff9 100644 --- a/xfa/fwl/core/ifwl_app.h +++ b/xfa/fwl/core/ifwl_app.h @@ -7,25 +7,14 @@ #ifndef XFA_FWL_CORE_IFWL_APP_H_ #define XFA_FWL_CORE_IFWL_APP_H_ -// The FWL app code contains three parallel classes, which reference each -// other via pointers as follows: -// -// m_pIface m_pImpl -// CXFA_FFApp ------------> IFWL_App -----------> CFWL_AppImp -// <----------- -// m_pIface - #include #include "core/fxcrt/fx_string.h" -#include "xfa/fwl/core/fwl_appimp.h" -#include "xfa/fwl/core/fwl_error.h" class CFWL_NoteDriver; class CFWL_WidgetMgr; class CXFA_FFApp; class CXFA_FWLAdapterWidgetMgr; -class IFWL_ThemeProvider; class IFWL_Widget; enum FWL_KeyFlag { @@ -40,32 +29,17 @@ enum FWL_KeyFlag { class IFWL_App { public: - static IFWL_App* Create(CXFA_FFApp* pAdapter); - - virtual ~IFWL_App(); + explicit IFWL_App(CXFA_FFApp* pAdapter); + ~IFWL_App(); - FWL_Error Initialize(); - FWL_Error Finalize(); CXFA_FFApp* GetAdapterNative(); CFWL_WidgetMgr* GetWidgetMgr(); - IFWL_ThemeProvider* GetThemeProvider(); - void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); - void Exit(int32_t iExitCode); - - // These call into polymorphic methods in the impl; no need to override. - void Release(); - - CFWL_AppImp* GetImpl() const { return m_pImpl.get(); } - - // Takes ownership of |pImpl|. - void SetImpl(CFWL_AppImp* pImpl) { m_pImpl.reset(pImpl); } - - CFWL_NoteDriver* GetNoteDriver() const; + CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver.get(); } private: - IFWL_App(); - - std::unique_ptr m_pImpl; + CXFA_FFApp* const m_pAdapterNative; + std::unique_ptr m_pWidgetMgr; + std::unique_ptr m_pNoteDriver; }; IFWL_App* FWL_GetApp(); diff --git a/xfa/fxfa/app/xfa_ffapp.cpp b/xfa/fxfa/app/xfa_ffapp.cpp index 6bedcd41a0..642ee56e9a 100644 --- a/xfa/fxfa/app/xfa_ffapp.cpp +++ b/xfa/fxfa/app/xfa_ffapp.cpp @@ -74,18 +74,12 @@ void CXFA_FileRead::Release() { CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) : m_pProvider(pProvider), m_pWidgetMgrDelegate(nullptr), - m_pFWLApp(IFWL_App::Create(this)) { + m_pFWLApp(pdfium::MakeUnique(this)) { FWL_SetApp(m_pFWLApp.get()); - m_pFWLApp->Initialize(); CXFA_TimeZoneProvider::Create(); } CXFA_FFApp::~CXFA_FFApp() { - if (m_pFWLApp) { - m_pFWLApp->Finalize(); - m_pFWLApp->Release(); - } - CXFA_TimeZoneProvider::Destroy(); } diff --git a/xfa/fxfa/app/xfa_fftext.cpp b/xfa/fxfa/app/xfa_fftext.cpp index 9fa6bafdf4..b8ad6716d0 100644 --- a/xfa/fxfa/app/xfa_fftext.cpp +++ b/xfa/fxfa/app/xfa_fftext.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/app/xfa_fftext.h" #include "xfa/fwl/core/fwl_widgetdef.h" +#include "xfa/fwl/core/fwl_widgethit.h" #include "xfa/fxfa/app/xfa_ffdraw.h" #include "xfa/fxfa/app/xfa_textlayout.h" #include "xfa/fxfa/xfa_ffapp.h" diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp index cac9ccf26d..0e84ad6be5 100644 --- a/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/xfa/fxfa/app/xfa_ffwidget.cpp @@ -15,6 +15,7 @@ #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" +#include "xfa/fwl/core/fwl_widgethit.h" #include "xfa/fxfa/app/xfa_textlayout.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/fxfa_widget.h" -- cgit v1.2.3