| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/include/fsdk_annothandler.h" | 7 #include "fpdfsdk/include/fsdk_annothandler.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); | 33 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); |
| 34 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); | 34 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); |
| 35 RegisterAnnotHandler(pHandler); | 35 RegisterAnnotHandler(pHandler); |
| 36 #ifdef PDF_ENABLE_XFA | 36 #ifdef PDF_ENABLE_XFA |
| 37 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler = | 37 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler = |
| 38 new CPDFSDK_XFAAnnotHandler(m_pApp); | 38 new CPDFSDK_XFAAnnotHandler(m_pApp); |
| 39 RegisterAnnotHandler(pXFAAnnotHandler); | 39 RegisterAnnotHandler(pXFAAnnotHandler); |
| 40 #endif // PDF_ENABLE_XFA | 40 #endif // PDF_ENABLE_XFA |
| 41 } | 41 } |
| 42 | 42 |
| 43 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { | 43 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {} |
| 44 for (int i = 0; i < m_Handlers.GetSize(); i++) { | |
| 45 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); | |
| 46 delete pHandler; | |
| 47 } | |
| 48 m_Handlers.RemoveAll(); | |
| 49 m_mapType2Handler.clear(); | |
| 50 } | |
| 51 | 44 |
| 52 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( | 45 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( |
| 53 IPDFSDK_AnnotHandler* pAnnotHandler) { | 46 IPDFSDK_AnnotHandler* pAnnotHandler) { |
| 54 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType())); | 47 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType())); |
| 55 | 48 |
| 56 m_Handlers.Add(pAnnotHandler); | 49 m_mapType2Handler[pAnnotHandler->GetType()].reset(pAnnotHandler); |
| 57 m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler; | |
| 58 } | 50 } |
| 59 | 51 |
| 60 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( | 52 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( |
| 61 IPDFSDK_AnnotHandler* pAnnotHandler) { | 53 IPDFSDK_AnnotHandler* pAnnotHandler) { |
| 62 m_mapType2Handler.erase(pAnnotHandler->GetType()); | 54 m_mapType2Handler.erase(pAnnotHandler->GetType()); |
| 63 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { | |
| 64 if (m_Handlers.GetAt(i) == pAnnotHandler) { | |
| 65 m_Handlers.RemoveAt(i); | |
| 66 break; | |
| 67 } | |
| 68 } | |
| 69 } | 55 } |
| 70 | 56 |
| 71 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, | 57 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, |
| 72 CPDFSDK_PageView* pPageView) { | 58 CPDFSDK_PageView* pPageView) { |
| 73 ASSERT(pPageView); | 59 ASSERT(pPageView); |
| 74 | 60 |
| 75 if (IPDFSDK_AnnotHandler* pAnnotHandler = | 61 if (IPDFSDK_AnnotHandler* pAnnotHandler = |
| 76 GetAnnotHandler(pAnnot->GetSubType())) { | 62 GetAnnotHandler(pAnnot->GetSubType())) { |
| 77 return pAnnotHandler->NewAnnot(pAnnot, pPageView); | 63 return pAnnotHandler->NewAnnot(pAnnot, pPageView); |
| 78 } | 64 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 #ifdef PDF_ENABLE_XFA | 118 #ifdef PDF_ENABLE_XFA |
| 133 if (pAnnot->GetXFAWidget()) | 119 if (pAnnot->GetXFAWidget()) |
| 134 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); | 120 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); |
| 135 #endif // PDF_ENABLE_XFA | 121 #endif // PDF_ENABLE_XFA |
| 136 return nullptr; | 122 return nullptr; |
| 137 } | 123 } |
| 138 | 124 |
| 139 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( | 125 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
| 140 const CFX_ByteString& sType) const { | 126 const CFX_ByteString& sType) const { |
| 141 auto it = m_mapType2Handler.find(sType); | 127 auto it = m_mapType2Handler.find(sType); |
| 142 return it != m_mapType2Handler.end() ? it->second : nullptr; | 128 return it != m_mapType2Handler.end() ? it->second.get() : nullptr; |
| 143 } | 129 } |
| 144 | 130 |
| 145 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, | 131 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, |
| 146 CPDFSDK_Annot* pAnnot, | 132 CPDFSDK_Annot* pAnnot, |
| 147 CFX_RenderDevice* pDevice, | 133 CFX_RenderDevice* pDevice, |
| 148 CFX_Matrix* pUser2Device, | 134 CFX_Matrix* pUser2Device, |
| 149 uint32_t dwFlags) { | 135 uint32_t dwFlags) { |
| 150 ASSERT(pAnnot); | 136 ASSERT(pAnnot); |
| 151 | 137 |
| 152 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | 138 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| (...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 | 1156 |
| 1171 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() { | 1157 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() { |
| 1172 if (m_pos < m_iteratorAnnotList.size()) | 1158 if (m_pos < m_iteratorAnnotList.size()) |
| 1173 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos]; | 1159 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos]; |
| 1174 return nullptr; | 1160 return nullptr; |
| 1175 } | 1161 } |
| 1176 | 1162 |
| 1177 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() { | 1163 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() { |
| 1178 return m_bReverse ? PrevAnnot() : NextAnnot(); | 1164 return m_bReverse ? PrevAnnot() : NextAnnot(); |
| 1179 } | 1165 } |
| OLD | NEW |