1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fpdfdoc/cpdf_aaction.h"
8
9 namespace {
10
11 constexpr const char* g_sAATypes[] = {
12 "E", // CursorEnter
13 "X", // CursorExit
14 "D", // ButtonDown
15 "U", // ButtonUp
16 "Fo", // GetFocus
17 "Bl", // LoseFocus
18 "PO", // PageOpen
19 "PC", // PageClose
20 "PV", // PageVisible
21 "PI", // PageInvisible
22 "O", // OpenPage
23 "C", // ClosePage
24 "K", // KeyStroke
25 "F", // Format
26 "V", // Validate
27 "C", // Calculate
28 "WC", // CloseDocument
29 "WS", // SaveDocument
30 "DS", // DocumentSaved
31 "WP", // PrintDocument
32 "DP", // DocumentPrinted
33 };
34
35 // |g_sAATypes| should have as many elements as enum AActionType.
36 static_assert(FX_ArraySize(g_sAATypes) == CPDF_AAction::NumberOfActions,
37 "g_sAATypes count mismatch");
38
39 } // namespace
40
CPDF_AAction(CPDF_Dictionary * pDict)41 CPDF_AAction::CPDF_AAction(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
42
43 CPDF_AAction::CPDF_AAction(const CPDF_AAction& that) = default;
44
~CPDF_AAction()45 CPDF_AAction::~CPDF_AAction() {}
46
ActionExist(AActionType eType) const47 bool CPDF_AAction::ActionExist(AActionType eType) const {
48 return m_pDict && m_pDict->KeyExist(g_sAATypes[eType]);
49 }
50
GetAction(AActionType eType) const51 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const {
52 return CPDF_Action(m_pDict ? m_pDict->GetDictFor(g_sAATypes[eType])
53 : nullptr);
54 }
55