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/fpdfxfa/cxfa_fwladaptertimermgr.h" | 7 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" |
8 | 8 |
| 9 #include <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 12 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
12 #include "fpdfsdk/fsdk_define.h" | 13 #include "fpdfsdk/fsdk_define.h" |
13 | 14 |
| 15 namespace { |
| 16 |
| 17 class CFWL_FWLAdapterTimerInfo : public CFWL_TimerInfo { |
| 18 public: |
| 19 CFWL_FWLAdapterTimerInfo(IFWL_AdapterTimerMgr* mgr, |
| 20 int32_t event, |
| 21 CFWL_Timer* timer) |
| 22 : CFWL_TimerInfo(mgr), idEvent(event), pTimer(timer) {} |
| 23 |
| 24 int32_t idEvent; |
| 25 CFWL_Timer* pTimer; |
| 26 }; |
| 27 |
| 28 } // namespace |
| 29 |
14 std::vector<CFWL_TimerInfo*>* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; | 30 std::vector<CFWL_TimerInfo*>* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; |
15 | 31 |
16 void CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer, | 32 void CXFA_FWLAdapterTimerMgr::Start(CFWL_Timer* pTimer, |
17 uint32_t dwElapse, | 33 uint32_t dwElapse, |
18 bool bImmediately, | 34 bool bImmediately, |
19 IFWL_TimerInfo** pTimerInfo) { | 35 CFWL_TimerInfo** pTimerInfo) { |
20 if (!m_pFormFillEnv) | 36 if (!m_pFormFillEnv) |
21 return; | 37 return; |
22 | 38 |
23 int32_t id_event = m_pFormFillEnv->SetTimer(dwElapse, TimerProc); | 39 int32_t id_event = m_pFormFillEnv->SetTimer(dwElapse, TimerProc); |
24 if (!s_TimerArray) | 40 if (!s_TimerArray) |
25 s_TimerArray = new std::vector<CFWL_TimerInfo*>; | 41 s_TimerArray = new std::vector<CFWL_TimerInfo*>; |
26 | 42 |
27 s_TimerArray->push_back(new CFWL_TimerInfo(this, id_event, pTimer)); | 43 *pTimerInfo = new CFWL_FWLAdapterTimerInfo(this, id_event, pTimer); |
28 *pTimerInfo = s_TimerArray->back(); | 44 s_TimerArray->push_back(*pTimerInfo); |
29 } | 45 } |
30 | 46 |
31 void CXFA_FWLAdapterTimerMgr::Stop(IFWL_TimerInfo* pTimerInfo) { | 47 void CXFA_FWLAdapterTimerMgr::Stop(CFWL_TimerInfo* pTimerInfo) { |
32 if (!pTimerInfo || !m_pFormFillEnv) | 48 if (!pTimerInfo || !m_pFormFillEnv) |
33 return; | 49 return; |
34 | 50 |
35 CFWL_TimerInfo* pInfo = static_cast<CFWL_TimerInfo*>(pTimerInfo); | 51 CFWL_FWLAdapterTimerInfo* pInfo = |
| 52 static_cast<CFWL_FWLAdapterTimerInfo*>(pTimerInfo); |
36 m_pFormFillEnv->KillTimer(pInfo->idEvent); | 53 m_pFormFillEnv->KillTimer(pInfo->idEvent); |
37 if (s_TimerArray) { | 54 if (!s_TimerArray) |
38 auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo); | 55 return; |
39 if (it != s_TimerArray->end()) { | 56 |
40 s_TimerArray->erase(it); | 57 auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo); |
41 delete pInfo; | 58 if (it != s_TimerArray->end()) { |
42 } | 59 s_TimerArray->erase(it); |
| 60 delete pInfo; |
43 } | 61 } |
44 } | 62 } |
45 | 63 |
46 // static | 64 // static |
47 void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { | 65 void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { |
48 if (!s_TimerArray) | 66 if (!s_TimerArray) |
49 return; | 67 return; |
50 | 68 |
51 for (CFWL_TimerInfo* pInfo : *s_TimerArray) { | 69 for (const auto info : *s_TimerArray) { |
| 70 CFWL_FWLAdapterTimerInfo* pInfo = |
| 71 static_cast<CFWL_FWLAdapterTimerInfo*>(info); |
52 if (pInfo->idEvent == idEvent) { | 72 if (pInfo->idEvent == idEvent) { |
53 pInfo->pTimer->Run(pInfo); | 73 pInfo->pTimer->Run(pInfo); |
54 break; | 74 break; |
55 } | 75 } |
56 } | 76 } |
57 } | 77 } |
OLD | NEW |