From 7b1e53c0ef09da360304c6f4397082d09a945a7e Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 15 Sep 2017 15:43:11 -0700 Subject: Use unsigned types for app age, value age in widgets. Then if they roll over, it doesn't matter, since we only check for change. And then we can pull a silly check. Then remove some no-op calls where we didn't use the result. Change-Id: I35ba470b42fb8c32a6984999e0311b21729791ca Reviewed-on: https://pdfium-review.googlesource.com/14210 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fpdfsdk/cpdfsdk_widget.cpp | 14 ++------- fpdfsdk/cpdfsdk_widget.h | 8 +++--- fpdfsdk/formfiller/cffl_formfiller.cpp | 10 +++---- fpdfsdk/formfiller/cffl_interactiveformfiller.cpp | 35 +++++++++++------------ fpdfsdk/formfiller/cffl_interactiveformfiller.h | 4 +-- 5 files changed, 29 insertions(+), 42 deletions(-) diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 60a4d52657..0183f587cf 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -57,7 +57,7 @@ CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_InterForm* pInterForm) : CPDFSDK_BAAnnot(pAnnot, pPageView), m_pInterForm(pInterForm), - m_nAppAge(0), + m_nAppearanceAge(0), m_nValueAge(0) #ifdef PDF_ENABLE_XFA , @@ -757,9 +757,7 @@ void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue, bool bValueChanged) { SetAppModified(); - m_nAppAge++; - if (m_nAppAge > 999999) - m_nAppAge = 0; + m_nAppearanceAge++; if (bValueChanged) m_nValueAge++; @@ -1048,11 +1046,3 @@ CFX_WideString CPDFSDK_Widget::GetAlternateName() const { CPDF_FormField* pFormField = GetFormField(); return pFormField->GetAlternateName(); } - -int32_t CPDFSDK_Widget::GetAppearanceAge() const { - return m_nAppAge; -} - -int32_t CPDFSDK_Widget::GetValueAge() const { - return m_nValueAge; -} diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h index 5c63400443..d33413afae 100644 --- a/fpdfsdk/cpdfsdk_widget.h +++ b/fpdfsdk/cpdfsdk_widget.h @@ -130,8 +130,8 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { void ClearAppModified(); bool IsAppModified() const; - int32_t GetAppearanceAge() const; - int32_t GetValueAge() const; + uint32_t GetAppearanceAge() const { return m_nAppearanceAge; } + uint32_t GetValueAge() const { return m_nValueAge; } bool IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode); void DrawAppearance(CFX_RenderDevice* pDevice, @@ -149,8 +149,8 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { private: CFX_UnownedPtr const m_pInterForm; bool m_bAppModified; - int32_t m_nAppAge; - int32_t m_nValueAge; + uint32_t m_nAppearanceAge; + uint32_t m_nValueAge; #ifdef PDF_ENABLE_XFA mutable CFX_UnownedPtr m_hMixXFAWidget; diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index e59cd0520f..fd569c7201 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -361,8 +361,8 @@ CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, auto* pPrivateData = new CFFL_PrivateData; pPrivateData->pWidget = m_pWidget.Get(); pPrivateData->pPageView = pPageView; - pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge(); - pPrivateData->nValueAge = 0; + pPrivateData->nWidgetAppearanceAge = m_pWidget->GetAppearanceAge(); + pPrivateData->nWidgetValueAge = 0; cp.pAttachedData = pPrivateData; CPWL_Wnd* pNewWnd = NewPDFWindow(cp); m_Maps[pPageView] = pNewWnd; @@ -370,11 +370,11 @@ CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, } auto* pPrivateData = static_cast(pWnd->GetAttachedData()); - if (pPrivateData->nWidgetAge == m_pWidget->GetAppearanceAge()) + if (pPrivateData->nWidgetAppearanceAge == m_pWidget->GetAppearanceAge()) return pWnd; - return ResetPDFWindow(pPageView, - m_pWidget->GetValueAge() == pPrivateData->nValueAge); + return ResetPDFWindow( + pPageView, pPrivateData->nWidgetValueAge == m_pWidget->GetValueAge()); } void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index 425c2add35..989539fad3 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -122,7 +122,7 @@ void CFFL_InteractiveFormFiller::OnMouseEnter( if (pWidget->GetAAction(CPDF_AAction::CursorEnter).GetDict()) { m_bNotifying = true; - int nValueAge = pWidget->GetValueAge(); + uint32_t nValueAge = pWidget->GetValueAge(); pWidget->ClearAppModified(); ASSERT(pPageView); @@ -154,9 +154,8 @@ void CFFL_InteractiveFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Widget* pWidget = static_cast(pAnnot->Get()); if (pWidget->GetAAction(CPDF_AAction::CursorExit).GetDict()) { m_bNotifying = true; - pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + uint32_t nValueAge = pWidget->GetValueAge(); pWidget->ClearAppModified(); ASSERT(pPageView); @@ -191,9 +190,8 @@ bool CFFL_InteractiveFormFiller::OnLButtonDown( if (Annot_HitTest(pPageView, pAnnot->Get(), point) && pWidget->GetAAction(CPDF_AAction::ButtonDown).GetDict()) { m_bNotifying = true; - pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + uint32_t nValueAge = pWidget->GetValueAge(); pWidget->ClearAppModified(); ASSERT(pPageView); @@ -271,8 +269,8 @@ bool CFFL_InteractiveFormFiller::OnButtonUp(CPDFSDK_Annot::ObservedPtr* pAnnot, m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + uint32_t nAge = pWidget->GetAppearanceAge(); + uint32_t nValueAge = pWidget->GetValueAge(); ASSERT(pPageView); PDFSDK_FieldAction fa; @@ -376,9 +374,8 @@ bool CFFL_InteractiveFormFiller::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_Widget* pWidget = static_cast(pAnnot->Get()); if (pWidget->GetAAction(CPDF_AAction::GetFocus).GetDict()) { m_bNotifying = true; - pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + uint32_t nValueAge = pWidget->GetValueAge(); pWidget->ClearAppModified(); CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, true); @@ -718,8 +715,8 @@ bool CFFL_InteractiveFormFiller::OnClick(CPDFSDK_Annot::ObservedPtr* pAnnot, return false; m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + uint32_t nAge = pWidget->GetAppearanceAge(); + uint32_t nValueAge = pWidget->GetValueAge(); PDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); @@ -748,8 +745,8 @@ bool CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot, return false; m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + uint32_t nAge = pWidget->GetAppearanceAge(); + uint32_t nValueAge = pWidget->GetValueAge(); PDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); @@ -801,8 +798,8 @@ bool CFFL_InteractiveFormFiller::OnPreOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, return false; m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + uint32_t nAge = pWidget->GetAppearanceAge(); + uint32_t nValueAge = pWidget->GetValueAge(); PDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); @@ -832,8 +829,8 @@ bool CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, return false; m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + uint32_t nAge = pWidget->GetAppearanceAge(); + uint32_t nValueAge = pWidget->GetValueAge(); PDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); @@ -888,8 +885,8 @@ std::pair CFFL_InteractiveFormFiller::OnBeforeKeyStroke( CFX_AutoRestorer restorer(&m_bNotifying); m_bNotifying = true; - int nAge = privateData.pWidget->GetAppearanceAge(); - int nValueAge = privateData.pWidget->GetValueAge(); + uint32_t nAge = privateData.pWidget->GetAppearanceAge(); + uint32_t nValueAge = privateData.pWidget->GetValueAge(); CPDFSDK_FormFillEnvironment* pFormFillEnv = privateData.pPageView->GetFormFillEnv(); diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.h b/fpdfsdk/formfiller/cffl_interactiveformfiller.h index ddab2adcda..0982f1d92b 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.h +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.h @@ -157,8 +157,8 @@ class CFFL_PrivateData : public CPWL_Wnd::PrivateData { public: CPDFSDK_Widget* pWidget; CPDFSDK_PageView* pPageView; - int nWidgetAge; - int nValueAge; + uint32_t nWidgetAppearanceAge; + uint32_t nWidgetValueAge; }; #endif // FPDFSDK_FORMFILLER_CFFL_INTERACTIVEFORMFILLER_H_ -- cgit v1.2.3