Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/cpdf_interform.h" | 7 #include "core/fpdfdoc/cpdf_interform.h" |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 | 662 |
| 663 CPDF_Array* pFields = m_pFormDict->GetArrayFor("Fields"); | 663 CPDF_Array* pFields = m_pFormDict->GetArrayFor("Fields"); |
| 664 if (!pFields) | 664 if (!pFields) |
| 665 return; | 665 return; |
| 666 | 666 |
| 667 for (size_t i = 0; i < pFields->GetCount(); ++i) | 667 for (size_t i = 0; i < pFields->GetCount(); ++i) |
| 668 LoadField(pFields->GetDictAt(i), 0); | 668 LoadField(pFields->GetDictAt(i), 0); |
| 669 } | 669 } |
| 670 | 670 |
| 671 CPDF_InterForm::~CPDF_InterForm() { | 671 CPDF_InterForm::~CPDF_InterForm() { |
| 672 for (auto it : m_ControlMap) | 672 m_ControlMap.clear(); |
|
Tom Sepez
2017/01/09 18:37:07
Note: Just to keep deletion order for now.
| |
| 673 delete it.second; | |
| 674 | |
| 675 size_t nCount = m_pFieldTree->m_Root.CountFields(); | 673 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
| 676 for (size_t i = 0; i < nCount; ++i) | 674 for (size_t i = 0; i < nCount; ++i) |
| 677 delete m_pFieldTree->m_Root.GetFieldAtIndex(i); | 675 delete m_pFieldTree->m_Root.GetFieldAtIndex(i); |
| 678 } | 676 } |
| 679 | 677 |
| 680 bool CPDF_InterForm::s_bUpdateAP = true; | 678 bool CPDF_InterForm::s_bUpdateAP = true; |
| 681 | 679 |
| 682 bool CPDF_InterForm::IsUpdateAPEnabled() { | 680 bool CPDF_InterForm::IsUpdateAPEnabled() { |
| 683 return s_bUpdateAP; | 681 return s_bUpdateAP; |
| 684 } | 682 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 for (size_t i = pAnnotList->GetCount(); i > 0; --i) { | 910 for (size_t i = pAnnotList->GetCount(); i > 0; --i) { |
| 913 size_t annot_index = i - 1; | 911 size_t annot_index = i - 1; |
| 914 CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(annot_index); | 912 CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(annot_index); |
| 915 if (!pAnnot) | 913 if (!pAnnot) |
| 916 continue; | 914 continue; |
| 917 | 915 |
| 918 const auto it = m_ControlMap.find(pAnnot); | 916 const auto it = m_ControlMap.find(pAnnot); |
| 919 if (it == m_ControlMap.end()) | 917 if (it == m_ControlMap.end()) |
| 920 continue; | 918 continue; |
| 921 | 919 |
| 922 CPDF_FormControl* pControl = it->second; | 920 CPDF_FormControl* pControl = it->second.get(); |
| 923 CFX_FloatRect rect = pControl->GetRect(); | 921 CFX_FloatRect rect = pControl->GetRect(); |
| 924 if (!rect.Contains(pdf_x, pdf_y)) | 922 if (!rect.Contains(pdf_x, pdf_y)) |
| 925 continue; | 923 continue; |
| 926 | 924 |
| 927 if (z_order) | 925 if (z_order) |
| 928 *z_order = static_cast<int>(annot_index); | 926 *z_order = static_cast<int>(annot_index); |
| 929 return pControl; | 927 return pControl; |
| 930 } | 928 } |
| 931 return nullptr; | 929 return nullptr; |
| 932 } | 930 } |
| 933 | 931 |
| 934 CPDF_FormControl* CPDF_InterForm::GetControlByDict( | 932 CPDF_FormControl* CPDF_InterForm::GetControlByDict( |
| 935 const CPDF_Dictionary* pWidgetDict) const { | 933 const CPDF_Dictionary* pWidgetDict) const { |
| 936 const auto it = m_ControlMap.find(pWidgetDict); | 934 const auto it = m_ControlMap.find(pWidgetDict); |
| 937 return it != m_ControlMap.end() ? it->second : nullptr; | 935 return it != m_ControlMap.end() ? it->second.get() : nullptr; |
| 938 } | 936 } |
| 939 | 937 |
| 940 bool CPDF_InterForm::NeedConstructAP() const { | 938 bool CPDF_InterForm::NeedConstructAP() const { |
| 941 return m_pFormDict && m_pFormDict->GetBooleanFor("NeedAppearances"); | 939 return m_pFormDict && m_pFormDict->GetBooleanFor("NeedAppearances"); |
| 942 } | 940 } |
| 943 | 941 |
| 944 int CPDF_InterForm::CountFieldsInCalculationOrder() { | 942 int CPDF_InterForm::CountFieldsInCalculationOrder() { |
| 945 if (!m_pFormDict) | 943 if (!m_pFormDict) |
| 946 return 0; | 944 return 0; |
| 947 | 945 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1143 if (pFieldDict->GetStringFor("Subtype") == "Widget") | 1141 if (pFieldDict->GetStringFor("Subtype") == "Widget") |
| 1144 AddControl(pField, pFieldDict); | 1142 AddControl(pField, pFieldDict); |
| 1145 } | 1143 } |
| 1146 return pField; | 1144 return pField; |
| 1147 } | 1145 } |
| 1148 | 1146 |
| 1149 CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, | 1147 CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, |
| 1150 CPDF_Dictionary* pWidgetDict) { | 1148 CPDF_Dictionary* pWidgetDict) { |
| 1151 const auto it = m_ControlMap.find(pWidgetDict); | 1149 const auto it = m_ControlMap.find(pWidgetDict); |
| 1152 if (it != m_ControlMap.end()) | 1150 if (it != m_ControlMap.end()) |
| 1153 return it->second; | 1151 return it->second.get(); |
| 1154 | 1152 |
| 1155 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict); | 1153 auto pNew = pdfium::MakeUnique<CPDF_FormControl>(pField, pWidgetDict); |
| 1156 m_ControlMap[pWidgetDict] = pControl; | 1154 CPDF_FormControl* pControl = pNew.get(); |
| 1157 pField->m_ControlList.Add(pControl); | 1155 m_ControlMap[pWidgetDict] = std::move(pNew); |
| 1156 pField->m_ControlList.push_back(pControl); | |
| 1158 return pControl; | 1157 return pControl; |
| 1159 } | 1158 } |
| 1160 | 1159 |
| 1161 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( | 1160 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( |
| 1162 const std::vector<CPDF_FormField*>* fields, | 1161 const std::vector<CPDF_FormField*>* fields, |
| 1163 bool bIncludeOrExclude) const { | 1162 bool bIncludeOrExclude) const { |
| 1164 size_t nCount = m_pFieldTree->m_Root.CountFields(); | 1163 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
| 1165 for (size_t i = 0; i < nCount; ++i) { | 1164 for (size_t i = 0; i < nCount; ++i) { |
| 1166 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1165 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
| 1167 if (!pField) | 1166 if (!pField) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1314 else if (iType == FIELDTYPE_LISTBOX) | 1313 else if (iType == FIELDTYPE_LISTBOX) |
| 1315 m_pFormNotify->AfterSelectionChange(pField); | 1314 m_pFormNotify->AfterSelectionChange(pField); |
| 1316 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) | 1315 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) |
| 1317 m_pFormNotify->AfterValueChange(pField); | 1316 m_pFormNotify->AfterValueChange(pField); |
| 1318 } | 1317 } |
| 1319 } | 1318 } |
| 1320 | 1319 |
| 1321 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { | 1320 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { |
| 1322 m_pFormNotify = pNotify; | 1321 m_pFormNotify = pNotify; |
| 1323 } | 1322 } |
| OLD | NEW |