summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc/doc_formfield.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-22 15:02:06 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-22 15:02:06 -0400
commit2b11dc1220746d2f6f97a940fc9e4235c8ed4975 (patch)
treee25b2ba13112f4ead789260ee57fe5b40c13b83e /core/src/fpdfdoc/doc_formfield.cpp
parentbc6c6723c37772b02de9e6e43fa0fd9439874905 (diff)
downloadpdfium-2b11dc1220746d2f6f97a940fc9e4235c8ed4975.tar.xz
Merge to XFA: Add type cast definitions for CPDF_Array.
This Cl adds ToArray, CPDF_Object::AsArray and CPDF_Object::IsArray and updates the src to use them as needed. BUG=pdfium:201 R=thestig@chromium.org, tsepez@chromium.org Review URL: https://codereview.chromium.org/1417893003 . (cherry picked from commit c2bfc000e502c42c9a3017038fd9104c7997d126) Review URL: https://codereview.chromium.org/1419643005 .
Diffstat (limited to 'core/src/fpdfdoc/doc_formfield.cpp')
-rw-r--r--core/src/fpdfdoc/doc_formfield.cpp70
1 files changed, 27 insertions, 43 deletions
diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp
index 0766eb0bc0..efa2ea23bd 100644
--- a/core/src/fpdfdoc/doc_formfield.cpp
+++ b/core/src/fpdfdoc/doc_formfield.cpp
@@ -307,10 +307,9 @@ CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) {
case PDFOBJ_STREAM:
return pValue->GetUnicodeText();
case PDFOBJ_ARRAY:
- pValue = ((CPDF_Array*)pValue)->GetElementValue(0);
- if (pValue) {
+ pValue = pValue->AsArray()->GetElementValue(0);
+ if (pValue)
return pValue->GetUnicodeText();
- }
break;
}
return CFX_WideString();
@@ -419,28 +418,24 @@ int CPDF_FormField::GetMaxLen() {
}
int CPDF_FormField::CountSelectedItems() {
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
- if (pValue == NULL) {
+ if (!pValue) {
pValue = FPDF_GetFieldAttr(m_pDict, "I");
- if (pValue == NULL) {
+ if (!pValue)
return 0;
- }
}
if (pValue->IsString() || pValue->IsNumber())
return pValue->GetString().IsEmpty() ? 0 : 1;
-
- if (pValue->GetType() != PDFOBJ_ARRAY) {
- return 0;
- }
- return ((CPDF_Array*)pValue)->GetCount();
+ if (CPDF_Array* pArray = pValue->AsArray())
+ return pArray->GetCount();
+ return 0;
}
int CPDF_FormField::GetSelectedIndex(int index) {
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
- if (pValue == NULL) {
+ if (!pValue) {
pValue = FPDF_GetFieldAttr(m_pDict, "I");
- if (pValue == NULL) {
+ if (!pValue)
return -1;
- }
}
if (pValue->IsNumber())
return pValue->GetInteger();
@@ -449,16 +444,13 @@ int CPDF_FormField::GetSelectedIndex(int index) {
if (pValue->IsString()) {
if (index != 0)
return -1;
-
sel_value = pValue->GetUnicodeText();
} else {
- if (pValue->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = pValue->AsArray();
+ if (!pArray || index < 0)
return -1;
- }
- if (index < 0) {
- return -1;
- }
- CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index);
+
+ CPDF_Object* elementValue = pArray->GetElementValue(index);
sel_value =
elementValue ? elementValue->GetUnicodeText() : CFX_WideString();
}
@@ -537,10 +529,10 @@ FX_BOOL CPDF_FormField::IsItemSelected(int index) {
return (pValue->GetInteger() == index);
}
- if (pValue->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = pValue->AsArray();
+ if (!pArray)
return FALSE;
- }
- CPDF_Array* pArray = (CPDF_Array*)pValue;
+
int iPos = -1;
for (int j = 0; j < CountSelectedOptions(); j++) {
if (GetSelectedOptionIndex(j) == index) {
@@ -584,11 +576,8 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
if (pValue->GetUnicodeText() == opt_value) {
m_pDict->RemoveAt("V");
}
- } else if (pValue->GetType() == PDFOBJ_ARRAY) {
+ } else if (pValue->IsArray()) {
CPDF_Array* pArray = CPDF_Array::Create();
- if (pArray == NULL) {
- return FALSE;
- }
int iCount = CountOptions();
for (int i = 0; i < iCount; i++) {
if (i != index) {
@@ -703,24 +692,19 @@ void CPDF_FormField::UpdateAP(CPDF_FormControl* pControl) {
}
}
int CPDF_FormField::CountOptions() {
- CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
- if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) {
- return 0;
- }
- return ((CPDF_Array*)pValue)->GetCount();
+ CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
+ return pArray ? pArray->GetCount() : 0;
}
CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) {
- CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
- if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) {
+ CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
+ if (!pArray)
return CFX_WideString();
- }
- CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index);
- if (pOption == NULL) {
+
+ CPDF_Object* pOption = pArray->GetElementValue(index);
+ if (!pOption)
return CFX_WideString();
- }
- if (pOption->GetType() == PDFOBJ_ARRAY) {
- pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index);
- }
+ if (CPDF_Array* pOptionArray = pOption->AsArray())
+ pOption = pOptionArray->GetElementValue(sub_index);
CPDF_String* pString = ToString(pOption);
return pString ? pString->GetUnicodeText() : CFX_WideString();
@@ -873,7 +857,7 @@ FX_BOOL CPDF_FormField::CheckControl(int iControlIndex,
}
}
CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
- if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) {
+ if (!ToArray(pOpt)) {
if (bChecked) {
m_pDict->SetAtName("V", csBExport);
} else {