Rename CXFA_Value methods for clarity

This CL marks the methods in CXFA_Value to make it clear which can
return nullptr and updates callsites as needed.

Change-Id: If1f794bcbbddaa57a1efdd67195df58a77b4373a
Reviewed-on: https://pdfium-review.googlesource.com/22773
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/xfa/fxfa/cxfa_ffarc.cpp b/xfa/fxfa/cxfa_ffarc.cpp
index a738221..64a4f70 100644
--- a/xfa/fxfa/cxfa_ffarc.cpp
+++ b/xfa/fxfa/cxfa_ffarc.cpp
@@ -31,5 +31,5 @@
   CFX_Matrix mtRotate = GetRotateMatrix();
   mtRotate.Concat(matrix);
 
-  DrawBorder(pGS, value->GetArc(), rtArc, mtRotate);
+  DrawBorder(pGS, value->GetArcIfExists(), rtArc, mtRotate);
 }
diff --git a/xfa/fxfa/cxfa_ffimage.cpp b/xfa/fxfa/cxfa_ffimage.cpp
index 3a5a63a..b4a0d32 100644
--- a/xfa/fxfa/cxfa_ffimage.cpp
+++ b/xfa/fxfa/cxfa_ffimage.cpp
@@ -70,8 +70,11 @@
   int32_t iImageXDpi = 0;
   int32_t iImageYDpi = 0;
   m_pNode->GetWidgetAcc()->GetImageDpi(iImageXDpi, iImageYDpi);
+
   auto* value = m_pNode->GetFormValueIfExists();
-  CXFA_Image* image = value ? value->GetImage() : nullptr;
-  XFA_DrawImage(pGS, rtImage, mtRotate, pDIBitmap, image->GetAspect(),
-                iImageXDpi, iImageYDpi, iHorzAlign, iVertAlign);
+  CXFA_Image* image = value ? value->GetImageIfExists() : nullptr;
+  if (image) {
+    XFA_DrawImage(pGS, rtImage, mtRotate, pDIBitmap, image->GetAspect(),
+                  iImageXDpi, iImageYDpi, iHorzAlign, iVertAlign);
+  }
 }
diff --git a/xfa/fxfa/cxfa_ffimageedit.cpp b/xfa/fxfa/cxfa_ffimageedit.cpp
index 15a8dc3..681370e 100644
--- a/xfa/fxfa/cxfa_ffimageedit.cpp
+++ b/xfa/fxfa/cxfa_ffimageedit.cpp
@@ -84,7 +84,7 @@
   XFA_AttributeEnum iAspect = XFA_AttributeEnum::Fit;
   CXFA_Value* value = m_pNode->GetFormValueIfExists();
   if (value) {
-    CXFA_Image* image = value->GetImage();
+    CXFA_Image* image = value->GetImageIfExists();
     if (image)
       iAspect = image->GetAspect();
   }
diff --git a/xfa/fxfa/cxfa_ffline.cpp b/xfa/fxfa/cxfa_ffline.cpp
index cdaca4a..4937a0e 100644
--- a/xfa/fxfa/cxfa_ffline.cpp
+++ b/xfa/fxfa/cxfa_ffline.cpp
@@ -91,20 +91,23 @@
   if (!value)
     return;
 
-  CXFA_Line* line = value->GetLine();
   FX_ARGB lineColor = 0xFF000000;
   float fLineWidth = 1.0f;
   XFA_AttributeEnum iStrokeType = XFA_AttributeEnum::Unknown;
   XFA_AttributeEnum iCap = XFA_AttributeEnum::Unknown;
-  CXFA_Edge* edge = line->GetEdgeIfExists();
-  if (edge && !edge->IsVisible())
-    return;
 
