summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-20 13:43:58 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-20 13:43:58 -0700
commit192bb33e621f7d29a7c940eba8b8a6050e430bf3 (patch)
treee188a863db2155203dd305eb68f601a6d61bebe7
parent5a5180ef4d6d2c169fc168c13912a1043d0e8a7e (diff)
downloadpdfium-192bb33e621f7d29a7c940eba8b8a6050e430bf3.tar.xz
Use std::map, std::unique_ptr in fwl_widgetmgrimp.h
Review-Url: https://codereview.chromium.org/1998303002
-rw-r--r--xfa/fwl/core/fwl_widgetmgrimp.cpp84
-rw-r--r--xfa/fwl/core/fwl_widgetmgrimp.h44
2 files changed, 54 insertions, 74 deletions
diff --git a/xfa/fwl/core/fwl_widgetmgrimp.cpp b/xfa/fwl/core/fwl_widgetmgrimp.cpp
index f4ceb78c48..ff379722e7 100644
--- a/xfa/fwl/core/fwl_widgetmgrimp.cpp
+++ b/xfa/fwl/core/fwl_widgetmgrimp.cpp
@@ -43,29 +43,18 @@ IFWL_WidgetMgr* FWL_GetWidgetMgr() {
return pApp->GetWidgetMgr();
}
-CFWL_WidgetMgr::CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative) : m_dwCapability(0) {
- m_pDelegate = new CFWL_WidgetMgrDelegate(this);
- m_pAdapter = pAdapterNative->GetWidgetMgr(m_pDelegate);
+CFWL_WidgetMgr::CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative)
+ : m_dwCapability(0),
+ m_pDelegate(new CFWL_WidgetMgrDelegate(this)),
+ m_pAdapter(pAdapterNative->GetWidgetMgr(m_pDelegate.get())) {
ASSERT(m_pAdapter);
- CFWL_WidgetMgrItem* pRoot = new CFWL_WidgetMgrItem;
- m_mapWidgetItem.SetAt(NULL, pRoot);
-
+ m_mapWidgetItem[nullptr].reset(new CFWL_WidgetMgrItem);
#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_)
m_rtScreen.Reset();
#endif
}
-CFWL_WidgetMgr::~CFWL_WidgetMgr() {
- FX_POSITION ps = m_mapWidgetItem.GetStartPosition();
- while (ps) {
- void* pWidget;
- CFWL_WidgetMgrItem* pItem;
- m_mapWidgetItem.GetNextAssoc(ps, pWidget, (void*&)pItem);
- delete pItem;
- }
- m_mapWidgetItem.RemoveAll();
- delete m_pDelegate;
-}
+CFWL_WidgetMgr::~CFWL_WidgetMgr() {}
int32_t CFWL_WidgetMgr::CountWidgets(IFWL_Widget* pParent) {
CFWL_WidgetMgrItem* pParentItem = GetWidgetMgrItem(pParent);
@@ -248,9 +237,8 @@ void CFWL_WidgetMgr::AddWidget(IFWL_Widget* pWidget) {
CFWL_WidgetMgrItem* pParentItem = GetWidgetMgrItem(NULL);
CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pWidget);
if (!pItem) {
- pItem = new CFWL_WidgetMgrItem;
- pItem->pWidget = pWidget;
- m_mapWidgetItem.SetAt(pWidget, pItem);
+ pItem = new CFWL_WidgetMgrItem(pWidget);
+ m_mapWidgetItem[pWidget].reset(pItem);
}
if (pItem->pParent && pItem->pParent != pParentItem) {
if (pItem->pPrevious) {
@@ -271,18 +259,15 @@ void CFWL_WidgetMgr::InsertWidget(IFWL_Widget* pParent,
int32_t nIndex) {
CFWL_WidgetMgrItem* pParentItem = GetWidgetMgrItem(pParent);
if (!pParentItem) {
- pParentItem = new CFWL_WidgetMgrItem;
- pParentItem->pWidget = pParent;
- m_mapWidgetItem.SetAt(pParent, pParentItem);
- CFWL_WidgetMgrItem* pRoot = GetWidgetMgrItem(NULL);
- pParentItem->pParent = pRoot;
+ pParentItem = new CFWL_WidgetMgrItem(pParent);
+ m_mapWidgetItem[pParent].reset(pParentItem);
+ pParentItem->pParent = GetWidgetMgrItem(nullptr);
SetWidgetIndex(pParent, -1);
}
CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pChild);
if (!pItem) {
- pItem = new CFWL_WidgetMgrItem;
- pItem->pWidget = pChild;
- m_mapWidgetItem.SetAt(pChild, pItem);
+ pItem = new CFWL_WidgetMgrItem(pChild);
+ m_mapWidgetItem[pChild].reset(pItem);
}
if (pItem->pParent && pItem->pParent != pParentItem) {
if (pItem->pPrevious) {
@@ -318,24 +303,20 @@ void CFWL_WidgetMgr::RemoveWidget(IFWL_Widget* pWidget) {
RemoveWidget(pChild->pWidget);
pChild = pNext;
}
- m_mapWidgetItem.RemoveKey(pWidget);
- delete pItem;
+ m_mapWidgetItem.erase(pWidget);
}
void CFWL_WidgetMgr::SetOwner(IFWL_Widget* pOwner, IFWL_Widget* pOwned) {
CFWL_WidgetMgrItem* pParentItem = GetWidgetMgrItem(pOwner);
if (!pParentItem) {
- pParentItem = new CFWL_WidgetMgrItem;
- pParentItem->pWidget = pOwner;
- m_mapWidgetItem.SetAt(pOwner, pParentItem);
- CFWL_WidgetMgrItem* pRoot = GetWidgetMgrItem(NULL);
- pParentItem->pParent = pRoot;
+ pParentItem = new CFWL_WidgetMgrItem(pOwner);
+ m_mapWidgetItem[pOwner].reset(pParentItem);
+ pParentItem->pParent = GetWidgetMgrItem(nullptr);
SetWidgetIndex(pOwner, -1);
}
CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pOwned);
if (!pItem) {
- pItem = new CFWL_WidgetMgrItem;
- pItem->pWidget = pOwned;
- m_mapWidgetItem.SetAt(pOwned, pItem);
+ pItem = new CFWL_WidgetMgrItem(pOwned);
+ m_mapWidgetItem[pOwned].reset(pItem);
}
pItem->pOwner = pParentItem;
}
@@ -383,8 +364,7 @@ FWL_Error CFWL_WidgetMgr::SetWidgetRect_Native(IFWL_Widget* pWidget,
CFX_DIBitmap* pBitmap = pDevice->GetBitmap();
if (pBitmap->GetWidth() - rect.width > 1 ||
pBitmap->GetHeight() - rect.height > 1) {
- delete pItem->pOffscreen;
- pItem->pOffscreen = NULL;
+ pItem->pOffscreen.reset();
}
}
}
@@ -429,12 +409,8 @@ IFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(IFWL_Widget* parent,
void CFWL_WidgetMgr::NotifySizeChanged(IFWL_Widget* pForm,
FX_FLOAT fx,
FX_FLOAT fy) {
- if (!FWL_UseOffscreen(pForm))
- return;
-
- CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pForm);
- delete pItem->pOffscreen;
- pItem->pOffscreen = nullptr;
+ if (FWL_UseOffscreen(pForm))
+ GetWidgetMgrItem(pForm)->pOffscreen.reset();
}
IFWL_Widget* CFWL_WidgetMgr::nextTab(IFWL_Widget* parent,
@@ -541,8 +517,12 @@ void CFWL_WidgetMgr::ResetRedrawCounts(IFWL_Widget* pWidget) {
CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pWidget);
pItem->iRedrawCounter = 0;
}
-CFWL_WidgetMgrItem* CFWL_WidgetMgr::GetWidgetMgrItem(IFWL_Widget* pWidget) {
- return static_cast<CFWL_WidgetMgrItem*>(m_mapWidgetItem.GetValueAt(pWidget));
+CFWL_WidgetMgrItem* CFWL_WidgetMgr::GetWidgetMgrItem(
+ IFWL_Widget* pWidget) const {
+ auto it = m_mapWidgetItem.find(pWidget);
+ return it != m_mapWidgetItem.end()
+ ? static_cast<CFWL_WidgetMgrItem*>(it->second.get())
+ : nullptr;
}
int32_t CFWL_WidgetMgr::TravelWidgetMgr(CFWL_WidgetMgrItem* pParent,
int32_t* pIndex,
@@ -756,7 +736,7 @@ CFX_Graphics* CFWL_WidgetMgrDelegate::DrawWidgetBefore(
CFWL_WidgetMgrItem* pItem = m_pWidgetMgr->GetWidgetMgrItem(pWidget);
if (!pItem->pOffscreen) {
- pItem->pOffscreen = new CFX_Graphics;
+ pItem->pOffscreen.reset(new CFX_Graphics);
CFX_RectF rect;
pWidget->GetWidgetRect(rect);
pItem->pOffscreen->Create((int32_t)rect.width, (int32_t)rect.height,
@@ -765,7 +745,7 @@ CFX_Graphics* CFWL_WidgetMgrDelegate::DrawWidgetBefore(
CFX_RectF rect;
pGraphics->GetClipRect(rect);
pItem->pOffscreen->SetClipRect(rect);
- return pItem->pOffscreen;
+ return pItem->pOffscreen.get();
}
void CFWL_WidgetMgrDelegate::DrawWidgetAfter(IFWL_Widget* pWidget,
@@ -774,8 +754,8 @@ void CFWL_WidgetMgrDelegate::DrawWidgetAfter(IFWL_Widget* pWidget,
const CFX_Matrix* pMatrix) {
if (FWL_UseOffscreen(pWidget)) {
CFWL_WidgetMgrItem* pItem = m_pWidgetMgr->GetWidgetMgrItem(pWidget);
- pGraphics->Transfer(pItem->pOffscreen, rtClip.left, rtClip.top, rtClip,
- pMatrix);
+ pGraphics->Transfer(pItem->pOffscreen.get(), rtClip.left, rtClip.top,
+ rtClip, pMatrix);
#ifdef _WIN32
pItem->pOffscreen->ClearClip();
#endif
diff --git a/xfa/fwl/core/fwl_widgetmgrimp.h b/xfa/fwl/core/fwl_widgetmgrimp.h
index fe17613364..6e4fffeca1 100644
--- a/xfa/fwl/core/fwl_widgetmgrimp.h
+++ b/xfa/fwl/core/fwl_widgetmgrimp.h
@@ -7,6 +7,9 @@
#ifndef XFA_FWL_CORE_FWL_WIDGETMGRIMP_H_
#define XFA_FWL_CORE_FWL_WIDGETMGRIMP_H_
+#include <map>
+#include <memory>
+
#include "core/fxcrt/include/fx_system.h"
#include "xfa/fwl/core/fwl_error.h"
#include "xfa/fwl/core/ifwl_widgetmgr.h"
@@ -25,14 +28,14 @@ class IFWL_Widget;
class CFWL_WidgetMgrItem {
public:
- CFWL_WidgetMgrItem()
- : pParent(NULL),
- pOwner(NULL),
- pChild(NULL),
- pPrevious(NULL),
- pNext(NULL),
- pWidget(NULL),
- pOffscreen(NULL),
+ CFWL_WidgetMgrItem() : CFWL_WidgetMgrItem(nullptr) {}
+ explicit CFWL_WidgetMgrItem(IFWL_Widget* widget)
+ : pParent(nullptr),
+ pOwner(nullptr),
+ pChild(nullptr),
+ pPrevious(nullptr),
+ pNext(nullptr),
+ pWidget(widget),
iRedrawCounter(0)
#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_)
,
@@ -40,19 +43,15 @@ class CFWL_WidgetMgrItem {
#endif
{
}
- ~CFWL_WidgetMgrItem() {
- if (pOffscreen) {
- delete pOffscreen;
- pOffscreen = NULL;
- }
- }
+ ~CFWL_WidgetMgrItem() {}
+
CFWL_WidgetMgrItem* pParent;
CFWL_WidgetMgrItem* pOwner;
CFWL_WidgetMgrItem* pChild;
CFWL_WidgetMgrItem* pPrevious;
CFWL_WidgetMgrItem* pNext;
- IFWL_Widget* pWidget;
- CFX_Graphics* pOffscreen;
+ IFWL_Widget* const pWidget;
+ std::unique_ptr<CFX_Graphics> pOffscreen;
int32_t iRedrawCounter;
#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_)
FX_BOOL bOutsideChanged;
@@ -96,8 +95,8 @@ class CFWL_WidgetMgr : public IFWL_WidgetMgr {
void AddRedrawCounts(IFWL_Widget* pWidget);
void ResetRedrawCounts(IFWL_Widget* pWidget);
CXFA_FWLAdapterWidgetMgr* GetAdapterWidgetMgr() const { return m_pAdapter; }
- CFWL_WidgetMgrDelegate* GetDelegate() const { return m_pDelegate; }
- CFWL_WidgetMgrItem* GetWidgetMgrItem(IFWL_Widget* pWidget);
+ CFWL_WidgetMgrDelegate* GetDelegate() const { return m_pDelegate.get(); }
+ CFWL_WidgetMgrItem* GetWidgetMgrItem(IFWL_Widget* pWidget) const;
bool IsThreadEnabled();
bool IsFormDisabled();
FX_BOOL GetAdapterPopupPos(IFWL_Widget* pWidget,
@@ -112,14 +111,15 @@ class CFWL_WidgetMgr : public IFWL_WidgetMgr {
CFWL_WidgetMgrItem* pItem,
IFWL_Widget** pWidget = NULL);
FX_BOOL IsAbleNative(IFWL_Widget* pWidget);
- CFX_MapPtrToPtr m_mapWidgetItem;
- CXFA_FWLAdapterWidgetMgr* m_pAdapter;
- CFWL_WidgetMgrDelegate* m_pDelegate;
- friend class CFWL_WidgetMgrDelegate;
+
uint32_t m_dwCapability;
+ std::unique_ptr<CFWL_WidgetMgrDelegate> m_pDelegate;
+ std::map<IFWL_Widget*, std::unique_ptr<CFWL_WidgetMgrItem>> m_mapWidgetItem;
+ CXFA_FWLAdapterWidgetMgr* const m_pAdapter;
#if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_)
CFX_RectF m_rtScreen;
#endif
+ friend class CFWL_WidgetMgrDelegate;
};
class CFWL_WidgetMgrDelegate {