summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-10 18:39:14 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-10 18:39:14 +0000
commitb353f8c32b2d17cbea5ace6eb5f7edb8663e37be (patch)
treead10260cd60754e1b9aa521db6a524b48462b5e9
parent461acb276e1c38c9ebb3546c5b3254fa5cf9c585 (diff)
downloadpdfium-b353f8c32b2d17cbea5ace6eb5f7edb8663e37be.tar.xz
Use pdfium::Optional in CPDFSDK_Widget.
Also make some methods const. Change-Id: Ie2d0f7e691ad9448b4e77227ce3c0b2b065e0da0 Reviewed-on: https://pdfium-review.googlesource.com/c/43602 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp32
-rw-r--r--fpdfsdk/cpdfsdk_widget.h11
-rw-r--r--fpdfsdk/formfiller/cffl_formfiller.cpp16
3 files changed, 34 insertions, 25 deletions
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index 70ad592f6f..c2a4754edc 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -72,7 +72,7 @@ CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
return nullptr;
}
-CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
+CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() const {
CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
if (pContext->GetFormType() != FormType::kXFAForeground)
return nullptr;
@@ -173,7 +173,7 @@ static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
return eEventType;
}
-bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
+bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const {
CXFA_FFWidget* hWidget = GetMixXFAWidget();
if (!hWidget)
return false;
@@ -398,31 +398,37 @@ WideString CPDFSDK_Widget::GetName() const {
}
#endif // PDF_ENABLE_XFA
-bool CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
+Optional<FX_COLORREF> CPDFSDK_Widget::GetFillColor() const {
CPDF_FormControl* pFormCtrl = GetFormControl();
int iColorType = 0;
- color = ArgbToColorRef(pFormCtrl->GetBackgroundColor(iColorType));
- return iColorType != CFX_Color::kTransparent;
+ FX_COLORREF color = ArgbToColorRef(pFormCtrl->GetBackgroundColor(iColorType));
+ if (iColorType == CFX_Color::kTransparent)
+ return {};
+ return color;
}
-bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
+Optional<FX_COLORREF> CPDFSDK_Widget::GetBorderColor() const {
CPDF_FormControl* pFormCtrl = GetFormControl();
int iColorType = 0;
- color = ArgbToColorRef(pFormCtrl->GetBorderColor(iColorType));
- return iColorType != CFX_Color::kTransparent;
+ FX_COLORREF color = ArgbToColorRef(pFormCtrl->GetBorderColor(iColorType));
+ if (iColorType == CFX_Color::kTransparent)
+ return {};
+ return color;
}
-bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
+Optional<FX_COLORREF> CPDFSDK_Widget::GetTextColor() const {
CPDF_FormControl* pFormCtrl = GetFormControl();
CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
FX_ARGB argb;
Optional<CFX_Color::Type> iColorType;
std::tie(iColorType, argb) = da.GetColor();
- if (!iColorType)
- return false;
+ if (!iColorType.has_value())
+ return {};
- color = ArgbToColorRef(argb);
- return *iColorType != CFX_Color::kTransparent;
+ FX_COLORREF color = ArgbToColorRef(argb);
+ if (iColorType.value() == CFX_Color::kTransparent)
+ return {};
+ return color;
}
float CPDFSDK_Widget::GetFontSize() const {
diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h
index 6ccfdfd31f..fb83ceb555 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -17,6 +17,7 @@
#include "core/fxge/cfx_color.h"
#include "fpdfsdk/cpdfsdk_baannot.h"
#include "fpdfsdk/cpdfsdk_fieldaction.h"
+#include "third_party/base/optional.h"
class CFX_RenderDevice;
class CPDF_Annot;
@@ -39,7 +40,7 @@ class CPDFSDK_Widget final : public CPDFSDK_BAAnnot {
CXFA_FFWidget* GetMixXFAWidget() const;
CXFA_FFWidgetHandler* GetXFAWidgetHandler() const;
- bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT);
+ bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const;
bool OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
CPDFSDK_FieldAction* data,
CPDFSDK_PageView* pPageView);
@@ -62,9 +63,9 @@ class CPDFSDK_Widget final : public CPDFSDK_BAAnnot {
int GetFieldFlags() const;
int GetRotate() const;
- bool GetFillColor(FX_COLORREF& color) const;
- bool GetBorderColor(FX_COLORREF& color) const;
- bool GetTextColor(FX_COLORREF& color) const;
+ Optional<FX_COLORREF> GetFillColor() const;
+ Optional<FX_COLORREF> GetBorderColor() const;
+ Optional<FX_COLORREF> GetTextColor() const;
float GetFontSize() const;
int GetSelectedIndex(int nIndex) const;
@@ -127,7 +128,7 @@ class CPDFSDK_Widget final : public CPDFSDK_BAAnnot {
private:
#ifdef PDF_ENABLE_XFA
- CXFA_FFWidget* GetGroupMixXFAWidget();
+ CXFA_FFWidget* GetGroupMixXFAWidget() const;
WideString GetName() const;
#endif // PDF_ENABLE_XFA
diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp
index 4b94bde271..94d80cae01 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_formfiller.cpp
@@ -340,16 +340,18 @@ CPWL_Wnd::CreateParams CFFL_FormFiller::GetCreateParam() {
if (dwFieldFlag & FIELDFLAG_READONLY)
dwCreateFlags |= PWS_READONLY;
- FX_COLORREF color;
- if (m_pWidget->GetFillColor(color))
- cp.sBackgroundColor = CFX_Color(color);
- if (m_pWidget->GetBorderColor(color))
- cp.sBorderColor = CFX_Color(color);
+ Optional<FX_COLORREF> color = m_pWidget->GetFillColor();
+ if (color.has_value())
+ cp.sBackgroundColor = CFX_Color(color.value());
+ color = m_pWidget->GetBorderColor();
+ if (color.has_value())
+ cp.sBorderColor = CFX_Color(color.value());
cp.sTextColor = CFX_Color(CFX_Color::kGray, 0);
- if (m_pWidget->GetTextColor(color))
- cp.sTextColor = CFX_Color(color);
+ color = m_pWidget->GetTextColor();
+ if (color.has_value())
+ cp.sTextColor = CFX_Color(color.value());
cp.fFontSize = m_pWidget->GetFontSize();
cp.dwBorderWidth = m_pWidget->GetBorderWidth();