From 1e6490da6fb813930d1073ac05ace8a21fa9ca28 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 10 Jan 2018 19:34:57 +0000 Subject: Rename GetCaption to GetCaptionIfExists This CL renames GetCaption to GetCaptionIfExists to make it clear the value returned can be a nullptr. The various callsites have been fixed which used the caption without validating. Change-Id: I9b600ac9ab5b9e04dfa6e8cee95ef3e9d629688d Reviewed-on: https://pdfium-review.googlesource.com/22670 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/cxfa_widgetacc.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'xfa/fxfa/cxfa_widgetacc.cpp') diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 0c55bd6ce6..222de47e89 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -122,7 +122,7 @@ class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { bool LoadCaption(CXFA_FFDoc* doc, CXFA_WidgetAcc* pAcc) { if (m_pCapTextLayout) return true; - CXFA_Caption* caption = pAcc->GetNode()->GetCaption(); + CXFA_Caption* caption = pAcc->GetNode()->GetCaptionIfExists(); if (!caption || caption->IsHidden()) return false; @@ -484,7 +484,7 @@ void CXFA_WidgetAcc::UpdateUIDisplay(CXFA_FFDocView* docView, } void CXFA_WidgetAcc::CalcCaptionSize(CXFA_FFDoc* doc, CFX_SizeF& szCap) { - CXFA_Caption* caption = m_pNode->GetCaption(); + CXFA_Caption* caption = m_pNode->GetCaptionIfExists(); if (!caption || !caption->IsVisible()) return; @@ -550,7 +550,10 @@ bool CXFA_WidgetAcc::CalculateFieldAutoSize(CXFA_FFDoc* doc, CFX_SizeF& size) { size.width += rtUIMargin.left + rtUIMargin.width; size.height += rtUIMargin.top + rtUIMargin.height; if (szCap.width > 0 && szCap.height > 0) { - switch (m_pNode->GetCaption()->GetPlacementType()) { + CXFA_Caption* caption = m_pNode->GetCaptionIfExists(); + XFA_AttributeEnum placement = + caption ? caption->GetPlacementType() : XFA_AttributeEnum::Left; + switch (placement) { case XFA_AttributeEnum::Left: case XFA_AttributeEnum::Right: case XFA_AttributeEnum::Inline: { @@ -651,7 +654,9 @@ bool CXFA_WidgetAcc::CalculateTextEditAutoSize(CXFA_FFDoc* doc, bool bCapExit = szCap.width > 0.01 && szCap.height > 0.01; XFA_AttributeEnum iCapPlacement = XFA_AttributeEnum::Unknown; if (bCapExit) { - iCapPlacement = m_pNode->GetCaption()->GetPlacementType(); + CXFA_Caption* caption = m_pNode->GetCaptionIfExists(); + iCapPlacement = + caption ? caption->GetPlacementType() : XFA_AttributeEnum::Left; switch (iCapPlacement) { case XFA_AttributeEnum::Left: case XFA_AttributeEnum::Right: @@ -985,7 +990,7 @@ bool CXFA_WidgetAcc::FindSplitPos(CXFA_FFDocView* docView, XFA_AttributeEnum iCapPlacement = XFA_AttributeEnum::Unknown; float fCapReserve = 0; if (iBlockIndex == 0) { - CXFA_Caption* caption = m_pNode->GetCaption(); + CXFA_Caption* caption = m_pNode->GetCaptionIfExists(); if (caption && !caption->IsHidden()) { iCapPlacement = caption->GetPlacementType(); fCapReserve = caption->GetReserve(); -- cgit v1.2.3