summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-16 15:49:16 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-16 15:49:16 +0000
commit316dd2fcd64d0cda1e1b2cdc39ca541a57766b35 (patch)
treeaf3745a818839a7cebc92927f9e115c429bbbe0b /xfa/fxfa
parentd021ad2f6306ae9d7b2ab5acf225c3bd8e957f8f (diff)
downloadpdfium-316dd2fcd64d0cda1e1b2cdc39ca541a57766b35.tar.xz
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>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/cxfa_ffarc.cpp2
-rw-r--r--xfa/fxfa/cxfa_ffimage.cpp9
-rw-r--r--xfa/fxfa/cxfa_ffimageedit.cpp2
-rw-r--r--xfa/fxfa/cxfa_ffline.cpp30
-rw-r--r--xfa/fxfa/cxfa_ffrectangle.cpp2
-rw-r--r--xfa/fxfa/cxfa_widgetacc.cpp11
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_value.cpp40
-rw-r--r--xfa/fxfa/parser/cxfa_value.h12
-rw-r--r--xfa/fxfa/parser/xfa_document_datamerger_imp.cpp7
10 files changed, 70 insertions, 47 deletions
diff --git a/xfa/fxfa/cxfa_ffarc.cpp b/xfa/fxfa/cxfa_ffarc.cpp
index a738221b05..64a4f70a61 100644
--- a/xfa/fxfa/cxfa_ffarc.cpp
+++ b/xfa/fxfa/cxfa_ffarc.cpp
@@ -31,5 +31,5 @@ void CXFA_FFArc::RenderWidget(CXFA_Graphics* pGS,
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 3a5a63a1e4..b4a0d32981 100644
--- a/xfa/fxfa/cxfa_ffimage.cpp
+++ b/xfa/fxfa/cxfa_ffimage.cpp
@@ -70,8 +70,11 @@ void CXFA_FFImage::RenderWidget(CXFA_Graphics* pGS,
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 15a8dc3fd4..681370edf5 100644
--- a/xfa/fxfa/cxfa_ffimageedit.cpp
+++ b/xfa/fxfa/cxfa_ffimageedit.cpp
@@ -84,7 +84,7 @@ void CXFA_FFImageEdit::RenderWidget(CXFA_Graphics* pGS,
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 cdaca4a88f..4937a0e7cc 100644
--- a/xfa/fxfa/cxfa_ffline.cpp
+++ b/xfa/fxfa/cxfa_ffline.cpp
@@ -91,20 +91,23 @@ void CXFA_FFLine::RenderWidget(CXFA_Graphics* pGS,
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 @@ void CXFA_FFLine::RenderWidget(CXFA_Graphics* pGS,
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 b3dd6f45c6..46c1009844 100644
--- a/xfa/fxfa/cxfa_ffrectangle.cpp
+++ b/xfa/fxfa/cxfa_ffrectangle.cpp
@@ -31,5 +31,5 @@ void CXFA_FFRectangle::RenderWidget(CXFA_Graphics* pGS,
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 d61d8989fb..407517f564 100644
--- a/xfa/fxfa/cxfa_widgetacc.cpp
+++ b/xfa/fxfa/cxfa_widgetacc.cpp
@@ -99,7 +99,7 @@ class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData {
if (!value)
return false;
- CXFA_Image* image = value->GetImage();
+ CXFA_Image* image = value->GetImageIfExists();
if (!image)
return false;
@@ -156,7 +156,10 @@ class CXFA_ImageEditData : public CXFA_FieldLayoutData {
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 @@ void CXFA_WidgetAcc::ResetData() {
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 @@ void CXFA_WidgetAcc::SetImageEdit(const WideString& wsContentType,
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 a9c4a69dc6..7797be342b 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1940,7 +1940,7 @@ WideString CXFA_Node::GetValidateCaptionName(bool bVersionFlag) {
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 dc93bba25c..7a952f7df3 100644
--- a/xfa/fxfa/parser/cxfa_value.cpp
+++ b/xfa/fxfa/parser/cxfa_value.cpp
@@ -63,31 +63,41 @@ XFA_Element CXFA_Value::GetChildValueClassID() const {
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 5067b715db..47aeefede2 100644
--- a/xfa/fxfa/parser/cxfa_value.h
+++ b/xfa/fxfa/parser/cxfa_value.h
@@ -24,12 +24,12 @@ class CXFA_Value : public CXFA_Node {
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 3332d90b66..65746c5caf 100644
--- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
+++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
@@ -140,7 +140,7 @@ void CreateDataBinding(CXFA_Node* pFormNode,
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 @@ void CreateDataBinding(CXFA_Node* pFormNode,
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 @@ void CreateDataBinding(CXFA_Node* pFormNode,
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");