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

Unified Diff: fpdfsdk/fsdk_baseform.cpp

Issue 2251453002: Only create widgets if really needed. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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 | fpdfsdk/include/fsdk_baseform.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/fsdk_baseform.cpp
diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/fsdk_baseform.cpp
index 4b12d78022bfad3bc8641f08056c19348389318a..4c8cf7efb7fd007da0e108fb20007976cd474e67 100644
--- a/fpdfsdk/fsdk_baseform.cpp
+++ b/fpdfsdk/fsdk_baseform.cpp
@@ -2060,7 +2060,8 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget,
return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
}
-CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
+CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl,
+ bool createIfNeeded) const {
if (!pControl || !m_pInterForm)
return nullptr;
@@ -2068,9 +2069,10 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
const auto it = m_Map.find(pControl);
if (it != m_Map.end())
pWidget = it->second;
-
if (pWidget)
return pWidget;
+ if (!createIfNeeded)
+ return nullptr;
CPDF_Dictionary* pControlDict = pControl->GetWidget();
CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
@@ -2092,6 +2094,7 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
if (!pPage)
return nullptr;
+
return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
}
@@ -2111,7 +2114,7 @@ void CPDFSDK_InterForm::GetWidgets(
for (int i = 0, sz = pField->CountControls(); i < sz; ++i) {
CPDF_FormControl* pFormCtrl = pField->GetControl(i);
ASSERT(pFormCtrl);
- CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
+ CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, true);
if (pWidget)
widgets->push_back(pWidget);
}
@@ -2276,7 +2279,6 @@ CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
IJS_Context* pContext = pRuntime->NewContext();
pContext->OnField_Format(pFormField, Value, TRUE);
-
CFX_WideString sInfo;
FX_BOOL bRet = pContext->RunScript(script, &sInfo);
pRuntime->ReleaseContext(pContext);
@@ -2298,7 +2300,7 @@ void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField,
for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
ASSERT(pFormCtrl);
- if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
+ if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false))
pWidget->ResetAppearance(sValue, bValueChanged);
}
}
@@ -2308,7 +2310,7 @@ void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) {
CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
ASSERT(pFormCtrl);
- if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
+ if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) {
CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
@@ -2378,7 +2380,7 @@ FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) {
CPDF_FormControl* pControl = pField->GetControl(i);
ASSERT(pControl);
- if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) {
+ if (CPDFSDK_Widget* pWidget = GetWidget(pControl, false)) {
uint32_t nFlags = pWidget->GetFlags();
nFlags &= ~ANNOTFLAG_INVISIBLE;
nFlags &= ~ANNOTFLAG_NOVIEW;
@@ -2501,7 +2503,7 @@ void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
FX_BOOL bSynchronizeElse) {
for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
- if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
+ if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) {
pWidget->Synchronize(bSynchronizeElse);
}
}
« no previous file with comments | « no previous file | fpdfsdk/include/fsdk_baseform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698