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