Refactor TextField to have a base struct FormField
This CL refactors TextField struct to have a base struct FormField. This change is needed so that other form fields can be populated in future. Bug: 1030242 Change-Id: I4e6f45ca2bcb0e4a5e57de35622d12d29889c8c0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2251615 Commit-Queue: Mansi Awasthi <maawas@microsoft.com> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Ankit Kumar 🌪️ <ankk@microsoft.com> Cr-Commit-Position: refs/heads/master@{#780853}
This commit is contained in:

committed by
Commit Bot

parent
9208e5687b
commit
cfc83f8a80
pdf/pdfium
@ -1169,11 +1169,7 @@ void PDFiumPage::PopulateAnnotations() {
|
||||
break;
|
||||
}
|
||||
case FPDF_ANNOT_WIDGET: {
|
||||
// TODO(crbug.com/1030242): Populate other types of form fields too.
|
||||
if (FPDFAnnot_GetFormFieldType(engine_->form(), annot.get()) ==
|
||||
FPDF_FORMFIELD_TEXTFIELD) {
|
||||
PopulateTextField(annot.get());
|
||||
}
|
||||
PopulateFormField(annot.get());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -1234,23 +1230,48 @@ void PDFiumPage::PopulateTextField(FPDF_ANNOTATION annot) {
|
||||
DCHECK_EQ(FPDFAnnot_GetFormFieldType(form_handle, annot),
|
||||
FPDF_FORMFIELD_TEXTFIELD);
|
||||
|
||||
FS_RECTF rect;
|
||||
if (!FPDFAnnot_GetRect(annot, &rect))
|
||||
TextField text_field;
|
||||
if (!PopulateFormFieldProperties(annot, &text_field))
|
||||
return;
|
||||
|
||||
TextField text_field;
|
||||
// We use the bounding box of the text field as the bounding rect.
|
||||
text_field.bounding_rect =
|
||||
PageToScreen(pp::Point(), 1.0, rect.left, rect.top, rect.right,
|
||||
rect.bottom, PageOrientation::kOriginal);
|
||||
text_field.value = base::UTF16ToUTF8(CallPDFiumWideStringBufferApi(
|
||||
base::BindRepeating(&FPDFAnnot_GetFormFieldValue, form_handle, annot),
|
||||
/*check_expected_size=*/true));
|
||||
text_field.name = base::UTF16ToUTF8(CallPDFiumWideStringBufferApi(
|
||||
text_fields_.push_back(std::move(text_field));
|
||||
}
|
||||
|
||||
void PDFiumPage::PopulateFormField(FPDF_ANNOTATION annot) {
|
||||
DCHECK_EQ(FPDFAnnot_GetSubtype(annot), FPDF_ANNOT_WIDGET);
|
||||
int form_field_type = FPDFAnnot_GetFormFieldType(engine_->form(), annot);
|
||||
|
||||
// TODO(crbug.com/1030242): Populate other types of form fields too.
|
||||
switch (form_field_type) {
|
||||
case FPDF_FORMFIELD_TEXTFIELD: {
|
||||
PopulateTextField(annot);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool PDFiumPage::PopulateFormFieldProperties(FPDF_ANNOTATION annot,
|
||||
FormField* form_field) {
|
||||
DCHECK(annot);
|
||||
FS_RECTF rect;
|
||||
if (!FPDFAnnot_GetRect(annot, &rect))
|
||||
return false;
|
||||
|
||||
// We use the bounding box of the form field as the bounding rect.
|
||||
form_field->bounding_rect =
|
||||
PageToScreen(pp::Point(), 1.0, rect.left, rect.top, rect.right,
|
||||
rect.bottom, PageOrientation::kOriginal);
|
||||
FPDF_FORMHANDLE form_handle = engine_->form();
|
||||
form_field->name = base::UTF16ToUTF8(CallPDFiumWideStringBufferApi(
|
||||
base::BindRepeating(&FPDFAnnot_GetFormFieldName, form_handle, annot),
|
||||
/*check_expected_size=*/true));
|
||||
text_field.flags = FPDFAnnot_GetFormFieldFlags(form_handle, annot);
|
||||
text_fields_.push_back(std::move(text_field));
|
||||
form_field->flags = FPDFAnnot_GetFormFieldFlags(form_handle, annot);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PDFiumPage::GetUnderlyingTextRangeForRect(const pp::FloatRect& rect,
|
||||
@ -1382,6 +1403,12 @@ PDFiumPage::Highlight::Highlight(const Highlight& that) = default;
|
||||
|
||||
PDFiumPage::Highlight::~Highlight() = default;
|
||||
|
||||
PDFiumPage::FormField::FormField() = default;
|
||||
|
||||
PDFiumPage::FormField::FormField(const FormField& that) = default;
|
||||
|
||||
PDFiumPage::FormField::~FormField() = default;
|
||||
|
||||
PDFiumPage::TextField::TextField() = default;
|
||||
|
||||
PDFiumPage::TextField::TextField(const TextField& that) = default;
|
||||
|
@ -235,18 +235,26 @@ class PDFiumPage {
|
||||
std::string note_text;
|
||||
};
|
||||
|
||||
// Represents a form field within the page.
|
||||
struct FormField {
|
||||
FormField();
|
||||
FormField(const FormField& other);
|
||||
~FormField();
|
||||
|
||||
pp::Rect bounding_rect;
|
||||
// Represents the name of form field as defined in the field dictionary.
|
||||
std::string name;
|
||||
// Represents the flags of form field as defined in the field dictionary.
|
||||
int flags;
|
||||
};
|
||||
|
||||
// Represents a text field within the page.
|
||||
struct TextField {
|
||||
struct TextField : FormField {
|
||||
TextField();
|
||||
TextField(const TextField& other);
|
||||
~TextField();
|
||||
|
||||
// Represents the name of form field as defined in the field dictionary.
|
||||
std::string name;
|
||||
std::string value;
|
||||
pp::Rect bounding_rect;
|
||||
// Represents the flags of form field as defined in the field dictionary.
|
||||
int flags;
|
||||
};
|
||||
|
||||
// Returns a link index if the given character index is over a link, or -1
|
||||
@ -266,6 +274,8 @@ class PDFiumPage {
|
||||
void PopulateHighlight(FPDF_ANNOTATION annot);
|
||||
// Populate |text_fields_| with |annot|.
|
||||
void PopulateTextField(FPDF_ANNOTATION annot);
|
||||
// Populate form fields like text field on the page.
|
||||
void PopulateFormField(FPDF_ANNOTATION annot);
|
||||
// Returns link type and fills target associated with a destination. Returns
|
||||
// NONSELECTABLE_AREA if detection failed.
|
||||
Area GetDestinationTarget(FPDF_DEST destination, LinkTarget* target);
|
||||
@ -305,6 +315,8 @@ class PDFiumPage {
|
||||
static uint32_t CountLinkHighlightOverlaps(
|
||||
const std::vector<Link>& links,
|
||||
const std::vector<Highlight>& highlights);
|
||||
bool PopulateFormFieldProperties(FPDF_ANNOTATION annot,
|
||||
FormField* form_field);
|
||||
|
||||
PDFiumEngine* engine_;
|
||||
ScopedFPDFPage page_;
|
||||
|
Reference in New Issue
Block a user