From ce7df754b0608887a923d5083f0bbb999a735fce Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 11 Jan 2018 16:35:12 +0000 Subject: Rename CXFA_Box methods to make return clearer This CL renames the methods in CXFA_Box to make it clearer they can return nullptr. Change-Id: I521c0e06af306f69e390a4057cabb7777a0d72f5 Reviewed-on: https://pdfium-review.googlesource.com/22740 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- fxjs/xfa/cjx_object.cpp | 21 ++++++++++++++------- xfa/fwl/theme/cfwl_edittp.cpp | 2 +- xfa/fxfa/cxfa_ffcheckbutton.cpp | 2 +- xfa/fxfa/cxfa_fffield.cpp | 2 +- xfa/fxfa/cxfa_ffpushbutton.cpp | 6 ++++-- xfa/fxfa/cxfa_ffwidget.cpp | 35 ++++++++++++++++++++++------------- xfa/fxfa/parser/cxfa_box.cpp | 12 ++++++++---- xfa/fxfa/parser/cxfa_box.h | 8 ++++---- xfa/fxfa/parser/cxfa_edge.h | 2 ++ 9 files changed, 57 insertions(+), 33 deletions(-) diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index 8608cc0e8d..6408cf3eb9 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -1323,7 +1323,7 @@ void CJX_Object::Script_Som_FillColor(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { CXFA_Border* border = ToNode(object_.Get())->GetOrCreateBorderIfPossible(); - CXFA_Fill* borderfill = border->GetOrCreateFill(); + CXFA_Fill* borderfill = border->GetOrCreateFillIfPossible(); if (!borderfill) return; @@ -1358,13 +1358,17 @@ void CJX_Object::Script_Som_BorderColor(CFXJSE_Value* pValue, int32_t b = 0; std::tie(r, g, b) = StrToRGB(pValue->ToWideString()); FX_ARGB rgb = ArgbEncode(100, r, g, b); - for (int32_t i = 0; i < iSize; ++i) - border->GetEdge(i)->SetColor(rgb); + for (int32_t i = 0; i < iSize; ++i) { + CXFA_Edge* edge = border->GetEdgeIfExists(i); + if (edge) + edge->SetColor(rgb); + } return; } - FX_ARGB color = border->GetEdge(0)->GetColor(); + CXFA_Edge* edge = border->GetEdgeIfExists(0); + FX_ARGB color = edge ? edge->GetColor() : CXFA_Edge::kDefaultColor; int32_t a; int32_t r; int32_t g; @@ -1379,15 +1383,18 @@ void CJX_Object::Script_Som_BorderWidth(CFXJSE_Value* pValue, XFA_Attribute eAttribute) { CXFA_Border* border = ToNode(object_.Get())->GetOrCreateBorderIfPossible(); if (bSetting) { - CXFA_Measurement thickness = border->GetEdge(0)->GetMSThickness(); + CXFA_Edge* edge = border->GetEdgeIfExists(0); + CXFA_Measurement thickness = + edge ? edge->GetMSThickness() : CXFA_Measurement(0.5, XFA_Unit::Pt); pValue->SetString(thickness.ToString().UTF8Encode().AsStringView()); return; } WideString wsThickness = pValue->ToWideString(); for (int32_t i = 0; i < border->CountEdges(); ++i) { - border->GetEdge(i)->SetMSThickness( - CXFA_Measurement(wsThickness.AsStringView())); + CXFA_Edge* edge = border->GetEdgeIfExists(i); + if (edge) + edge->SetMSThickness(CXFA_Measurement(wsThickness.AsStringView())); } } diff --git a/xfa/fwl/theme/cfwl_edittp.cpp b/xfa/fwl/theme/cfwl_edittp.cpp index a1df805df0..599a4dda69 100644 --- a/xfa/fwl/theme/cfwl_edittp.cpp +++ b/xfa/fwl/theme/cfwl_edittp.cpp @@ -27,7 +27,7 @@ void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { FX_ARGB cr = 0xFF000000; float fWidth = 1.0f; if (borderUI) { - CXFA_Edge* edge = borderUI->GetEdge(0); + CXFA_Edge* edge = borderUI->GetEdgeIfExists(0); if (edge) { cr = edge->GetColor(); fWidth = edge->GetThickness(); diff --git a/xfa/fxfa/cxfa_ffcheckbutton.cpp b/xfa/fxfa/cxfa_ffcheckbutton.cpp index 2f79408e74..b50349f211 100644 --- a/xfa/fxfa/cxfa_ffcheckbutton.cpp +++ b/xfa/fxfa/cxfa_ffcheckbutton.cpp @@ -175,7 +175,7 @@ bool CXFA_FFCheckButton::PerformLayout() { m_rtCheckBox = m_rtUI; CXFA_Border* borderUI = m_pNode->GetWidgetAcc()->GetUIBorder(); if (borderUI) { - CXFA_Margin* borderMargin = borderUI->GetMargin(); + CXFA_Margin* borderMargin = borderUI->GetMarginIfExists(); if (borderMargin) XFA_RectWithoutMargin(m_rtUI, borderMargin); } diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index 53a81bdad9..b07d80f108 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -269,7 +269,7 @@ void CXFA_FFField::CapPlacement() { CXFA_Border* borderUI = m_pNode->GetWidgetAcc()->GetUIBorder(); if (borderUI) { - CXFA_Margin* borderMargin = borderUI->GetMargin(); + CXFA_Margin* borderMargin = borderUI->GetMarginIfExists(); if (borderMargin) XFA_RectWithoutMargin(m_rtUI, borderMargin); } diff --git a/xfa/fxfa/cxfa_ffpushbutton.cpp b/xfa/fxfa/cxfa_ffpushbutton.cpp index 779fada905..85805b4d76 100644 --- a/xfa/fxfa/cxfa_ffpushbutton.cpp +++ b/xfa/fxfa/cxfa_ffpushbutton.cpp @@ -121,8 +121,10 @@ bool CXFA_FFPushButton::PerformLayout() { float CXFA_FFPushButton::GetLineWidth() { CXFA_Border* border = m_pNode->GetBorderIfExists(); - if (border && border->GetPresence() == XFA_AttributeEnum::Visible) - return border->GetEdge(0)->GetThickness(); + if (border && border->GetPresence() == XFA_AttributeEnum::Visible) { + CXFA_Edge* edge = border->GetEdgeIfExists(0); + return edge ? edge->GetThickness() : 0; + } return 0; } diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index cff0697c82..e28aa4314e 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -250,7 +250,8 @@ void XFA_BOX_GetFillPath(CXFA_Box* box, CXFA_GEPath& fillPath, uint16_t dwFlags) { if (box->IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { - float fThickness = std::fmax(0.0, box->GetEdge(0)->GetThickness()); + CXFA_Edge* edge = box->GetEdgeIfExists(0); + float fThickness = std::fmax(0.0, edge ? edge->GetThickness() : 0); float fHalf = fThickness / 2; XFA_AttributeEnum iHand = box->GetHand(); if (iHand == XFA_AttributeEnum::Left) @@ -391,12 +392,13 @@ void XFA_BOX_GetFillPath(CXFA_Box* box, } } -void XFA_BOX_Fill_Radial(CXFA_Box* box, +void XFA_BOX_Fill_Radial(CXFA_Fill* fill, CXFA_Graphics* pGS, CXFA_GEPath& fillPath, CFX_RectF rtFill, const CFX_Matrix& matrix) { - CXFA_Fill* fill = box->GetFill(); + ASSERT(fill); + FX_ARGB crStart = fill->GetColor(false); FX_ARGB crEnd = fill->GetRadialColor(); if (!fill->IsRadialToEdge()) @@ -411,12 +413,13 @@ void XFA_BOX_Fill_Radial(CXFA_Box* box, pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); } -void XFA_BOX_Fill_Pattern(CXFA_Box* box, +void XFA_BOX_Fill_Pattern(CXFA_Fill* fill, CXFA_Graphics* pGS, CXFA_GEPath& fillPath, CFX_RectF rtFill, const CFX_Matrix& matrix) { - CXFA_Fill* fill = box->GetFill(); + ASSERT(fill); + FX_ARGB crStart = fill->GetColor(false); FX_ARGB crEnd = fill->GetPatternColor(); FX_HatchStyle iHatch = FX_HatchStyle::Cross; @@ -445,12 +448,13 @@ void XFA_BOX_Fill_Pattern(CXFA_Box* box, pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); } -void XFA_BOX_Fill_Linear(CXFA_Box* box, +void XFA_BOX_Fill_Linear(CXFA_Fill* fill, CXFA_Graphics* pGS, CXFA_GEPath& fillPath, CFX_RectF rtFill, const CFX_Matrix& matrix) { - CXFA_Fill* fill = box->GetFill(); + ASSERT(fill); + FX_ARGB crStart = fill->GetColor(false); FX_ARGB crEnd = fill->GetLinearColor(); @@ -488,7 +492,7 @@ void XFA_BOX_Fill(CXFA_Box* box, const CFX_RectF& rtWidget, const CFX_Matrix& matrix, uint32_t dwFlags) { - CXFA_Fill* fill = box->GetFill(); + CXFA_Fill* fill = box->GetFillIfExists(); if (!fill || !fill->IsVisible()) return; @@ -500,13 +504,13 @@ void XFA_BOX_Fill(CXFA_Box* box, XFA_Element eType = fill->GetFillType(); switch (eType) { case XFA_Element::Radial: - XFA_BOX_Fill_Radial(box, pGS, fillPath, rtWidget, matrix); + XFA_BOX_Fill_Radial(fill, pGS, fillPath, rtWidget, matrix); break; case XFA_Element::Pattern: - XFA_BOX_Fill_Pattern(box, pGS, fillPath, rtWidget, matrix); + XFA_BOX_Fill_Pattern(fill, pGS, fillPath, rtWidget, matrix); break; case XFA_Element::Linear: - XFA_BOX_Fill_Linear(box, pGS, fillPath, rtWidget, matrix); + XFA_BOX_Fill_Linear(fill, pGS, fillPath, rtWidget, matrix); break; default: { FX_ARGB cr; @@ -559,7 +563,7 @@ void XFA_BOX_StrokeArc(CXFA_Box* box, CFX_RectF rtWidget, const CFX_Matrix& matrix, uint32_t dwFlags) { - CXFA_Edge* edge = box->GetEdge(0); + CXFA_Edge* edge = box->GetEdgeIfExists(0); if (!edge || !edge->IsVisible()) return; @@ -987,7 +991,7 @@ void CXFA_FFWidget::RenderWidget(CXFA_Graphics* pGS, return; CFX_RectF rtBorder = GetRectWithoutRotate(); - CXFA_Margin* margin = border->GetMargin(); + CXFA_Margin* margin = border->GetMarginIfExists(); if (margin) XFA_RectWithoutMargin(rtBorder, margin); @@ -998,18 +1002,23 @@ void CXFA_FFWidget::RenderWidget(CXFA_Graphics* pGS, bool CXFA_FFWidget::IsLoaded() { return !!m_pPageView; } + bool CXFA_FFWidget::LoadWidget() { PerformLayout(); return true; } + void CXFA_FFWidget::UnloadWidget() {} + bool CXFA_FFWidget::PerformLayout() { RecacheWidgetRect(); return true; } + bool CXFA_FFWidget::UpdateFWLData() { return false; } + void CXFA_FFWidget::UpdateWidgetProperty() {} void CXFA_FFWidget::DrawBorder(CXFA_Graphics* pGS, diff --git a/xfa/fxfa/parser/cxfa_box.cpp b/xfa/fxfa/parser/cxfa_box.cpp index 443362f449..5f8bed9aa1 100644 --- a/xfa/fxfa/parser/cxfa_box.cpp +++ b/xfa/fxfa/parser/cxfa_box.cpp @@ -81,7 +81,7 @@ int32_t CXFA_Box::CountEdges() { return CountChildren(XFA_Element::Edge, false); } -CXFA_Edge* CXFA_Box::GetEdge(int32_t nIndex) { +CXFA_Edge* CXFA_Box::GetEdgeIfExists(int32_t nIndex) { if (nIndex == 0) return JSObject()->GetOrCreateProperty(nIndex, XFA_Element::Edge); @@ -104,15 +104,15 @@ Optional CXFA_Box::GetSweepAngle() { return JSObject()->TryInteger(XFA_Attribute::SweepAngle, false); } -CXFA_Fill* CXFA_Box::GetFill() const { +CXFA_Fill* CXFA_Box::GetFillIfExists() const { return JSObject()->GetProperty(0, XFA_Element::Fill); } -CXFA_Fill* CXFA_Box::GetOrCreateFill() { +CXFA_Fill* CXFA_Box::GetOrCreateFillIfPossible() { return JSObject()->GetOrCreateProperty(0, XFA_Element::Fill); } -CXFA_Margin* CXFA_Box::GetMargin() { +CXFA_Margin* CXFA_Box::GetMarginIfExists() { return GetChild(0, XFA_Element::Margin, false); } @@ -144,6 +144,8 @@ std::vector CXFA_Box::GetStrokesInternal(bool bNull) { corner = JSObject()->GetProperty(i, XFA_Element::Corner); } + // TODO(dsinclair): If i == 0 and GetOrCreateProperty failed, we can end up + // with a null corner in the first position. if (corner || i == 0) { strokes[j] = corner; } else if (!bNull) { @@ -160,6 +162,8 @@ std::vector CXFA_Box::GetStrokesInternal(bool bNull) { else edge = JSObject()->GetProperty(i, XFA_Element::Edge); + // TODO(dsinclair): If i == 0 and GetOrCreateProperty failed, we can end up + // with a null edge in the first position. if (edge || i == 0) { strokes[j] = edge; } else if (!bNull) { diff --git a/xfa/fxfa/parser/cxfa_box.h b/xfa/fxfa/parser/cxfa_box.h index c85d0164af..216a981c83 100644 --- a/xfa/fxfa/parser/cxfa_box.h +++ b/xfa/fxfa/parser/cxfa_box.h @@ -30,10 +30,10 @@ class CXFA_Box : public CXFA_Node { std::tuple Get3DStyle(); int32_t CountEdges(); - CXFA_Edge* GetEdge(int32_t nIndex); - CXFA_Fill* GetFill() const; - CXFA_Fill* GetOrCreateFill(); - CXFA_Margin* GetMargin(); + CXFA_Edge* GetEdgeIfExists(int32_t nIndex); + CXFA_Fill* GetFillIfExists() const; + CXFA_Fill* GetOrCreateFillIfPossible(); + CXFA_Margin* GetMarginIfExists(); std::vector GetStrokes(); diff --git a/xfa/fxfa/parser/cxfa_edge.h b/xfa/fxfa/parser/cxfa_edge.h index 8bf9f6ea28..36fee55624 100644 --- a/xfa/fxfa/parser/cxfa_edge.h +++ b/xfa/fxfa/parser/cxfa_edge.h @@ -11,6 +11,8 @@ class CXFA_Edge : public CXFA_Stroke { public: + static constexpr FX_ARGB kDefaultColor = 0xFF000000; + CXFA_Edge(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Edge() override; }; -- cgit v1.2.3