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