-  if (edge) {
-    lineColor = edge->GetColor();
-    iStrokeType = edge->GetStrokeType();
-    fLineWidth = edge->GetThickness();
-    iCap = edge->GetCapType();
+  CXFA_Line* line = value->GetLineIfExists();
+  if (line) {
+    CXFA_Edge* edge = line->GetEdgeIfExists();
+    if (edge && !edge->IsVisible())
+      return;
+
+    if (edge) {
+      lineColor = edge->GetColor();
+      iStrokeType = edge->GetStrokeType();
+      fLineWidth = edge->GetThickness();
+      iCap = edge->GetCapType();
+    }
   }
 
   CFX_Matrix mtRotate = GetRotateMatrix();
@@ -115,12 +118,15 @@
   if (margin)
     XFA_RectWithoutMargin(rtLine, margin);
 
-  GetRectFromHand(rtLine, line->GetHand(), fLineWidth);
+  GetRectFromHand(rtLine, line ? line->GetHand() : XFA_AttributeEnum::Left,
+                  fLineWidth);
   CXFA_GEPath linePath;
-  if (line->GetSlope() && rtLine.right() > 0.0f && rtLine.bottom() > 0.0f)
+  if (line && line->GetSlope() && rtLine.right() > 0.0f &&
+      rtLine.bottom() > 0.0f) {
     linePath.AddLine(rtLine.TopRight(), rtLine.BottomLeft());
-  else
+  } else {
     linePath.AddLine(rtLine.TopLeft(), rtLine.BottomRight());
+  }
 
   pGS->SaveGraphState();
   pGS->SetLineWidth(fLineWidth);
diff --git a/xfa/fxfa/cxfa_ffrectangle.cpp b/xfa/fxfa/cxfa_ffrectangle.cpp
index b3dd6f4..46c1009 100644
--- a/xfa/fxfa/cxfa_ffrectangle.cpp
+++ b/xfa/fxfa/cxfa_ffrectangle.cpp
@@ -31,5 +31,5 @@
   CFX_Matrix mtRotate = GetRotateMatrix();
   mtRotate.Concat(matrix);
 
-  DrawBorder(pGS, value->GetRectangle(), rect, mtRotate);
+  DrawBorder(pGS, value->GetRectangleIfExists(), rect, mtRotate);
 }
diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp
index d61d898..407517f 100644
--- a/xfa/fxfa/cxfa_widgetacc.cpp
+++ b/xfa/fxfa/cxfa_widgetacc.cpp
@@ -99,7 +99,7 @@
     if (!value)
       return false;
 
-    CXFA_Image* image = value->GetImage();
+    CXFA_Image* image = value->GetImageIfExists();
     if (!image)
       return false;
 
@@ -156,7 +156,10 @@
     if (!value)
       return false;
 
-    CXFA_Image* image = value->GetImage();
+    CXFA_Image* image = value->GetImageIfExists();
+    if (!image)
+      return false;
+
     pAcc->SetImageEditImage(XFA_LoadImageData(doc, image, m_bNamedImage,
                                               m_iImageXDpi, m_iImageYDpi));
     return !!m_pDIBitmap;
