Return "circle" for the default radio button style.
Unlike checkboxes, radio buttons don't use the "check" style by default.
Change-Id: If60b8930f4ed44f441e2d30c34c8ae111d2a0cd9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/91310
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 318d062..a515ccf 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -34,6 +34,13 @@
namespace {
+constexpr wchar_t kCheckSelector = L'4';
+constexpr wchar_t kCircleSelector = L'l';
+constexpr wchar_t kCrossSelector = L'8';
+constexpr wchar_t kDiamondSelector = L'u';
+constexpr wchar_t kSquareSelector = L'n';
+constexpr wchar_t kStarSelector = L'H';
+
bool IsCheckBoxOrRadioButton(const CPDF_FormField* pFormField) {
return pFormField->GetFieldType() == FormFieldType::kCheckBox ||
pFormField->GetFieldType() == FormFieldType::kRadioButton;
@@ -528,6 +535,19 @@
}
}
+wchar_t GetSelectorFromCaptionForFieldType(const WideString& caption,
+ CPDF_FormField::Type type) {
+ if (!caption.IsEmpty())
+ return caption[0];
+
+ switch (type) {
+ case CPDF_FormField::kRadioButton:
+ return kCircleSelector;
+ default:
+ return kCheckSelector;
+ }
+}
+
} // namespace
const JSPropertySpec CJS_Field::PropertySpecs[] = {
@@ -1865,27 +1885,28 @@
if (!pFormControl)
return CJS_Result::Failure(JSMessage::kBadObjectError);
- WideString csWCaption = pFormControl->GetNormalCaption();
- wchar_t selector = !csWCaption.IsEmpty() ? csWCaption[0] : L'4';
+ wchar_t selector = GetSelectorFromCaptionForFieldType(
+ pFormControl->GetNormalCaption(), pFormControl->GetType());
ByteString csBCaption;
switch (selector) {
- case L'l':
+ case kCircleSelector:
csBCaption = "circle";
break;
- case L'8':
+ case kCrossSelector:
csBCaption = "cross";
break;
- case L'u':
+ case kDiamondSelector:
csBCaption = "diamond";
break;
- case L'n':
+ case kSquareSelector:
csBCaption = "square";
break;
- case L'H':
+ case kStarSelector:
csBCaption = "star";
break;
- default: // L'4'
+ case kCheckSelector:
+ default:
csBCaption = "check";
break;
}
diff --git a/testing/resources/javascript/field_properties.in b/testing/resources/javascript/field_properties.in
index 0a84430d..3887787 100644
--- a/testing/resources/javascript/field_properties.in
+++ b/testing/resources/javascript/field_properties.in
@@ -118,7 +118,7 @@
try {
testROProperty(field, "exportValues", "Yes");
testRIProperty(field, "radiosInUnison", false);
- testRIProperty(field, "style", "check");
+ testRIProperty(field, "style", "circle");
testROProperty(field, "type", "radiobutton");
testRIProperty(field, "value", "Off");
testROProperty(field, "valueAsString", "Off");
diff --git a/testing/resources/javascript/field_properties_expected.txt b/testing/resources/javascript/field_properties_expected.txt
index b3d8195..2c57daf 100644
--- a/testing/resources/javascript/field_properties_expected.txt
+++ b/testing/resources/javascript/field_properties_expected.txt
@@ -100,8 +100,8 @@
Alert: PASS: exportValues threw Field.exportValues: Object no longer exists.
Alert: PASS: radiosInUnison = false
Alert: PASS: radiosInUnison = false
-Alert: PASS: style = check
-Alert: PASS: style = check
+Alert: PASS: style = circle
+Alert: PASS: style = circle
Alert: PASS: type = radiobutton
Alert: PASS: type threw Field.type: Operation not supported.
Alert: PASS: value = Off