From 4f261fffddddd97602e88fe462fef1a18a0b4782 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 10 Oct 2018 18:44:45 +0000 Subject: Get rid of non-const ref parameter in CPDFSDK_InterForm::OnFormat(). Return Optional instead. Change the call stack to accept Optional. Change-Id: I020589fac8a1de4974070268a19b4acad64c4092 Reviewed-on: https://pdfium-review.googlesource.com/c/43601 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- fpdfsdk/pwl/cpwl_appstream.cpp | 21 +++++++++------------ fpdfsdk/pwl/cpwl_appstream.h | 9 +++++---- 2 files changed, 14 insertions(+), 16 deletions(-) (limited to 'fpdfsdk/pwl') diff --git a/fpdfsdk/pwl/cpwl_appstream.cpp b/fpdfsdk/pwl/cpwl_appstream.cpp index 8ced563161..d2ffd2a9b1 100644 --- a/fpdfsdk/pwl/cpwl_appstream.cpp +++ b/fpdfsdk/pwl/cpwl_appstream.cpp @@ -1580,7 +1580,7 @@ void CPWL_AppStream::SetAsRadioButton() { widget_->SetAppState("Off"); } -void CPWL_AppStream::SetAsComboBox(const WideString* sValue) { +void CPWL_AppStream::SetAsComboBox(Optional sValue) { CPDF_FormControl* pControl = widget_->GetFormControl(); CPDF_FormField* pField = pControl->GetField(); std::ostringstream sBody; @@ -1614,8 +1614,8 @@ void CPWL_AppStream::SetAsComboBox(const WideString* sValue) { pEdit->Initialize(); - if (sValue) { - pEdit->SetText(*sValue); + if (sValue.has_value()) { + pEdit->SetText(sValue.value()); } else { int32_t nCurSel = pField->GetSelectedIndex(0); if (nCurSel < 0) @@ -1736,7 +1736,7 @@ void CPWL_AppStream::SetAsListBox() { ""); } -void CPWL_AppStream::SetAsTextField(const WideString* sValue) { +void CPWL_AppStream::SetAsTextField(Optional sValue) { CPDF_FormControl* pControl = widget_->GetFormControl(); CPDF_FormField* pField = pControl->GetField(); std::ostringstream sBody; @@ -1775,11 +1775,8 @@ void CPWL_AppStream::SetAsTextField(const WideString* sValue) { float fFontSize = widget_->GetFontSize(); #ifdef PDF_ENABLE_XFA - WideString sValueTmp; - if (!sValue && widget_->GetMixXFAWidget()) { - sValueTmp = widget_->GetValue(); - sValue = &sValueTmp; - } + if (!sValue.has_value() && widget_->GetMixXFAWidget()) + sValue = widget_->GetValue(); #endif // PDF_ENABLE_XFA if (nMaxLen > 0) { @@ -1791,8 +1788,8 @@ void CPWL_AppStream::SetAsTextField(const WideString* sValue) { rcClient, nMaxLen); } } else { - if (sValue) - nMaxLen = sValue->GetLength(); + if (sValue.has_value()) + nMaxLen = sValue.value().GetLength(); pEdit->SetLimitChar(nMaxLen); } } @@ -1803,7 +1800,7 @@ void CPWL_AppStream::SetAsTextField(const WideString* sValue) { pEdit->SetFontSize(fFontSize); pEdit->Initialize(); - pEdit->SetText(sValue ? *sValue : pField->GetValue()); + pEdit->SetText(sValue.value_or(pField->GetValue())); CFX_FloatRect rcContent = pEdit->GetContentRect(); ByteString sEdit = diff --git a/fpdfsdk/pwl/cpwl_appstream.h b/fpdfsdk/pwl/cpwl_appstream.h index 810e79c9e7..1c3afab592 100644 --- a/fpdfsdk/pwl/cpwl_appstream.h +++ b/fpdfsdk/pwl/cpwl_appstream.h @@ -9,6 +9,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/unowned_ptr.h" +#include "third_party/base/optional.h" class CPDFSDK_Widget; class CPDF_Dictionary; @@ -22,9 +23,9 @@ class CPWL_AppStream { void SetAsPushButton(); void SetAsCheckBox(); void SetAsRadioButton(); - void SetAsComboBox(const WideString* sValue); + void SetAsComboBox(Optional sValue); void SetAsListBox(); - void SetAsTextField(const WideString* sValue); + void SetAsTextField(Optional sValue); private: void AddImage(const ByteString& sAPType, CPDF_Stream* pImage); @@ -36,8 +37,8 @@ class CPWL_AppStream { ByteString GetBackgroundAppStream() const; ByteString GetBorderAppStream() const; - UnownedPtr widget_; - UnownedPtr dict_; + UnownedPtr const widget_; + UnownedPtr const dict_; }; #endif // FPDFSDK_PWL_CPWL_APPSTREAM_H_ -- cgit v1.2.3