OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfdoc/include/cpdf_formfield.h" | 7 #include "core/fpdfdoc/include/cpdf_formfield.h" |
8 | 8 |
| 9 #include <set> |
| 10 |
9 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
15 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 17 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
16 #include "core/fpdfdoc/cpvt_generateap.h" | 18 #include "core/fpdfdoc/cpvt_generateap.h" |
17 #include "core/fpdfdoc/include/cpdf_formcontrol.h" | 19 #include "core/fpdfdoc/include/cpdf_formcontrol.h" |
18 #include "core/fpdfdoc/include/cpdf_interform.h" | 20 #include "core/fpdfdoc/include/cpdf_interform.h" |
| 21 #include "third_party/base/stl_util.h" |
19 | 22 |
20 namespace { | 23 namespace { |
21 | 24 |
22 const int kMaxRecursion = 32; | 25 const int kMaxRecursion = 32; |
23 | 26 |
24 const int kFormListMultiSelect = 0x100; | 27 const int kFormListMultiSelect = 0x100; |
25 | 28 |
26 const int kFormComboEdit = 0x100; | 29 const int kFormComboEdit = 0x100; |
27 | 30 |
28 const int kFormFieldReadOnly = 0x01; | 31 const int kFormFieldReadOnly = 0x01; |
(...skipping 29 matching lines...) Expand all Loading... |
58 return pAttr; | 61 return pAttr; |
59 | 62 |
60 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); | 63 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); |
61 if (!pParent) | 64 if (!pParent) |
62 return nullptr; | 65 return nullptr; |
63 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); | 66 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); |
64 } | 67 } |
65 | 68 |
66 CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) { | 69 CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) { |
67 CFX_WideString full_name; | 70 CFX_WideString full_name; |
| 71 std::set<CPDF_Dictionary*> visited; |
68 CPDF_Dictionary* pLevel = pFieldDict; | 72 CPDF_Dictionary* pLevel = pFieldDict; |
69 while (pLevel) { | 73 while (pLevel) { |
| 74 visited.insert(pLevel); |
70 CFX_WideString short_name = pLevel->GetUnicodeTextBy("T"); | 75 CFX_WideString short_name = pLevel->GetUnicodeTextBy("T"); |
71 if (short_name != L"") { | 76 if (!short_name.IsEmpty()) { |
72 if (full_name == L"") | 77 if (full_name.IsEmpty()) |
73 full_name = short_name; | 78 full_name = short_name; |
74 else | 79 else |
75 full_name = short_name + L"." + full_name; | 80 full_name = short_name + L"." + full_name; |
76 } | 81 } |
77 pLevel = pLevel->GetDictBy("Parent"); | 82 pLevel = pLevel->GetDictBy("Parent"); |
| 83 if (pdfium::ContainsKey(visited, pLevel)) |
| 84 break; |
78 } | 85 } |
79 return full_name; | 86 return full_name; |
80 } | 87 } |
81 | 88 |
82 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) | 89 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) |
83 : m_Type(Unknown), | 90 : m_Type(Unknown), |
84 m_pForm(pForm), | 91 m_pForm(pForm), |
85 m_pDict(pDict), | 92 m_pDict(pDict), |
86 m_FontSize(0), | 93 m_FontSize(0), |
87 m_pFont(nullptr) { | 94 m_pFont(nullptr) { |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 | 679 |
673 CFX_ByteString csStr = | 680 CFX_ByteString csStr = |
674 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); | 681 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); |
675 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); | 682 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); |
676 CPDF_Array* pOpt = ToArray(pValue); | 683 CPDF_Array* pOpt = ToArray(pValue); |
677 if (!pOpt) { | 684 if (!pOpt) { |
678 pOpt = new CPDF_Array; | 685 pOpt = new CPDF_Array; |
679 m_pDict->SetAt("Opt", pOpt); | 686 m_pDict->SetAt("Opt", pOpt); |
680 } | 687 } |
681 | 688 |
682 int iCount = (int)pOpt->GetCount(); | 689 int iCount = pdfium::base::checked_cast<int, size_t>(pOpt->GetCount()); |
683 if (index < 0 || index >= iCount) { | 690 if (index >= iCount) { |
684 pOpt->AddString(csStr); | 691 pOpt->AddString(csStr); |
685 index = iCount; | 692 index = iCount; |
686 } else { | 693 } else { |
687 CPDF_String* pString = new CPDF_String(csStr, FALSE); | 694 CPDF_String* pString = new CPDF_String(csStr, FALSE); |
688 pOpt->InsertAt(index, pString); | 695 pOpt->InsertAt(index, pString); |
689 } | 696 } |
690 | 697 |
691 if (bNotify) | 698 if (bNotify) |
692 NotifyListOrComboBoxAfterChange(); | 699 NotifyListOrComboBoxAfterChange(); |
693 return index; | 700 return index; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 case ListBox: | 995 case ListBox: |
989 NotifyAfterSelectionChange(); | 996 NotifyAfterSelectionChange(); |
990 break; | 997 break; |
991 case ComboBox: | 998 case ComboBox: |
992 NotifyAfterValueChange(); | 999 NotifyAfterValueChange(); |
993 break; | 1000 break; |
994 default: | 1001 default: |
995 break; | 1002 break; |
996 } | 1003 } |
997 } | 1004 } |
OLD | NEW |