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