diff options
author | Lei Zhang <thestig@chromium.org> | 2017-06-15 12:37:33 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-15 20:42:01 +0000 |
commit | 77e3fc5cebfb19aed09f920536200e017cff9a0b (patch) | |
tree | 64700810faf138812cdcf7573a9caff08fb0411b /fpdfsdk/formfiller/cffl_textfield.cpp | |
parent | b7384b5b997975c36bb37d25c63e2c900eca41f9 (diff) | |
download | pdfium-77e3fc5cebfb19aed09f920536200e017cff9a0b.tar.xz |
Change some CFFL classes to use early returns.chromium/3132
Also switch C-style casts to the appropriate C++ casts, and add helper
functions in some cases.
Change-Id: I73f1ab36c6c89ced9d2b7b98393805142661dcac
Reviewed-on: https://pdfium-review.googlesource.com/6650
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/formfiller/cffl_textfield.cpp')
-rw-r--r-- | fpdfsdk/formfiller/cffl_textfield.cpp | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index c34bf3e54e..da8c14d0ff 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -97,26 +97,28 @@ bool CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) { switch (nChar) { - case FWL_VKEY_Return: - if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { - CPDFSDK_PageView* pPageView = GetCurPageView(true); - ASSERT(pPageView); - m_bValid = !m_bValid; - m_pFormFillEnv->Invalidate(pAnnot->GetUnderlyingPage(), - pAnnot->GetRect().ToFxRect()); - - if (m_bValid) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) - pWnd->SetFocus(); - } else { - if (CommitData(pPageView, nFlags)) { - DestroyPDFWindow(pPageView); - return true; - } - return false; - } + case FWL_VKEY_Return: { + if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE) + break; + + CPDFSDK_PageView* pPageView = GetCurPageView(true); + ASSERT(pPageView); + m_bValid = !m_bValid; + m_pFormFillEnv->Invalidate(pAnnot->GetUnderlyingPage(), + pAnnot->GetRect().ToFxRect()); + + if (m_bValid) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) + pWnd->SetFocus(); + break; } - break; + + if (!CommitData(pPageView, nFlags)) + return false; + + DestroyPDFWindow(pPageView); + return true; + } case FWL_VKEY_Escape: { CPDFSDK_PageView* pPageView = GetCurPageView(true); ASSERT(pPageView); @@ -129,22 +131,22 @@ bool CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, } bool CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) - return pEdit->GetText() != m_pWidget->GetValue(); - - return false; + CPWL_Edit* pEdit = GetEdit(pPageView, false); + return pEdit && pEdit->GetText() != m_pWidget->GetValue(); } void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { - CFX_WideString sOldValue = m_pWidget->GetValue(); - CFX_WideString sNewValue = pWnd->GetText(); - - m_pWidget->SetValue(sNewValue, false); - m_pWidget->ResetFieldAppearance(true); - m_pWidget->UpdateField(); - SetChangeMark(); - } + CPWL_Edit* pWnd = GetEdit(pPageView, false); + if (!pWnd) + return; + + CFX_WideString sOldValue = m_pWidget->GetValue(); + CFX_WideString sNewValue = pWnd->GetText(); + + m_pWidget->SetValue(sNewValue, false); + m_pWidget->ResetFieldAppearance(true); + m_pWidget->UpdateField(); + SetChangeMark(); } void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, @@ -152,7 +154,7 @@ void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, PDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::KeyStroke: - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { + if (CPWL_Edit* pWnd = GetEdit(pPageView, false)) { fa.bFieldFull = pWnd->IsTextFull(); fa.sValue = pWnd->GetText(); @@ -164,7 +166,7 @@ void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, } break; case CPDF_AAction::Validate: - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { + if (CPWL_Edit* pWnd = GetEdit(pPageView, false)) { fa.sValue = pWnd->GetText(); } break; @@ -182,7 +184,7 @@ void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, const PDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::KeyStroke: - if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { + if (CPWL_Edit* pEdit = GetEdit(pPageView, false)) { pEdit->SetFocus(); pEdit->SetSel(fa.nSelStart, fa.nSelEnd); pEdit->ReplaceSel(fa.sChange); @@ -211,19 +213,23 @@ bool CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) { ASSERT(pPageView); - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { - pWnd->GetSel(m_State.nStart, m_State.nEnd); - m_State.sValue = pWnd->GetText(); - } + CPWL_Edit* pWnd = GetEdit(pPageView, false); + if (!pWnd) + return; + + pWnd->GetSel(m_State.nStart, m_State.nEnd); + m_State.sValue = pWnd->GetText(); } void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) { ASSERT(pPageView); - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, true)) { - pWnd->SetText(m_State.sValue); - pWnd->SetSel(m_State.nStart, m_State.nEnd); - } + CPWL_Edit* pWnd = GetEdit(pPageView, true); + if (!pWnd) + return; + + pWnd->SetText(m_State.sValue); + pWnd->SetSel(m_State.nStart, m_State.nEnd); } CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, @@ -235,25 +241,17 @@ CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, CPWL_Wnd* pRet = nullptr; - if (bRestoreValue) { + if (bRestoreValue) RestoreState(pPageView); - pRet = GetPDFWindow(pPageView, false); - } else { - pRet = GetPDFWindow(pPageView, true); - } - + pRet = GetPDFWindow(pPageView, !bRestoreValue); m_pWidget->UpdateField(); - return pRet; } #ifdef PDF_ENABLE_XFA bool CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { - return pWnd->IsTextFull(); - } - - return false; + CPWL_Edit* pWnd = GetEdit(pPageView, false); + return pWnd && pWnd->IsTextFull(); } #endif // PDF_ENABLE_XFA @@ -271,3 +269,7 @@ void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { auto* pBuffer = reinterpret_cast<const unsigned short*>(bsUTFText.c_str()); m_pFormFillEnv->OnSetFieldInputFocus(pBuffer, nCharacters, true); } + +CPWL_Edit* CFFL_TextField::GetEdit(CPDFSDK_PageView* pPageView, bool bNew) { + return static_cast<CPWL_Edit*>(GetPDFWindow(pPageView, bNew)); +} |