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

Unified Diff: fpdfsdk/javascript/Field.cpp

Issue 2255843002: Factor out the duplicated logic in Field::SetDisplay (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Factor out the duplicated logic in Field::SetDisplay Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/javascript/Field.cpp
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index 1f4a18375adfe9ca2355375070c97d8c28cda630..a0fa2785b7b58da1d9db5172111b14733618ad71 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -26,6 +26,48 @@
#include "fpdfsdk/javascript/cjs_runtime.h"
#include "fpdfsdk/javascript/color.h"
+namespace {
+
+bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
+ if (!pWidget)
+ return false;
+
+ uint32_t dwFlag = pWidget->GetFlags();
+ switch (value) {
+ case 0:
+ dwFlag &= ~ANNOTFLAG_INVISIBLE;
+ dwFlag &= ~ANNOTFLAG_HIDDEN;
+ dwFlag &= ~ANNOTFLAG_NOVIEW;
+ dwFlag |= ANNOTFLAG_PRINT;
+ break;
+ case 1:
+ dwFlag &= ~ANNOTFLAG_INVISIBLE;
+ dwFlag &= ~ANNOTFLAG_NOVIEW;
+ dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ break;
+ case 2:
+ dwFlag &= ~ANNOTFLAG_INVISIBLE;
+ dwFlag &= ~ANNOTFLAG_PRINT;
+ dwFlag &= ~ANNOTFLAG_HIDDEN;
+ dwFlag &= ~ANNOTFLAG_NOVIEW;
+ break;
+ case 3:
+ dwFlag |= ANNOTFLAG_NOVIEW;
+ dwFlag |= ANNOTFLAG_PRINT;
+ dwFlag &= ~ANNOTFLAG_HIDDEN;
+ break;
+ }
+
+ if (dwFlag != pWidget->GetFlags()) {
+ pWidget->SetFlags(dwFlag);
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace
+
BEGIN_JS_STATIC_CONST(CJS_Field)
END_JS_STATIC_CONST()
@@ -1239,86 +1281,29 @@ void Field::SetDisplay(CPDFSDK_Document* pDocument,
GetFormFields(pDocument, swFieldName);
for (CPDF_FormField* pFormField : FieldArray) {
if (nControlIndex < 0) {
- FX_BOOL bSet = FALSE;
+ bool bAnySet = false;
for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
CPDF_FormControl* pFormControl = pFormField->GetControl(i);
ASSERT(pFormControl);
- if (CPDFSDK_Widget* pWidget =
- pInterForm->GetWidget(pFormControl, true)) {
- uint32_t dwFlag = pWidget->GetFlags();
- switch (number) {
- case 0:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= ANNOTFLAG_PRINT;
- break;
- case 1:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- break;
- case 2:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_PRINT);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- break;
- case 3:
- dwFlag |= ANNOTFLAG_NOVIEW;
- dwFlag |= ANNOTFLAG_PRINT;
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- break;
- }
-
- if (dwFlag != pWidget->GetFlags()) {
- pWidget->SetFlags(dwFlag);
- bSet = TRUE;
- }
- }
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true);
+ if (SetWidgetDisplayStatus(pWidget, number))
+ bAnySet = true;
}
- if (bSet)
+ if (bAnySet)
UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
} else {
if (nControlIndex >= pFormField->CountControls())
return;
- if (CPDF_FormControl* pFormControl =
- pFormField->GetControl(nControlIndex)) {
- if (CPDFSDK_Widget* pWidget =
- pInterForm->GetWidget(pFormControl, true)) {
- uint32_t dwFlag = pWidget->GetFlags();
- switch (number) {
- case 0:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= ANNOTFLAG_PRINT;
- break;
- case 1:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- break;
- case 2:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_PRINT);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- break;
- case 3:
- dwFlag |= ANNOTFLAG_NOVIEW;
- dwFlag |= ANNOTFLAG_PRINT;
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- break;
- }
- if (dwFlag != pWidget->GetFlags()) {
- pWidget->SetFlags(dwFlag);
- UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
- }
- }
- }
+
+ CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
+ if (!pFormControl)
+ return;
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true);
+ if (SetWidgetDisplayStatus(pWidget, number))
+ UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
}
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698