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

Side by Side Diff: fpdfsdk/cpdfsdk_interform.cpp

Issue 2473103003: Revert: Only create widgets if really needed (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « fpdfsdk/cpdfsdk_interform.h ('k') | fpdfsdk/javascript/Field.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/cpdfsdk_interform.h" 7 #include "fpdfsdk/cpdfsdk_interform.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 bool bNext) const { 75 bool bNext) const {
76 std::unique_ptr<CBA_AnnotIterator> pIterator(new CBA_AnnotIterator( 76 std::unique_ptr<CBA_AnnotIterator> pIterator(new CBA_AnnotIterator(
77 pWidget->GetPageView(), CPDF_Annot::Subtype::WIDGET)); 77 pWidget->GetPageView(), CPDF_Annot::Subtype::WIDGET));
78 78
79 if (bNext) 79 if (bNext)
80 return static_cast<CPDFSDK_Widget*>(pIterator->GetNextAnnot(pWidget)); 80 return static_cast<CPDFSDK_Widget*>(pIterator->GetNextAnnot(pWidget));
81 81
82 return static_cast<CPDFSDK_Widget*>(pIterator->GetPrevAnnot(pWidget)); 82 return static_cast<CPDFSDK_Widget*>(pIterator->GetPrevAnnot(pWidget));
83 } 83 }
84 84
85 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl, 85 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
86 bool createIfNeeded) const {
87 if (!pControl || !m_pInterForm) 86 if (!pControl || !m_pInterForm)
88 return nullptr; 87 return nullptr;
89 88
90 CPDFSDK_Widget* pWidget = nullptr; 89 CPDFSDK_Widget* pWidget = nullptr;
91 const auto it = m_Map.find(pControl); 90 const auto it = m_Map.find(pControl);
92 if (it != m_Map.end()) 91 if (it != m_Map.end())
93 pWidget = it->second; 92 pWidget = it->second;
94 if (pWidget) 93 if (pWidget)
95 return pWidget; 94 return pWidget;
96 if (!createIfNeeded)
97 return nullptr;
98 95
99 CPDF_Dictionary* pControlDict = pControl->GetWidget(); 96 CPDF_Dictionary* pControlDict = pControl->GetWidget();
100 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); 97 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
101 CPDFSDK_PageView* pPage = nullptr; 98 CPDFSDK_PageView* pPage = nullptr;
102 99
103 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictFor("P")) { 100 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictFor("P")) {
104 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); 101 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
105 if (nPageIndex >= 0) 102 if (nPageIndex >= 0)
106 pPage = m_pFormFillEnv->GetPageView(nPageIndex); 103 pPage = m_pFormFillEnv->GetPageView(nPageIndex);
107 } 104 }
(...skipping 19 matching lines...) Expand all
127 GetWidgets(pFormField, widgets); 124 GetWidgets(pFormField, widgets);
128 } 125 }
129 } 126 }
130 127
131 void CPDFSDK_InterForm::GetWidgets( 128 void CPDFSDK_InterForm::GetWidgets(
132 CPDF_FormField* pField, 129 CPDF_FormField* pField,
133 std::vector<CPDFSDK_Widget*>* widgets) const { 130 std::vector<CPDFSDK_Widget*>* widgets) const {
134 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { 131 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) {
135 CPDF_FormControl* pFormCtrl = pField->GetControl(i); 132 CPDF_FormControl* pFormCtrl = pField->GetControl(i);
136 ASSERT(pFormCtrl); 133 ASSERT(pFormCtrl);
137 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, true); 134 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
138 if (pWidget) 135 if (pWidget)
139 widgets->push_back(pWidget); 136 widgets->push_back(pWidget);
140 } 137 }
141 } 138 }
142 139
143 int CPDFSDK_InterForm::GetPageIndexByAnnotDict( 140 int CPDFSDK_InterForm::GetPageIndexByAnnotDict(
144 CPDF_Document* pDocument, 141 CPDF_Document* pDocument,
145 CPDF_Dictionary* pAnnotDict) const { 142 CPDF_Dictionary* pAnnotDict) const {
146 ASSERT(pAnnotDict); 143 ASSERT(pAnnotDict);
147 144
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return m_bXfaValidationsEnabled; 203 return m_bXfaValidationsEnabled;
207 } 204 }
208 void CPDFSDK_InterForm::XfaSetValidationsEnabled(bool bEnabled) { 205 void CPDFSDK_InterForm::XfaSetValidationsEnabled(bool bEnabled) {
209 m_bXfaValidationsEnabled = bEnabled; 206 m_bXfaValidationsEnabled = bEnabled;
210 } 207 }
211 208
212 void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, 209 void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
213 bool bSynchronizeElse) { 210 bool bSynchronizeElse) {
214 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 211 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
215 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); 212 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
216 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) 213 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
217 pWidget->Synchronize(bSynchronizeElse); 214 pWidget->Synchronize(bSynchronizeElse);
218 } 215 }
219 } 216 }
220 #endif // PDF_ENABLE_XFA 217 #endif // PDF_ENABLE_XFA
221 218
222 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { 219 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
223 if (!m_pFormFillEnv->IsJSInitiated()) 220 if (!m_pFormFillEnv->IsJSInitiated())
224 return; 221 return;
225 222
226 if (m_bBusy) 223 if (m_bBusy)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 312
316 return sValue; 313 return sValue;
317 } 314 }
318 315
319 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, 316 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField,
320 const CFX_WideString* sValue, 317 const CFX_WideString* sValue,
321 bool bValueChanged) { 318 bool bValueChanged) {
322 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 319 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
323 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); 320 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
324 ASSERT(pFormCtrl); 321 ASSERT(pFormCtrl);
325 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) 322 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
326 pWidget->ResetAppearance(sValue, bValueChanged); 323 pWidget->ResetAppearance(sValue, bValueChanged);
327 } 324 }
328 } 325 }
329 326
330 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { 327 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) {
331 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { 328 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
332 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); 329 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
333 ASSERT(pFormCtrl); 330 ASSERT(pFormCtrl);
334 331
335 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { 332 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
336 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); 333 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
337 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); 334 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false);
338 FX_RECT rcBBox = m_pFormFillEnv->GetInteractiveFormFiller()->GetViewBBox( 335 FX_RECT rcBBox = m_pFormFillEnv->GetInteractiveFormFiller()->GetViewBBox(
339 pPageView, pWidget); 336 pPageView, pWidget);
340 337
341 m_pFormFillEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, 338 m_pFormFillEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right,
342 rcBBox.bottom); 339 rcBBox.bottom);
343 } 340 }
344 } 341 }
345 } 342 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); 389 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
393 390
394 bool bHide = action.GetHideStatus(); 391 bool bHide = action.GetHideStatus();
395 bool bChanged = false; 392 bool bChanged = false;
396 393
397 for (CPDF_FormField* pField : fields) { 394 for (CPDF_FormField* pField : fields) {
398 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { 395 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) {
399 CPDF_FormControl* pControl = pField->GetControl(i); 396 CPDF_FormControl* pControl = pField->GetControl(i);
400 ASSERT(pControl); 397 ASSERT(pControl);
401 398
402 if (CPDFSDK_Widget* pWidget = GetWidget(pControl, false)) { 399 if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) {
403 uint32_t nFlags = pWidget->GetFlags(); 400 uint32_t nFlags = pWidget->GetFlags();
404 nFlags &= ~ANNOTFLAG_INVISIBLE; 401 nFlags &= ~ANNOTFLAG_INVISIBLE;
405 nFlags &= ~ANNOTFLAG_NOVIEW; 402 nFlags &= ~ANNOTFLAG_NOVIEW;
406 if (bHide) 403 if (bHide)
407 nFlags |= ANNOTFLAG_HIDDEN; 404 nFlags |= ANNOTFLAG_HIDDEN;
408 else 405 else
409 nFlags &= ~ANNOTFLAG_HIDDEN; 406 nFlags &= ~ANNOTFLAG_HIDDEN;
410 pWidget->SetFlags(nFlags); 407 pWidget->SetFlags(nFlags);
411 pWidget->GetPageView()->UpdateView(pWidget); 408 pWidget->GetPageView()->UpdateView(pWidget);
412 bChanged = true; 409 bChanged = true;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 } 703 }
707 } 704 }
708 705
709 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { 706 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) {
710 if (nFieldType < 0 || nFieldType > kNumFieldTypes) 707 if (nFieldType < 0 || nFieldType > kNumFieldTypes)
711 return FXSYS_RGB(255, 255, 255); 708 return FXSYS_RGB(255, 255, 255);
712 if (nFieldType == 0) 709 if (nFieldType == 0)
713 return m_aHighlightColor[0]; 710 return m_aHighlightColor[0];
714 return m_aHighlightColor[nFieldType - 1]; 711 return m_aHighlightColor[nFieldType - 1];
715 } 712 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_interform.h ('k') | fpdfsdk/javascript/Field.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698