1 // Copyright 2016 The PDFium Authors
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 #include <iterator>
10 #include <utility>
11
12 #include "core/fpdfapi/parser/cpdf_dictionary.h"
13
14 namespace {
15
16 constexpr const char* kAATypes[] = {
17 "E", // kCursorEnter
18 "X", // kCursorExit
19 "D", // kButtonDown
20 "U", // kButtonUp
21 "Fo", // kGetFocus
22 "Bl", // kLoseFocus
23 "PO", // kPageOpen
24 "PC", // kPageClose
25 "PV", // kPageVisible
26 "PI", // kPageInvisible
27 "O", // kOpenPage
28 "C", // kClosePage
29 "K", // kKeyStroke
30 "F", // kFormat
31 "V", // kValidate
32 "C", // kCalculate
33 "WC", // kCloseDocument
34 "WS", // kSaveDocument
35 "DS", // kDocumentSaved
36 "WP", // kPrintDocument
37 "DP", // kDocumentPrinted
38 };
39
40 // |kAATypes| should have one less element than enum AActionType due to
41 // |kDocumentOpen|, which is an artificial type.
42 static_assert(std::size(kAATypes) == CPDF_AAction::kNumberOfActions - 1,
43 "kAATypes count mismatch");
44
45 } // namespace
46
CPDF_AAction(RetainPtr<const CPDF_Dictionary> pDict)47 CPDF_AAction::CPDF_AAction(RetainPtr<const CPDF_Dictionary> pDict)
48 : m_pDict(std::move(pDict)) {}
49
50 CPDF_AAction::CPDF_AAction(const CPDF_AAction& that) = default;
51
52 CPDF_AAction::~CPDF_AAction() = default;
53
ActionExist(AActionType eType) const54 bool CPDF_AAction::ActionExist(AActionType eType) const {
55 return m_pDict && m_pDict->KeyExist(kAATypes[eType]);
56 }
57
GetAction(AActionType eType) const58 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const {
59 return CPDF_Action(m_pDict ? m_pDict->GetDictFor(kAATypes[eType]) : nullptr);
60 }
61
62 // static
IsUserInput(AActionType type)63 bool CPDF_AAction::IsUserInput(AActionType type) {
64 switch (type) {
65 case kButtonUp:
66 case kButtonDown:
67 case kKeyStroke:
68 return true;
69 default:
70 return false;
71 }
72 }
73