Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: core/src/fpdfdoc/doc_formcontrol.cpp

Issue 1541703003: Use std::map as CPDF_Dictionary's underlying store. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments, rebase, fix embedder test Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfdoc/doc_action.cpp ('k') | core/src/fpdfdoc/doc_utils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/include/fpdfdoc/fpdf_doc.h" 7 #include "core/include/fpdfdoc/fpdf_doc.h"
8 8
9 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, 9 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField,
10 CPDF_Dictionary* pWidgetDict) { 10 CPDF_Dictionary* pWidgetDict) {
11 m_pField = pField; 11 m_pField = pField;
12 m_pWidgetDict = pWidgetDict; 12 m_pWidgetDict = pWidgetDict;
13 m_pForm = m_pField->m_pForm; 13 m_pForm = m_pField->m_pForm;
14 } 14 }
15 CFX_FloatRect CPDF_FormControl::GetRect() const { 15 CFX_FloatRect CPDF_FormControl::GetRect() const {
16 return m_pWidgetDict->GetRect("Rect"); 16 return m_pWidgetDict->GetRect("Rect");
17 } 17 }
18 CFX_ByteString CPDF_FormControl::GetOnStateName() { 18 CFX_ByteString CPDF_FormControl::GetOnStateName() {
19 ASSERT(GetType() == CPDF_FormField::CheckBox || 19 ASSERT(GetType() == CPDF_FormField::CheckBox ||
20 GetType() == CPDF_FormField::RadioButton); 20 GetType() == CPDF_FormField::RadioButton);
21 CFX_ByteString csOn; 21 CFX_ByteString csOn;
22 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP"); 22 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP");
23 if (!pAP) { 23 if (!pAP) {
24 return csOn; 24 return csOn;
25 } 25 }
26 CPDF_Dictionary* pN = pAP->GetDict("N"); 26 CPDF_Dictionary* pN = pAP->GetDict("N");
27 if (!pN) { 27 if (!pN) {
28 return csOn; 28 return csOn;
29 } 29 }
30 FX_POSITION pos = pN->GetStartPos(); 30 for (const auto& it : *pN) {
31 while (pos) { 31 if (it.first != "Off") {
32 pN->GetNextElement(pos, csOn); 32 return it.first;
33 if (csOn != "Off") {
34 return csOn;
35 } 33 }
36 } 34 }
37 return CFX_ByteString(); 35 return CFX_ByteString();
38 } 36 }
39 void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { 37 void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) {
40 ASSERT(GetType() == CPDF_FormField::CheckBox || 38 ASSERT(GetType() == CPDF_FormField::CheckBox ||
41 GetType() == CPDF_FormField::RadioButton); 39 GetType() == CPDF_FormField::RadioButton);
42 CFX_ByteString csValue = csOn; 40 CFX_ByteString csValue = csOn;
43 if (csValue.IsEmpty()) { 41 if (csValue.IsEmpty()) {
44 csValue = "Yes"; 42 csValue = "Yes";
45 } 43 }
46 if (csValue == "Off") { 44 if (csValue == "Off") {
47 csValue = "Yes"; 45 csValue = "Yes";
48 } 46 }
49 CFX_ByteString csAS = m_pWidgetDict->GetString("AS", "Off"); 47 CFX_ByteString csAS = m_pWidgetDict->GetString("AS", "Off");
50 if (csAS != "Off") { 48 if (csAS != "Off") {
51 m_pWidgetDict->SetAtName("AS", csValue); 49 m_pWidgetDict->SetAtName("AS", csValue);
52 } 50 }
53 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP"); 51 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP");
54 if (!pAP) { 52 if (!pAP) {
55 return; 53 return;
56 } 54 }
57 FX_POSITION pos1 = pAP->GetStartPos(); 55 for (const auto& it : *pAP) {
58 while (pos1) { 56 CPDF_Object* pObj1 = it.second;
59 CFX_ByteString csKey1;
60 CPDF_Object* pObj1 = pAP->GetNextElement(pos1, csKey1);
61 if (!pObj1) { 57 if (!pObj1) {
62 continue; 58 continue;
63 } 59 }
64 CPDF_Object* pObjDirect1 = pObj1->GetDirect(); 60 CPDF_Object* pObjDirect1 = pObj1->GetDirect();
65 CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary(); 61 CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary();
66 if (!pSubDict) 62 if (!pSubDict)
67 continue; 63 continue;
68 64
69 FX_POSITION pos2 = pSubDict->GetStartPos(); 65 for (const auto& subdict_it : *pSubDict) {
70 while (pos2) { 66 const CFX_ByteString& csKey2 = subdict_it.first;
71 CFX_ByteString csKey2; 67 CPDF_Object* pObj2 = subdict_it.second;
72 CPDF_Object* pObj2 = pSubDict->GetNextElement(pos2, csKey2);
73 if (!pObj2) { 68 if (!pObj2) {
74 continue; 69 continue;
75 } 70 }
76 if (csKey2 != "Off") { 71 if (csKey2 != "Off") {
77 pSubDict->ReplaceKey(csKey2, csValue); 72 pSubDict->ReplaceKey(csKey2, csValue);
78 break; 73 break;
79 } 74 }
80 } 75 }
81 } 76 }
82 } 77 }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return m_pDict ? m_pDict->GetStream(csEntry) : nullptr; 412 return m_pDict ? m_pDict->GetStream(csEntry) : nullptr;
418 } 413 }
419 414
420 CPDF_IconFit CPDF_ApSettings::GetIconFit() const { 415 CPDF_IconFit CPDF_ApSettings::GetIconFit() const {
421 return m_pDict ? m_pDict->GetDict("IF") : nullptr; 416 return m_pDict ? m_pDict->GetDict("IF") : nullptr;
422 } 417 }
423 418
424 int CPDF_ApSettings::GetTextPosition() const { 419 int CPDF_ApSettings::GetTextPosition() const {
425 return m_pDict ? m_pDict->GetInteger("TP", TEXTPOS_CAPTION) : TEXTPOS_CAPTION; 420 return m_pDict ? m_pDict->GetInteger("TP", TEXTPOS_CAPTION) : TEXTPOS_CAPTION;
426 } 421 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_action.cpp ('k') | core/src/fpdfdoc/doc_utils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698