summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_widget.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-30 14:25:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-30 14:25:00 +0000
commitaf9f83656f986b1fd2316972f92f9b3f4c17f620 (patch)
treef1541dfcef122735ee8ca4398709572f494062fa /fpdfsdk/cpdfsdk_widget.cpp
parent95b232f791231a0db0de780b568a0825a2e6e989 (diff)
downloadpdfium-af9f83656f986b1fd2316972f92f9b3f4c17f620.tar.xz
Combine more combo and list code
This CL combines more code where the loops for combo and list were almost identical. Change-Id: Id2ab9e2cb093e78d6922813ff18d7c6736032a03 Reviewed-on: https://pdfium-review.googlesource.com/24553 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/cpdfsdk_widget.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp32
1 files changed, 6 insertions, 26 deletions
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index 429391cf38..e0a033ee8d 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -362,6 +362,7 @@ void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
CXFA_Node* node = hWidget->GetNode();
switch (pFormField->GetFieldType()) {
+ case FormFieldType::kRadioButton:
case FormFieldType::kCheckBox: {
if (node->IsWidgetReady()) {
pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
@@ -370,45 +371,24 @@ void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
}
break;
}
- case FormFieldType::kRadioButton: {
- // TODO(weili): Check whether we need to handle checkbox and radio
- // button differently, otherwise, merge these two cases.
- if (node->IsWidgetReady()) {
- pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
- node->GetCheckState() == XFA_CHECKSTATE_On,
- true);
- }
- break;
- }
case FormFieldType::kTextField: {
if (node->IsWidgetReady())
pFormField->SetValue(node->GetValue(XFA_VALUEPICTURE_Display), true);
break;
}
+ case FormFieldType::kComboBox:
case FormFieldType::kListBox: {
pFormField->ClearSelection(false);
if (node->IsWidgetReady()) {
- for (int i = 0, sz = node->CountSelectedItems(); i < sz; i++) {
- int nIndex = node->GetSelectedItem(i);
-
- if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
- pFormField->SetItemSelection(nIndex, true, true);
- }
- }
- }
- break;
- }
- case FormFieldType::kComboBox: {
- pFormField->ClearSelection(false);
-
- if (node->IsWidgetReady()) {
- for (int i = 0, sz = node->CountSelectedItems(); i < sz; i++) {
+ int32_t item_count = node->CountSelectedItems();
+ for (int i = 0; i < item_count; ++i) {
int nIndex = node->GetSelectedItem(i);
if (nIndex > -1 && nIndex < pFormField->CountOptions())
pFormField->SetItemSelection(nIndex, true, true);
}
- pFormField->SetValue(node->GetValue(XFA_VALUEPICTURE_Display), true);
+ if (pFormField->GetFieldType() == FormFieldType::kComboBox)
+ pFormField->SetValue(node->GetValue(XFA_VALUEPICTURE_Display), true);
}
break;
}