From 640d8ffad8536c789103892c7a4e69e5d30172c8 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 10 Jan 2018 16:28:57 +0000 Subject: Make methods which create nodes more obvious This CL converts the various methods Get methods which take a boolean value to explicit Get* and GetOrCreate* methods to make the usage clearer. Change-Id: I2af68448b1b69b95713e739bf7fe14a4336d2b65 Reviewed-on: https://pdfium-review.googlesource.com/22590 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_box.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'xfa/fxfa/parser/cxfa_box.cpp') diff --git a/xfa/fxfa/parser/cxfa_box.cpp b/xfa/fxfa/parser/cxfa_box.cpp index 3bc641bbcd..443362f449 100644 --- a/xfa/fxfa/parser/cxfa_box.cpp +++ b/xfa/fxfa/parser/cxfa_box.cpp @@ -82,8 +82,10 @@ int32_t CXFA_Box::CountEdges() { } CXFA_Edge* CXFA_Box::GetEdge(int32_t nIndex) { - return JSObject()->GetProperty(nIndex, XFA_Element::Edge, - nIndex == 0); + if (nIndex == 0) + return JSObject()->GetOrCreateProperty(nIndex, + XFA_Element::Edge); + return JSObject()->GetProperty(nIndex, XFA_Element::Edge); } std::vector CXFA_Box::GetStrokes() { @@ -102,8 +104,12 @@ Optional CXFA_Box::GetSweepAngle() { return JSObject()->TryInteger(XFA_Attribute::SweepAngle, false); } -CXFA_Fill* CXFA_Box::GetFill(bool bModified) { - return JSObject()->GetProperty(0, XFA_Element::Fill, bModified); +CXFA_Fill* CXFA_Box::GetFill() const { + return JSObject()->GetProperty(0, XFA_Element::Fill); +} + +CXFA_Fill* CXFA_Box::GetOrCreateFill() { + return JSObject()->GetOrCreateProperty(0, XFA_Element::Fill); } CXFA_Margin* CXFA_Box::GetMargin() { @@ -130,8 +136,14 @@ std::vector CXFA_Box::GetStrokesInternal(bool bNull) { strokes.resize(8); for (int32_t i = 0, j = 0; i < 4; i++) { - CXFA_Corner* corner = - JSObject()->GetProperty(i, XFA_Element::Corner, i == 0); + CXFA_Corner* corner; + if (i == 0) { + corner = + JSObject()->GetOrCreateProperty(i, XFA_Element::Corner); + } else { + corner = JSObject()->GetProperty(i, XFA_Element::Corner); + } + if (corner || i == 0) { strokes[j] = corner; } else if (!bNull) { @@ -142,8 +154,12 @@ std::vector CXFA_Box::GetStrokesInternal(bool bNull) { } j++; - CXFA_Edge* edge = - JSObject()->GetProperty(i, XFA_Element::Edge, i == 0); + CXFA_Edge* edge; + if (i == 0) + edge = JSObject()->GetOrCreateProperty(i, XFA_Element::Edge); + else + edge = JSObject()->GetProperty(i, XFA_Element::Edge); + if (edge || i == 0) { strokes[j] = edge; } else if (!bNull) { -- cgit v1.2.3