@@ -376,7 +379,7 @@
   switch (eUIType) {
     case XFA_Element::ImageEdit: {
       CXFA_Value* imageValue = m_pNode->GetDefaultValueIfExists();
-      CXFA_Image* image = imageValue ? imageValue->GetImage() : nullptr;
+      CXFA_Image* image = imageValue ? imageValue->GetImageIfExists() : nullptr;
       WideString wsContentType, wsHref;
       if (image) {
         wsValue = image->GetContent();
@@ -440,7 +443,7 @@
                                   const WideString& wsHref,
                                   const WideString& wsData) {
   CXFA_Value* formValue = m_pNode->GetFormValueIfExists();
-  CXFA_Image* image = formValue ? formValue->GetImage() : nullptr;
+  CXFA_Image* image = formValue ? formValue->GetImageIfExists() : nullptr;
   if (image) {
     image->SetContentType(WideString(wsContentType));
     image->SetHref(wsHref);
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index a9c4a69..7797be3 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1940,7 +1940,7 @@
     if (caption) {
       CXFA_Value* capValue = caption->GetValueIfExists();
       if (capValue) {
-        CXFA_Text* captionText = capValue->GetText();
+        CXFA_Text* captionText = capValue->GetTextIfExists();
         if (captionText)
           wsCaptionName = captionText->GetContent();
       }
diff --git a/xfa/fxfa/parser/cxfa_value.cpp b/xfa/fxfa/parser/cxfa_value.cpp
index dc93bba..7a952f7 100644
--- a/xfa/fxfa/parser/cxfa_value.cpp
+++ b/xfa/fxfa/parser/cxfa_value.cpp
@@ -63,31 +63,41 @@
 
 WideString CXFA_Value::GetChildValueContent() const {
   CXFA_Node* pNode = GetFirstChild();
-  if (!pNode)
-    return L"";
-  return pNode->JSObject()->TryContent(false, true).value_or(L"");
+  return pNode ? pNode->JSObject()->TryContent(false, true).value_or(L"") : L"";
 }
 
-CXFA_Arc* CXFA_Value::GetArc() const {
-  return static_cast<CXFA_Arc*>(GetFirstChild());
+CXFA_Arc* CXFA_Value::GetArcIfExists() const {
+  CXFA_Node* node = GetFirstChild();
+  ASSERT(!node || node->GetElementType() == XFA_Element::Arc);
+  return static_cast<CXFA_Arc*>(node);
 }
 
-CXFA_Line* CXFA_Value::GetLine() const {
-  return static_cast<CXFA_Line*>(GetFirstChild());
+CXFA_Line* CXFA_Value::GetLineIfExists() const {
+  CXFA_Node* node = GetFirstChild();
+  ASSERT(!node || node->GetElementType() == XFA_Element::Line);
+  return static_cast<CXFA_Line*>(node);
 }
 
-CXFA_Rectangle* CXFA_Value::GetRectangle() const {
-  return static_cast<CXFA_Rectangle*>(GetFirstChild());
+CXFA_Rectangle* CXFA_Value::GetRectangleIfExists() const {
+  CXFA_Node* node = GetFirstChild();
+  ASSERT(!node || node->GetElementType() == XFA_Element::Rectangle);
+  return static_cast<CXFA_Rectangle*>(node);
 }
 
-CXFA_Text* CXFA_Value::GetText() const {
-  return static_cast<CXFA_Text*>(GetFirstChild());
+CXFA_Text* CXFA_Value::GetTextIfExists() const {
+  CXFA_Node* node = GetFirstChild();
+  ASSERT(!node || node->GetElementType() == XFA_Element::Text);
+  return static_cast<CXFA_Text*>(node);
 }
 
-CXFA_ExData* CXFA_Value::GetExData() const {
-  return static_cast<CXFA_ExData*>(GetFirstChild());
+CXFA_ExData* CXFA_Value::GetExDataIfExists() const {
+  CXFA_Node* node = GetFirstChild();
+  ASSERT(!node || node->GetElementType() == XFA_Element::ExData);
+  return static_cast<CXFA_ExData*>(node);
 }
 
-CXFA_Image* CXFA_Value::GetImage() const {
-  return static_cast<CXFA_Image*>(GetFirstChild());
+CXFA_Image* CXFA_Value::GetImageIfExists() const {
+  CXFA_Node* node = GetFirstChild();
+  ASSERT(!node || node->GetElementType() == XFA_Element::Image);
+  return static_cast<CXFA_Image*>(node);
 }
diff --git a/xfa/fxfa/parser/cxfa_value.h b/xfa/fxfa/parser/cxfa_value.h
index 5067b71..47aeefe 100644
--- a/xfa/fxfa/parser/cxfa_value.h
+++ b/xfa/fxfa/parser/cxfa_value.h
@@ -24,12 +24,12 @@
 
   XFA_Element GetChildValueClassID() const;
   WideString GetChildValueContent() const;
-  CXFA_Arc* GetArc() const;
-  CXFA_Line* GetLine() const;
-  CXFA_Rectangle* GetRectangle() const;
-  CXFA_Text* GetText() const;
-  CXFA_ExData* GetExData() const;
-  CXFA_Image* GetImage() const;
+  CXFA_Arc* GetArcIfExists() const;
+  CXFA_Line* GetLineIfExists() const;
+  CXFA_Rectangle* GetRectangleIfExists() const;
+  CXFA_Text* GetTextIfExists() const;
+  CXFA_ExData* GetExDataIfExists() const;
+  CXFA_Image* GetImageIfExists() const;
 };
 
 #endif  // XFA_FXFA_PARSER_CXFA_VALUE_H_
diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
index 3332d90..65746c5 100644
--- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
+++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
@@ -140,7 +140,7 @@
     WideString wsValue;
     switch (eUIType) {
       case XFA_Element::ImageEdit: {
-        CXFA_Image* image = defValue ? defValue->GetImage() : nullptr;
+        CXFA_Image* image = defValue ? defValue->GetImageIfExists() : nullptr;
         WideString wsContentType;
         WideString wsHref;
         if (image) {
@@ -293,7 +293,7 @@
     case XFA_Element::ImageEdit: {
       FormValueNode_SetChildContent(defValue, wsNormalizeValue,
                                     XFA_Element::Image);
-      CXFA_Image* image = defValue ? defValue->GetImage() : nullptr;
+      CXFA_Image* image = defValue ? defValue->GetImageIfExists() : nullptr;
       if (image) {
         CFX_XMLElement* pXMLDataElement =
             static_cast<CFX_XMLElement*>(pDataNode->GetXMLMappingNode());
@@ -329,7 +329,8 @@
 
             wsNormalizeValue += wsItem;
           }
-          CXFA_ExData* exData = defValue ? defValue->GetExData() : nullptr;
+          CXFA_ExData* exData =
+              defValue ? defValue->GetExDataIfExists() : nullptr;
           ASSERT(exData);
 
           exData->SetContentType(single ? L"text/plain" : L"text/xml");